OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 DWORD init_error_; | 131 DWORD init_error_; |
132 base::Lock lock_; | 132 base::Lock lock_; |
133 DISALLOW_COPY_AND_ASSIGN(SymbolContext); | 133 DISALLOW_COPY_AND_ASSIGN(SymbolContext); |
134 }; | 134 }; |
135 | 135 |
136 } // namespace | 136 } // namespace |
137 | 137 |
| 138 // Disable optimizations for the StackTrace::StackTrace function. It is |
| 139 // important to disable at least frame pointer optimization ("y"), since |
| 140 // that breaks CaptureStackBackTrace() and prevents StackTrace from working |
| 141 // in Release builds (it may still be janky if other frames are using FPO, |
| 142 // but at least it will make it further). |
| 143 #if defined(COMPILER_MSVC) |
| 144 #pragma optimize("", off) |
| 145 #endif |
| 146 |
138 StackTrace::StackTrace() { | 147 StackTrace::StackTrace() { |
139 // When walking our own stack, use CaptureStackBackTrace(). | 148 // When walking our own stack, use CaptureStackBackTrace(). |
140 count_ = CaptureStackBackTrace(0, arraysize(trace_), trace_, NULL); | 149 count_ = CaptureStackBackTrace(0, arraysize(trace_), trace_, NULL); |
141 } | 150 } |
142 | 151 |
| 152 #if defined(COMPILER_MSVC) |
| 153 #pragma optimize("", on) |
| 154 #endif |
| 155 |
143 StackTrace::StackTrace(EXCEPTION_POINTERS* exception_pointers) { | 156 StackTrace::StackTrace(EXCEPTION_POINTERS* exception_pointers) { |
144 // When walking an exception stack, we need to use StackWalk64(). | 157 // When walking an exception stack, we need to use StackWalk64(). |
145 count_ = 0; | 158 count_ = 0; |
146 // Initialize stack walking. | 159 // Initialize stack walking. |
147 STACKFRAME64 stack_frame; | 160 STACKFRAME64 stack_frame; |
148 memset(&stack_frame, 0, sizeof(stack_frame)); | 161 memset(&stack_frame, 0, sizeof(stack_frame)); |
149 #if defined(_WIN64) | 162 #if defined(_WIN64) |
150 int machine_type = IMAGE_FILE_MACHINE_AMD64; | 163 int machine_type = IMAGE_FILE_MACHINE_AMD64; |
151 stack_frame.AddrPC.Offset = exception_pointers->ContextRecord->Rip; | 164 stack_frame.AddrPC.Offset = exception_pointers->ContextRecord->Rip; |
152 stack_frame.AddrFrame.Offset = exception_pointers->ContextRecord->Rbp; | 165 stack_frame.AddrFrame.Offset = exception_pointers->ContextRecord->Rbp; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 (*os) << "\t" << trace_[i] << "\n"; | 201 (*os) << "\t" << trace_[i] << "\n"; |
189 } | 202 } |
190 } else { | 203 } else { |
191 (*os) << "Backtrace:\n"; | 204 (*os) << "Backtrace:\n"; |
192 context->OutputTraceToStream(trace_, count_, os); | 205 context->OutputTraceToStream(trace_, count_, os); |
193 } | 206 } |
194 } | 207 } |
195 | 208 |
196 } // namespace debug | 209 } // namespace debug |
197 } // namespace base | 210 } // namespace base |
OLD | NEW |