From 1e068aea46aede60db6c8fe4410fd6d2633ce2da Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 19 Aug 2012 16:04:36 -0400 Subject: [PATCH] Slight improvement to tracing output. - If a trace entry has a stack trace, attempt to demangle the associated symbols. Could be enhanced further to also demangle the arguments but doesn't yet. Interestingly there are some mangled symbols that our demangler appears to not handle correctly (gcc4). --- src/system/kernel/debug/tracing.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/system/kernel/debug/tracing.cpp b/src/system/kernel/debug/tracing.cpp index 72cbb959aa..b9ecd1618c 100644 --- a/src/system/kernel/debug/tracing.cpp +++ b/src/system/kernel/debug/tracing.cpp @@ -1,6 +1,7 @@ /* * Copyright 2008-2011, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2008-2009, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2012, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -13,6 +14,7 @@ #include #include +#include #include #include #include @@ -141,22 +143,37 @@ print_stack_trace(struct tracing_stack_trace* stackTrace, if (stackTrace == NULL || stackTrace->depth <= 0) return; + static const size_t kBufferSize = 256; + char* buffer = (char*)debug_malloc(kBufferSize); + for (int32 i = 0; i < stackTrace->depth; i++) { addr_t address = stackTrace->return_addresses[i]; const char* symbol; + const char* demangledName = NULL; const char* imageName; bool exactMatch; addr_t baseAddress; if (elf_debug_lookup_symbol_address(address, &baseAddress, &symbol, &imageName, &exactMatch) == B_OK) { - print(" %p %s + 0x%lx (%s)%s\n", (void*)address, symbol, + + if (buffer != NULL) { + bool isObjectMethod; + demangledName = debug_demangle_symbol(symbol, buffer, + kBufferSize, &isObjectMethod); + } + + print(" %p %s + 0x%lx (%s)%s\n", (void*)address, + demangledName != NULL ? demangledName : symbol, address - baseAddress, imageName, exactMatch ? "" : " (nearest)"); } else print(" %p\n", (void*)address); } + + if (buffer != NULL) + debug_free(buffer); }