summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Sandoval <[email protected]>2023-09-27 11:21:01 -0700
committerMark Wielaard <[email protected]>2023-11-02 21:39:00 +0100
commit6902b610939fbe15887905a0e2390c2f46cb1eb9 (patch)
tree667df697dced58d57c1ed7830c8017bd95be45c2
parent7878737f1c60dd444f47b701c208ade0b5a2becf (diff)
tests: Optionally dump all units in dwarf-getmacros
If instead of a CU offset an empty string is given as the second argument, dump all units. Signed-off-by: Omar Sandoval <[email protected]>
-rw-r--r--tests/ChangeLog3
-rw-r--r--tests/dwarf-getmacros.c51
2 files changed, 44 insertions, 10 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 71fbb559..d97749f5 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -3,6 +3,9 @@
* dwarf-getmacros.c (mac): Add DW_MACRO_define_sup,
DW_MACRO_define_strx, DW_MACRO_undef_sup, and DW_MACRO_undef_strx
cases to opcode switch statement.
+ (getmacros): New function.
+ (main): If second argument is empty, call getmacros on every unit.
+ Otherwise, call getmacros on given unit.
2023-09-27 Omar Sandoval <[email protected]>
diff --git a/tests/dwarf-getmacros.c b/tests/dwarf-getmacros.c
index e291bfd2..8381d42c 100644
--- a/tests/dwarf-getmacros.c
+++ b/tests/dwarf-getmacros.c
@@ -121,26 +121,57 @@ include (Dwarf *dbg, Dwarf_Off macoff, ptrdiff_t token)
}
}
+static void
+getmacros (Dwarf *dbg, Dwarf_Die *die, bool new_style)
+{
+ for (ptrdiff_t off = new_style ? DWARF_GETMACROS_START : 0;
+ (off = dwarf_getmacros (die, mac, dbg, off)); )
+ if (off == -1)
+ {
+ puts (dwarf_errmsg (-1));
+ break;
+ }
+}
+
int
main (int argc, char *argv[])
{
assert (argc >= 3);
const char *name = argv[1];
- ptrdiff_t cuoff = strtol (argv[2], NULL, 0);
bool new_style = argc > 3;
int fd = open (name, O_RDONLY);
Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
- Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem);
-
- for (ptrdiff_t off = new_style ? DWARF_GETMACROS_START : 0;
- (off = dwarf_getmacros (cudie, mac, dbg, off)); )
- if (off == -1)
- {
- puts (dwarf_errmsg (dwarf_errno ()));
- break;
- }
+ if (argv[2][0] == '\0')
+ {
+ Dwarf_CU *cu = NULL;
+ Dwarf_Die cudie, subdie;
+ uint8_t unit_type;
+ while (dwarf_get_units (dbg, cu, &cu, NULL,
+ &unit_type, &cudie, &subdie) == 0)
+ {
+ Dwarf_Die *die = (unit_type == DW_UT_skeleton
+ ? &subdie : &cudie);
+ if (! dwarf_hasattr (die, DW_AT_macro_info)
+ && ! dwarf_hasattr (die, DW_AT_GNU_macros)
+ && ! dwarf_hasattr (die, DW_AT_macros))
+ continue;
+ printf ("CU %s\n", dwarf_diename (die));
+ getmacros (dbg, die, new_style);
+ }
+ }
+ else
+ {
+ ptrdiff_t cuoff = strtol (argv[2], NULL, 0);
+ Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem);
+ if (cudie == NULL)
+ {
+ puts (dwarf_errmsg (-1));
+ return 1;
+ }
+ getmacros (dbg, cudie, new_style);
+ }
dwarf_end (dbg);