| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/debug_util.h" | 5 #include "base/debug_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <dbghelp.h> | 8 #include <dbghelp.h> |
| 9 | 9 |
| 10 #include <iostream> | 10 #include <iostream> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 const int kMaxNameLength = 256; | 114 const int kMaxNameLength = 256; |
| 115 DWORD_PTR frame = reinterpret_cast<DWORD_PTR>(trace[i]); | 115 DWORD_PTR frame = reinterpret_cast<DWORD_PTR>(trace[i]); |
| 116 | 116 |
| 117 // Code adapted from MSDN example: | 117 // Code adapted from MSDN example: |
| 118 // http://msdn.microsoft.com/en-us/library/ms680578(VS.85).aspx | 118 // http://msdn.microsoft.com/en-us/library/ms680578(VS.85).aspx |
| 119 ULONG64 buffer[ | 119 ULONG64 buffer[ |
| 120 (sizeof(SYMBOL_INFO) + | 120 (sizeof(SYMBOL_INFO) + |
| 121 kMaxNameLength * sizeof(wchar_t) + | 121 kMaxNameLength * sizeof(wchar_t) + |
| 122 sizeof(ULONG64) - 1) / | 122 sizeof(ULONG64) - 1) / |
| 123 sizeof(ULONG64)]; | 123 sizeof(ULONG64)]; |
| 124 memset(buffer, 0, sizeof(buffer)); |
| 124 | 125 |
| 125 // Initialize symbol information retrieval structures. | 126 // Initialize symbol information retrieval structures. |
| 126 DWORD64 sym_displacement = 0; | 127 DWORD64 sym_displacement = 0; |
| 127 PSYMBOL_INFO symbol = reinterpret_cast<PSYMBOL_INFO>(&buffer[0]); | 128 PSYMBOL_INFO symbol = reinterpret_cast<PSYMBOL_INFO>(&buffer[0]); |
| 128 symbol->SizeOfStruct = sizeof(SYMBOL_INFO); | 129 symbol->SizeOfStruct = sizeof(SYMBOL_INFO); |
| 129 symbol->MaxNameLen = kMaxNameLength; | 130 symbol->MaxNameLen = kMaxNameLength - 1; |
| 130 BOOL has_symbol = SymFromAddr(GetCurrentProcess(), frame, | 131 BOOL has_symbol = SymFromAddr(GetCurrentProcess(), frame, |
| 131 &sym_displacement, symbol); | 132 &sym_displacement, symbol); |
| 132 | 133 |
| 133 // Attempt to retrieve line number information. | 134 // Attempt to retrieve line number information. |
| 134 DWORD line_displacement = 0; | 135 DWORD line_displacement = 0; |
| 135 IMAGEHLP_LINE64 line = {}; | 136 IMAGEHLP_LINE64 line = {}; |
| 136 line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); | 137 line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); |
| 137 BOOL has_line = SymGetLineFromAddr64(GetCurrentProcess(), frame, | 138 BOOL has_line = SymGetLineFromAddr64(GetCurrentProcess(), frame, |
| 138 &line_displacement, &line); | 139 &line_displacement, &line); |
| 139 | 140 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 (*os) << "Error initializing symbols (" << error | 272 (*os) << "Error initializing symbols (" << error |
| 272 << "). Dumping unresolved backtrace:\n"; | 273 << "). Dumping unresolved backtrace:\n"; |
| 273 for (int i = 0; (i < count_) && os->good(); ++i) { | 274 for (int i = 0; (i < count_) && os->good(); ++i) { |
| 274 (*os) << "\t" << trace_[i] << "\n"; | 275 (*os) << "\t" << trace_[i] << "\n"; |
| 275 } | 276 } |
| 276 } else { | 277 } else { |
| 277 (*os) << "Backtrace:\n"; | 278 (*os) << "Backtrace:\n"; |
| 278 context->OutputTraceToStream(trace_, count_, os); | 279 context->OutputTraceToStream(trace_, count_, os); |
| 279 } | 280 } |
| 280 } | 281 } |
| OLD | NEW |