[04/14] libdw: Handle other string forms in dwarf_macro_param2

Message ID a8f01e3a1f58a9b41f3af6409f97b15e0cc8e39e.1695837512.git.osandov@fb.com
State Committed
Headers
Series elfutils: DWARF package (.dwp) file support |

Commit Message

Omar Sandoval Sept. 27, 2023, 6:20 p.m. UTC
  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

Mark Wielaard Oct. 3, 2023, 4:11 p.m. UTC | #1
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
  

Patch

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index e84432f6..7528c093 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -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>
 
diff --git a/libdw/dwarf_macro_param2.c b/libdw/dwarf_macro_param2.c
index cc902c99..f12e6f9a 100644
--- a/libdw/dwarf_macro_param2.c
+++ b/libdw/dwarf_macro_param2.c
@@ -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);
 }