]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Handle other string forms in dwarf_macro_param2
authorOmar Sandoval <osandov@fb.com>
Wed, 27 Sep 2023 18:20:53 +0000 (11:20 -0700)
committerMark Wielaard <mark@klomp.org>
Tue, 3 Oct 2023 16:06:39 +0000 (18:06 +0200)
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
libdw/dwarf_macro_param2.c

index e84432f677cfd4f60c0f74643bf17ea761800801..7528c09302c3fbdce53ca3c501f4c930bc60c9aa 100644 (file)
@@ -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>
 
index cc902c9997e5a384a09b7521b7839eece9c3a80c..f12e6f9a4da81c59b8f83774159c5d30de5a2c46 100644 (file)
@@ -44,12 +44,21 @@ dwarf_macro_param2 (Dwarf_Macro *macro, Dwarf_Word *paramp, const char **strp)
   if (dwarf_macro_param (macro, 1, &param) != 0)
     return -1;
 
-  if (param.form == DW_FORM_string
-      || param.form == DW_FORM_strp)
+  switch (param.form)
     {
-      *strp = dwarf_formstring (&param);
-      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 (&param);
+       return 0;
+      default:
+       return dwarf_formudata (&param, paramp);
     }
-  else
-    return dwarf_formudata (&param, paramp);
 }