OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
(...skipping 18 matching lines...) Expand all Loading... |
29 // badly with breakpad if breakpad is invoked in a separate thread while | 29 // badly with breakpad if breakpad is invoked in a separate thread while |
30 // we are using the Sym* functions. This is because breakpad does now | 30 // we are using the Sym* functions. This is because breakpad does now |
31 // share a lock with this function. See this related bug: | 31 // share a lock with this function. See this related bug: |
32 // | 32 // |
33 // http://code.google.com/p/google-breakpad/issues/detail?id=311 | 33 // http://code.google.com/p/google-breakpad/issues/detail?id=311 |
34 // | 34 // |
35 // This is a very unlikely edge case, and the current solution is to | 35 // This is a very unlikely edge case, and the current solution is to |
36 // just ignore it. | 36 // just ignore it. |
37 class SymbolContext { | 37 class SymbolContext { |
38 public: | 38 public: |
39 static SymbolContext* Get() { | 39 static SymbolContext* GetInstance() { |
40 // We use a leaky singleton because code may call this during process | 40 // We use a leaky singleton because code may call this during process |
41 // termination. | 41 // termination. |
42 return | 42 return |
43 Singleton<SymbolContext, LeakySingletonTraits<SymbolContext> >::get(); | 43 Singleton<SymbolContext, LeakySingletonTraits<SymbolContext> >::get(); |
44 } | 44 } |
45 | 45 |
46 // Returns the error code of a failed initialization. | 46 // Returns the error code of a failed initialization. |
47 DWORD init_error() const { | 47 DWORD init_error() const { |
48 return init_error_; | 48 return init_error_; |
49 } | 49 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 count_ < arraysize(trace_)) { | 172 count_ < arraysize(trace_)) { |
173 trace_[count_++] = reinterpret_cast<void*>(stack_frame.AddrPC.Offset); | 173 trace_[count_++] = reinterpret_cast<void*>(stack_frame.AddrPC.Offset); |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 void StackTrace::PrintBacktrace() { | 177 void StackTrace::PrintBacktrace() { |
178 OutputToStream(&std::cerr); | 178 OutputToStream(&std::cerr); |
179 } | 179 } |
180 | 180 |
181 void StackTrace::OutputToStream(std::ostream* os) { | 181 void StackTrace::OutputToStream(std::ostream* os) { |
182 SymbolContext* context = SymbolContext::Get(); | 182 SymbolContext* context = SymbolContext::GetInstance(); |
183 DWORD error = context->init_error(); | 183 DWORD error = context->init_error(); |
184 if (error != ERROR_SUCCESS) { | 184 if (error != ERROR_SUCCESS) { |
185 (*os) << "Error initializing symbols (" << error | 185 (*os) << "Error initializing symbols (" << error |
186 << "). Dumping unresolved backtrace:\n"; | 186 << "). Dumping unresolved backtrace:\n"; |
187 for (int i = 0; (i < count_) && os->good(); ++i) { | 187 for (int i = 0; (i < count_) && os->good(); ++i) { |
188 (*os) << "\t" << trace_[i] << "\n"; | 188 (*os) << "\t" << trace_[i] << "\n"; |
189 } | 189 } |
190 } else { | 190 } else { |
191 (*os) << "Backtrace:\n"; | 191 (*os) << "Backtrace:\n"; |
192 context->OutputTraceToStream(trace_, count_, os); | 192 context->OutputTraceToStream(trace_, count_, os); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 } // namespace debug | 196 } // namespace debug |
197 } // namespace base | 197 } // namespace base |
OLD | NEW |