Skip to content

Commit d2ffdc1

Browse files
samitolvanenmasahir0y
authored andcommitted
gendwarfksyms: Add die_map debugging
Debugging the DWARF processing can be somewhat challenging, so add more detailed debugging output for die_map operations. Add the --dump-die-map flag, which adds color coded tags to the output for die_map changes. Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Reviewed-by: Petr Pavlu <petr.pavlu@suse.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent f936c12 commit d2ffdc1

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

scripts/gendwarfksyms/dwarf.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ static void process(struct die *cache, const char *s)
146146
if (dump_dies)
147147
fputs(s, stderr);
148148

149+
if (cache)
150+
die_debug_r("cache %p string '%s'", cache, s);
149151
die_map_add_string(cache, s);
150152
}
151153

@@ -594,6 +596,8 @@ static void process_cached(struct state *state, struct die *cache,
594596
list_for_each_entry(df, &cache->fragments, list) {
595597
switch (df->type) {
596598
case FRAGMENT_STRING:
599+
die_debug_b("cache %p STRING '%s'", cache,
600+
df->data.str);
597601
process(NULL, df->data.str);
598602
break;
599603
case FRAGMENT_LINEBREAK:
@@ -603,6 +607,8 @@ static void process_cached(struct state *state, struct die *cache,
603607
if (!dwarf_die_addr_die(dwarf_cu_getdwarf(die->cu),
604608
(void *)df->data.addr, &child))
605609
error("dwarf_die_addr_die failed");
610+
die_debug_b("cache %p DIE addr %" PRIxPTR " tag %x",
611+
cache, df->data.addr, dwarf_tag(&child));
606612
check(process_type(state, NULL, &child));
607613
break;
608614
default:
@@ -671,13 +677,19 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
671677
cache = die_map_get(die, want_state);
672678

673679
if (cache->state == want_state) {
680+
die_debug_g("cached addr %p tag %x -- %s", die->addr, tag,
681+
die_state_name(cache->state));
682+
674683
process_cached(state, cache, die);
675684
die_map_add_die(parent, cache);
676685

677686
expansion_state_restore(&state->expand, &saved);
678687
return 0;
679688
}
680689

690+
die_debug_g("addr %p tag %x -- %s -> %s", die->addr, tag,
691+
die_state_name(cache->state), die_state_name(want_state));
692+
681693
switch (tag) {
682694
/* Type modifiers */
683695
PROCESS_TYPE(atomic)
@@ -713,6 +725,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
713725
error("unexpected type: %x", tag);
714726
}
715727

728+
die_debug_r("parent %p cache %p die addr %p tag %x", parent, cache,
729+
die->addr, tag);
730+
716731
/* Update cache state and append to the parent (if any) */
717732
cache->tag = tag;
718733
cache->state = want_state;

scripts/gendwarfksyms/gendwarfksyms.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
int debug;
2020
/* Dump DIE contents */
2121
int dump_dies;
22+
/* Print debugging information about die_map changes */
23+
int dump_die_map;
2224

2325
static void usage(void)
2426
{
2527
fputs("Usage: gendwarfksyms [options] elf-object-file ... < symbol-list\n\n"
2628
"Options:\n"
2729
" -d, --debug Print debugging information\n"
2830
" --dump-dies Dump DWARF DIE contents\n"
31+
" --dump-die-map Print debugging information about die_map changes\n"
2932
" -h, --help Print this message\n"
3033
"\n",
3134
stderr);
@@ -75,6 +78,7 @@ int main(int argc, char **argv)
7578
static const struct option opts[] = {
7679
{ "debug", 0, NULL, 'd' },
7780
{ "dump-dies", 0, &dump_dies, 1 },
81+
{ "dump-die-map", 0, &dump_die_map, 1 },
7882
{ "help", 0, NULL, 'h' },
7983
{ 0, 0, NULL, 0 }
8084
};
@@ -95,6 +99,9 @@ int main(int argc, char **argv)
9599
}
96100
}
97101

102+
if (dump_die_map)
103+
dump_dies = 1;
104+
98105
if (optind >= argc) {
99106
usage();
100107
error("no input files?");

scripts/gendwarfksyms/gendwarfksyms.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
extern int debug;
2323
extern int dump_dies;
24+
extern int dump_die_map;
2425

2526
/*
2627
* Output helpers
@@ -43,6 +44,18 @@ extern int dump_dies;
4344
exit(1); \
4445
} while (0)
4546

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

0 commit comments

Comments
 (0)