Index: third_party/tcmalloc/chromium/src/windows/addr2line-pdb.c |
diff --git a/third_party/tcmalloc/chromium/src/windows/addr2line-pdb.c b/third_party/tcmalloc/chromium/src/windows/addr2line-pdb.c |
index 97b614b41ea2bd874a10de0bf8392fa3190892e2..7a2bf3e6f45f52d5b8533eb0ea5660d17b18be20 100644 |
--- a/third_party/tcmalloc/chromium/src/windows/addr2line-pdb.c |
+++ b/third_party/tcmalloc/chromium/src/windows/addr2line-pdb.c |
@@ -35,9 +35,17 @@ |
* c:\websymbols without asking. |
*/ |
+#ifndef WIN32_LEAN_AND_MEAN |
#define WIN32_LEAN_AND_MEAN |
+#endif |
+ |
+#ifndef _CRT_SECURE_NO_WARNINGS |
#define _CRT_SECURE_NO_WARNINGS |
+#endif |
+ |
+#ifndef _CRT_SECURE_NO_DEPRECATE |
#define _CRT_SECURE_NO_DEPRECATE |
+#endif |
#include <stdio.h> |
#include <stdlib.h> |
@@ -67,7 +75,8 @@ int main(int argc, char *argv[]) { |
} else if (strcmp(argv[i], "--demangle") == 0 || |
strcmp(argv[i], "-C") == 0) { |
symopts |= SYMOPT_UNDNAME; |
- } else if (strcmp(argv[i], "-e") == 0) { |
+ } else if (strcmp(argv[i], "--exe") == 0 || |
+ strcmp(argv[i], "-e") == 0) { |
if (i + 1 >= argc) { |
fprintf(stderr, "FATAL ERROR: -e must be followed by a filename\n"); |
return 1; |
@@ -86,7 +95,7 @@ int main(int argc, char *argv[]) { |
if (!SymInitialize(process, NULL, FALSE)) { |
error = GetLastError(); |
- fprintf(stderr, "SymInitialize returned error : %d\n", error); |
+ fprintf(stderr, "SymInitialize returned error : %lu\n", error); |
return 1; |
} |
@@ -100,13 +109,13 @@ int main(int argc, char *argv[]) { |
strcat(search, ";" WEBSYM); |
} else { |
error = GetLastError(); |
- fprintf(stderr, "SymGetSearchPath returned error : %d\n", error); |
+ fprintf(stderr, "SymGetSearchPath returned error : %lu\n", error); |
rv = 1; /* An error, but not a fatal one */ |
strcpy(search, WEBSYM); /* Use a default value */ |
} |
if (!SymSetSearchPath(process, search)) { |
error = GetLastError(); |
- fprintf(stderr, "SymSetSearchPath returned error : %d\n", error); |
+ fprintf(stderr, "SymSetSearchPath returned error : %lu\n", error); |
rv = 1; /* An error, but not a fatal one */ |
} |
@@ -115,7 +124,7 @@ int main(int argc, char *argv[]) { |
if (!module_base) { |
/* SymLoadModuleEx failed */ |
error = GetLastError(); |
- fprintf(stderr, "SymLoadModuleEx returned error : %d for %s\n", |
+ fprintf(stderr, "SymLoadModuleEx returned error : %lu for %s\n", |
error, filename); |
SymCleanup(process); |
return 1; |
@@ -126,7 +135,7 @@ int main(int argc, char *argv[]) { |
/* GNU addr2line seems to just do a strtol and ignore any |
* weird characters it gets, so we will too. |
*/ |
- unsigned __int64 addr = _strtoui64(buf, NULL, 16); |
+ unsigned __int64 reladdr = _strtoui64(buf, NULL, 16); |
ULONG64 buffer[(sizeof(SYMBOL_INFO) + |
MAX_SYM_NAME*sizeof(TCHAR) + |
sizeof(ULONG64) - 1) |
@@ -134,17 +143,25 @@ int main(int argc, char *argv[]) { |
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; |
IMAGEHLP_LINE64 line; |
DWORD dummy; |
+ |
+ // Just ignore overflow. In an overflow scenario, the resulting address |
+ // will be lower than module_base which hasn't been mapped by any prior |
+ // SymLoadModuleEx() command. This will cause SymFromAddr() and |
+ // SymGetLineFromAddr64() both to return failures and print the correct |
+ // ?? and ??:0 message variant. |
+ ULONG64 absaddr = reladdr + module_base; |
+ |
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); |
pSymbol->MaxNameLen = MAX_SYM_NAME; |
if (print_function_name) { |
- if (SymFromAddr(process, (DWORD64)addr, NULL, pSymbol)) { |
+ if (SymFromAddr(process, (DWORD64)absaddr, NULL, pSymbol)) { |
printf("%s\n", pSymbol->Name); |
} else { |
printf("??\n"); |
} |
} |
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); |
- if (SymGetLineFromAddr64(process, (DWORD64)addr, &dummy, &line)) { |
+ if (SymGetLineFromAddr64(process, (DWORD64)absaddr, &dummy, &line)) { |
printf("%s:%d\n", line.FileName, (int)line.LineNumber); |
} else { |
printf("??:0\n"); |