[PATCH v2 12/19] gendwarfksyms: Add die_map debugging

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 scripts/gendwarfksyms/dwarf.c         | 19 +++++++++++++++++--
 scripts/gendwarfksyms/gendwarfksyms.c |  9 +++++++++
 scripts/gendwarfksyms/gendwarfksyms.h | 14 ++++++++++++++
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/scripts/gendwarfksyms/dwarf.c b/scripts/gendwarfksyms/dwarf.c
index 2f1601015c4e..9bca21a71639 100644
--- a/scripts/gendwarfksyms/dwarf.c
+++ b/scripts/gendwarfksyms/dwarf.c
@@ -84,15 +84,17 @@ static int process(struct state *state, struct die *cache, const char *s)
 {
 	s = s ?: "<null>";
 
-	if (debug && do_linebreak) {
+	if (dump_dies && do_linebreak) {
 		fputs("\n", stderr);
 		for (int i = 0; i < indentation_level; i++)
 			fputs("  ", stderr);
 		do_linebreak = false;
 	}
-	if (debug)
+	if (dump_dies)
 		fputs(s, stderr);
 
+	if (cache)
+		die_debug_r("cache %p string '%s'", cache, s);
 	return check(die_map_add_string(cache, s));
 }
 
@@ -510,6 +512,8 @@ static int process_cached(struct state *state, struct die *cache,
 	while (df) {
 		switch (df->type) {
 		case STRING:
+			die_debug_b("cache %p STRING '%s'", cache,
+				    df->data.str);
 			check(process(state, NULL, df->data.str));
 			break;
 		case LINEBREAK:
@@ -522,6 +526,8 @@ static int process_cached(struct state *state, struct die *cache,
 				error("dwarf_die_addr_die failed");
 				return -1;
 			}
+			die_debug_b("cache %p DIE addr %" PRIxPTR " tag %d",
+				    cache, df->data.addr, dwarf_tag(&child));
 			check(process_type(state, NULL, &child));
 			break;
 		default:
@@ -619,6 +625,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
 	check(die_map_get(die, want_state, &cache));
 
 	if (cache->state == want_state) {
+		die_debug_g("cached addr %p tag %d -- %s", die->addr, tag,
+			    die_state_name(cache->state));
+
 		if (want_state == COMPLETE && is_expanded_type(tag))
 			check(cache_mark_expanded(&state->expansion_cache,
 						  die->addr));
@@ -630,6 +639,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
 		return 0;
 	}
 
+	die_debug_g("addr %p tag %d -- INCOMPLETE -> %s", die->addr, tag,
+		    die_state_name(want_state));
+
 	switch (tag) {
 	/* Type modifiers */
 	PROCESS_TYPE(atomic)
@@ -665,6 +677,9 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
 		return -1;
 	}
 
+	die_debug_r("parent %p cache %p die addr %p tag %d", parent, cache,
+		    die->addr, tag);
+
 	/* Update cache state and append to the parent (if any) */
 	cache->tag = tag;
 	cache->state = want_state;
diff --git a/scripts/gendwarfksyms/gendwarfksyms.c b/scripts/gendwarfksyms/gendwarfksyms.c
index 55a7fc902bf4..1349e592783b 100644
--- a/scripts/gendwarfksyms/gendwarfksyms.c
+++ b/scripts/gendwarfksyms/gendwarfksyms.c
@@ -16,6 +16,10 @@
 
 /* Print out debugging information to stderr */
 bool debug;
+/* Print out die_map contents */
+bool dump_dies;
+/* Print out inline debugging information about die_map changes */
+bool dump_die_map;
 
 static const struct {
 	const char *arg;
@@ -23,6 +27,8 @@ static const struct {
 	const char **param;
 } options[] = {
 	{ "--debug", &debug, NULL },
+	{ "--dump-dies", &dump_dies, NULL },
+	{ "--dump-die-map", &dump_die_map, NULL },
 };
 
 static int usage(void)
@@ -111,6 +117,9 @@ int main(int argc, const char **argv)
 	if (parse_options(argc, argv) < 0)
 		return usage();
 
+	if (dump_die_map)
+		dump_dies = true;
+
 	check(symbol_read_exports(stdin));
 
 	for (n = 0; n < object_count; n++) {
diff --git a/scripts/gendwarfksyms/gendwarfksyms.h b/scripts/gendwarfksyms/gendwarfksyms.h
index 6482503e7d6e..7cd907e3d5e3 100644
--- a/scripts/gendwarfksyms/gendwarfksyms.h
+++ b/scripts/gendwarfksyms/gendwarfksyms.h
@@ -20,6 +20,8 @@
  * Options -- in gendwarfksyms.c
  */
 extern bool debug;
+extern bool dump_dies;
+extern bool dump_die_map;
 
 #define MAX_INPUT_FILES 128
 
@@ -40,6 +42,18 @@ extern bool debug;
 #define warn(format, ...) __println("warning: ", format, ##__VA_ARGS__)
 #define error(format, ...) __println("error: ", format, ##__VA_ARGS__)
 
+#define __die_debug(color, format, ...)                                 \
+	do {                                                            \
+		if (dump_dies && dump_die_map)                          \
+			fprintf(stderr,                                 \
+				"\033[" #color "m<" format ">\033[39m", \
+				__VA_ARGS__);                           \
+	} while (0)
+
+#define die_debug_r(format, ...) __die_debug(91, format, __VA_ARGS__)
+#define die_debug_g(format, ...) __die_debug(92, format, __VA_ARGS__)
+#define die_debug_b(format, ...) __die_debug(94, format, __VA_ARGS__)
+
 /*
  * Error handling helpers
  */
-- 
2.46.0.184.g6999bdac58-goog





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux