blob: e4bc0353682f6702eceb2a0b53ea8131e8253516 [file] [log] [blame]
Elliott Hughesffe67362011-07-17 12:09:27 -07001// Copyright 2011 Google Inc. All Rights Reserved.
Elliott Hughesffe67362011-07-17 12:09:27 -07002
3#include "runtime.h"
4
5#include <execinfo.h>
6
7#include "logging.h"
8#include "scoped_ptr.h"
9#include "stringprintf.h"
10
11namespace art {
12
13void 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 Shapiro2ed144c2011-07-26 16:52:08 -070024 scoped_ptr_malloc<char*> symbols(backtrace_symbols(frames, frame_count));
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070025 if (symbols == NULL) {
Elliott Hughesffe67362011-07-17 12:09:27 -070026 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