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