Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/tcmalloc/chromium/src/windows/addr2line-pdb.c

Issue 2832643004: Fix potential missing nul character on resolved symbol names (Closed)
Patch Set: nit Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/tcmalloc/README.chromium ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2008, Google Inc. 1 /* Copyright (c) 2008, Google Inc.
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * 29 *
30 * --- 30 * ---
31 * Author: David Vitek 31 * Author: David Vitek
32 * 32 *
33 * Dump function addresses using Microsoft debug symbols. This works 33 * Dump function addresses using Microsoft debug symbols. This works
34 * on PDB files. Note that this program will download symbols to 34 * on PDB files. Note that this program will download symbols to
35 * c:\websymbols without asking. 35 * c:\websymbols without asking.
36 */ 36 */
37 37
38 #ifndef WIN32_LEAN_AND_MEAN 38 #ifndef WIN32_LEAN_AND_MEAN
39 #define WIN32_LEAN_AND_MEAN 39 #define WIN32_LEAN_AND_MEAN
40 #endif 40 #endif
41 41
42 #ifndef _CRT_SECURE_NO_WARNINGS 42 #ifndef _CRT_SECURE_NO_WARNINGS
43 #define _CRT_SECURE_NO_WARNINGS 43 #define _CRT_SECURE_NO_WARNINGS
44 #endif 44 #endif
45 45
46 #ifndef _CRT_SECURE_NO_DEPRECATE 46 #ifndef _CRT_SECURE_NO_DEPRECATE
47 #define _CRT_SECURE_NO_DEPRECATE 47 #define _CRT_SECURE_NO_DEPRECATE
48 #endif 48 #endif
49 49
50 #include <stdio.h> 50 #include <stdio.h>
51 #include <stdlib.h> 51 #include <stdlib.h>
52 52
53 #include <windows.h> 53 #include <windows.h>
54 #include <dbghelp.h> 54 #include <dbghelp.h>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 buf[sizeof(buf)-1] = '\0'; /* Just to be safe */ 133 buf[sizeof(buf)-1] = '\0'; /* Just to be safe */
134 while (fgets(buf, sizeof(buf)-1, stdin)) { 134 while (fgets(buf, sizeof(buf)-1, stdin)) {
135 /* GNU addr2line seems to just do a strtol and ignore any 135 /* GNU addr2line seems to just do a strtol and ignore any
136 * weird characters it gets, so we will too. 136 * weird characters it gets, so we will too.
137 */ 137 */
138 unsigned __int64 reladdr = _strtoui64(buf, NULL, 16); 138 unsigned __int64 reladdr = _strtoui64(buf, NULL, 16);
139 ULONG64 buffer[(sizeof(SYMBOL_INFO) + 139 ULONG64 buffer[(sizeof(SYMBOL_INFO) +
140 MAX_SYM_NAME*sizeof(TCHAR) + 140 MAX_SYM_NAME*sizeof(TCHAR) +
141 sizeof(ULONG64) - 1) 141 sizeof(ULONG64) - 1)
142 / sizeof(ULONG64)]; 142 / sizeof(ULONG64)];
143 memset(buffer, 0, sizeof(buffer));
143 PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; 144 PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
144 IMAGEHLP_LINE64 line; 145 IMAGEHLP_LINE64 line;
145 DWORD dummy; 146 DWORD dummy;
146 147
147 // Just ignore overflow. In an overflow scenario, the resulting address 148 // Just ignore overflow. In an overflow scenario, the resulting address
148 // will be lower than module_base which hasn't been mapped by any prior 149 // will be lower than module_base which hasn't been mapped by any prior
149 // SymLoadModuleEx() command. This will cause SymFromAddr() and 150 // SymLoadModuleEx() command. This will cause SymFromAddr() and
150 // SymGetLineFromAddr64() both to return failures and print the correct 151 // SymGetLineFromAddr64() both to return failures and print the correct
151 // ?? and ??:0 message variant. 152 // ?? and ??:0 message variant.
152 ULONG64 absaddr = reladdr + module_base; 153 ULONG64 absaddr = reladdr + module_base;
153 154
154 pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); 155 pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
155 pSymbol->MaxNameLen = MAX_SYM_NAME; 156 // The length of the name is not including the null-terminating character.
157 pSymbol->MaxNameLen = MAX_SYM_NAME - 1;
156 if (print_function_name) { 158 if (print_function_name) {
157 if (SymFromAddr(process, (DWORD64)absaddr, NULL, pSymbol)) { 159 if (SymFromAddr(process, (DWORD64)absaddr, NULL, pSymbol)) {
158 printf("%s\n", pSymbol->Name); 160 printf("%s\n", pSymbol->Name);
159 } else { 161 } else {
160 printf("??\n"); 162 printf("??\n");
161 } 163 }
162 } 164 }
163 line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); 165 line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
164 if (SymGetLineFromAddr64(process, (DWORD64)absaddr, &dummy, &line)) { 166 if (SymGetLineFromAddr64(process, (DWORD64)absaddr, &dummy, &line)) {
165 printf("%s:%d\n", line.FileName, (int)line.LineNumber); 167 printf("%s:%d\n", line.FileName, (int)line.LineNumber);
166 } else { 168 } else {
167 printf("??:0\n"); 169 printf("??:0\n");
168 } 170 }
169 } 171 }
170 SymUnloadModule64(process, module_base); 172 SymUnloadModule64(process, module_base);
171 SymCleanup(process); 173 SymCleanup(process);
172 return rv; 174 return rv;
173 } 175 }
OLDNEW
« no previous file with comments | « third_party/tcmalloc/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698