Merge "Let external/mksh install directly into /system/bin/sh."
diff --git a/include/backtrace/backtrace.h b/include/backtrace/backtrace.h
index b35a6d5..8a45690 100644
--- a/include/backtrace/backtrace.h
+++ b/include/backtrace/backtrace.h
@@ -17,12 +17,20 @@
 #ifndef _BACKTRACE_H
 #define _BACKTRACE_H
 
-#include <sys/types.h>
+#include <stdint.h>
 #include <stdbool.h>
-#include <inttypes.h>
+#include <sys/types.h>
 
 __BEGIN_DECLS
 
+// When the pid to be traced is set to this value, then trace the current
+// process. If the tid value is not BACKTRACE_NO_TID, then the specified
+// thread from the current process will be traced.
+#define BACKTRACE_CURRENT_PROCESS -1
+// When the tid to be traced is set to this value, then trace the specified
+// pid.
+#define BACKTRACE_NO_TID -1
+
 #define MAX_BACKTRACE_FRAMES 64
 
 typedef struct backtrace_map_info {
diff --git a/libbacktrace/Android.mk b/libbacktrace/Android.mk
index 66d7e62..eb55b47 100644
--- a/libbacktrace/Android.mk
+++ b/libbacktrace/Android.mk
@@ -23,7 +23,7 @@
 	liblog \
 
 # To enable using libunwind on each arch, add it to the list below.
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),))
+ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm))
 
 #----------------------------------------------------------------------------
 # The native libbacktrace library with libunwind.
@@ -137,6 +137,7 @@
 	thread_utils.c \
 
 LOCAL_CFLAGS += \
+	$(common_cflags) \
 	-fno-builtin \
 	-fstack-protector-all \
 	-O0 \
@@ -149,7 +150,6 @@
 
 LOCAL_CPPFLAGS += \
 	$(common_cppflags) \
-	-fpermissive \
 
 LOCAL_SHARED_LIBRARIES += \
 	libcutils \
@@ -241,6 +241,7 @@
 	thread_utils.c \
 
 LOCAL_CFLAGS += \
+	$(common_cflags) \
 	-fno-builtin \
 	-fstack-protector-all \
 	-O0 \
@@ -251,9 +252,6 @@
 	libbacktrace_test \
 	libbacktrace \
 
-LOCAL_CPPFLAGS += \
-	-fpermissive \
-
 LOCAL_LDLIBS := \
 	-lpthread \
 
