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.

-- 
                Dodji

>From 87f97cc32bfac37264aa414c43d4ad47a9a35d72 Mon Sep 17 00:00:00 2001
From: Dodji Seketeli <do...@redhat.com>
Date: Tue, 29 Mar 2011 16:56:20 +0200
Subject: [PATCH] PR debug/47471 (set prologue_end in .debug_line)

gcc/
        * dwarf2out.c (dwarf2out_source_line):
        Avoid emitting redundant consecutive .loc asm directives.

gcc/testsuite/

        * gcc.dg/debug/dwarf2/line-prog-1.c: New test.
---
 gcc/dwarf2out.c |   37 +++++++++++++++++++++++++------------
 1 files changed, 25 insertions(+), 12 deletions(-)

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)
        {
-- 
1.7.3.4

Reply via email to