public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dodji at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug debug/47471] [4.6/4.7 Regression] stdarg functions extraneous too-early prologue end
Date: Tue, 29 Mar 2011 15:48:00 -0000	[thread overview]
Message-ID: <bug-47471-4-3UnrhZrcmq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-47471-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47471

--- Comment #2 from Dodji Seketeli <dodji at gcc dot gnu.org> 2011-03-29 15:24:07 UTC ---
I believe the issue is that for that source code, GCC emits two
identical .loc asm directives for line 3.  In theory I don't thing
doing that would be wrong.

But in practise the second .loc directive triggers a special opcode in
the generated line program that increments the line with an increment
of zero; it also increments the current program address with a
increment of zero.  And that happens before the first line that
doesn't belong to the prologue.

That seems to break GDB's heuristic, and is also a bit of bloat.

The patch below avoids emitting two identical consecutive line number
debug information and seems to fix the issue for me.  I am currently
regression-testing it.

>From eb1450a263a4e50b43132ef9b914f49a971c8e9d Mon Sep 17 00:00:00 2001
From: Dodji Seketeli <dodji@redhat.com>
Date: Tue, 29 Mar 2011 16:56:20 +0200
Subject: [PATCH] PR debug/47471

gcc/
    * dwarf2out.c (dwarf2out_source_line):  Avoid emitting two
    identical contiguous .loc asm directive.

gcc/testsuite/
    * gcc.dg/debug/dwarf2/line-prog-1.c: New test.
---
 gcc/dwarf2out.c                                 |   33 +++++++++++++++-------
 gcc/testsuite/gcc.dg/debug/dwarf2/line-prog-1.c |   25 +++++++++++++++++
 2 files changed, 47 insertions(+), 11 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/line-prog-1.c

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 7803ab7..b350f43 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -22068,6 +22068,8 @@ dwarf2out_source_line (unsigned int line, const char
*filename,
       && line != 0)
     {
       int file_num = maybe_emit_file (lookup_filename (filename));
+      static int prev_file_num;
+      static unsigned int prev_line;

       switch_to_section (current_function_section ());

@@ -22078,19 +22080,28 @@ 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 int prev_file_num;
+      static unsigned int prev_line;
+      if (prev_file_num != file_num
+          || prev_line != line)
         {
-          fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
-          last_is_stmt = is_stmt;
-        }
-      if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
-        fprintf (asm_out_file, " discriminator %d", discriminator);
-      fputc ('\n', asm_out_file);
+          /* 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);
+          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++;

-      /* Indicate that line number info exists.  */
-      line_info_table_in_use++;
+          prev_file_num = file_num;
+          prev_line = line;
+        }
     }
       else if (function_section (current_function_decl) != text_section)
     {
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/line-prog-1.c
b/gcc/testsuite/gcc.dg/debug/dwarf2/line-prog-1.c
new file mode 100644
index 0000000..63637dc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/line-prog-1.c
@@ -0,0 +1,25 @@
+/*
+  Origin: PR debug/47471
+  { dg-options "-g -dA" }
+ */
+
+int v;
+void f (int i, ...)
+{
+  v++;
+}
+
+int
+main (void)
+{
+  f (1);
+  return 0;
+}
+
+/* We want to have only one .loc directive that points to the opening
+   curly bracket of the definition of function f, at line 8.  */
+
+/*
+  { dg-final { scan-assembler-times "\.loc 1 8 0" 1 } }
+
+ */
-- 
1.7.3.4


  parent reply	other threads:[~2011-03-29 15:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-26 11:05 [Bug debug/47471] New: " jan.kratochvil at redhat dot com
2011-02-13 17:44 ` [Bug debug/47471] [4.6 Regression] " jsm28 at gcc dot gnu.org
2011-02-13 17:53 ` jsm28 at gcc dot gnu.org
2011-03-25 20:02 ` [Bug debug/47471] [4.6/4.7 " jakub at gcc dot gnu.org
2011-03-28 20:11 ` dodji at gcc dot gnu.org
2011-03-29 15:48 ` dodji at gcc dot gnu.org [this message]
2011-03-29 17:52 ` jan.kratochvil at redhat dot com
2011-03-29 18:09 ` jan.kratochvil at redhat dot com
2011-06-27 15:51 ` jakub at gcc dot gnu.org
2011-09-19 14:09 ` philipp at marek dot priv.at
2011-09-19 14:10 ` jan.kratochvil at redhat dot com
2011-10-26 18:06 ` jakub at gcc dot gnu.org
2012-03-01 15:15 ` jakub at gcc dot gnu.org
2013-04-12 15:18 ` [Bug debug/47471] [4.7/4.8/4.9 " jakub at gcc dot gnu.org
2013-12-03 16:46 ` psmith at gnu dot org
2014-06-12 13:49 ` [Bug debug/47471] [4.7/4.8/4.9/4.10 " rguenth at gcc dot gnu.org
2014-12-19 13:34 ` [Bug debug/47471] [4.8/4.9/5 " jakub at gcc dot gnu.org
2015-06-23  8:26 ` [Bug debug/47471] [4.8/4.9/5/6 " rguenth at gcc dot gnu.org
2015-06-26 20:01 ` [Bug debug/47471] [4.9/5/6 " jakub at gcc dot gnu.org
2015-06-26 20:31 ` jakub at gcc dot gnu.org
2021-05-14  9:46 ` [Bug debug/47471] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-01  8:05 ` rguenth at gcc dot gnu.org
2022-05-27  9:34 ` [Bug debug/47471] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:29 ` jakub at gcc dot gnu.org
2023-01-30 14:26 ` vries at gcc dot gnu.org
2023-02-01  7:09 ` jan at jankratochvil dot net

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-47471-4-3UnrhZrcmq@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).