diff --git a/libbacktrace/Backtrace.cpp b/libbacktrace/Backtrace.cpp
index 17d9e1d..b22d301 100644
--- a/libbacktrace/Backtrace.cpp
+++ b/libbacktrace/Backtrace.cpp
@@ -213,13 +213,13 @@
 }
 
 Backtrace* Backtrace::Create(pid_t pid, pid_t tid) {
-  if (pid < 0 || pid == getpid()) {
-    if (tid < 0 || tid == gettid()) {
+  if (pid == BACKTRACE_CURRENT_PROCESS || pid == getpid()) {
+    if (tid == BACKTRACE_NO_TID || tid == gettid()) {
       return CreateCurrentObj();
     } else {
       return CreateThreadObj(tid);
     }
-  } else if (tid < 0) {
+  } else if (tid == BACKTRACE_NO_TID) {
     return CreatePtraceObj(pid, pid);
   } else {
     return CreatePtraceObj(pid, tid);
diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp
index 48e2bdc..2603e1f 100644
--- a/libbacktrace/backtrace_test.cpp
+++ b/libbacktrace/backtrace_test.cpp
@@ -143,7 +143,7 @@
 void VerifyLevelBacktrace(void*) {
   backtrace_context_t context;
 
-  ASSERT_TRUE(backtrace_create_context(&context, -1, -1, 0));
+  ASSERT_TRUE(backtrace_create_context(&context, BACKTRACE_CURRENT_PROCESS, BACKTRACE_NO_TID, 0));
 
   VerifyLevelDump(context.backtrace);
 
@@ -165,7 +165,7 @@
 void VerifyMaxBacktrace(void*) {
   backtrace_context_t context;
 
-  ASSERT_TRUE(backtrace_create_context(&context, -1, -1, 0));
+  ASSERT_TRUE(backtrace_create_context(&context, BACKTRACE_CURRENT_PROCESS, BACKTRACE_NO_TID, 0));
 
   VerifyMaxDump(context.backtrace);
 
@@ -232,15 +232,15 @@
 
 void VerifyLevelIgnoreFrames(void*) {
   backtrace_context_t all;
-  ASSERT_TRUE(backtrace_create_context(&all, -1, -1, 0));
+  ASSERT_TRUE(backtrace_create_context(&all, BACKTRACE_CURRENT_PROCESS, BACKTRACE_NO_TID, 0));
   ASSERT_TRUE(all.backtrace != NULL);
 
   backtrace_context_t ign1;
-  ASSERT_TRUE(backtrace_create_context(&ign1, -1, -1, 1));
+  ASSERT_TRUE(backtrace_create_context(&ign1, BACKTRACE_CURRENT_PROCESS, BACKTRACE_NO_TID, 1));
   ASSERT_TRUE(ign1.backtrace != NULL);
 
   backtrace_context_t ign2;
-  ASSERT_TRUE(backtrace_create_context(&ign2, -1, -1, 2));
+  ASSERT_TRUE(backtrace_create_context(&ign2, BACKTRACE_CURRENT_PROCESS, BACKTRACE_NO_TID, 2));
   ASSERT_TRUE(ign2.backtrace != NULL);
 
   VerifyIgnoreFrames(all.backtrace, ign1.backtrace, ign2.backtrace,
@@ -296,7 +296,7 @@
     ASSERT_NE(test_level_one(1, 2, 3, 4, NULL, NULL), 0);
     exit(1);
   }
-  VerifyProcTest(pid, -1, ReadyLevelBacktrace, VerifyLevelDump);
+  VerifyProcTest(pid, BACKTRACE_NO_TID, ReadyLevelBacktrace, VerifyLevelDump);
 
   kill(pid, SIGKILL);
   int status;
@@ -309,7 +309,7 @@
     ASSERT_NE(test_recursive_call(MAX_BACKTRACE_FRAMES+10, NULL, NULL), 0);
     exit(1);
   }
-  VerifyProcTest(pid, -1, ReadyMaxBacktrace, VerifyMaxDump);
+  VerifyProcTest(pid, BACKTRACE_NO_TID, ReadyMaxBacktrace, VerifyMaxDump);
 
   kill(pid, SIGKILL);
   int status;
@@ -320,11 +320,11 @@
   pid_t pid = bt_all->pid;
 
   backtrace_context_t ign1;
-  ASSERT_TRUE(backtrace_create_context(&ign1, pid, -1, 1));
+  ASSERT_TRUE(backtrace_create_context(&ign1, pid, BACKTRACE_NO_TID, 1));
   ASSERT_TRUE(ign1.backtrace != NULL);
 
   backtrace_context_t ign2;
-  ASSERT_TRUE(backtrace_create_context(&ign2, pid, -1, 2));
+  ASSERT_TRUE(backtrace_create_context(&ign2, pid, BACKTRACE_NO_TID, 2));
   ASSERT_TRUE(ign2.backtrace != NULL);
 
   VerifyIgnoreFrames(bt_all, ign1.backtrace, ign2.backtrace, NULL);
@@ -339,7 +339,7 @@
     ASSERT_NE(test_level_one(1, 2, 3, 4, NULL, NULL), 0);
     exit(1);
   }
-  VerifyProcTest(pid, -1, ReadyLevelBacktrace, VerifyProcessIgnoreFrames);
+  VerifyProcTest(pid, BACKTRACE_NO_TID, ReadyLevelBacktrace, VerifyProcessIgnoreFrames);
 
   kill(pid, SIGKILL);
   int status;
@@ -614,10 +614,10 @@
 TEST(libbacktrace, format_test) {
   backtrace_context_t context;
 
-  ASSERT_TRUE(backtrace_create_context(&context, -1, -1, 0));
+  ASSERT_TRUE(backtrace_create_context(&context, BACKTRACE_CURRENT_PROCESS, BACKTRACE_NO_TID, 0));
   ASSERT_TRUE(context.backtrace != NULL);
 
-  backtrace_frame_data_t* frame = &context.backtrace->frames[1];
+  backtrace_frame_data_t* frame = const_cast<backtrace_frame_data_t*>(&context.backtrace->frames[1]);
   backtrace_frame_data_t save_frame = *frame;
 
   memset(frame, 0, sizeof(backtrace_frame_data_t));
@@ -638,7 +638,7 @@
   EXPECT_STREQ(buf, "#01 pc 12345678  MapFake");
 #endif
 
-  frame->func_name = "ProcFake";
+  frame->func_name = const_cast<char*>("ProcFake");
   backtrace_format_frame_data(&context, 1, buf, sizeof(buf));
 #if defined(__LP64__)
   EXPECT_STREQ(buf, "#01 pc 0000000012345678  MapFake (ProcFake)");