Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
From cedfa69e6afe381a074d22bdf1e6f2d9e6731038 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 14 Jul 2021 16:36:44 -0400
Subject: [PATCH 19/26] 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>
---
include/test.h | 2 ++
include/test.mk | 21 ++++++++++++++++-----
test.c | 26 ++++++++++++++++++++++++++
3 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/include/test.h b/include/test.h
index 49a27a9..fedeb78 100644
--- a/include/test.h
+++ b/include/test.h
@@ -69,6 +69,8 @@ extern int debug;
#define dprint(fmt, ...) {( if (debug) printf("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__); })
#endif
+void print_traceback(int skip);
+
#define eassert(cond, fmt, ...) \
({ \
if (!(cond)) { \
diff --git a/include/test.mk b/include/test.mk
index c66b46d..23bf805 100644
--- a/include/test.mk
+++ b/include/test.mk
@@ -14,14 +14,25 @@ CFLAGS = -O2 -ggdb -std=gnu11 \
-isystem $(TOPDIR)/include/system \
$(EFI_INCLUDES) \
-Iinclude -iquote . \
- -fshort-wchar -flto -fno-builtin \
- -Wall \
- -Wextra \
+ -isystem /usr/include \
+ -isystem $(shell $(CC) $(ARCH_CFLAGS) -print-file-name=include) \
+ $(ARCH_CFLAGS) \
+ -fshort-wchar \
+ -flto \
+ -fno-builtin \
+ -rdynamic \
+ -fno-inline \
+ -fno-eliminate-unused-debug-types \
+ -fno-eliminate-unused-debug-symbols \
+ -gpubnames \
+ -grecord-gcc-switches \
+ $(DEFAULT_WARNFLAGS) \
-Wsign-compare \
-Wno-deprecated-declarations \
+ -Wno-unused-but-set-variable \
+ -Wno-unused-variable \
-Wno-pointer-sign \
- -Wno-unused \
- -Werror \
+ $(DEFAULT_WERRFLAGS) \
-Werror=nonnull \
$(shell $(CC) -Werror=nonnull-compare -E -x c /dev/null >/dev/null 2>&1 && echo -Werror=nonnull-compare) \
$(ARCH_DEFINES) \
diff --git a/test.c b/test.c
index 81578c5..d9902eb 100644
--- a/test.c
+++ b/test.c
@@ -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"
--
2.32.0