diff mbox series

Emit .file 0 marker earlier in DWARF 5

Message ID 3430317.R56niFO833@fomalhaut
State New
Headers show
Series Emit .file 0 marker earlier in DWARF 5 | expand

Commit Message

Eric Botcazou June 23, 2021, 10:06 a.m. UTC
Hi,

when the assembler supports it, the compiler automatically passes --gdwarf-5
to it, which has an interesting side effect: any assembly instruction prior
to the first .file directive defines a new line associated with .file 0 in
the .debug_line section and, of course, the numbering of these implicit lines
has nothing to do with that of the source code.  This can be problematic in
Ada where we do not generate .file/.loc directives for some compiled-generated
functions to avoid too jumpy a debugging experience.

The attached patch moves the .file 0 marker from the .debug_line section to the
beginning of the file (next to the .cfi_sections marker).

Tested on x86-64/Linux and x86[-64]/Windows, OK for mainline and 11 branch?


2021-06-23  Eric Botcazou  <ebotcazou@adacore.com>

	* dwarf2out.c (dwarf2out_assembly_start): Emit .file 0 marker here...
	(dwarf2out_finish): ...instead of here.

Comments

Jeff Law June 23, 2021, 2:39 p.m. UTC | #1
On 6/23/2021 4:06 AM, Eric Botcazou wrote:
> Hi,
>
> when the assembler supports it, the compiler automatically passes --gdwarf-5
> to it, which has an interesting side effect: any assembly instruction prior
> to the first .file directive defines a new line associated with .file 0 in
> the .debug_line section and, of course, the numbering of these implicit lines
> has nothing to do with that of the source code.  This can be problematic in
> Ada where we do not generate .file/.loc directives for some compiled-generated
> functions to avoid too jumpy a debugging experience.
>
> The attached patch moves the .file 0 marker from the .debug_line section to the
> beginning of the file (next to the .cfi_sections marker).
>
> Tested on x86-64/Linux and x86[-64]/Windows, OK for mainline and 11 branch?
>
>
> 2021-06-23  Eric Botcazou  <ebotcazou@adacore.com>
>
> 	* dwarf2out.c (dwarf2out_assembly_start): Emit .file 0 marker here...
> 	(dwarf2out_finish): ...instead of here.
OK for the trunk now and 11 backport (your call on backporting now or 
after soak time).

jeff
diff mbox series

Patch

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 88eb3f9c455..9a91981acb0 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -29363,6 +29363,30 @@  dwarf2out_assembly_start (void)
       && dwarf2out_do_cfi_asm ()
       && !dwarf2out_do_eh_frame ())
     fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
+
+#if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
+  if (output_asm_line_debug_info () && dwarf_version >= 5)
+    {
+      /* When gas outputs DWARF5 .debug_line[_str] then we have to
+	 tell it the comp_dir and main file name for the zero entry
+	 line table.  */
+      const char *comp_dir, *filename0;
+
+      comp_dir = comp_dir_string ();
+      if (comp_dir == NULL)
+	comp_dir = "";
+
+      filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
+      if (filename0 == NULL)
+	filename0 = "";
+
+      fprintf (asm_out_file, "\t.file 0 ");
+      output_quoted_string (asm_out_file, remap_debug_filename (comp_dir));
+      fputc (' ', asm_out_file);
+      output_quoted_string (asm_out_file, remap_debug_filename (filename0));
+      fputc ('\n', asm_out_file);
+    }
+#endif
 }
 
 /* A helper function for dwarf2out_finish called through
@@ -32315,27 +32339,6 @@  dwarf2out_finish (const char *filename)
   ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
   if (! output_asm_line_debug_info ())
     output_line_info (false);
-  else if (asm_outputs_debug_line_str ())
-    {
-      /* When gas outputs DWARF5 .debug_line[_str] then we have to
-	 tell it the comp_dir and main file name for the zero entry
-	 line table.  */
-      const char *comp_dir, *filename0;
-
-      comp_dir = comp_dir_string ();
-      if (comp_dir == NULL)
-	comp_dir = "";
-
-      filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
-      if (filename0 == NULL)
-	filename0 = "";
-
-      fprintf (asm_out_file, "\t.file 0 ");
-      output_quoted_string (asm_out_file, remap_debug_filename (comp_dir));
-      fputc (' ', asm_out_file);
-      output_quoted_string (asm_out_file, remap_debug_filename (filename0));
-      fputc ('\n', asm_out_file);
-    }
 
   if (dwarf_split_debug_info && info_section_emitted)
     {