[3/3,binutils/readelf] Fix handling of DW_MACRO_define_strx in dwo file

Message ID 20240514105522.10107-3-tdevries@suse.de
State New
Headers
Series [1/3,binutils/readelf] Fix printing of dwarf4 .debug_str_offsets.dwo |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm fail Testing failed

Commit Message

Tom de Vries May 14, 2024, 10:55 a.m. UTC
  When printing a DW_MACRO_define_strx entry in a .debug_macro.dwo section, we
run into:
...
 DW_MACRO_define_strx lineno : 0 macro : <no .debug_str_offsets section>
...

Fix this in display_debug_macro by passing the correct dwo argument to a
fetch_indexed_string call.

That works fine for readelf -w, with with readelf -wm we have:
...
 DW_MACRO_define_strx lineno : 0 macro : <no .debug_str_offsets.dwo section>
...

Fix this in display_debug_macro by doing load_debug_section_with_follow for
str_dwo / str_index_dwo sections instead of str / str_index sections when
handling .debug_macro.dwo.

PR 31735
---
 binutils/dwarf.c                                   | 14 +++++++++++---
 .../binutils-all/readelf-debug-str-offsets-dw4.d   | 11 +++++++++--
 .../binutils-all/readelf-debug-str-offsets-dw4.s   |  7 +++++++
 3 files changed, 27 insertions(+), 5 deletions(-)
  

Comments

