Implement Runtime::Abort and switch LOG(FATAL) over to it.

Runtime::Abort takes arguments so it can provide less misleading log output,
but this shouldn't matter to callers because they should be using LOG(FATAL)
anyway.

This patch also fixes an errno/errno_ mixup in the logging code.

Change-Id: If24b66b7bbf0bf7c0ecb93dd806d82b1d21ee239
diff --git a/src/runtime_linux.cc b/src/runtime_linux.cc
new file mode 100644
index 0000000..e59111f
--- /dev/null
+++ b/src/runtime_linux.cc
@@ -0,0 +1,37 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+// Author: enh@google.com (Elliott Hughes)
+
+#include "runtime.h"
+
+#include <execinfo.h>
+
+#include "logging.h"
+#include "scoped_ptr.h"
+#include "stringprintf.h"
+
+namespace art {
+
+void Runtime::PlatformAbort(const char* file, int line) {
+  // On the host, we don't have debuggerd to dump a stack for us.
+
+  // Get the raw stack frames.
+  size_t MAX_STACK_FRAMES = 64;
+  void* frames[MAX_STACK_FRAMES];
+  size_t frame_count = backtrace(frames, MAX_STACK_FRAMES);
+
+  // Turn them into something human-readable with symbols.
+  // TODO: in practice, we may find that we should use backtrace_symbols_fd
+  // to avoid allocation, rather than use our own custom formatting.
+  art::scoped_ptr_malloc<char*> symbols(backtrace_symbols(frames, frame_count));
+  if (symbols.get() == NULL) {
+    PLOG(ERROR) << "backtrace_symbols failed";
+    return;
+  }
+
+  for (size_t i = 0; i < frame_count; ++i) {
+    LogMessage(file, line, ERROR, -1).stream()
+        << StringPrintf("\t#%02d %s", i, symbols.get()[i]);
+  }
+}
+
+}  // namespace art