⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inter.c

📁 debug source code under unix platform.
💻 C
📖 第 1 页 / 共 5 页
字号:
            __mp_memcopy(q, p, l);            return q;        }    savesignals();    if (__mp_processid() != memhead.pid)        __mp_reinit();    /* Determine the call stack details.     */    __mp_newframe(&i, NULL);    if (__mp_getframe(&i))    {        j = __mp_getframe(&i);        while ((k > 0) && (j != 0))        {            j = __mp_getframe(&i);            k--;        }    }    /* If no filename was passed through then attempt to read any debugging     * information to determine the source location of the call.     */    if ((memhead.recur == 1) && (t == NULL) && (i.addr != NULL) &&        __mp_findsource(&memhead.syms, (char *) i.addr - 1, &s, &t, &u))    {        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectstrtab(&memhead.syms.strings, MA_READWRITE);        if (s != NULL)            s = __mp_addstring(&memhead.syms.strings, s);        if (t != NULL)            t = __mp_addstring(&memhead.syms.strings, t);        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectstrtab(&memhead.syms.strings, MA_READONLY);    }    v.ltype = LT_MAX;    v.type = f;    v.func = s;    v.file = t;    v.line = u;    v.stack = &i;    v.typestr = NULL;    v.typesize = 0;    v.logged = 0;    checkalloca(&v, 0);    q = __mp_copymemory(&memhead, p, q, l, c, &v);    restoresignals();    return q;}/* Attempt to locate the position of one block of memory in another block. */MP_APIvoid *__mp_locatemem(void *p, size_t l, void *q, size_t m, alloctype f, char *s,               char *t, unsigned long u, size_t k){    void *r;    stackinfo i;    loginfo v;    int j;    unsigned char b;    if (f == AT_MEMCHR)    {        /* If the function that called us was memchr() then we must convert the         * second length to a character and set up the new pointer and length.         */        b = (unsigned char) (m & 0xFF);        q = (void *) &b;        m = 1;    }    if (!memhead.init || memhead.fini)        return __mp_memfind(p, l, q, m);    savesignals();    if (__mp_processid() != memhead.pid)        __mp_reinit();    /* Determine the call stack details.     */    __mp_newframe(&i, NULL);    if (__mp_getframe(&i))    {        j = __mp_getframe(&i);        while ((k > 0) && (j != 0))        {            j = __mp_getframe(&i);            k--;        }    }    /* If no filename was passed through then attempt to read any debugging     * information to determine the source location of the call.     */    if ((memhead.recur == 1) && (t == NULL) && (i.addr != NULL) &&        __mp_findsource(&memhead.syms, (char *) i.addr - 1, &s, &t, &u))    {        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectstrtab(&memhead.syms.strings, MA_READWRITE);        if (s != NULL)            s = __mp_addstring(&memhead.syms.strings, s);        if (t != NULL)            t = __mp_addstring(&memhead.syms.strings, t);        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectstrtab(&memhead.syms.strings, MA_READONLY);    }    v.ltype = LT_MAX;    v.type = f;    v.func = s;    v.file = t;    v.line = u;    v.stack = &i;    v.typestr = NULL;    v.typesize = 0;    v.logged = 0;    checkalloca(&v, 0);    r = __mp_locatememory(&memhead, p, l, q, m, &v);    restoresignals();    return r;}/* Compare two blocks of memory. */MP_APIint__mp_comparemem(void *p, void *q, size_t l, alloctype f, char *s, char *t,                unsigned long u, size_t k){    void *m;    stackinfo i;    loginfo v;    int j, r;    if (!memhead.init || memhead.fini)        if (m = __mp_memcompare(p, q, l))        {            l = (char *) m - (char *) p;            return (int) ((unsigned char *) p)[l] -                   (int) ((unsigned char *) q)[l];        }        else            return 0;    savesignals();    if (__mp_processid() != memhead.pid)        __mp_reinit();    /* Determine the call stack details.     */    __mp_newframe(&i, NULL);    if (__mp_getframe(&i))    {        j = __mp_getframe(&i);        while ((k > 0) && (j != 0))        {            j = __mp_getframe(&i);            k--;        }    }    /* If no filename was passed through then attempt to read any debugging     * information to determine the source location of the call.     */    if ((memhead.recur == 1) && (t == NULL) && (i.addr != NULL) &&        __mp_findsource(&memhead.syms, (char *) i.addr - 1, &s, &t, &u))    {        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectstrtab(&memhead.syms.strings, MA_READWRITE);        if (s != NULL)            s = __mp_addstring(&memhead.syms.strings, s);        if (t != NULL)            t = __mp_addstring(&memhead.syms.strings, t);        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectstrtab(&memhead.syms.strings, MA_READONLY);    }    v.ltype = LT_MAX;    v.type = f;    v.func = s;    v.file = t;    v.line = u;    v.stack = &i;    v.typestr = NULL;    v.typesize = 0;    v.logged = 0;    checkalloca(&v, 0);    r = __mp_comparememory(&memhead, p, q, l, &v);    restoresignals();    return r;}/* Return the full version number of the mpatrol library. */MP_APIunsigned long__mp_libversion(void){    return MP_VERNUM;}/* Return an error message corresponding to a given error type. */MP_APIchar *__mp_strerror(errortype e){    if ((e >= (errortype) 0) && (e <= ET_MAX))        return __mp_errordetails[e].string;    return NULL;}/* Return the name of the function corresponding to a given allocation type. */MP_APIchar *__mp_function(alloctype f){    if ((f >= (alloctype) 0) && (f < AT_MAX))        return __mp_functionnames[f];    return NULL;}/* Set the user data for a given memory allocation. */MP_APIint__mp_setuser(void *p, void *d){    allocnode *n;    infonode *m;    int r;    savesignals();    if (!memhead.init)        __mp_init();    if (__mp_processid() != memhead.pid)        __mp_reinit();    /* Check that we know something about the address that was supplied.     */    if (((n = __mp_findalloc(&memhead.alloc, p)) == NULL) ||        ((m = (infonode *) n->info) == NULL))        r = 0;    else    {        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectinfo(&memhead, MA_READWRITE);        m->data.userdata = d;        if ((memhead.recur == 1) && !(memhead.flags & FLG_NOPROTECT))            __mp_protectinfo(&memhead, MA_READONLY);        r = 1;    }    restoresignals();    return r;}/* Set the marked flag for a given memory allocation. */MP_APIint__mp_setmark(void *p){    allocnode *n;    infonode *m;    int r;    savesignals();    if (!memhead.init)        __mp_init();    if (__mp_processid() != memhead.pid)        __mp_reinit();    /* Check that we know something about the address that was supplied.     */    if (((n = __mp_findalloc(&memhead.alloc, p)) == NULL) ||        ((m = (infonode *) n->info) == NULL) || (m->data.flags & FLG_MARKED) ||        (m->data.type == AT_ALLOCA) || (m->data.type == AT_STRDUPA) ||        (m->data.type == AT_STRNDUPA))        r = 0;    else    {        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectinfo(&memhead, MA_READWRITE);        m->data.flags |= FLG_MARKED;        if ((memhead.recur == 1) && !(memhead.flags & FLG_NOPROTECT))            __mp_protectinfo(&memhead, MA_READONLY);        memhead.mcount++;        memhead.mtotal += n->size;        r = 1;    }    restoresignals();    return r;}/* Obtain any details about the memory block that contains a given address. */MP_APIint__mp_info(void *p, allocinfo *d){    addrnode *a;    symnode *s;    allocnode *n;    infonode *m;    savesignals();    if (!memhead.init)        __mp_init();    if (__mp_processid() != memhead.pid)        __mp_reinit();    /* Check that we know something about the address that was supplied.     */    if ((n = __mp_findnode(&memhead.alloc, p, 1)) == NULL)    {        restoresignals();        return 0;    }    /* Return mostly empty fields if the pointer is in free memory.     */    if ((m = (infonode *) n->info) == NULL)    {        d->block = n->block;        d->size = n->size;        d->type = AT_MAX;        d->alloc = 0;        d->realloc = 0;        d->thread = 0;        d->event = 0;        d->func = NULL;        d->file = NULL;        d->line = 0;        d->stack = NULL;        d->typestr = NULL;        d->typesize = 0;        d->userdata = NULL;        d->allocated = 0;        d->freed = 0;        d->marked = 0;        d->profiled = 0;        d->traced = 0;        d->internal = 0;        restoresignals();        return 1;    }    /* We now fill in the details for the supplied structure.     */    d->block = n->block;    d->size = n->size;    d->type = m->data.type;    d->alloc = m->data.alloc;    d->realloc = m->data.realloc;#if MP_THREADS_SUPPORT    d->thread = m->data.thread;#else /* MP_THREADS_SUPPORT */    d->thread = 0;#endif /* MP_THREADS_SUPPORT */    d->event = m->data.event;    d->func = m->data.func;    d->file = m->data.file;    d->line = m->data.line;    d->stack = m->data.stack;    d->typestr = m->data.typestr;    d->typesize = m->data.typesize;    d->userdata = m->data.userdata;    d->allocated = 1;    d->freed = ((m->data.flags & FLG_FREED) != 0);    d->marked = ((m->data.flags & FLG_MARKED) != 0);    d->profiled = ((m->data.flags & FLG_PROFILED) != 0);    d->traced = ((m->data.flags & FLG_TRACED) != 0);    d->internal = ((m->data.flags & FLG_INTERNAL) != 0);    if (!(memhead.flags & FLG_NOPROTECT))        __mp_protectinfo(&memhead, MA_READWRITE);    /* The names of the symbols in the call stack may not have been determined     * yet, so we traverse the stack, filling in any known symbol names as we     * go.     */    for (a = m->data.stack; a != NULL; a = a->data.next)        if ((a->data.name == NULL) &&            (s = __mp_findsymbol(&memhead.syms, a->data.addr)))            a->data.name = s->data.name;    if ((memhead.recur == 1) && !(memhead.flags & FLG_NOPROTECT))        __mp_protectinfo(&memhead, MA_READONLY);    restoresignals();    return 1;}/* Obtain any details about the function symbol that contains a given address. */MP_APIint__mp_syminfo(void *p, symbolinfo *d){    symnode *n;    char *s, *t;    unsigned long u;    int r;    savesignals();    if (!memhead.init)        __mp_init();    if (__mp_processid() != memhead.pid)        __mp_reinit();    n = __mp_findsymbol(&memhead.syms, p);    r = __mp_findsource(&memhead.syms, p, &s, &t, &u);    if (((n == NULL) && (s != NULL)) || (t != NULL))    {        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectstrtab(&memhead.syms.strings, MA_READWRITE);        if ((n == NULL) && (s != NULL))            s = __mp_addstring(&memhead.syms.strings, s);        if (t != NULL)            t = __mp_addstring(&memhead.syms.strings, t);        if (!(memhead.flags & FLG_NOPROTECT))            __mp_protectstrtab(&memhead.syms.strings, MA_READONLY);    }    if ((n != NULL) || (r != 0))    {        if (n != NULL)        {            d->name = n->data.name;            d->object = n->data.file;            d->addr = n->data.addr;            d->size = n->data.size;        }        else        {            d->name = s;            d->object = NULL;            d->addr = NULL;            d->size = 0;        }        d->file = t;        d->line = u;        r = 1;    }    restoresignals();    return r;}/* Obtain the name of the function symbol that contains a given address. */MP_APIchar *__mp_symbol(void *p){    symnode *n;    char *s, *t;    unsigned long u;    savesignals();    if (!memhead.init)        __mp_init();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -