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/debuggerd/backtrace.c b/debuggerd/backtrace.c
index 6f82792..aa7a3c2 100644
--- a/debuggerd/backtrace.c
+++ b/debuggerd/backtrace.c
@@ -89,12 +89,12 @@
wait_for_stop(tid, total_sleep_time_usec);
- backtrace_t backtrace;
- if (!backtrace_get_data(&backtrace, tid)) {
+ backtrace_context_t context;
+ if (!backtrace_create_context(&context, tid, -1, 0)) {
_LOG(log, SCOPE_AT_FAULT, "Could not create backtrace context.\n");
} else {
- dump_backtrace_to_log(&backtrace, log, SCOPE_AT_FAULT, " ");
- backtrace_free_data(&backtrace);
+ dump_backtrace_to_log(&context, log, SCOPE_AT_FAULT, " ");
+ backtrace_destroy_context(&context);
}
if (!attached && ptrace(PTRACE_DETACH, tid, 0, 0) != 0) {
@@ -137,11 +137,11 @@
dump_process_footer(&log, pid);
}
-void dump_backtrace_to_log(const backtrace_t* backtrace, log_t* log,
+void dump_backtrace_to_log(const backtrace_context_t* context, log_t* log,
int scope_flags, const char* prefix) {
char buf[512];
- for (size_t i = 0; i < backtrace->num_frames; i++) {
- backtrace_format_frame_data(&backtrace->frames[i], i, buf, sizeof(buf));
+ for (size_t i = 0; i < context->backtrace->num_frames; i++) {
+ backtrace_format_frame_data(context, i, buf, sizeof(buf));
_LOG(log, scope_flags, "%s%s\n", prefix, buf);
}
}