Rewrite libbacktrace using C++.
The old code was essentially trying to be C++ in C and was awkward. This
change makes it all objects with a thin layer that C code can use.
There is a C++ backtrace object that is not very useful, this code will
replace it.
This change also includes moving the backtrace test to a gtest, and adding
coverage of all major functionality.
Bug: 8410085
Change-Id: Iae0f1b09b3dd60395f71ed66010c1ea5cdd37841
diff --git a/libbacktrace/backtrace_testlib.c b/libbacktrace/backtrace_testlib.c
index 9400549..d4d15db 100644
--- a/libbacktrace/backtrace_testlib.c
+++ b/libbacktrace/backtrace_testlib.c
@@ -14,13 +14,12 @@
* limitations under the License.
*/
-#include <stdbool.h>
-#include <unistd.h>
+#include <stdio.h>
int test_level_four(int one, int two, int three, int four,
- bool (*callback_func)(pid_t)) {
+ void (*callback_func)(void*), void* data) {
if (callback_func != NULL) {
- callback_func(-1);
+ callback_func(data);
} else {
while (1) {
}
@@ -29,25 +28,25 @@
}
int test_level_three(int one, int two, int three, int four,
- bool (*callback_func)(pid_t)) {
- return test_level_four(one+3, two+6, three+9, four+12, callback_func) + 3;
+ void (*callback_func)(void*), void* data) {
+ return test_level_four(one+3, two+6, three+9, four+12, callback_func, data) + 3;
}
int test_level_two(int one, int two, int three, int four,
- bool (*callback_func)(pid_t)) {
- return test_level_three(one+2, two+4, three+6, four+8, callback_func) + 2;
+ void (*callback_func)(void*), void* data) {
+ return test_level_three(one+2, two+4, three+6, four+8, callback_func, data) + 2;
}
int test_level_one(int one, int two, int three, int four,
- bool (*callback_func)(pid_t)) {
- return test_level_two(one+1, two+2, three+3, four+4, callback_func) + 1;
+ void (*callback_func)(void*), void* data) {
+ return test_level_two(one+1, two+2, three+3, four+4, callback_func, data) + 1;
}
-int test_recursive_call(int level, bool (*callback_func)(pid_t)) {
+int test_recursive_call(int level, void (*callback_func)(void*), void* data) {
if (level > 0) {
- return test_recursive_call(level - 1, callback_func) + level;
+ return test_recursive_call(level - 1, callback_func, data) + level;
} else if (callback_func != NULL) {
- callback_func(-1);
+ callback_func(data);
} else {
while (1) {
}