diff options
| author | Peter Jones <pjones@redhat.com> | 2021-07-14 16:36:44 -0400 |
|---|---|---|
| committer | Peter Jones <pjones@redhat.com> | 2021-07-20 09:44:25 -0400 |
| commit | cedfa69e6afe381a074d22bdf1e6f2d9e6731038 (patch) | |
| tree | 7a6aaaa03f9edfed395b7061b027ed23b7b45481 /test.c | |
| parent | fea0a3fd026f1f4ec82a513269764b8349ffd4a5 (diff) | |
| download | efi-boot-shim-cedfa69e6afe381a074d22bdf1e6f2d9e6731038.tar.gz efi-boot-shim-cedfa69e6afe381a074d22bdf1e6f2d9e6731038.zip | |
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 <pjones@redhat.com>
Diffstat (limited to 'test.c')
| -rw-r--r-- | test.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -9,9 +9,35 @@ #endif #include "shim.h" +#include <execinfo.h> +#include <stdio.h> +#include <string.h> + +#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" |
