📄 mpatrol.c
字号:
"\tSpecifies the limit in bytes up to which memory allocations should be\n" "\tclassified as small allocations for profiling purposes.\n"}, {"threads", OF_THREADS, NULL, "\tSpecifies that the program to be run is multithreaded if the\n" "\t--dynamic option is used.\n"}, {"trace", OF_TRACE, NULL, "\tSpecifies that all memory allocations are to be traced and sent to\n" "\tthe tracing output file.\n"}, {"trace-file", OF_TRACEFILE, "string", "\tSpecifies an alternative file in which to place all memory allocation\n" "\ttracing information from the mpatrol library.\n"}, {"unfreed-abort", OF_UNFREEDABORT, "unsigned integer", "\tSpecifies the minimum number of unfreed allocations at which to abort\n" "\tthe program just before program termination.\n"}, {"use-debug", OF_USEDEBUG, NULL, "\tSpecifies that any debugging information in the executable file\n" "\tshould be used to obtain additional source-level information.\n"}, {"use-mmap", OF_USEMMAP, NULL, "\tSpecifies that the library should use mmap() instead of sbrk() to\n" "\tallocate user memory.\n"}, {"version", OF_VERSION, NULL, "\tDisplays the version number of this program.\n"}, NULL};/* Add an option and possibly an associated value to the options buffer. */staticvoidaddoption(char *o, char *v, int s){ size_t l; int q; q = 0; l = strlen(o) + (s == 0); if (v != NULL) { l += strlen(v) + 1; if (strchr(v, ' ')) { l += 2; q = 1; } } if (optlen + l >= sizeof(options)) { fprintf(stderr, "%s: Environment variable too long\n", progname); exit(EXIT_FAILURE); } if (q == 1) sprintf(options + optlen, "%s%s=\"%s\"", (s == 0) ? " " : "", o, v); else if (v != NULL) sprintf(options + optlen, "%s%s=%s", (s == 0) ? " " : "", o, v); else sprintf(options + optlen, "%s%s", (s == 0) ? " " : "", o); optlen += l;}/* Build the environment variable containing mpatrol library options. */staticvoidsetoptions(int r, int s){ char *t; sprintf(options, "%s=", MP_OPTIONS); optlen = strlen(options); if (r != 0) if (((t = getenv(MP_OPTIONS)) != NULL) && (*t != '\0')) { strcpy(options + optlen, t); optlen += strlen(t); } else r = 0; addoption("LOGFILE", logfile, (r == 0)); if (allocbyte) addoption("ALLOCBYTE", allocbyte, 0); if (allocstop) addoption("ALLOCSTOP", allocstop, 0); if (allowoflow) addoption("ALLOWOFLOW", NULL, 0); if (autosave) addoption("AUTOSAVE", autosave, 0); if (check) addoption("CHECK", check, 0); if (checkallocs && checkfrees && checkmemory && checkreallocs) addoption("CHECKALL", NULL, 0); else { if (checkallocs) addoption("CHECKALLOCS", NULL, 0); if (checkfrees) addoption("CHECKFREES", NULL, 0); if (checkmemory) addoption("CHECKMEMORY", NULL, 0); if (checkreallocs) addoption("CHECKREALLOCS", NULL, 0); } if (checkfork) addoption("CHECKFORK", NULL, 0); if (defalign) addoption("DEFALIGN", defalign, 0); if (editlist == 1) addoption("EDIT", NULL, 0); if (failfreq) addoption("FAILFREQ", failfreq, 0); if (failseed) addoption("FAILSEED", failseed, 0); if (freebyte) addoption("FREEBYTE", freebyte, 0); if (freestop) addoption("FREESTOP", freestop, 0); if (html) addoption("HTML", NULL, 0); if (largebound) addoption("LARGEBOUND", largebound, 0); if (leaktable) addoption("LEAKTABLE", NULL, 0); if (limit) addoption("LIMIT", limit, 0); if (editlist == 2) addoption("LIST", NULL, 0); if (logallocs && logfrees && logmemory && logreallocs) addoption("LOGALL", NULL, 0); else { if (logallocs) addoption("LOGALLOCS", NULL, 0); if (logfrees) addoption("LOGFREES", NULL, 0); if (logmemory) addoption("LOGMEMORY", NULL, 0); if (logreallocs) addoption("LOGREALLOCS", NULL, 0); } if (mediumbound) addoption("MEDIUMBOUND", mediumbound, 0); if (nofree) addoption("NOFREE", nofree, 0); if (noprotect) addoption("NOPROTECT", NULL, 0); if (oflowbyte) addoption("OFLOWBYTE", oflowbyte, 0); if (oflowsize) addoption("OFLOWSIZE", oflowsize, 0); if (oflowwatch) addoption("OFLOWWATCH", NULL, 0); if (pagealloc) addoption("PAGEALLOC", pagealloc, 0); if (preserve) addoption("PRESERVE", NULL, 0); if (prof) addoption("PROF", NULL, 0); if (proffile) addoption("PROFFILE", proffile, 0); if (progfile) addoption("PROGFILE", progfile, 0); if (reallocstop) addoption("REALLOCSTOP", reallocstop, 0); if (safesignals) addoption("SAFESIGNALS", NULL, 0); if (showfree && showfreed && showmap && showsymbols && showunfreed) addoption("SHOWALL", NULL, 0); else { if (showfree) addoption("SHOWFREE", NULL, 0); if (showfreed) addoption("SHOWFREED", NULL, 0); if (showmap) addoption("SHOWMAP", NULL, 0); if (showsymbols) addoption("SHOWSYMBOLS", NULL, 0); if (showunfreed) addoption("SHOWUNFREED", NULL, 0); } if (smallbound) addoption("SMALLBOUND", smallbound, 0); if (trace) addoption("TRACE", NULL, 0); if (tracefile) addoption("TRACEFILE", tracefile, 0); if (unfreedabort) addoption("UNFREEDABORT", unfreedabort, 0); if (usedebug) addoption("USEDEBUG", NULL, 0); if (usemmap) addoption("USEMMAP", NULL, 0); if (s != 0) fprintf(stdout, "%s\n", strchr(options, '=') + 1); else if (putenv(options)) { fprintf(stderr, "%s: Cannot set environment variable `%s'\n", progname, MP_OPTIONS); exit(EXIT_FAILURE); }}#if MP_PRELOAD_SUPPORT/* Build the environment variable containing the list of libraries to preload. */staticchar *addlibraries(char *v, ...){ static char p[256]; char *s, *t; va_list l; t = p; sprintf(t, "%s=%s", MP_PRELOAD_NAME, v); t += strlen(t); va_start(l, v); while ((s = va_arg(l, char *)) != NULL) { sprintf(t, "%s%s", MP_PRELOAD_SEP, s); t += strlen(t); } va_end(l); return p;}#endif /* MP_PRELOAD_SUPPORT */#if TARGET == TARGET_UNIX/* Search for an executable file in the current search path. */staticchar *execpath(char *s){ static char t[MAXPATHLEN]; char *p, *x, *y; if (strchr(s, '/')) return s; if ((p = getenv("PATH")) == NULL) p = ""; if ((p = strdup(p)) == NULL) { fprintf(stderr, "%s: Out of memory\n", progname); exit(EXIT_FAILURE); } for (x = y = p; y != NULL; x = y + 1) { if (y = strchr(x, ':')) *y = '\0'; if (*x == '\0') x = "."; sprintf(t, "%s/%s", x, s); if (access(t, X_OK) == 0) { s = t; break; } } free(p); return s;}#endif /* TARGET *//* Convert the command line options to mpatrol library options and run the * specified command and arguments. */intmain(int argc, char **argv){ char b[256]; char *a;#if MP_PRELOAD_SUPPORT char *p;#endif /* MP_PRELOAD_SUPPORT */#if TARGET == TARGET_UNIX pid_t f;#else /* TARGET */#if TARGET == TARGET_WINDOWS char **s;#else /* TARGET */ char *s;#endif /* TARGET */ size_t i, l;#endif /* TARGET */ int c, d, e, h, r, t, v, w, x; d = e = h = r = t = v = w = x = 0; progname = __mp_basename(argv[0]); if ((a = getenv(MP_LOGDIR)) && (*a != '\0')) logfile = "%n.%p.log"; else logfile = "mpatrol.%n.log"; if ((a = getenv(MP_PROFDIR)) && (*a != '\0')) proffile = "%n.%p.out"; else proffile = "mpatrol.%n.out"; if ((a = getenv(MP_TRACEDIR)) && (*a != '\0')) tracefile = "%n.%p.trace"; else tracefile = "mpatrol.%n.trace"; while ((c = __mp_getopt(argc, argv, __mp_shortopts(b, options_table), options_table)) != EOF) switch (c) { case OF_ALLOCBYTE: allocbyte = __mp_optarg; break; case OF_ALLOCSTOP: allocstop = __mp_optarg; break; case OF_ALLOWOFLOW: allowoflow = 1; break; case OF_AUTOSAVE: autosave = __mp_optarg; break; case OF_CHECK: check = __mp_optarg; break; case OF_CHECKALL: checkallocs = 1; checkreallocs = 1; checkfrees = 1; checkmemory = 1; break; case OF_CHECKALLOCS: checkallocs = 1; break; case OF_CHECKFORK: checkfork = 1; break; case OF_CHECKFREES: checkfrees = 1; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -