This change supports "always on" tracing, in the sense that every function entry/exit will have the ability to turn on tracing for that functions entry, and/or some or all exits. When 8l is invoked with the -pt switch, entry code looks like this: entry: jmp .+5 call _tracein To enable tracing, path the +5 to +2 Exits look like this: ret call _traceout ret To enable exit tracing, patch the 1-byte ret to a nop. Patching can be done at runtime or statically before boot. If this patch is accepted, the next step is to submit the support code for the kernel to allow it to be enabled at runtime. But, it will be also quite easy to have acid do the needed patching before boot as well. Ron Reference: /n/sources/patch/applied/embedded_trace Date: Sat Oct 31 01:16:00 CET 2009 Signed-off-by: rminnich@gmail.com --- /sys/src/cmd/8l/obj.c Sat Oct 31 01:13:21 2009 +++ /sys/src/cmd/8l/obj.c Sat Oct 31 01:13:19 2009 @@ -1231,16 +1231,24 @@ doprof2(void) { Sym *s2, *s4; - Prog *p, *q, *ps2, *ps4; + Prog *p, *q, *q2, *ps2, *ps4; if(debug['v']) Bprint(&bso, "%5.2f profile 2\n", cputime()); Bflush(&bso); - s2 = lookup("_profin", 0); - s4 = lookup("_profout", 0); + if(debug['t']){ + s2 = lookup("_tracein", 0); + s4 = lookup("_traceout", 0); + }else{ + s2 = lookup("_profin", 0); + s4 = lookup("_profout", 0); + } if(s2->type != STEXT || s4->type != STEXT) { - diag("_profin/_profout not defined"); + if(debug['t']) + diag("_tracein/_traceout not defined %d %d", s2->type, s4->type); + else + diag("_profin/_profout not defined"); return; } @@ -1281,7 +1289,20 @@ q->line = p->line; q->pc = p->pc; q->link = p->link; - p->link = q; + if(debug['t']){ + q2 = prg(); + p->link = q2; + q2->link = q; + + q2->line = p->line; + q2->pc = p->pc; + + q2->as = AJMP; + q2->to.type = D_BRANCH; + q2->to.sym = p->to.sym; + q2->pcond = q->link; + }else + p->link = q; p = q; p->as = ACALL; p->to.type = D_BRANCH; @@ -1292,6 +1313,17 @@ } if(p->as == ARET) { /* + * RET (default) + */ + if(debug['t']){ + q = prg(); + q->line = p->line; + q->pc = p->pc; + q->link = p->link; + p->link = q; + p = q; + } + /* * RET */ q = prg(); @@ -1498,4 +1530,4 @@ } } Bterm(b); -} +}