1 // trace user malloc pool - trace malloc, realloc, and free calls
2 // if trumpsbrk is set, we trace sbrkalloc and sbrkmerge too.
13 if (notes[0]!="sys: breakpoint") then
15 print(pid,": ",reason(*TRAP),"\t");
16 print(fmt(pc,97),"\t",fmt(pc,105),"\n");
17 print("Notes pending:\n");
21 print("\t",head l,"\n");
30 local frame, stk, pcs, lst, x;
33 stk = strace(*PC,*SP,0);
35 pcs = append pcs, stk[0][1];
42 if trumphexaddrs != 0 then
46 print(" src(", x, ");");
57 sbrkallocPC = sbrkalloc;
58 sbrkmergePC = sbrkmerge;
60 // linker might fill delay slot with first instruction
61 if objtype == "mips" then {
62 mallocPC = mallocPC+4;
63 malloczPC = malloczPC+4;
65 reallocPC = reallocPC+4;
66 sbrkallocPC = sbrkallocPC+4;
67 sbrkmergePC = sbrkmergePC+4;
92 stop(pid); // already stopped, but flushes output
98 bpset(follow(main)[0]);
101 // clear the hang bit, which is left set by newproc, so programs we fork/exec don't hang
102 printto("/proc/"+itoa(pid)+"/ctl", "nohang");
106 local arg0, arg1, stk, retpc, params;
108 stk = strace(*PC, *SP, 0);
113 if tail params != {} then
115 return {arg0, arg1, retpc};
119 if objtype=="386" then
121 if objtype=="mips" then
123 if objtype=="power" || objtype=="alpha" then
128 local arg0, arg1, pc, ret, x;
133 while !_stoprunning do {
135 if notes[0]!="sys: breakpoint" then {
143 if pc == reallocPC || pc == sbrkmergePC then
149 if pc == mallocPC then
150 print(ret\X, " malloc ", arg0\D);
151 if pc == malloczPC then
152 print(ret\X, " mallocz ", arg0\D);
154 print(arg0\X, " free");
155 if pc == reallocPC then
156 print(ret\X, " realloc ", arg0\X, " ", arg1\D);
157 if pc == sbrkallocPC then
158 print(ret\X, " sbrkalloc ", arg0\D);
159 if pc == sbrkmergePC then
160 print("sbrkmerge ", arg0\X, " ", arg1\X, " = ", ret\D);