[04/14] libdw: Handle other string forms in dwarf_macro_param2
Commit Message
From: Omar Sandoval <osandov@fb.com>
dwarf_getmacros handles the additional macro string forms added by DWARF
5, but dwarf_macro_param2 doesn't. Update it with the list of all
string forms allowed in .debug_macro. In particular, GCC and Clang
generate DW_MACRO_define_strx and DW_MACRO_undef_strx, which
dwarf_macro_param2 couldn't handle.
Fixes: cdf865b890c2 ("readelf, libdw: Handle DWARF5 .debug_macro.")
Signed-off-by: Omar Sandoval <osandov@fb.com>
---
libdw/ChangeLog | 3 +++
libdw/dwarf_macro_param2.c | 21 +++++++++++++++------
2 files changed, 18 insertions(+), 6 deletions(-)
Comments
Hi Omar,
On Wed, 2023-09-27 at 11:20 -0700, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
>
> dwarf_getmacros handles the additional macro string forms added by DWARF
> 5, but dwarf_macro_param2 doesn't. Update it with the list of all
> string forms allowed in .debug_macro. In particular, GCC and Clang
> generate DW_MACRO_define_strx and DW_MACRO_undef_strx, which
> dwarf_macro_param2 couldn't handle.
So as far as I can see this is always only used for DWARF5 forms and
never uses the DW_FORM_GNU_strp_alt or DW_FORM_GNU_str_index because
the GNU DebugFission extension for DWARF4 kept the old macinfo format,
just moved it to the dwo.
Thanks for catching this. Applied.
Cheers,
Mark
@@ -4,6 +4,9 @@
* dwarf_entrypc.c (dwarf_entrypc): Call dwarf_lowpc.
* dwarf_ranges.c (dwarf_ranges): Use skeleton ranges section for
skeleton units.
+ * dwarf_macro_param2.c (dwarf_macro_param2): Change form condition to
+ switch statement and add DW_FORM_line_strp, DW_FORM_strp_sup,
+ DW_FORM_strx, and DW_FORM_strx[1-4].
2023-02-22 Mark Wielaard <mark@klomp.org>
@@ -44,12 +44,21 @@ dwarf_macro_param2 (Dwarf_Macro *macro, Dwarf_Word *paramp, const char **strp)
if (dwarf_macro_param (macro, 1, ¶m) != 0)
return -1;
- if (param.form == DW_FORM_string
- || param.form == DW_FORM_strp)
+ switch (param.form)
{
- *strp = dwarf_formstring (¶m);
- return 0;
+ /* String forms allowed by libdw_valid_user_form. */
+ case DW_FORM_line_strp:
+ case DW_FORM_string:
+ case DW_FORM_strp:
+ case DW_FORM_strp_sup:
+ case DW_FORM_strx:
+ case DW_FORM_strx1:
+ case DW_FORM_strx2:
+ case DW_FORM_strx3:
+ case DW_FORM_strx4:
+ *strp = dwarf_formstring (¶m);
+ return 0;
+ default:
+ return dwarf_formudata (¶m, paramp);
}
- else
- return dwarf_formudata (¶m, paramp);
}