diff mbox

PR debug/47471 (set prologue_end in .debug_line)

Message ID m3mxkbuzlr.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli March 31, 2011, 2:35 p.m. UTC
Richard,

Thank you for the crystal clear explanation.  Now I understand why we
were not using the end_prologue debug hook before :-).

From what you say and from what Jan said, I think we could just keep the
part (of my earlier patch) that avoids emitting two consecutive
redundant .loc directives.  It seems to me that in the case of direct
output (i.e when we the underlying assembler doesn't support the .loc
directive) we already avoid the duplication.  And that avoidance fixes
the immediate issue GDB is facing, with -g -O0.

With -g -O>0, GDB doesn't have the issue as the DW_AT_location
attributes of the variable DIEs are locations that are valid in the
region of the prologue, so it doesn't need to know where the prologue
ends.  Just trusting DW_AT_location is enough.

I am currently testing the stripped down patch below.

Thanks.

Comments

Richard Henderson March 31, 2011, 3:37 p.m. UTC | #1
On 03/31/2011 07:35 AM, Dodji Seketeli wrote:
> redundant .loc directives.  It seems to me that in the case of direct
> output (i.e when we the underlying assembler doesn't support the .loc
> directive) we already avoid the duplication.  And that avoidance fixes
> the immediate issue GDB is facing, with -g -O0.

There's no avoidance with direct output either.  See the #if 0 bits
inside output_line_info itself.

#if 0
      /* Don't emit anything for redundant notes.  */
      if (line_info->dw_line_num == current_line
          && line_info->dw_file_num == current_file
          && line_info->function == function)
        goto cont;
#endif

> With -g -O>0, GDB doesn't have the issue as the DW_AT_location
> attributes of the variable DIEs are locations that are valid in the
> region of the prologue, so it doesn't need to know where the prologue
> ends.  Just trusting DW_AT_location is enough.

Ah, I see.  And I can see how having end_prologue might help there.
Well, let's see if we can clean things up here then.

As for your patch itself, you're not checking to see if you're outputting
to the same section, which could cause line info to go missing at the
beginning of a different section.

That said, the patch I'm working on will do this elimination in one place
for both direct output and assembler output, and be mindful of sections.


r~
diff mbox

Patch

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 91be9a4..7134315 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -22145,8 +22145,6 @@  static void
 dwarf2out_source_line (unsigned int line, const char *filename,
                        int discriminator, bool is_stmt)
 {
-  static bool last_is_stmt = true;
-
   if (debug_info_level >= DINFO_LEVEL_NORMAL
       && line != 0)
     {
@@ -22161,19 +22159,34 @@  dwarf2out_source_line (unsigned int line, const char *filename,
 
       if (DWARF2_ASM_LINE_DEBUG_INFO)
 	{
-	  /* Emit the .loc directive understood by GNU as.  */
-	  fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
-	  if (is_stmt != last_is_stmt)
+	  static bool last_is_stmt = true;
+	  static int last_file_num = -1;
+	  static unsigned last_line = 0;
+	  static int last_discriminator = -1;
+
+	  if (last_file_num != file_num
+	      || last_line != line
+	      || last_is_stmt != is_stmt
+	      || last_discriminator != discriminator)
 	    {
-	      fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
+	      /* Emit the .loc directive understood by GNU as.  */
+	      fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
+
+	      if (is_stmt != last_is_stmt)
+		fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
+
+	      if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
+		fprintf (asm_out_file, " discriminator %d", discriminator);
+	      fputc ('\n', asm_out_file);
+
+	      /* Indicate that line number info exists.  */
+	      line_info_table_in_use++;
+
+	      last_file_num = file_num;
+	      last_line = line;
+	      last_discriminator = discriminator;
 	      last_is_stmt = is_stmt;
 	    }
-	  if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
-	    fprintf (asm_out_file, " discriminator %d", discriminator);
-	  fputc ('\n', asm_out_file);
-
-	  /* Indicate that line number info exists.  */
-	  line_info_table_in_use++;
 	}
       else if (function_section (current_function_decl) != text_section)
 	{