summaryrefslogtreecommitdiffstats
path: root/base/debug_util_win.cc
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-08 23:53:53 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-08 23:53:53 +0000
commit0fe31f2ba217cceb277b670e2812667c3aee8e80 (patch)
tree3d2adea86b5d61d297318ea60c3faf1b1636c996 /base/debug_util_win.cc
parent2f66ed584522a2383f0f7193b264b3da7928eb82 (diff)
downloadchromium_src-0fe31f2ba217cceb277b670e2812667c3aee8e80.zip
chromium_src-0fe31f2ba217cceb277b670e2812667c3aee8e80.tar.gz
chromium_src-0fe31f2ba217cceb277b670e2812667c3aee8e80.tar.bz2
Print stack trace on exception in unit tests on Windows.
Also remove std::vector<> from StackTrace to reduce heap usage during potential unstable execution. TEST=none BUG=http://crbug.com/20996 Review URL: http://codereview.chromium.org/201050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25685 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/debug_util_win.cc')
-rw-r--r--base/debug_util_win.cc56
1 files changed, 40 insertions, 16 deletions
diff --git a/base/debug_util_win.cc b/base/debug_util_win.cc
index 08bfb41..8adbf8f 100644
--- a/base/debug_util_win.cc
+++ b/base/debug_util_win.cc
@@ -105,10 +105,12 @@ class SymbolContext {
// This function should only be called if Init() has been called. We do not
// LOG(FATAL) here because this code is called might be triggered by a
// LOG(FATAL) itself.
- void OutputTraceToStream(const std::vector<void*>& trace, std::ostream* os) {
+ void OutputTraceToStream(const void* const* trace,
+ int count,
+ std::ostream* os) {
AutoLock lock(lock_);
- for (size_t i = 0; (i < trace.size()) && os->good(); ++i) {
+ for (size_t i = 0; (i < count) && os->good(); ++i) {
const int kMaxNameLength = 256;
DWORD_PTR frame = reinterpret_cast<DWORD_PTR>(trace[i]);
@@ -220,19 +222,41 @@ void DebugUtil::BreakDebugger() {
}
StackTrace::StackTrace() {
- // From http://msdn.microsoft.com/en-us/library/bb204633(VS.85).aspx,
- // the sum of FramesToSkip and FramesToCapture must be less than 63,
- // so set it to 62.
- const int kMaxCallers = 62;
+ // When walking our own stack, use CaptureStackBackTrace().
+ count_ = CaptureStackBackTrace(0, arraysize(trace_), trace_, NULL);
+}
- void* callers[kMaxCallers];
- // TODO(ajwong): Migrate this to StackWalk64.
- int count = CaptureStackBackTrace(0, kMaxCallers, callers, NULL);
- if (count > 0) {
- trace_.resize(count);
- memcpy(&trace_[0], callers, sizeof(callers[0]) * count);
- } else {
- trace_.resize(0);
+StackTrace::StackTrace(EXCEPTION_POINTERS* exception_pointers) {
+ // When walking an exception stack, we need to use StackWalk64().
+ count_ = 0;
+ // Initialize stack walking.
+ STACKFRAME64 stack_frame;
+ memset(&stack_frame, 0, sizeof(stack_frame));
+#if defined(_WIN64)
+ int machine_type = IMAGE_FILE_MACHINE_AMD64;
+ stack_frame.AddrPC.Offset = exception_pointers->ContextRecord->Rip;
+ stack_frame.AddrFrame.Offset = exception_pointers->ContextRecord->Rbp;
+ stack_frame.AddrStack.Offset = exception_pointers->ContextRecord->Rsp;
+#else
+ int machine_type = IMAGE_FILE_MACHINE_I386;
+ stack_frame.AddrPC.Offset = exception_pointers->ContextRecord->Eip;
+ stack_frame.AddrFrame.Offset = exception_pointers->ContextRecord->Ebp;
+ stack_frame.AddrStack.Offset = exception_pointers->ContextRecord->Esp;
+#endif
+ stack_frame.AddrPC.Mode = AddrModeFlat;
+ stack_frame.AddrFrame.Mode = AddrModeFlat;
+ stack_frame.AddrStack.Mode = AddrModeFlat;
+ while (StackWalk64(machine_type,
+ GetCurrentProcess(),
+ GetCurrentThread(),
+ &stack_frame,
+ exception_pointers->ContextRecord,
+ NULL,
+ &SymFunctionTableAccess64,
+ &SymGetModuleBase64,
+ NULL) &&
+ count_ < arraysize(trace_)) {
+ trace_[count_++] = reinterpret_cast<void*>(stack_frame.AddrPC.Offset);
}
}
@@ -246,11 +270,11 @@ void StackTrace::OutputToStream(std::ostream* os) {
if (error != ERROR_SUCCESS) {
(*os) << "Error initializing symbols (" << error
<< "). Dumping unresolved backtrace:\n";
- for (size_t i = 0; (i < trace_.size()) && os->good(); ++i) {
+ for (int i = 0; (i < count_) && os->good(); ++i) {
(*os) << "\t" << trace_[i] << "\n";
}
} else {
(*os) << "Backtrace:\n";
- context->OutputTraceToStream(trace_, os);
+ context->OutputTraceToStream(trace_, count_, os);
}
}