Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <mach.h>
6 /*
7 * XXX could remove the rock by hiding it in a special regs.
8 * That would still be sleazy but would be thread-safe.
9 */
11 static struct {
12 int found;
13 int nframe;
14 Loc l;
15 char *fn;
16 char *var;
17 } rock;
19 static int
20 ltrace(Map *map, Regs *regs, ulong pc, ulong nextpc, Symbol *sym, int depth)
21 {
22 ulong v;
23 Symbol s1;
25 USED(pc);
26 USED(nextpc);
27 USED(depth);
29 if(sym==nil || strcmp(sym->name, rock.fn) != 0)
30 return ++rock.nframe < 40;
31 if(lookuplsym(sym, rock.var, &s1) < 0)
32 return 0;
33 if(locsimplify(map, regs, s1.loc, &rock.l) < 0)
34 return 0;
35 if(rock.l.type == LREG && rget(regs, rock.l.reg, &v) >= 0)
36 rock.l = locconst(v);
37 if(rock.l.type != LADDR && rock.l.type != LCONST)
38 return 0;
39 rock.found = 1;
40 return 0;
41 }
43 int
44 localaddr(Map *map, Regs *regs, char *fn, char *var, ulong *val)
45 {
46 rock.found = 0;
47 rock.nframe = 0;
48 rock.fn = fn;
49 rock.var = var;
50 stacktrace(map, regs, ltrace);
51 if(rock.found){
52 *val = rock.l.addr;
53 return 0;
54 }
55 return -1;
56 }