mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-15 12:39:19 +00:00
7fab97f364
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
38 lines
615 B
C++
38 lines
615 B
C++
#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);
|
|
}
|