DWARF5 .debug_line DW_LNCT_* reorder for readelf [Re: [PATCH] DWARF5 .debug_line{,_str} support]
diff mbox

Message ID 20161124150722.GA26566@host1.jankratochvil.net
State New
Headers show

Commit Message

Jan Kratochvil Nov. 24, 2016, 3:07 p.m. UTC
Hi,

On Thu, 20 Oct 2016 01:30:39 +0200, Jakub Jelinek wrote:
> This patch adds support for DWARF5 .debug_line{,_str} section format,
> though only if !DWARF2_ASM_LINE_DEBUG_INFO, because otherwise
> .debug_line is emitted by the assembler.

with current GCC trunk (with the GCC patch above) binutils readelf DWARF-5
patch being prepared outputs:

 The File name Table (offset 0x30):
  Entry	Name	Dir
  0	(indirect line string, offset: 0x0): /home/jkratoch/t/classic.C	0
  1	(indirect line string, offset: 0x11): classic.C	1

Please see the tabs there.

After this GCC patch below readelf would output:

 The File name Table (offset 0x30):
  Entry	Dir	Name
  0	0	(indirect line string, offset: 0x0): /home/jkratoch/t/classic.C
  1	1	(indirect line string, offset: 0x11): classic.C

That 'indirect line string' may get removed, that is irrelevant for this mail.

I could reorder that in readelf but I find it easier to do in GCC.
Also binutils has not switched to C++ yet so I have found the reordering not
trivial to do in readelf itself.

The readelf patch being prepared - not yet submitted:
	https://people.redhat.com/jkratoch/readelf-dwarf5.patch

OK for GCC trunk?

Sorry I have not regression tested it, I would handle that before a check-in.


Thanks,
Jan
gcc/
2016-11-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2out.c (output_file_names) Reorder DW_LNCT_directory_index and
	DW_LNCT_path.

Comments

Jakub Jelinek Nov. 24, 2016, 3:22 p.m. UTC | #1
On Thu, Nov 24, 2016 at 04:07:22PM +0100, Jan Kratochvil wrote:
> On Thu, 20 Oct 2016 01:30:39 +0200, Jakub Jelinek wrote:
> > This patch adds support for DWARF5 .debug_line{,_str} section format,
> > though only if !DWARF2_ASM_LINE_DEBUG_INFO, because otherwise
> > .debug_line is emitted by the assembler.
> 
> with current GCC trunk (with the GCC patch above) binutils readelf DWARF-5
> patch being prepared outputs:
> 
>  The File name Table (offset 0x30):
>   Entry	Name	Dir
>   0	(indirect line string, offset: 0x0): /home/jkratoch/t/classic.C	0
>   1	(indirect line string, offset: 0x11): classic.C	1
> 
> Please see the tabs there.
> 
> After this GCC patch below readelf would output:
> 
>  The File name Table (offset 0x30):
>   Entry	Dir	Name
>   0	0	(indirect line string, offset: 0x0): /home/jkratoch/t/classic.C
>   1	1	(indirect line string, offset: 0x11): classic.C
> 
> That 'indirect line string' may get removed, that is irrelevant for this mail.
> 
> I could reorder that in readelf but I find it easier to do in GCC.
> Also binutils has not switched to C++ yet so I have found the reordering not
> trivial to do in readelf itself.
> 
> The readelf patch being prepared - not yet submitted:
> 	https://people.redhat.com/jkratoch/readelf-dwarf5.patch
> 
> OK for GCC trunk?
> 
> Sorry I have not regression tested it, I would handle that before a check-in.

Dunno, will defer to Jason.  I'd think that reordering for improved
readability should be readelf's job, and that the current order better
matches the DWARF4 order.  But it isn't a big deal for me.
Some other producer might emit it in a different order though...
E.g. readelf could print each entry in 2 passes, first prints selected
subset of DW_LCNT_* and the other pass prints the remaining ones.

	Jakub

Patch
diff mbox

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 1dfff38..ff4318c 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -11592,8 +11592,7 @@  output_file_names (void)
 #else
       dw2_asm_output_data (1, 2, "File name entry format count");
 #endif
-      dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
-      dw2_asm_output_data_uleb128 (str_form, get_DW_FORM_name (str_form));
+      /* Keep DW_LNCT_path last for better binutils readelf readability.  */
       dw2_asm_output_data_uleb128 (DW_LNCT_directory_index,
 				   "DW_LNCT_directory_index");
       dw2_asm_output_data_uleb128 (idx_form, get_DW_FORM_name (idx_form));
@@ -11603,9 +11602,10 @@  output_file_names (void)
       dw2_asm_output_data_uleb128 (DW_LNCT_size, "DW_LNCT_size");
       dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
 #endif
-      dw2_asm_output_data_uleb128 (numfiles + 1, "File names count");
+      dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
+      dw2_asm_output_data_uleb128 (str_form, get_DW_FORM_name (str_form));
 
-      output_line_string (str_form, filename0, "File Entry", 0);
+      dw2_asm_output_data_uleb128 (numfiles + 1, "File names count");
 
       /* Include directory index.  */
       if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
@@ -11618,6 +11618,8 @@  output_file_names (void)
       dw2_asm_output_data_uleb128 (0, NULL);
       dw2_asm_output_data_uleb128 (0, NULL);
 #endif
+
+      output_line_string (str_form, filename0, "File Entry", 0);
     }
 
   /* Now write all the file names.  */
@@ -11644,7 +11646,8 @@  output_file_names (void)
       snprintf (filebuf, maxfilelen, "%s;%d",
 	        files[file_idx].path + dirs[dir_idx].length, ver);
 
-      output_line_string (str_form, filebuf, "File Entry", (unsigned) i + 1);
+      if (dwarf_version < 5)
+	output_line_string (str_form, filebuf, "File Entry", (unsigned) i + 1);
 
       /* Include directory index.  */
       if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
@@ -11662,10 +11665,14 @@  output_file_names (void)
       dw2_asm_output_data_uleb128 ((vms_file_stats_name (files[file_idx].path,
 							 0, &siz, 0, 0) == 0)
 				   ? siz : 0, NULL);
+
+      if (dwarf_version >= 5)
+	output_line_string (str_form, filebuf, "File Entry", (unsigned) i + 1);
 #else
-      output_line_string (str_form,
-			  files[file_idx].path + dirs[dir_idx].length,
-			  "File Entry", (unsigned) i + 1);
+      if (dwarf_version < 5)
+	output_line_string (str_form,
+			    files[file_idx].path + dirs[dir_idx].length,
+			    "File Entry", (unsigned) i + 1);
 
       /* Include directory index.  */
       if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
@@ -11675,13 +11682,17 @@  output_file_names (void)
 	dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
 
       if (dwarf_version >= 5)
-	continue;
-
-      /* Modification time.  */
-      dw2_asm_output_data_uleb128 (0, NULL);
+	output_line_string (str_form,
+			    files[file_idx].path + dirs[dir_idx].length,
+			    "File Entry", (unsigned) i + 1);
+      else
+	{
+	  /* Modification time.  */
+	  dw2_asm_output_data_uleb128 (0, NULL);
 
-      /* File length in bytes.  */
-      dw2_asm_output_data_uleb128 (0, NULL);
+	  /* File length in bytes.  */
+	  dw2_asm_output_data_uleb128 (0, NULL);
+	}
 #endif /* VMS_DEBUGGING_INFO */
     }