public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/5] gdb/testsuite/: Use -qualified in runto_main / mi_runto_main
Date: Mon, 12 Oct 2020 01:47:30 +0100	[thread overview]
Message-ID: <20201012004732.22999-4-pedro@palves.net> (raw)
In-Reply-To: <20201012004732.22999-1-pedro@palves.net>

In some runtimes, there may be a "main" function in some class or
namespace.  The breakpoint created by runto_main may therefore have
unexpected locations on some other functions than the actual main.
These breakpoint locations can unexpectedly get hit during tests and
lead to failures.

I saw this while playing with AMD's ROCm toolchain -- I wrote a board
file to run the testsuite against device kernels.  There, the runtime
calls a "main" function before the device kernel code is reached:

 Thread 4 "bit_extract" hit Breakpoint 1, 0x00007ffeea140960 in lld::elf::LinkerDriver::main(llvm::ArrayRef<char const*>) () from /opt/rocm/lib/libamd_comgr.so.1
 (gdb) bt
 #0  0x00007ffeea140960 in lld::elf::LinkerDriver::main(llvm::ArrayRef<char const*>) () from /opt/rocm/lib/libamd_comgr.so.1
 #1  0x00007ffeea2257a5 in lld::elf::link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&, llvm::raw_ostream&) () from /opt/rocm/lib/libamd_comgr.so.1
 #2  0x00007ffeea1bc374 in COMGR::linkWithLLD(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&) () from /opt/rocm/lib/libamd_comgr.so.1
 #3  0x00007ffeea1bfb09 in COMGR::InProcessDriver::execute(llvm::ArrayRef<char const*>) () from /opt/rocm/lib/libamd_comgr.so.1
 #4  0x00007ffeea1c4da9 in COMGR::AMDGPUCompiler::linkToExecutable() () from /opt/rocm/lib/libamd_comgr.so.1
 #5  0x00007ffeea1fde20 in dispatchCompilerAction(amd_comgr_action_kind_s, COMGR::DataAction*, COMGR::DataSet*, COMGR::DataSet*, llvm::raw_ostream&) () from /opt/rocm/lib/libamd_comgr.so.1
 #6  0x00007ffeea203a87 in amd_comgr_do_action () from /opt/rocm/lib/libamd_comgr.so.1
 ...

To avoid that, pass "qualified" to runto, in runto_main, so that
gdb_breakpoint ends up creating a breakpoint with -qualified.  This
avoids creating breakpoints locations for other unrelated "main"
functions.

Note: I first tried making runto itself use "-qualified", but that
caused regressions in the gdb.ada/ tests, which use runto without
specifying the whole fully-qualified function name (i.e., without the
package).  So I end up restricting the -qualified to
runto_main/mi_runto_main.

The gdb.base/ui-redirect.exp change is necessary because that testcase
is looking at what "save breakpoint" generates.

gdb/testsuite/ChangeLog:

	* gdb.base/ui-redirect.exp: Expect "break -qualified main" in
	saved breakpoints file.
	* gdb.guile/scm-breakpoint.exp: Expect "-qualified main" when
	inspecting breakpoint list.
	* lib/gdb.exp (runto_main): Add "qualified" to options.
	* lib/mi-support.exp (mi_runto_helper): Add 'qualified' parameter,
	and handle it.
	(mi_runto_main): Pass 1 as qualified argument.

