libmach
This commit is contained in:
parent
0e3cc9f456
commit
a84cbb2a17
53 changed files with 12038 additions and 0 deletions
56
src/libmach/localaddr.c
Normal file
56
src/libmach/localaddr.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <bio.h>
|
||||
#include <mach.h>
|
||||
|
||||
/*
|
||||
* XXX could remove the rock by hiding it in a special regs.
|
||||
* That would still be sleazy but would be thread-safe.
|
||||
*/
|
||||
|
||||
static struct {
|
||||
int found;
|
||||
int nframe;
|
||||
Loc l;
|
||||
char *fn;
|
||||
char *var;
|
||||
} rock;
|
||||
|
||||
static int
|
||||
ltrace(Map *map, Regs *regs, ulong pc, ulong nextpc, Symbol *sym, int depth)
|
||||
{
|
||||
ulong v;
|
||||
Symbol s1;
|
||||
|
||||
USED(pc);
|
||||
USED(nextpc);
|
||||
USED(depth);
|
||||
|
||||
if(sym==nil || strcmp(sym->name, rock.fn) != 0)
|
||||
return ++rock.nframe < 40;
|
||||
if(lookuplsym(sym, rock.var, &s1) < 0)
|
||||
return 0;
|
||||
if(locsimplify(map, regs, s1.loc, &rock.l) < 0)
|
||||
return 0;
|
||||
if(rock.l.type == LREG && rget(regs, rock.l.reg, &v) >= 0)
|
||||
rock.l = locconst(v);
|
||||
if(rock.l.type != LADDR && rock.l.type != LCONST)
|
||||
return 0;
|
||||
rock.found = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
localaddr(Map *map, Regs *regs, char *fn, char *var, ulong *val)
|
||||
{
|
||||
rock.found = 0;
|
||||
rock.nframe = 0;
|
||||
rock.fn = fn;
|
||||
rock.var = var;
|
||||
stacktrace(map, regs, ltrace);
|
||||
if(rock.found){
|
||||
*val = rock.l.addr;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue