Skip to content

Commit 46dc55b

Browse files
committed
gendwarfksyms: Add die_map debugging
Debugging the DWARF processing can be somewhat challenging, so add more detailed debugging output for die_map operations. Move parsed die_map output behind --dump-dies to clean up the --debug output, and add a --dump-die-map flag, which adds highlighted tags to the output about die_map operations. Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
1 parent 1a067da commit 46dc55b

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

scripts/gendwarfksyms/dwarf.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ static int process(struct state *state, struct die *cache, const char *s)
8484
{
8585
s = s ?: "<null>";
8686

87-
if (debug && do_linebreak) {
87+
if (dump_dies && do_linebreak) {
8888
fputs("\n", stderr);
8989
for (int i = 0; i < indentation_level; i++)
9090
fputs(" ", stderr);
9191
do_linebreak = false;
9292
}
93-
if (debug)
93+
if (dump_dies)
9494
fputs(s, stderr);
9595

96+
if (cache)
97+
die_debug_r("cache %p string '%s'", cache, s);
9698
return check(die_map_add_string(cache, s));
9799
}
98100

@@ -510,6 +512,8 @@ static int process_cached(struct state *state, struct die *cache,
510512
while (df) {
511513
switch (df->type) {
512514
case STRING:
515+
die_debug_b("cache %p STRING '%s'", cache,
516+
df->data.str);
513517
check(process(state, NULL, df->data.str));
514518
break;
515519
case LINEBREAK:
@@ -522,6 +526,8 @@ static int process_cached(struct state *state, struct die *cache,
522526
error("dwarf_die_addr_die failed");
523527
return -1;
524528
}
529+
die_debug_b("cache %p DIE addr %" PRIxPTR " tag %d",
530+
cache, df->data.addr, dwarf_tag(&child));
525531
check(process_type(state, NULL, &child));
526532
break;
527533
default:
@@ -619,6 +625,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
619625
check(die_map_get(die, want_state, &cache));
620626

621627
if (cache->state == want_state) {
628+
die_debug_g("cached addr %p tag %d -- %s", die->addr, tag,
629+
die_state_name(cache->state));
630+
622631
if (want_state == COMPLETE && is_expanded_type(tag))
623632
check(cache_mark_expanded(&state->expansion_cache,
624633
die->addr));
@@ -630,6 +639,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
630639
return 0;
631640
}
632641

642+
die_debug_g("addr %p tag %d -- INCOMPLETE -> %s", die->addr, tag,
643+
die_state_name(want_state));
644+
633645
switch (tag) {
634646
/* Type modifiers */
635647
PROCESS_TYPE(atomic)
@@ -665,6 +677,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
665677
return -1;
666678
}
667679

680+
die_debug_r("parent %p cache %p die addr %p tag %d", parent, cache,
681+
die->addr, tag);
682+
668683
/* Update cache state and append to the parent (if any) */
669684
cache->tag = tag;
670685
cache->state = want_state;

scripts/gendwarfksyms/gendwarfksyms.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616

1717
/* Print out debugging information to stderr */
1818
bool debug;
19+
/* Print out die_map contents */
20+
bool dump_dies;
21+
/* Print out inline debugging information about die_map changes */
22+
bool dump_die_map;
1923

2024
static const struct {
2125
const char *arg;
2226
bool *flag;
2327
const char **param;
2428
} options[] = {
2529
{ "--debug", &debug, NULL },
30+
{ "--dump-dies", &dump_dies, NULL },
31+
{ "--dump-die-map", &dump_die_map, NULL },
2632
};
2733

2834
static int usage(void)
@@ -111,6 +117,9 @@ int main(int argc, const char **argv)
111117
if (parse_options(argc, argv) < 0)
112118
return usage();
113119

120+
if (dump_die_map)
121+
dump_dies = true;
122+
114123
check(symbol_read_exports(stdin));
115124

116125
for (n = 0; n < object_count; n++) {

scripts/gendwarfksyms/gendwarfksyms.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* Options -- in gendwarfksyms.c
2121
*/
2222
extern bool debug;
23+
extern bool dump_dies;
24+
extern bool dump_die_map;
2325

2426
#define MAX_INPUT_FILES 128
2527

@@ -40,6 +42,18 @@ extern bool debug;
4042
#define warn(format, ...) __println("warning: ", format, ##__VA_ARGS__)
4143
#define error(format, ...) __println("error: ", format, ##__VA_ARGS__)
4244

45+
#define __die_debug(color, format, ...) \
46+
do { \
47+
if (dump_dies && dump_die_map) \
48+
fprintf(stderr, \
49+
"\033[" #color "m<" format ">\033[39m", \
50+
__VA_ARGS__); \
51+
} while (0)
52+
53+
#define die_debug_r(format, ...) __die_debug(91, format, __VA_ARGS__)
54+
#define die_debug_g(format, ...) __die_debug(92, format, __VA_ARGS__)
55+
#define die_debug_b(format, ...) __die_debug(94, format, __VA_ARGS__)
56+
4357
/*
4458
* Error handling helpers
4559
*/

0 commit comments

Comments
 (0)