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

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: refactor symbolize 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
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..7c567a3e186de5c4b52cd8a5389c51ba125a7248 100644
--- a/base/debug/stack_trace_android.cc
+++ b/base/debug/stack_trace_android.cc
@@ -8,8 +8,9 @@
#include <sys/types.h>
#include <unistd.h>
#include <unwind.h> // TODO(dmikurube): Remove. See http://crbug.com/236855.
+#include <iomanip>
-#include "base/logging.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
void StackTrace::PrintBacktrace() const {
// Get the current handler of SIGSTKFLT for later use.
sighandler_t sig_handler = signal(SIGSTKFLT, SIG_DFL);
@@ -118,7 +122,33 @@ void StackTrace::PrintBacktrace() const {
}
void StackTrace::OutputToStream(std::ostream* os) const {
- NOTIMPLEMENTED();
+ std::ios_base::fmtflags flags = os->flags();
+
+ for (size_t i = 0; i < count_; ++i) {
+ // 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).
+ char path[1024];
+ uint64 start_address;
satorux1 2013/06/13 01:58:10 Please move them to where these are used. I'd als
scherkus (not reviewing) 2013/06/13 02:20:46 Done.
+
+ *os << "#" << std::dec << std::setfill('0') << std::setw(2) << i << " ";
satorux1 2013/06/13 01:58:10 For formatting, I think base::StringPrintf() is mo
scherkus (not reviewing) 2013/06/13 02:20:46 Yeah -- part of me wanted to make things async saf
satorux1 2013/06/13 03:34:25 For now, maybe add a TODO comment?
+
+ // 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;
+ if (google::FindObjectFileNameContainingPcAndGetStartAddress(
+ address, path, sizeof(path), &start_address)) {
+ uintptr_t rel_pc = reinterpret_cast<uintptr_t>(address) - start_address;
+ *os << "pc " << std::hex << std::setfill('0') << std::setw(8) << rel_pc
+ << " " << path;
+ } else {
+ *os << "<unknown>";
+ }
+
+ *os << "\n";
+ }
+
+ os->flags(flags);
}
} // namespace debug

Powered by Google App Engine
This is Rietveld 408576698