Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 2 | |
| 3 | #include "runtime.h" |
| 4 | |
| 5 | #include <execinfo.h> |
| 6 | |
| 7 | #include "logging.h" |
| 8 | #include "scoped_ptr.h" |
| 9 | #include "stringprintf.h" |
| 10 | |
| 11 | namespace art { |
| 12 | |
| 13 | void Runtime::PlatformAbort(const char* file, int line) { |
| 14 | // On the host, we don't have debuggerd to dump a stack for us. |
| 15 | |
| 16 | // Get the raw stack frames. |
| 17 | size_t MAX_STACK_FRAMES = 64; |
| 18 | void* frames[MAX_STACK_FRAMES]; |
| 19 | size_t frame_count = backtrace(frames, MAX_STACK_FRAMES); |
| 20 | |
| 21 | // Turn them into something human-readable with symbols. |
| 22 | // TODO: in practice, we may find that we should use backtrace_symbols_fd |
| 23 | // to avoid allocation, rather than use our own custom formatting. |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 24 | scoped_ptr_malloc<char*> symbols(backtrace_symbols(frames, frame_count)); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 25 | if (symbols == NULL) { |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 26 | PLOG(ERROR) << "backtrace_symbols failed"; |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | for (size_t i = 0; i < frame_count; ++i) { |
| 31 | LogMessage(file, line, ERROR, -1).stream() |
| 32 | << StringPrintf("\t#%02d %s", i, symbols.get()[i]); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | } // namespace art |