public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>, Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv2 2/2] gdb/testsuite: fix gdb.debuginfod/fetch_src_and_symbols.exp with Clang
Date: Thu, 17 Nov 2022 11:38:06 +0000	[thread overview]
Message-ID: <ddaa73456d3b605d200b0af63a9c21ceca75cefa.1668684812.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1668684812.git.aburgess@redhat.com>

The gdb.debuginfod/fetch_src_and_symbols.exp test is showing a single
failure when run with some older versions of Clang, e.g. 9.0.1.

The problem appears to be with Clang's generated line table.  The test
source looks like this:

  int
  main()
  {
    asm ("main_label: .globl main_label");
    return 0;
  }

In GDB, when we 'start', we expect to stop at the 'return 0;' line.
This is the behaviour when the compiler is gcc, or later versions of
Clang.

However, with Clang 9.0.2, I see GDB stop on the 'asm' line.

In this commit I'll fix this issue by placing a breakpoint on the
return line, and then using gdb_continue_to_breakpoint to ensure we
have stopped in the correct place.

Of course, using gdb_continue_to_breakpoint will only work if we are
not already stopped at the breakpoint location, so I've added some
filler work before the 'return 0;' line.  With this done we can use
gdb_continue_to_breakpoint in all cases.

As a result of adding the new filler work, one of the later tests,
that used the 'list' command, no longer see the correct expected
output (the top line of the source file is no longer included in the
output).  I've fixed this by listing a known specific line, the test
is checking that GDB managed to find the source file, it doesn't
matter which source line we list, as long as we can list something.
---
 gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.c   | 5 ++++-
 gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp | 7 ++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.c b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.c
index 412bd53edda..7215e3c6484 100644
--- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.c
+++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.c
@@ -15,11 +15,14 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+volatile int global_var = 0;
+
 /* Dummy main function.  */
 
 int
 main()
 {
   asm ("main_label: .globl main_label");
-  return 0;
+  ++global_var;
+  return 0;	/* Breakpoint here.  */
 }
diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
index 8b3c2cf709e..e95526a069f 100644
--- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
+++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
@@ -161,6 +161,10 @@ proc_with_prefix no_url { } {
     if ![runto_main] {
 	return -1
     }
+
+    gdb_breakpoint [gdb_get_line_number "Breakpoint here"]
+    gdb_continue_to_breakpoint "stop at last line of main"
+
     gdb_test "generate-core-file $::corefile" "Saved corefile $::corefile" \
 	"file [file tail $::corefile] gen"
     file rename -force ${binfile}2 $debugdir
@@ -217,7 +221,8 @@ proc_with_prefix local_url { } {
     gdb_test_no_output "set substitute-path $outputdir /dev/null" \
 	"set substitute-path"
     gdb_test "br main" "Breakpoint 1 at.*file.*"
-    gdb_test "l" ".*This program is distributed in the hope.*"
+    set lineno [gdb_get_line_number "Breakpoint here"]
+    gdb_test "list $lineno" "return 0;\[^\r\n\]+Breakpoint here\\. .*"
 
     # GDB should now find the executable file.
     clean_restart
-- 
2.25.4


  parent reply	other threads:[~2022-11-17 11:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 16:36 [PATCH 0/6] The DWARF assembler and Clang Andrew Burgess
2022-11-11 16:36 ` [PATCH 1/6] gdb/testsuite: don't avoid DWARF assembler tests with Clang Andrew Burgess
2022-11-11 16:36 ` [PATCH 2/6] gdb/testsuite: fix gdb.trace/unavailable-dwarf-piece.exp " Andrew Burgess
2022-11-16 14:41   ` Bruno Larsen
2022-11-17 11:06     ` Andrew Burgess
2022-12-12 17:55   ` Tom Tromey
2022-12-13 15:39     ` Andrew Burgess
2022-11-11 16:36 ` [PATCH 3/6] gdb/testsuite: fix gdb.compile/compile-ops.exp with clang Andrew Burgess
2022-11-16 16:27   ` Tom Tromey
2022-11-11 16:36 ` [PATCH 4/6] gdb/testsuite: add (and use) a new build-id compile option Andrew Burgess
2022-11-11 16:36 ` [PATCH 5/6] gdb/testsuite: fix gdb.debuginfod/fetch_src_and_symbols.exp with Clang Andrew Burgess
2022-11-16 16:29   ` Tom Tromey
2022-11-17 11:38     ` [PATCHv2 0/2] Fix " Andrew Burgess
2022-11-17 11:38       ` [PATCHv2 1/2] gdb/testsuite: rename source file gdb.debuginfod/main.c Andrew Burgess
2022-11-17 11:38       ` Andrew Burgess [this message]
2022-11-17 19:29       ` [PATCHv2 0/2] Fix gdb.debuginfod/fetch_src_and_symbols.exp with Clang Tom Tromey
2022-11-11 16:36 ` [PATCH 6/6] gdb/testsuite: rewrite gdb.cp/call-method-register.exp with dwarf assembler Andrew Burgess
2022-11-16 11:59   ` Lancelot SIX
2022-11-16 16:32 ` [PATCH 0/6] The DWARF assembler and Clang Tom Tromey
2022-11-18 11:48   ` Andrew Burgess

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=ddaa73456d3b605d200b0af63a9c21ceca75cefa.1668684812.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).