Change-Id: I51468359ab0a518f05f7c0394c97f7e33b45fe69
---
 gdb/testsuite/gdb.base/ui-redirect.exp     |  2 +-
 gdb/testsuite/gdb.guile/scm-breakpoint.exp |  2 +-
 gdb/testsuite/lib/gdb.exp                  |  2 +-
 gdb/testsuite/lib/mi-support.exp           | 10 +++++++---
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
index ef0a79178c7..9e0a694c798 100644
--- a/gdb/testsuite/gdb.base/ui-redirect.exp
+++ b/gdb/testsuite/gdb.base/ui-redirect.exp
@@ -47,7 +47,7 @@ gdb_breakpoint "foo"
 gdb_breakpoint "bar"
 
 set cmds [multi_line_input \
-	      "break main" \
+	      "break -qualified main" \
 	      "  commands" \
 	      "    print 1" \
 	      "  end" \
diff --git a/gdb/testsuite/gdb.guile/scm-breakpoint.exp b/gdb/testsuite/gdb.guile/scm-breakpoint.exp
index 7545392452e..3bcd5c81546 100644
--- a/gdb/testsuite/gdb.guile/scm-breakpoint.exp
+++ b/gdb/testsuite/gdb.guile/scm-breakpoint.exp
@@ -43,7 +43,7 @@ proc test_bkpt_basic { } {
 	gdb_scm_test_silent_cmd "guile (define blist (breakpoints))" \
 	    "get breakpoint list 1"
 	gdb_test "guile (print (car blist))" \
-	    "<gdb:breakpoint #1 BP_BREAKPOINT enabled noisy hit:1 ignore:0 @main>" \
+	    "<gdb:breakpoint #1 BP_BREAKPOINT enabled noisy hit:1 ignore:0 @-qualified main>" \
 	    "check main breakpoint"
 	gdb_test "guile (print (breakpoint-location (car blist)))" \
 	    "main" "check main breakpoint location"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 608469953bf..4c9675f255f 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -689,7 +689,7 @@ proc runto { function args } {
 # If you don't want that, use gdb_start_cmd.
 
 proc runto_main { } {
-    return [runto main no-message]
+    return [runto main no-message qualified]
 }
 
 ### Continue, and expect to hit a breakpoint.
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 732aed27b27..693c7d2c467 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -1056,7 +1056,7 @@ proc mi_run_to_main { } {
 #   -1  if test suppressed, failed, timedout
 #    0  if test passed
 
-proc mi_runto_helper {func run_or_continue} {
+proc mi_runto_helper {func run_or_continue {qualified 0}} {
   global suppress_flag
   if { $suppress_flag } {
     return -1
@@ -1068,7 +1068,11 @@ proc mi_runto_helper {func run_or_continue} {
   set test "mi runto $func"
   set bp [mi_make_breakpoint -type breakpoint -disp del \
 	      -func $func\(\\\(.*\\\)\)?]
-  mi_gdb_test "200-break-insert -t $func" "200\\^done,$bp" \
+  set extra_opts ""
+  if {$qualified} {
+      append extra_opts "--qualified"
+  }
+  mi_gdb_test "200-break-insert $extra_opts -t $func" "200\\^done,$bp" \
       "breakpoint at $func"
 
   if {$run_or_continue == "run"} {
@@ -1089,7 +1093,7 @@ proc mi_runto {func} {
 # Just like runto_main but works with the MI interface.
 
 proc mi_runto_main {} {
-    return [mi_runto_helper "main" "run"]
+    return [mi_runto_helper "main" "run" 1]
 }
 
 # Next to the next statement
-- 
2.14.5


  parent reply	other threads:[~2020-10-12  0:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12  0:47 [PATCH 0/5] runto_main and -qualified Pedro Alves
2020-10-12  0:47 ` [PATCH 1/5] 'runto main' -> 'runto_main' throughout Pedro Alves
2020-10-13 17:57   ` Simon Marchi
2020-10-12  0:47 ` [PATCH 2/5] Introduce mi_runto_main Pedro Alves
2020-10-13 18:00   ` Simon Marchi
2020-10-12  0:47 ` Pedro Alves [this message]
2020-10-13 18:06   ` [PATCH 3/5] gdb/testsuite/: Use -qualified in runto_main / mi_runto_main Simon Marchi
2020-10-13 21:33     ` Pedro Alves
2020-10-12  0:47 ` [PATCH 4/5] gdb/testsuite/: Use "-qualified" in explicit "break main", etc Pedro Alves
2020-10-13 18:07   ` Simon Marchi
2020-10-12 18:56 ` [RESEND][PATCH 5/5] Eliminate mi_run_to_main, introduce mi_clean_restart Pedro Alves
2020-10-13 18:19   ` Simon Marchi
2020-10-13 21:36     ` Pedro Alves
2020-10-14  8:40       ` Tom de Vries

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=20201012004732.22999-4-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.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).