📄 inter.c
字号:
if (__mp_processid() != memhead.pid) __mp_reinit(); if (n = __mp_findsymbol(&memhead.syms, p)) t = n->data.name; else if (__mp_findsource(&memhead.syms, p, &s, &t, &u) && (s != NULL)) { if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectstrtab(&memhead.syms.strings, MA_READWRITE); t = __mp_addstring(&memhead.syms.strings, s); if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectstrtab(&memhead.syms.strings, MA_READONLY); } else t = NULL; restoresignals(); return t;}/* Display any details about the memory block that contains a given address. * This is for calling within a symbolic debugger and will result in output to * the standard error file stream instead of the log file. */MP_APIint__mp_printinfo(void *p){ addrnode *a; symnode *s; allocnode *n; infonode *m; savesignals(); if (memhead.init && (__mp_processid() != memhead.pid)) __mp_reinit(); /* Check that we know something about the address that was supplied. */ n = NULL; if (!memhead.init || memhead.fini || ((n = __mp_findnode(&memhead.alloc, p, 1)) == NULL) || ((m = (infonode *) n->info) == NULL)) { fprintf(stderr, "address " MP_POINTER, p); if (n == NULL) fputs(" not in heap\n", stderr); else { fputs(" located in free memory:\n", stderr); fprintf(stderr, " start of block: " MP_POINTER "\n", n->block); fprintf(stderr, " size of block: %lu byte%s\n", n->size, (n->size == 1) ? "" : "s"); } restoresignals(); return 0; } /* We now display the details of the associated memory block. */ fprintf(stderr, "address " MP_POINTER " located in %s block:\n", p, (m->data.flags & FLG_FREED) ? "freed" : "allocated"); fprintf(stderr, " start of block: " MP_POINTER "\n", n->block); fprintf(stderr, " size of block: %lu byte%s\n", n->size, (n->size == 1) ? "" : "s"); fprintf(stderr, " stored type: %s\n", m->data.typestr ? m->data.typestr : "<unknown>"); fputs(" stored type size: ", stderr); if (m->data.typesize) fprintf(stderr, "%lu byte%s\n", m->data.typesize, (m->data.typesize == 1) ? "" : "s"); else fputs("<unknown>\n", stderr); fprintf(stderr, " user data: " MP_POINTER "\n", m->data.userdata); if (m->data.flags & FLG_FREED) fputs(" freed by: ", stderr); else fputs(" allocated by: ", stderr); fprintf(stderr, "%s\n", __mp_functionnames[m->data.type]); fprintf(stderr, " allocation index: %lu\n", m->data.alloc); fprintf(stderr, " reallocation index: %lu\n", m->data.realloc);#if MP_THREADS_SUPPORT fprintf(stderr, " thread identifier: %lu\n", m->data.thread);#endif /* MP_THREADS_SUPPORT */ fprintf(stderr, " modification event: %lu\n", m->data.event); fputs(" flags: ", stderr); if (m->data.flags == 0) fputs(" none\n", stderr); else { if (m->data.flags & FLG_FREED) fputs(" freed", stderr); if (m->data.flags & FLG_MARKED) fputs(" marked", stderr); if (m->data.flags & FLG_PROFILED) fputs(" profiled", stderr); if (m->data.flags & FLG_TRACED) fputs(" traced", stderr); if (m->data.flags & FLG_INTERNAL) fputs(" internal", stderr); fputc('\n', stderr); } fprintf(stderr, " calling function: %s\n", m->data.func ? m->data.func : "<unknown>"); fprintf(stderr, " called from file: %s\n", m->data.file ? m->data.file : "<unknown>"); fputs(" called at line: ", stderr); if (m->data.line) fprintf(stderr, "%lu\n", m->data.line); else fputs("<unknown>\n", stderr); /* Traverse the function call stack, displaying as much information as * possible. */ if (a = m->data.stack) { fputs(" function call stack:\n", stderr); do { fprintf(stderr, "\t" MP_POINTER " ", a->data.addr); if (a->data.name) fputs(a->data.name, stderr); else if (s = __mp_findsymbol(&memhead.syms, a->data.addr)) fputs(s->data.name, stderr); else fputs("???", stderr); fputc('\n', stderr); a = a->data.next; } while (a != NULL); } restoresignals(); return 1;}/* Return the current allocation event count for later use when examining * the difference in the list of allocations between now and a future point. */MP_APIunsigned long__mp_snapshot(void){ unsigned long i; savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); i = memhead.event; restoresignals(); return i;}/* Iterate over all of the allocated and freed memory blocks, calling a * user-supplied function for each one encountered, selecting only those * memory blocks that have been modified since a given allocation event. */MP_APIsize_t__mp_iterate(int (*f)(void *, void *), void *d, unsigned long s){ allocnode *n, *p; infonode *m; size_t i; int r; savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); i = 0; for (n = (allocnode *) memhead.alloc.list.head; p = (allocnode *) n->lnode.next; n = p) if ((m = (infonode *) n->info) && !(m->data.flags & FLG_INTERNAL) && (m->data.event > s)) { if (f == NULL) r = __mp_printinfo(n->block); else r = f(n->block, d); if (r > 0) i++; else if (r < 0) break; } restoresignals(); return i;}/* Iterate over all of the allocated, freed and free memory blocks, calling * a user-supplied function for each one encountered. */MP_APIsize_t__mp_iterateall(int (*f)(void *, void *), void *d){ allocnode *n, *p; size_t i; int r; savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); i = 0; for (n = (allocnode *) memhead.alloc.list.head; p = (allocnode *) n->lnode.next; n = p) { if (f == NULL) r = __mp_printinfo(n->block); else r = f(n->block, d); if (r > 0) i++; else if (r < 0) break; } restoresignals(); return i;}/* Add a memory allocation to the leak table. */MP_APIint__mp_addallocentry(char *f, unsigned long l, size_t c){ int r; savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectinfo(&memhead, MA_READWRITE); r = __mp_allocentry(&memhead.ltable, f, l, c); if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectinfo(&memhead, MA_READONLY); restoresignals(); return r;}/* Remove a memory allocation from the leak table. */MP_APIint__mp_addfreeentry(char *f, unsigned long l, size_t c){ int r; savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectleaktab(&memhead.ltable, MA_READWRITE); r = __mp_freeentry(&memhead.ltable, f, l, c); if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectleaktab(&memhead.ltable, MA_READONLY); restoresignals(); return r;}/* Clear the leak table. */MP_APIvoid__mp_clearleaktable(void){ savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectleaktab(&memhead.ltable, MA_READWRITE); __mp_clearleaktab(&memhead.ltable); if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectleaktab(&memhead.ltable, MA_READONLY); restoresignals();}/* Start recording memory allocation events in the leak table. */MP_APIint__mp_startleaktable(void){ int r; savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); r = memhead.ltable.tracing; memhead.ltable.tracing = 1; restoresignals(); return r;}/* Stop recording memory allocation events in the leak table. */MP_APIint__mp_stopleaktable(void){ int r; savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); r = memhead.ltable.tracing; memhead.ltable.tracing = 0; restoresignals(); return r;}/* Display the leak table. */MP_APIvoid__mp_leaktable(size_t l, int o, unsigned char f){ savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectleaktab(&memhead.ltable, MA_READWRITE); __mp_printleaktab(&memhead, l, o, f); if (!(memhead.flags & FLG_NOPROTECT)) __mp_protectleaktab(&memhead.ltable, MA_READONLY); restoresignals();}/* Display a complete memory map of the heap and (optionally) a summary of * all mpatrol library settings and statistics. */MP_APIvoid__mp_memorymap(int s){ savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); if (s != 0) __mp_printsummary(&memhead); if (memhead.alloc.list.size > 0) { if (s != 0) __mp_diag("\n"); __mp_printmap(&memhead); } restoresignals();}/* Display a summary of all mpatrol library settings and statistics. */MP_APIvoid__mp_summary(void){ savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); __mp_printsummary(&memhead); restoresignals();}/* Return statistics about the current state of the heap. */MP_APIint__mp_stats(heapinfo *d){ savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); d->acount = memhead.alloc.atree.size; d->atotal = memhead.alloc.asize; d->fcount = memhead.alloc.ftree.size; d->ftotal = memhead.alloc.fsize; d->gcount = memhead.alloc.gtree.size; d->gtotal = memhead.alloc.gsize; d->icount = memhead.alloc.heap.itree.size + memhead.alloc.itree.size + memhead.addr.list.size + memhead.syms.strings.list.size + memhead.syms.strings.tree.size + memhead.syms.itree.size + memhead.ltable.list.size + memhead.prof.ilist.size + memhead.list.size + memhead.alist.size; d->itotal = memhead.alloc.heap.isize + memhead.alloc.isize + memhead.addr.size + memhead.syms.strings.size + memhead.syms.size + memhead.ltable.isize + memhead.prof.size + memhead.size; d->mcount = memhead.mcount; d->mtotal = memhead.mtotal; restoresignals(); return 1;}/* Check the validity of all memory blocks that have been filled with * a predefined pattern. */MP_APIvoid__mp_checkheap(char *s, char *t, unsigned long u){ stackinfo i; loginfo v; savesignals(); if (!memhead.init) __mp_init(); if (__mp_processid() != memhead.pid) __mp_reinit(); /* Determine the call stack details in case we need to free any * allocations that were made by alloca(). */ __mp_newframe(&i, NULL); if (__mp_getframe(&i)) __mp_getframe(&i)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -