📄 diag.c
字号:
int__mp_remalloc(char *s, unsigned long n){ if (remove(allocfile(s, n))) return 0; return 1;}/* Display up to sixteen bytes of memory in one line. */staticvoidprintline(char *s, size_t l){ size_t i; __mp_diag("\t" MP_POINTER " ", s); for (i = 0; i < 16; i++) { if (i < l) __mp_diag("%02X", (unsigned char) s[i]); else __mp_diag(" "); if (i % 4 == 3) __mp_diag(" "); } __mp_diag(" "); for (i = 0; i < l; i++) if (isprint(s[i])) __mp_diag("%c", s[i]); else __mp_diag("."); __mp_diag("\n");}/* Display a hex dump of a specified memory location and length. */MP_GLOBALvoid__mp_printmemory(void *p, size_t l){ while (l >= 16) { printline((char *) p, 16); p = (char *) p + 16; l -= 16; } if (l > 0) printline((char *) p, l);}/* Display a size in bytes. */MP_GLOBALvoid__mp_printsize(size_t l){ __mp_diag("%lu byte", l); if (l != 1) __mp_diag("s");}/* Display the type of memory allocation along with the allocation count * and reallocation count. */MP_GLOBALvoid__mp_printtype(infonode *n){ __mp_diag("{%s:%lu:%lu}", __mp_functionnames[n->data.type], n->data.alloc, n->data.realloc);}/* Display the function name, file name and line number where a memory * allocation took place. Also display the thread identifier if the thread * safe library is being used. */MP_GLOBALvoid__mp_printloc(infonode *n){ __mp_diag("[");#if MP_THREADS_SUPPORT __mp_diag("%lu|", n->data.thread);#endif /* MP_THREADS_SUPPORT */ if (n->data.func) __mp_diag("%s", n->data.func); else __mp_diag("-"); __mp_diag("|"); if (n->data.file) __mp_diag("%s", n->data.file); else __mp_diag("-"); __mp_diag("|"); if (n->data.line) __mp_diag("%lu", n->data.line); else __mp_diag("-"); __mp_diag("]");}/* Display the type of data that is stored in the memory allocation along * with the number of objects stored. */MP_GLOBALvoid__mp_printtypeinfo(infonode *n, size_t s){ __mp_diag("(%s", n->data.typestr); if ((s /= n->data.typesize) > 1) __mp_diag(" x %lu", s); __mp_diag(")");}/* Display the name of a symbol associated with a particular address. */MP_GLOBALvoid__mp_printsymbol(symhead *y, void *a){ symnode *n; char *s, *t; unsigned long u; __mp_findsource(y, (char *) a - 1, &s, &t, &u); if (n = __mp_findsymbol(y, a)) { if (__mp_diagflags & FLG_HTML) __mp_diagtag("<TT>"); __mp_diag("%s", n->data.name); if (__mp_diagflags & FLG_HTML) __mp_diagtag("</TT>"); if (a != n->data.addr) __mp_diag("%+ld", (char *) a - (char *) n->data.addr); } else if (s != NULL) { if (__mp_diagflags & FLG_HTML) __mp_diagtag("<TT>"); __mp_diag("%s", s); if (__mp_diagflags & FLG_HTML) __mp_diagtag("</TT>"); } else __mp_diag("???"); if ((t != NULL) && (u != 0)) { __mp_diag(" at "); if (__mp_diagflags & FLG_HTML) __mp_diagtag("<TT>"); __mp_diag("%s", t); if (__mp_diagflags & FLG_HTML) __mp_diagtag("</TT>"); __mp_diag(":%lu", u); }}/* Display details of all of the symbols that have been read. */MP_GLOBALvoid__mp_printsymbols(symhead *y){ symnode *n; if (__mp_diagflags & FLG_HTML) __mp_diagtag("<HR>"); __mp_diag("\nsymbols read: %lu\n", y->dtree.size); if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<BLOCKQUOTE>\n"); __mp_diagtag("<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0>\n"); } for (n = (symnode *) __mp_minimum(y->dtree.root); n != NULL; n = (symnode *) __mp_successor(&n->data.node)) { if (__mp_diagflags & FLG_HTML) __mp_diagtag("<TR>\n"); if (n->data.size == 0) if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<TD>"); __mp_diagtag("</TD>\n"); __mp_diagtag("<TD>"); __mp_diag(MP_POINTER, n->data.addr); __mp_diagtag("</TD>\n"); } else {#if ENVIRON == ENVIRON_64 __mp_diag("\t");#endif /* ENVIRON */ __mp_diag("\t " MP_POINTER, n->data.addr); } else if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<TD ALIGN=RIGHT>"); __mp_diag(MP_POINTER "-", n->data.addr); __mp_diagtag("</TD>\n"); __mp_diagtag("<TD>"); __mp_diag(MP_POINTER, (char *) n->data.addr + n->data.size - 1); __mp_diagtag("</TD>\n"); } else __mp_diag(" " MP_POINTER "-" MP_POINTER, n->data.addr, (char *) n->data.addr + n->data.size - 1); if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<TD>"); __mp_diagtag("<TT>"); } else __mp_diag(" "); __mp_diag("%s", n->data.name); if (__mp_diagflags & FLG_HTML) __mp_diagtag("</TT>"); __mp_diag(" ["); if (__mp_diagflags & FLG_HTML) __mp_diagtag("<TT>"); __mp_diag("%s", n->data.file); if (__mp_diagflags & FLG_HTML) __mp_diagtag("</TT>"); __mp_diag("] ("); __mp_printsize(n->data.size); __mp_diag(")"); if (__mp_diagflags & FLG_HTML) { __mp_diagtag("</TT>"); __mp_diagtag("</TD>\n"); __mp_diagtag("</TR>"); } __mp_diag("\n"); } if (__mp_diagflags & FLG_HTML) { __mp_diagtag("</TABLE>\n"); __mp_diagtag("</BLOCKQUOTE>\n"); }}/* Display the call stack details for an address node. */MP_GLOBALvoid__mp_printaddrs(symhead *y, addrnode *n){ if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<BLOCKQUOTE>\n"); __mp_diagtag("<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0>\n"); } while (n != NULL) { if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<TR>\n"); __mp_diagtag("<TD>"); __mp_diag(MP_POINTER, n->data.addr); __mp_diagtag("</TD>\n"); __mp_diagtag("<TD>"); } else __mp_diag("\t" MP_POINTER " ", n->data.addr); __mp_printsymbol(y, n->data.addr); if (__mp_diagflags & FLG_HTML) { __mp_diagtag("</TD>\n"); __mp_diagtag("</TR>"); } __mp_diag("\n"); n = n->data.next; } if (__mp_diagflags & FLG_HTML) { __mp_diagtag("</TABLE>\n"); __mp_diagtag("</BLOCKQUOTE>\n"); }}/* Display the call stack details for a call stack handle. */MP_GLOBALvoid__mp_printstack(symhead *y, stackinfo *p){ stackinfo s; s = *p; if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<BLOCKQUOTE>\n"); __mp_diagtag("<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0>\n"); } if ((p->frame != NULL) && (p->addr != NULL)) { if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<TR>\n"); __mp_diagtag("<TD>"); __mp_diag(MP_POINTER, p->addr); __mp_diagtag("</TD>\n"); __mp_diagtag("<TD>"); } else __mp_diag("\t" MP_POINTER " ", p->addr); __mp_printsymbol(y, p->addr); if (__mp_diagflags & FLG_HTML) { __mp_diagtag("</TD>\n"); __mp_diagtag("</TR>"); } __mp_diag("\n"); while (__mp_getframe(p) && (p->addr != NULL)) { if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<TR>\n"); __mp_diagtag("<TD>"); __mp_diag(MP_POINTER, p->addr); __mp_diagtag("</TD>\n"); __mp_diagtag("<TD>"); } else __mp_diag("\t" MP_POINTER " ", p->addr); __mp_printsymbol(y, p->addr); if (__mp_diagflags & FLG_HTML) { __mp_diagtag("</TD>\n"); __mp_diagtag("</TR>"); } __mp_diag("\n"); } } if (__mp_diagflags & FLG_HTML) { __mp_diagtag("</TABLE>\n"); __mp_diagtag("</BLOCKQUOTE>\n"); } *p = s;}/* Display the details of an individual allocation node. */MP_GLOBALvoid__mp_printalloc(symhead *y, allocnode *n){ infonode *m; m = (infonode *) n->info; __mp_diag(" " MP_POINTER " (", n->block); __mp_printsize(n->size); __mp_diag(") "); __mp_printtype(m); __mp_diag(" "); __mp_printloc(m); if ((m->data.typestr != NULL) && (m->data.typesize != 0)) { __mp_diag(" "); __mp_printtypeinfo(m, n->size); } __mp_diag("\n"); __mp_printaddrs(y, m->data.stack);}/* Log the details of where a function call came from. */staticvoidlogcall(infohead *h, loginfo *i, size_t s){ __mp_diag("[");#if MP_THREADS_SUPPORT __mp_diag("%lu|", __mp_threadid());#endif /* MP_THREADS_SUPPORT */ __mp_diag("%s|%s|", (i->func ? i->func : "-"), (i->file ? i->file : "-")); if (i->line == 0) __mp_diag("-"); else __mp_diag("%lu", i->line); __mp_diag("]"); if ((i->typestr != NULL) && (i->typesize != 0)) { __mp_diag(" (%s", i->typestr); if ((s /= i->typesize) > 1) __mp_diag(" x %lu", s); __mp_diag(")"); } __mp_diag("\n"); __mp_printstack(&h->syms, i->stack); __mp_diag("\n");}/* Log the details of a call to the mpatrol library. */MP_GLOBALvoid__mp_log(infohead *h, loginfo *i){ if ((h->recur == 1) && !i->logged) { i->logged = 1; if (__mp_diagflags & FLG_HTML) { __mp_diagtag("<P>\n"); __mp_diagtag("<B>"); } __mp_diag("%s", __mp_lognames[i->ltype]); if (__mp_diagflags & FLG_HTML) __mp_diagtag("</B>"); __mp_diag(": "); if (__mp_diagflags & FLG_HTML) __mp_diagtag("<TT>"); __mp_diag("%s", __mp_functionnames[i->type]); if (__mp_diagflags & FLG_HTML) __mp_diagtag("</TT>"); switch (i->ltype) { case LT_ALLOC: __mp_diag(" (%lu, ", h->count); __mp_printsize(i->variant.logalloc.size); __mp_diag(", "); if (i->variant.logalloc.align == 0) __mp_printsize(h->alloc.heap.memory.align); else __mp_printsize(i->variant.logalloc.align); __mp_diag(") "); logcall(h, i, i->variant.logalloc.size); break; case LT_REALLOC: __mp_diag(" (" MP_POINTER ", ", i->variant.logrealloc.block); __mp_printsize(i->variant.logrealloc.size); __mp_diag(", "); if (i->variant.logrealloc.align == 0) __mp_printsize(h->alloc.heap.memory.align); else __mp_printsize(i->variant.logrealloc.align); __mp_diag(") "); logcall(h, i, i->variant.logrealloc.size); break; case LT_FREE:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -