diff options
| author | Yang Liu <liuyang22@iscas.ac.cn> | 2025-04-09 17:16:32 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-09 11:16:32 +0200 |
| commit | c9b6b5fbe0888f443a080c43fc38a215fddb42b3 (patch) | |
| tree | 4cc4b7dfa769110faeb7a778dcaa3b4a8d3928d9 /src/os/backtrace.c | |
| parent | 62765f151a2fcd5c1bd4fe5d46fc6277d3a1bee3 (diff) | |
| download | box64-c9b6b5fbe0888f443a080c43fc38a215fddb42b3.tar.gz box64-c9b6b5fbe0888f443a080c43fc38a215fddb42b3.zip | |
Added backtrace.h for holding backtrace-related functions (#2515)
Diffstat (limited to 'src/os/backtrace.c')
| -rw-r--r-- | src/os/backtrace.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/os/backtrace.c b/src/os/backtrace.c new file mode 100644 index 00000000..f0345cd6 --- /dev/null +++ b/src/os/backtrace.c @@ -0,0 +1,46 @@ +#include "backtrace.h" + +#if !defined(ANDROID) && !defined(_WIN32) + +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> +#include <signal.h> +#include <errno.h> +#include <string.h> +#include <execinfo.h> + +#include "debug.h" +#include "box64context.h" + +#define BT_BUF_SIZE 100 +void ShowNativeBT(int log_minimum) +{ + // grab current name + // and temporarily rename binary to original box64 + // to get exact backtrace + size_t boxpath_lenth = strlen(my_context->box64path) + 1; + char current_name[boxpath_lenth]; + memcpy(current_name, my_context->orig_argv[0], boxpath_lenth); + memcpy(my_context->orig_argv[0], my_context->box64path, boxpath_lenth); + // show native bt + int nptrs; + void* buffer[BT_BUF_SIZE]; + char** strings; + + nptrs = backtrace(buffer, BT_BUF_SIZE); + strings = backtrace_symbols(buffer, nptrs); + if (strings) { + for (int j = 0; j < nptrs; j++) + printf_log(log_minimum, "NativeBT: %s\n", strings[j]); + free(strings); + } else + printf_log(log_minimum, "NativeBT: none (%d/%s)\n", errno, strerror(errno)); + // restore modified name + memcpy(my_context->box64path, my_context->orig_argv[0], boxpath_lenth); +} +#undef BT_BUF_SIZE + +#else +void ShowNativeBT(int log_minimum) { } +#endif \ No newline at end of file |