Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/stack_trace.h" | 5 #include "base/debug/stack_trace.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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/path_service.h" | |
| 15 #include "base/process_util.h" | 16 #include "base/process_util.h" |
| 17 #include "base/string_util.h" | |
| 16 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 17 | 19 |
| 18 namespace base { | 20 namespace base { |
| 19 namespace debug { | 21 namespace debug { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // Previous unhandled filter. Will be called if not NULL when we intercept an | 25 // Previous unhandled filter. Will be called if not NULL when we intercept an |
| 24 // exception. Only used in unit tests. | 26 // exception. Only used in unit tests. |
| 25 LPTOP_LEVEL_EXCEPTION_FILTER g_previous_filter = NULL; | 27 LPTOP_LEVEL_EXCEPTION_FILTER g_previous_filter = NULL; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 private: | 124 private: |
| 123 friend struct DefaultSingletonTraits<SymbolContext>; | 125 friend struct DefaultSingletonTraits<SymbolContext>; |
| 124 | 126 |
| 125 SymbolContext() : init_error_(ERROR_SUCCESS) { | 127 SymbolContext() : init_error_(ERROR_SUCCESS) { |
| 126 // Initializes the symbols for the process. | 128 // Initializes the symbols for the process. |
| 127 // Defer symbol load until they're needed, use undecorated names, and | 129 // Defer symbol load until they're needed, use undecorated names, and |
| 128 // get line numbers. | 130 // get line numbers. |
| 129 SymSetOptions(SYMOPT_DEFERRED_LOADS | | 131 SymSetOptions(SYMOPT_DEFERRED_LOADS | |
| 130 SYMOPT_UNDNAME | | 132 SYMOPT_UNDNAME | |
| 131 SYMOPT_LOAD_LINES); | 133 SYMOPT_LOAD_LINES); |
| 132 if (SymInitialize(GetCurrentProcess(), NULL, TRUE)) { | 134 if (!SymInitialize(GetCurrentProcess(), NULL, TRUE)) { |
| 133 init_error_ = ERROR_SUCCESS; | |
| 134 } else { | |
| 135 init_error_ = GetLastError(); | 135 init_error_ = GetLastError(); |
| 136 // TODO(awong): Handle error: SymInitialize can fail with | 136 // TODO(awong): Handle error: SymInitialize can fail with |
| 137 // ERROR_INVALID_PARAMETER. | 137 // ERROR_INVALID_PARAMETER. |
| 138 // When it fails, we should not call debugbreak since it kills the current | 138 // When it fails, we should not call debugbreak since it kills the current |
| 139 // process (prevents future tests from running or kills the browser | 139 // process (prevents future tests from running or kills the browser |
| 140 // process). | 140 // process). |
| 141 DLOG(ERROR) << "SymInitialize failed: " << init_error_; | 141 DLOG(ERROR) << "SymInitialize failed: " << init_error_; |
| 142 return; | |
| 143 } | |
| 144 | |
| 145 init_error_ = ERROR_SUCCESS; | |
| 146 | |
| 147 // When transferring the binaries e.g. between bots, path put | |
| 148 // into the executable will get off. To still retrieve symbols correctly, | |
| 149 // add the directory of the executable to symbol search path. | |
| 150 // All following errors are non-fatal. | |
| 151 wchar_t symbols_path[1024]; | |
| 152 if (!SymGetSearchPathW(GetCurrentProcess(), | |
| 153 symbols_path, | |
| 154 sizeof(symbols_path))) { | |
|
cpu_(ooo_6.6-7.5)
2013/03/07 20:31:50
last parameter looks incorrect, I don't think it i
| |
| 155 DLOG(WARNING) << "SymGetSearchPath failed: "; | |
| 156 return; | |
| 157 } | |
| 158 | |
| 159 FilePath module_path; | |
| 160 if (!PathService::Get(FILE_EXE, &module_path)) { | |
| 161 DLOG(WARNING) << "PathService::Get(FILE_EXE) failed."; | |
| 162 return; | |
| 163 } | |
| 164 | |
| 165 std::wstring new_path(std::wstring(symbols_path) + | |
| 166 L";" + module_path.DirName().value()); | |
| 167 if (!SymSetSearchPathW(GetCurrentProcess(), new_path.c_str())) { | |
| 168 DLOG(WARNING) << "SymSetSearchPath failed."; | |
| 169 return; | |
| 142 } | 170 } |
| 143 } | 171 } |
| 144 | 172 |
| 145 DWORD init_error_; | 173 DWORD init_error_; |
| 146 base::Lock lock_; | 174 base::Lock lock_; |
| 147 DISALLOW_COPY_AND_ASSIGN(SymbolContext); | 175 DISALLOW_COPY_AND_ASSIGN(SymbolContext); |
| 148 }; | 176 }; |
| 149 | 177 |
| 150 } // namespace | 178 } // namespace |
| 151 | 179 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 (*os) << "\t" << trace_[i] << "\n"; | 254 (*os) << "\t" << trace_[i] << "\n"; |
| 227 } | 255 } |
| 228 } else { | 256 } else { |
| 229 (*os) << "Backtrace:\n"; | 257 (*os) << "Backtrace:\n"; |
| 230 context->OutputTraceToStream(trace_, count_, os); | 258 context->OutputTraceToStream(trace_, count_, os); |
| 231 } | 259 } |
| 232 } | 260 } |
| 233 | 261 |
| 234 } // namespace debug | 262 } // namespace debug |
| 235 } // namespace base | 263 } // namespace base |
| OLD | NEW |