Alan Modra May 15, 2024, 7:41 a.m. UTC | #1
On Tue, May 14, 2024 at 12:55:22PM +0200, Tom de Vries wrote:
> When printing a DW_MACRO_define_strx entry in a .debug_macro.dwo section, we
> run into:
> ...
>  DW_MACRO_define_strx lineno : 0 macro : <no .debug_str_offsets section>
> ...
> 
> Fix this in display_debug_macro by passing the correct dwo argument to a
> fetch_indexed_string call.
> 
> That works fine for readelf -w, with with readelf -wm we have:
> ...
>  DW_MACRO_define_strx lineno : 0 macro : <no .debug_str_offsets.dwo section>
> ...
> 
> Fix this in display_debug_macro by doing load_debug_section_with_follow for
> str_dwo / str_index_dwo sections instead of str / str_index sections when
> handling .debug_macro.dwo.
> 
> PR 31735
> ---
>  binutils/dwarf.c                                   | 14 +++++++++++---
>  .../binutils-all/readelf-debug-str-offsets-dw4.d   | 11 +++++++++--
>  .../binutils-all/readelf-debug-str-offsets-dw4.s   |  7 +++++++
>  3 files changed, 27 insertions(+), 5 deletions(-)
> 
> diff --git a/binutils/dwarf.c b/binutils/dwarf.c
> index f49989dc536..cdf73a7bc50 100644
> --- a/binutils/dwarf.c
> +++ b/binutils/dwarf.c
> @@ -6293,9 +6293,17 @@ display_debug_macro (struct dwarf_section *section,
>    if (suffix && strcmp (suffix, ".dwo") == 0)
>      is_dwo = true;
>  
> -  load_debug_section_with_follow (str, file);
> +  if (is_dwo)
> +    {
> +      load_debug_section_with_follow (str_dwo, file);
> +      load_debug_section_with_follow (str_index_dwo, file);
> +    }
> +  else
> +    {
> +      load_debug_section_with_follow (str, file);
> +      load_debug_section_with_follow (str_index, file);
> +    }
>    load_debug_section_with_follow (line, file);
> -  load_debug_section_with_follow (str_index, file);
>  
>    introduce (section, false);
>  
> @@ -6504,7 +6512,7 @@ display_debug_macro (struct dwarf_section *section,
>  	      READ_ULEB (lineno, curr, end);
>  	      READ_ULEB (offset, curr, end);
>  	      string = (const unsigned char *)
> -		fetch_indexed_string (offset, NULL, offset_size, false, 0);
> +		fetch_indexed_string (offset, NULL, offset_size, is_dwo, 0);
>  	      if (op == DW_MACRO_define_strx)
>  		printf (" DW_MACRO_define_strx ");
>  	      else
> diff --git a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
> index 23581e70f3e..2f41f2331f2 100644
> --- a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
> +++ b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
> @@ -1,6 +1,6 @@
> -#name: readelf -ws readelf-debug-str-offsets-dw4
> +#name: readelf -wsm readelf-debug-str-offsets-dw4
>  #source: readelf-debug-str-offsets-dw4.s
> -#readelf: -ws
> +#readelf: -wsm
>  
>  Contents of the .debug_str.dwo section:
>  
> @@ -12,3 +12,10 @@ Contents of the .debug_str_offsets.dwo section:
>         Index   Offset \[String\]
>             0 00000000  FIRST
>             1 00000006  SECOND
> +Contents of the .debug_macro.dwo section:
> +
> +  Offset:                      0
> +  Version:                     4
> +  Offset size:                 4
> +
> + DW_MACRO_define_strx lineno : 0 macro : FIRST
> diff --git a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
> index 68f64dde234..c28750bbe24 100644
> --- a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
> +++ b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
> @@ -4,3 +4,10 @@
>  	.section	.debug_str_offsets.dwo,"MS",@progbits,1
>  	.4byte 0
>  	.4byte 6
> +	.section        .debug_macro.dwo,"e",@progbits
> +	.2byte  0x4     /* DWARF macro version number.  */
> +	.byte   0x0     /* Flags: 32-bit dwarf.  */
> +	.byte   0xb     /* Define macro strx.  */
> +	.uleb128 0      /* At line number 0.  */
> +	.uleb128 0x0    /* .debug_str_offsets.dwo entry 0.  */
> +	.byte   0       /* End compilation unit.  */
> -- 
> 2.35.3

OK, but please fix the @progbits problem in the testcase.
  

Patch

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index f49989dc536..cdf73a7bc50 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -6293,9 +6293,17 @@  display_debug_macro (struct dwarf_section *section,
   if (suffix && strcmp (suffix, ".dwo") == 0)
     is_dwo = true;
 
-  load_debug_section_with_follow (str, file);
+  if (is_dwo)
+    {
+      load_debug_section_with_follow (str_dwo, file);
+      load_debug_section_with_follow (str_index_dwo, file);
+    }
+  else
+    {
+      load_debug_section_with_follow (str, file);
+      load_debug_section_with_follow (str_index, file);
+    }
   load_debug_section_with_follow (line, file);
-  load_debug_section_with_follow (str_index, file);
 
   introduce (section, false);
 
@@ -6504,7 +6512,7 @@  display_debug_macro (struct dwarf_section *section,
 	      READ_ULEB (lineno, curr, end);
 	      READ_ULEB (offset, curr, end);
 	      string = (const unsigned char *)
-		fetch_indexed_string (offset, NULL, offset_size, false, 0);
+		fetch_indexed_string (offset, NULL, offset_size, is_dwo, 0);
 	      if (op == DW_MACRO_define_strx)
 		printf (" DW_MACRO_define_strx ");
 	      else
diff --git a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
index 23581e70f3e..2f41f2331f2 100644
--- a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
+++ b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.d
@@ -1,6 +1,6 @@ 
-#name: readelf -ws readelf-debug-str-offsets-dw4
+#name: readelf -wsm readelf-debug-str-offsets-dw4
 #source: readelf-debug-str-offsets-dw4.s
-#readelf: -ws
+#readelf: -wsm
 
 Contents of the .debug_str.dwo section:
 
@@ -12,3 +12,10 @@  Contents of the .debug_str_offsets.dwo section:
        Index   Offset \[String\]
            0 00000000  FIRST
            1 00000006  SECOND
+Contents of the .debug_macro.dwo section:
+
+  Offset:                      0
+  Version:                     4
+  Offset size:                 4
+
+ DW_MACRO_define_strx lineno : 0 macro : FIRST
diff --git a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
index 68f64dde234..c28750bbe24 100644
--- a/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
+++ b/binutils/testsuite/binutils-all/readelf-debug-str-offsets-dw4.s
@@ -4,3 +4,10 @@ 
 	.section	.debug_str_offsets.dwo,"MS",@progbits,1
 	.4byte 0
 	.4byte 6
+	.section        .debug_macro.dwo,"e",@progbits
+	.2byte  0x4     /* DWARF macro version number.  */
+	.byte   0x0     /* Flags: 32-bit dwarf.  */
+	.byte   0xb     /* Define macro strx.  */
+	.uleb128 0      /* At line number 0.  */
+	.uleb128 0x0    /* .debug_str_offsets.dwo entry 0.  */
+	.byte   0       /* End compilation unit.  */