13 .ta \w'\fBxxxxxx'u +\w'\fBxxxxxx'u
14 int stacktrace(Map *map, Rgetter rget, Tracer trace)
17 int localvar(Map *map, char *fn, char *val, Loc *loc)
20 provides machine-independent
21 implementations of process stack traces.
22 They must retrieve data and register contents from an executing
23 image. Sometimes the desired registers are not the current
24 registers but rather a set of saved registers stored elsewhere
26 The caller may specify an initial register set in the form of an
31 .B "ulong rget(Map *map, char *name)
34 It returns the contents of a register when given a map
36 It is usually sufficient for the register function
37 to return meaningful values only for
41 and for the link register
46 Given the map and the rgetter,
48 unwinds the stack starting at the innermost function.
49 At each level in the trace, it calls the tracer function, which has the form
52 .B "int trace(Map *map, ulong pc, ulong callerpc,
54 .B " Rgetter rget, Symbol *s)
57 The tracer is passed the map, the current program counter,
58 the program counter of the caller (zero if the caller is unknown),
61 function, and a symbol
64 describing the current function
65 (nil if no symbol is known).
66 The value returned by the tracer
67 controls whether the stack trace continues:
68 a zero or negative return value stops the trace,
69 while a positive return value continues it.
71 The rgetter passed to the tracer is not the rgetter
75 Instead, it is a function returning the register values
76 at the time of the call, to the extent that they can be
78 The most common use for this rgetter
81 etc., when evaluating the locations of local variables.
86 to walk up the stack looking for the innermost instance of a function named
88 once it finds the function,
89 it looks for the parameter or local variable
91 storing the location of the variable in
94 The following code writes a simple stack trace to standard output,
95 stopping after at most 20 stack frames.
99 .ta \w'xxxx'u +\w'xxxx'u +\w'xxxx'u +\w'xxxx'u +\w'xxxx'u
101 trace(Map *map, ulong pc, ulong callerpc,
102 Rgetter rget, Symbol *s, int depth)
110 print("%s+%lx", s->name, pc - loceval(s->loc));
115 for(i=0; indexlsym(s, &i, &s2)>=0; i++){
116 if(s.class != CPARAM)
120 if(lget4(map, rget, s->loc, &v) >= 0)
121 print("%s=%#lux", s->name, (ulong)v);
123 print("%s=???", s->name);
125 print(") called from ");
126 symoff(buf, sizeof buf, callerpc, CTEXT);
131 if(stacktrace(map, nil, trace) <= 0)
132 print("no stack frame\n");
135 .B /usr/local/plan9/src/libmach