Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2361)

Unified Diff: base/debug/stack_trace_android.cc

Issue 16770006: Implement basic stack traces on Android and reenable unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/base.gyp ('k') | base/debug/stack_trace_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/stack_trace_android.cc
diff --git a/base/debug/stack_trace_android.cc b/base/debug/stack_trace_android.cc
index 050a2d8c501904b17e3bee5cf13993fafd639026..067c5ba67a0bec214462d7f1fc6b225c93de0ea4 100644
--- a/base/debug/stack_trace_android.cc
+++ b/base/debug/stack_trace_android.cc
@@ -9,7 +9,8 @@
#include <unistd.h>
#include <unwind.h> // TODO(dmikurube): Remove. See http://crbug.com/236855.
-#include "base/logging.h"
+#include "base/stringprintf.h"
+#include "base/third_party/symbolize/symbolize.h"
#ifdef __MIPSEL__
// SIGSTKFLT is not defined for MIPS.
@@ -96,6 +97,9 @@ StackTrace::StackTrace() {
// Sends fake SIGSTKFLT signals to let the Android linker and debuggerd dump
// stack. See inlined comments and Android bionic/linker/debugger.c and
// system/core/debuggerd/debuggerd.c for details.
+//
+// TODO(scherkus): This should probably use OutputToStream() and print to
+// stderr. Instead it crashes the program http://crbug.com/248775
digit 2013/06/13 08:17:25 Small clarification here: outputting to stderr wil
void StackTrace::PrintBacktrace() const {
// Get the current handler of SIGSTKFLT for later use.
sighandler_t sig_handler = signal(SIGSTKFLT, SIG_DFL);
@@ -117,8 +121,29 @@ void StackTrace::PrintBacktrace() const {
signal(SIGSTKFLT, sig_handler);
digit 2013/06/13 08:17:25 Note: Oops, we should never use signal() to save/r
}
+// NOTE: Native libraries in APKs are stripped before installing. Print out the
+// relocatable address and library names so host computers can use tools to
+// symbolize and demangle (e.g., addr2line, c++filt).
void StackTrace::OutputToStream(std::ostream* os) const {
- NOTIMPLEMENTED();
+ for (size_t i = 0; i < count_; ++i) {
+ *os << base::StringPrintf("#%02d ", i);
+
+ // Subtract by one as return address of function may be in the next
+ // function when a function is annotated as noreturn.
+ void* address = static_cast<char*>(trace_[i]) - 1;
+
+ char path[1024];
+ uint64 start_address = 0;
+ if (google::FindObjectFileNameContainingPcAndGetStartAddress(
+ address, path, sizeof(path), &start_address)) {
+ uintptr_t rel_pc = reinterpret_cast<uintptr_t>(address) - start_address;
+ *os << base::StringPrintf("pc %08x %s", rel_pc, path);
satorux1 2013/06/13 03:34:25 http://google-styleguide.googlecode.com/svn/trunk/
digit 2013/06/13 08:17:25 nit: That would be very wrong, uintptr_t is always
scherkus (not reviewing) 2013/06/13 17:35:05 Open to ideas ... I tried using PRIxPTR but got si
satorux1 2013/06/14 01:45:41 Ah, I misunderstood that we were handling uint64 h
+ } else {
+ *os << "<unknown>";
digit 2013/06/13 08:17:25 I'd suggest printing the address value as well, ju
scherkus (not reviewing) 2013/06/13 17:35:05 Done.
+ }
+
+ *os << "\n";
+ }
}
} // namespace debug
« no previous file with comments | « base/base.gyp ('k') | base/debug/stack_trace_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698