libunwind: Fix unw_step() for ARM EHABI.

This commit fixes the unw_step() for ARM EHABI.  However, this commit
also changes the implementation details for ARM EHABI.

The first change is that the personality function should call
__gnu_unwind_frame() for default (or de facto) frame unwinding based on
the ARM-defined unwind opcode.  The function __gnu_unwind_frame() will
in turn calls unw_step() which actually unwinds the frame.

The second change is that the implementation _Unwind_Backtrace() should
no longer calls unw_step() to unwind the frame; since according to ARM
EHABI, the personality function should unwind the frame for us.

Special thanks to Anton for helpful suggestion on the initial version of
this patch.

llvm-svn: 238560
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 7fab97f364d2e2f0beb7fffa3e42885db72982d5
diff --git a/test/libunwind_02.pass.cpp b/test/libunwind_02.pass.cpp
new file mode 100644
index 0000000..892c087
--- /dev/null
+++ b/test/libunwind_02.pass.cpp
@@ -0,0 +1,37 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <unwind.h>
+
+#define EXPECTED_NUM_FRAMES 50
+#define NUM_FRAMES_UPPER_BOUND 100
+
+_Unwind_Reason_Code callback(_Unwind_Context *context, void *cnt) {
+  int *i = (int *)cnt;
+  ++*i;
+  if (*i > NUM_FRAMES_UPPER_BOUND) {
+    abort();
+  }
+  return _URC_NO_REASON;
+}
+
+void test_backtrace() {
+  int n = 0;
+  _Unwind_Backtrace(&callback, &n);
+  if (n < EXPECTED_NUM_FRAMES) {
+    abort();
+  }
+}
+
+int test(int i) {
+  if (i == 0) {
+    test_backtrace();
+    return 0;
+  } else {
+    return i + test(i - 1);
+  }
+}
+
+int main() {
+  int total = test(50);
+  assert(total == 1275);
+}