void colon(char *addr, char *cp) { int argc; char *argv[100]; char tbuf[512]; cp = nextc(cp); switch(*cp) { default: Bprint(bioout, "?\n"); return; case 'b': breakpoint(addr, cp+1); return; case 'd': delbpt(addr); return; /* These fall through to print the stopped address */ case 'r': reset(); argc = buildargv(cp+1, argv, 100); initstk(argc, argv); count = 0; atbpt = 0; run(); break; case 'c': count = 0; atbpt = 0; run(); break; case 's': cp = nextc(cp+1); count = 0; if(*cp) count = strtoul(cp, 0, 0); if(count == 0) count = 1; atbpt = 0; run(); break; } dot = reg.pc; Bprint(bioout, "%s at #%lux ", atbpt ? "breakpoint" : "stopped", dot); symoff(tbuf, sizeof(tbuf), dot, CTEXT); Bprint(bioout, tbuf); if(fmt == 'z') printsource(dot); Bprint(bioout, "\n"); }
void iprofile(void) { Prof *p, *n; int i, b, e; ulong total; extern ulong textbase; i = 0; p = prof; if(textsym(&p->s, i) == 0) return; i++; for(;;) { n = p+1; if(textsym(&n->s, i) == 0) break; b = (p->s.value-textbase)/PROFGRAN; e = (n->s.value-textbase)/PROFGRAN; while(b < e) p->count += iprof[b++]; i++; p = n; } qsort(prof, i, sizeof(Prof), profcmp); total = 0; for(b = 0; b < i; b++) total += prof[b].count; Bprint(bioout, " cycles %% symbol file\n"); for(b = 0; b < i; b++) { if(prof[b].count == 0) continue; Bprint(bioout, "%8ld %3ld.%ld %-15s ", prof[b].count, 100*prof[b].count/total, (1000*prof[b].count/total)%10, prof[b].s.name); printsource(prof[b].s.value); Bputc(bioout, '\n'); } memset(prof, 0, sizeof(Prof)*i); }
int pfmt(char fmt, int mem, uint32_t val) { int c, i; Symbol s; char *p, ch, str[1024]; c = 0; switch(fmt) { default: Bprint(bioout, "bad modifier\n"); return 0; case 'o': c = Bprint(bioout, "%-4lo ", mem ? (uint16_t)getmem_2(dot) : val); inc = 2; break; case 'O': c = Bprint(bioout, "%-8lo ", mem ? getmem_4(dot) : val); inc = 4; break; case 'q': c = Bprint(bioout, "%-4lo ", mem ? (int16_t)getmem_2(dot) : val); inc = 2; break; case 'Q': c = Bprint(bioout, "%-8lo ", mem ? (int32_t)getmem_4(dot) : val); inc = 4; break; case 'd': c = Bprint(bioout, "%-5ld ", mem ? (int16_t)getmem_2(dot) : val); inc = 2; break; case 'D': c = Bprint(bioout, "%-8ld ", mem ? (int32_t)getmem_4(dot) : val); inc = 4; break; case 'x': c = Bprint(bioout, "#%-4lux ", mem ? (int32_t)getmem_2(dot) : val); inc = 2; break; case 'X': c = Bprint(bioout, "#%-8lux ", mem ? (int32_t)getmem_4(dot) : val); inc = 4; break; case 'u': c = Bprint(bioout, "%-5ld ", mem ? (uint16_t)getmem_2(dot) : val); inc = 2; break; case 'U': c = Bprint(bioout, "%-8ld ", mem ? (uint32_t)getmem_4(dot) : val); inc = 4; break; case 'b': c = Bprint(bioout, "%-3d ", (int)(mem ? getmem_b(dot) : val)); inc = 1; break; case 'c': c = Bprint(bioout, "%c ", (int)(mem ? getmem_b(dot) : val)); inc = 1; break; case 'C': ch = mem ? getmem_b(dot) : val; if(isprint(ch)) c = Bprint(bioout, "%c ", ch); else c = Bprint(bioout, "\\x%.2x ", ch); inc = 1; break; case 's': i = 0; while(ch = getmem_b(dot+i)) str[i++] = ch; str[i] = '\0'; dot += i; c = Bprint(bioout, "%s", str); inc = 0; break; case 'S': i = 0; while(ch = getmem_b(dot+i)) str[i++] = ch; str[i] = '\0'; dot += i; for(p = str; *p; p++) if(isprint(*p)) c += Bprint(bioout, "%c", *p); else c += Bprint(bioout, "\\x%.2ux", *p); inc = 0; break; case 'Y': p = ctime(mem ? getmem_b(dot) : val); p[30] = '\0'; c = Bprint(bioout, "%s", p); inc = 4; break; case 'a': symoff(str, sizeof(str), dot, CTEXT); Bprint(bioout, "%s", str); inc = 0; break; case 'e': for (i = 0; globalsym(&s, i); i++) Bprint(bioout, "%-15s #%lux\n", s.name, getmem_4(s.value)); inc = 0; break; case 'I': case 'i': inc = machdata->das(symmap, dot, fmt, str, sizeof(str)); if (inc < 0) { Bprint(bioout, "ki: %r\n"); return 0; } c = Bprint(bioout, "\t%s", str); break; case 'n': c = width+1; inc = 0; break; case '-': c = 0; inc = -1; break; case '+': c = 0; inc = 1; break; case '^': c = 0; if(inc > 0) inc = -inc; break; case 'z': if (findsym(dot, CTEXT, &s)) Bprint(bioout, " %s() ", s.name); printsource(dot); inc = 0; break; } return c; }
/* Read an event from the tracing output file. */ #if MP_GUI_SUPPORT static int readevent(XtPointer p) #else /* MP_GUI_SUPPORT */ static int readevent(void) #endif /* MP_GUI_SUPPORT */ { char s[4]; allocation *f; char *g, *h; void *a; size_t i, l, m; unsigned long n, t, u; if (refill(1)) switch (*bufferpos) { case 'A': bufferpos++; bufferlen--; currentevent++; n = getuleb128(); a = (void *) getuleb128(); l = getuleb128(); getsource(&t, &g, &h, &u); f = newalloc(n, currentevent, a, l); stats.acount++; stats.atotal += l; if (stats.pcount < stats.acount - stats.fcount) stats.pcount = stats.acount - stats.fcount; if (stats.ptotal < stats.atotal - stats.ftotal) stats.ptotal = stats.atotal - stats.ftotal; if ((stats.lsize == 0) || (stats.lsize > l)) stats.lsize = l; if (stats.usize < l) stats.usize = l; if (verbose) { fprintf(stdout, "%6lu alloc %6lu " MP_POINTER " %8lu" " %6lu %8lu\n", currentevent, n, a, l, stats.acount - stats.fcount, stats.atotal - stats.ftotal); if (displaysource) printsource(t, g, h, u); } if (hatffile != NULL) fprintf(hatffile, "1 %lu 0x%lx\n", l, a); if (f->entry != NULL) { if ((m = slotentry(f)) > maxslots) maxslots = m; fprintf(simfile, " {%lu, %lu, 0},\n", m, l); } #if MP_GUI_SUPPORT if (usegui) { if (addrbase == NULL) addrbase = (void *) __mp_rounddown((unsigned long) a, 1024); drawmemory(a, l, algc); return 0; } #endif /* MP_GUI_SUPPORT */ return 1; case 'R': bufferpos++; bufferlen--; currentevent++; n = getuleb128(); a = (void *) getuleb128(); l = getuleb128(); getsource(&t, &g, &h, &u); if (f = (allocation *) __mp_search(alloctree.root, n)) { if (f->time != 0) fprintf(stderr, "%s: Allocation index `%lu' has already " "been freed\n", progname, n); stats.acount++; stats.atotal += l; stats.fcount++; stats.ftotal += f->size; if (stats.pcount < stats.acount - stats.fcount) stats.pcount = stats.acount - stats.fcount; if (stats.ptotal < stats.atotal - stats.ftotal) stats.ptotal = stats.atotal - stats.ftotal; if ((stats.lsize == 0) || (stats.lsize > l)) stats.lsize = l; if (stats.usize < l) stats.usize = l; if (verbose) { fprintf(stdout, "%6lu realloc %6lu " MP_POINTER " %8lu %6lu %8lu\n", currentevent, n, a, l, stats.acount - stats.fcount, stats.atotal - stats.ftotal); if (displaysource) printsource(t, g, h, u); } if (hatffile != NULL) fprintf(hatffile, "4 %lu 0x%lx 0x%lx\n", l, f->addr, a); if (f->entry != NULL) { m = slotentry(f); fprintf(simfile, " {%lu, %lu, 1},\n", m, l); } #if MP_GUI_SUPPORT if (usegui) { drawmemory(f->addr, f->size, frgc); drawmemory(a, l, algc); } #endif /* MP_GUI_SUPPORT */ f->addr = a; f->size = l; } else fprintf(stderr, "%s: Unknown allocation index `%lu'\n", progname, n); #if MP_GUI_SUPPORT if (usegui) return 0; #endif /* MP_GUI_SUPPORT */ return 1; case 'F': bufferpos++; bufferlen--; currentevent++; n = getuleb128(); getsource(&t, &g, &h, &u); if (f = (allocation *) __mp_search(alloctree.root, n)) { if (f->time != 0) fprintf(stderr, "%s: Allocation index `%lu' has already " "been freed\n", progname, n); f->time = currentevent - f->event; stats.fcount++; stats.ftotal += f->size; if (verbose) { fprintf(stdout, "%6lu free %6lu " MP_POINTER " %8lu " "%6lu %6lu %8lu\n", currentevent, n, f->addr, f->size, f->time, stats.acount - stats.fcount, stats.atotal - stats.ftotal); if (displaysource) printsource(t, g, h, u); } if (hatffile != NULL) fprintf(hatffile, "2 0x%lx\n", f->addr); if (f->entry != NULL) { fprintf(simfile, " {%lu, 0, 0},\n", slotentry(f)); __mp_freeslot(&table, f->entry); f->entry = NULL; } #if MP_GUI_SUPPORT if (usegui) drawmemory(f->addr, f->size, frgc); #endif /* MP_GUI_SUPPORT */ } else fprintf(stderr, "%s: Unknown allocation index `%lu'\n", progname, n); #if MP_GUI_SUPPORT if (usegui) return 0; #endif /* MP_GUI_SUPPORT */ return 1; case 'H': bufferpos++; bufferlen--; a = (void *) getuleb128(); l = getuleb128(); if (verbose) fprintf(stdout, " reserve " MP_POINTER " %8lu\n", a, l); stats.rcount++; stats.rtotal += l; #if MP_GUI_SUPPORT if (usegui) { if (addrbase == NULL) addrbase = (void *) __mp_rounddown((unsigned long) a, 1024); drawmemory(a, l, frgc); return 0; } #endif /* MP_GUI_SUPPORT */ return 1; case 'I': bufferpos++; bufferlen--; a = (void *) getuleb128(); l = getuleb128(); if (verbose) fprintf(stdout, " internal " MP_POINTER " %8lu\n", a, l); stats.icount++; stats.itotal += l; #if MP_GUI_SUPPORT if (usegui) { drawmemory(a, l, ingc); return 0; } #endif /* MP_GUI_SUPPORT */ return 1; default: break; } if ((hatffile != NULL) && (hatffile != stdout) && (hatffile != stderr)) fclose(hatffile); if (simfile != NULL) { fputs(" {0, 0, 0}\n};\n\n\n", simfile); fputs("int main(void)\n{\n", simfile); fprintf(simfile, " void *p[%lu];\n", maxslots); fputs(" event *e;\n\n", simfile); fputs(" for (e = events; e->index != 0; e++)\n", simfile); fputs(" if (e->resize)\n", simfile); fputs(" {\n", simfile); fputs(" if ((p[e->index - 1] = realloc(p[e->index - 1], " "e->size)) == NULL)\n", simfile); fputs(" {\n", simfile); fputs(" fputs(\"out of memory\\n\", stderr);\n", simfile); fputs(" exit(EXIT_FAILURE);\n", simfile); fputs(" }\n", simfile); fputs(" }\n", simfile); fputs(" else if (e->size == 0)\n", simfile); fputs(" free(p[e->index - 1]);\n", simfile); fputs(" else if ((p[e->index - 1] = malloc(e->size)) == NULL)\n", simfile); fputs(" {\n", simfile); fputs(" fputs(\"out of memory\\n\", stderr);\n", simfile); fputs(" exit(EXIT_FAILURE);\n", simfile); fputs(" }\n", simfile); fputs(" return EXIT_SUCCESS;\n}\n", simfile); if ((simfile != stdout) && (simfile != stderr)) fclose(simfile); } getentry(s, sizeof(char), 4, 0); if (memcmp(s, MP_TRACEMAGIC, 4) != 0) { fprintf(stderr, "%s: Invalid file format\n", progname); exit(EXIT_FAILURE); } if (verbose) fputc('\n', stdout); showstats(); for (i = 0; i < MP_NAMECACHE_SIZE; i++) { if (funcnames[i] != NULL) free(funcnames[i]); if (filenames[i] != NULL) free(filenames[i]); } freeallocs(); fclose(tracefile); #if MP_GUI_SUPPORT if (usegui) return 1; #endif /* MP_GUI_SUPPORT */ return 0; }