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 |