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

📄 mpatrol.c

📁 debug source code under unix platform.
💻 C
📖 第 1 页 / 共 3 页
字号:
          case OF_CHECKMEMORY:            checkmemory = 1;            break;          case OF_CHECKREALLOCS:            checkreallocs = 1;            break;          case OF_DEFALIGN:            defalign = __mp_optarg;            break;          case OF_DYNAMIC:            d = 1;            break;          case OF_EDIT:            editlist = 1;            break;          case OF_FAILFREQ:            failfreq = __mp_optarg;            break;          case OF_FAILSEED:            failseed = __mp_optarg;            break;          case OF_FREEBYTE:            freebyte = __mp_optarg;            break;          case OF_FREESTOP:            freestop = __mp_optarg;            break;          case OF_HELP:            h = 1;            break;          case OF_HTML:            html = 1;            break;          case OF_LARGEBOUND:            largebound = __mp_optarg;            break;          case OF_LEAKTABLE:            leaktable = 1;            break;          case OF_LIST:            editlist = 2;            break;          case OF_LIMIT:            limit = __mp_optarg;            break;          case OF_LOGALL:            logallocs = 1;            logreallocs = 1;            logfrees = 1;            logmemory = 1;            break;          case OF_LOGALLOCS:            logallocs = 1;            break;          case OF_LOGFILE:            logfile = __mp_optarg;            break;          case OF_LOGFREES:            logfrees = 1;            break;          case OF_LOGMEMORY:            logmemory = 1;            break;          case OF_LOGREALLOCS:            logreallocs = 1;            break;          case OF_MEDIUMBOUND:            mediumbound = __mp_optarg;            break;          case OF_NOFREE:            nofree = __mp_optarg;            break;          case OF_NOPROTECT:            noprotect = 1;            break;          case OF_OFLOWBYTE:            oflowbyte = __mp_optarg;            break;          case OF_OFLOWSIZE:            oflowsize = __mp_optarg;            break;          case OF_OFLOWWATCH:            oflowwatch = 1;            break;          case OF_PAGEALLOCLOWER:            pagealloc = "LOWER";            break;          case OF_PAGEALLOCUPPER:            pagealloc = "UPPER";            break;          case OF_PRESERVE:            preserve = 1;            break;          case OF_PROF:            prof = 1;            break;          case OF_PROFFILE:            proffile = __mp_optarg;            break;          case OF_PROGFILE:            progfile = __mp_optarg;            break;          case OF_READENV:            x = 1;            break;          case OF_REALLOCSTOP:            reallocstop = __mp_optarg;            break;          case OF_SAFESIGNALS:            safesignals = 1;            break;          case OF_SHOWALL:            showmap = 1;            showsymbols = 1;            showfree = 1;            showfreed = 1;            showunfreed = 1;            break;          case OF_SHOWENV:            w = 1;            break;          case OF_SHOWFREE:            showfree = 1;            break;          case OF_SHOWFREED:            showfreed = 1;            break;          case OF_SHOWMAP:            showmap = 1;            break;          case OF_SHOWSYMBOLS:            showsymbols = 1;            break;          case OF_SHOWUNFREED:            showunfreed = 1;            break;          case OF_SMALLBOUND:            smallbound = __mp_optarg;            break;          case OF_THREADS:            t = 1;            break;          case OF_TRACE:            trace = 1;            break;          case OF_TRACEFILE:            tracefile = __mp_optarg;            break;          case OF_UNFREEDABORT:            unfreedabort = __mp_optarg;            break;          case OF_USEDEBUG:            usedebug = 1;            break;          case OF_USEMMAP:            usemmap = 1;            break;          case OF_VERSION:            v = 1;            break;          default:            e = 1;            break;        }    argc -= __mp_optindex;    argv += __mp_optindex;    if (v == 1)    {        fprintf(stdout, "%s %s\n%s %s\n\n", progname, PROGVERSION,                __mp_copyright, __mp_author);        fputs("This is free software, and you are welcome to redistribute it "              "under certain\n", stdout);        fputs("conditions; see the GNU Library General Public License for "              "details.\n\n", stdout);        fputs("For the latest mpatrol release and documentation,\n", stdout);        fprintf(stdout, "visit %s.\n\n", __mp_homepage);    }    else if ((argc == 0) && (h == 0) && (w == 0))        e = 1;    if ((argc == 0) || (e == 1) || (h == 1) || (w == 1))    {        if ((e == 1) || (h == 1))        {            fprintf(stdout, "Usage: %s [options] <command> [arguments]\n\n",                    progname);            if (h == 0)                fprintf(stdout, "Type `%s --help' for a complete list of "                        "options.\n", progname);            else                __mp_showopts(options_table);        }        if (w == 1)            setoptions(x, 1);        if (e == 1)            exit(EXIT_FAILURE);        exit(EXIT_SUCCESS);    }    setoptions(x, 0);#if MP_PRELOAD_SUPPORT    /* The dynamic linker on some UNIX systems supports requests for it to     * preload a specified list of shared libraries before running a process,     * via the MP_PRELOAD_NAME environment variable.  If any of the specified     * libraries only exist as archive libraries then the mpatrol library     * should be built to contain them since there is no way to preload an     * archive library.  However, this may have repercussions when building a     * shared library from position-dependent code.     */    if (d == 1)    {        if (t == 1)            p = addlibraries(MP_PRELOADMT_LIBS, NULL);        else            p = addlibraries(MP_PRELOAD_LIBS, NULL);        if (putenv(p))        {            fprintf(stderr, "%s: Cannot set environment variable `%s'\n",                    progname, MP_PRELOAD_NAME);            exit(EXIT_FAILURE);        }    }#endif /* MP_PRELOAD_SUPPORT */    /* Prepare to run the command that is to be tested.  We return the exit     * status from the command after it has been run in case it was originally     * run from a script.     */    fflush(NULL);#if TARGET == TARGET_UNIX    /* We need to use the fork() and execvp() combination on UNIX platforms     * in case we are using the -d option, in which case we cannot use system()     * since that will use the shell to invoke the command, possibly resulting     * in an extra log file tracing the shell itself.     */    if ((f = fork()) < 0)    {        fprintf(stderr, "%s: Cannot create process\n", progname);        exit(EXIT_FAILURE);    }    if (f == 0)    {        /* Programs invoked with the execvp() function will not contain the         * full path that they were run with in argv[0].  We need to patch         * this here since otherwise the mpatrol library is unlikely to find         * the executable file to read symbols from.  Hopefully argv is located         * on the stack, otherwise it may be read-only and cause the following         * assignment to crash.         */        argv[0] = execpath(argv[0]);        execvp(argv[0], argv);        fprintf(stderr, "%s: Cannot execute command `%s'\n", progname, argv[0]);        exit(EXIT_FAILURE);    }    while (waitpid(f, &r, 0) < 0)        if (errno != EINTR)        {            fprintf(stderr, "%s: Process could not be created\n", progname);            exit(EXIT_FAILURE);        }    if (!WIFEXITED(r))        exit(EXIT_FAILURE);    r = WEXITSTATUS(r);#elif TARGET == TARGET_WINDOWS    /* To avoid extra overhead we call the spawnvp() function on Windows     * platforms.  However, for some strange reason, it concatenates all     * of its arguments into a single string with spaces in between arguments,     * but does NOT quote arguments with spaces in them!  For that reason,     * we'll have to do some extra work here.     */    if ((s = (char **) calloc(argc + 1, sizeof(char *))) == NULL)    {        fprintf(stderr, "%s: Out of memory\n", progname);        exit(EXIT_FAILURE);    }    for (i = 0; i < argc; i++)        if (strchr(argv[i], ' '))        {            l = strlen(argv[i]) + 3;            if ((s[i] = (char *) malloc(l)) == NULL)            {                fprintf(stderr, "%s: Out of memory\n", progname);                exit(EXIT_FAILURE);            }            sprintf(s[i], "\"%s\"", argv[i]);        }        else if ((s[i] = strdup(argv[i])) == NULL)        {            fprintf(stderr, "%s: Out of memory\n", progname);            exit(EXIT_FAILURE);        }    if ((r = spawnvp(_P_WAIT, s[0], s)) == -1)    {        fprintf(stderr, "%s: Cannot execute command `%s'\n", progname, argv[0]);        exit(EXIT_FAILURE);    }    for (i = 0; i < argc; i++)        free(s[i]);    free(s);#else /* TARGET */    /* Because we are using system() to run the command, we need to ensure     * that all arguments that contain spaces are correctly quoted.  We also     * need to convert the argument array to a string, so we perform two     * passes.  The first pass counts the number of characters required for     * the final command string and allocates that amount of memory from the     * heap.  The second pass then fills in the command string and executes     * the command.     */    for (i = l = 0; i < argc; i++)    {        l += strlen(argv[i]) + 1;        if (strchr(argv[i], ' '))            l += 2;    }    if ((s = (char *) malloc(l)) == NULL)    {        fprintf(stderr, "%s: Out of memory\n", progname);        exit(EXIT_FAILURE);    }    for (i = l = 0; i < argc; i++)        if (strchr(argv[i], ' '))        {            sprintf(s + l, "%s\"%s\"", (i > 0) ? " " : "", argv[i]);            l += strlen(argv[i]) + (i > 0) + 2;        }        else        {            sprintf(s + l, "%s%s", (i > 0) ? " " : "", argv[i]);            l += strlen(argv[i]) + (i > 0);        }    if ((r = system(s)) == -1)    {        fprintf(stderr, "%s: Cannot execute command `%s'\n", progname, argv[0]);        exit(EXIT_FAILURE);    }    free(s);#if (TARGET == TARGET_AMIGA && defined(__GNUC__))    /* When gcc is used on AmigaOS, the return value from system() is similar     * to that on UNIX, so we need to modify it here.     */    r = ((unsigned int) r >> 8) & 0xFF;#endif /* TARGET && __GNUC__ */#endif /* TARGET */    return r;}

⌨️ 快捷键说明

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