From cedfa69e6afe381a074d22bdf1e6f2d9e6731038 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 14 Jul 2021 16:36:44 -0400 Subject: test: Add a basic traceback printer Some tests have some complex flows, and it's useful to be able to see the call path when there's a failure. This patch adds a very simple traceback printer, along with changing the test build arguments to include more debug information. The result you get from this traceback printer just gives you a function name and the index into its .txt content, so to use it for more than "which function calls which", you'll need to use eu-addr2line with the output. Signed-off-by: Peter Jones --- test.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test.c') diff --git a/test.c b/test.c index 81578c5a..d9902ebc 100644 --- a/test.c +++ b/test.c @@ -9,9 +9,35 @@ #endif #include "shim.h" +#include +#include +#include + +#define BT_BUF_SIZE (4096/sizeof(void *)) + +static void *frames[BT_BUF_SIZE] = { 0, }; + UINT8 in_protocol = 0; int debug = DEFAULT_DEBUG_PRINT_STATE; +void +print_traceback(int skip) +{ + int nptrs; + char **strings; + + nptrs = backtrace(frames, BT_BUF_SIZE); + if (nptrs < skip) + return; + + strings = backtrace_symbols(frames, nptrs); + for (int i = skip; strings != NULL && i < nptrs; i++) { + printf("%p %s\n", (void *)frames[i], strings[i]); + } + if (strings) + free(strings); +} + #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-function" -- cgit v1.2.3