public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] [gdb/testsuite] Fix another fail and tcl error in gdb.dap/sources.exp
Date: Tue, 13 Feb 2024 17:18:23 +0100	[thread overview]
Message-ID: <20240213161823.25945-1-tdevries@suse.de> (raw)

With gdb.dap/sources.exp on aarch64-linux, I'm running into:
...
{"request_seq": 3, "type": "response", "command": "loadedSources", \
  "success": false, "message": "notStopped", "seq": 7}Content-Length: 92^M
^M
{"type": "event", "event": "thread", \
  "body": {"reason": "started", "threadId": 1}, \
  "seq": 8}FAIL: gdb.dap/sources.exp: loadedSources success
ERROR: tcl error sourcing gdb.dap/sources.exp.
ERROR: tcl error code TCL LOOKUP DICT body
ERROR: key "body" not known in dictionary
    while executing
"dict get [lindex $obj 0] body sources"
...

These are the same type of tcl error and FAIL I just fixed for a later
request in the same test-case.

Fix this by:
- moving the wait-for-stop to before the loadedSources request to fix the
  FAIL, and
- checking for $obj == "" to fix the tcl error.

Also make the code a bit less indented and more readable by wrapping the tests
in a proc, allowing the use of return to bail out, while still running
dap_shutdown afterwards.

Tested on aarch64-linux.
---
 gdb/testsuite/gdb.dap/sources.exp | 41 ++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/gdb/testsuite/gdb.dap/sources.exp b/gdb/testsuite/gdb.dap/sources.exp
index 9b56337e5a8..ee853cc68aa 100644
--- a/gdb/testsuite/gdb.dap/sources.exp
+++ b/gdb/testsuite/gdb.dap/sources.exp
@@ -33,30 +33,37 @@ if {[dap_launch $testfile stop_at_main 1] == ""} {
     return
 }
 
-set obj [dap_check_request_and_response loadedSources loadedSources]
-set path ""
-foreach src [dict get [lindex $obj 0] body sources] {
-    if {[file tail [dict get $src name]] == "sources.c"} {
-	set path [dict get $src path]
-    }	
-}
-
-if {$path == ""} {
-    fail "sources.c in loadedSources"
-} else {
-    pass "sources.c in loadedSources"
-
+proc do_tests {} {
     dap_wait_for_event_and_check "stopped at function breakpoint" stopped \
 	"body reason" breakpoint
 
+    set obj [dap_check_request_and_response loadedSources loadedSources]
+    if { $obj == "" } {
+	return
+    }
+
+    set path ""
+    foreach src [dict get [lindex $obj 0] body sources] {
+	if {[file tail [dict get $src name]] == "sources.c"} {
+	    set path [dict get $src path]
+	}
+    }
+    gdb_assert {$path != "" } "sources.c in loadedSources"
+    if {$path == ""} {
+	return
+    }
+
     set obj [dap_check_request_and_response "get source" source \
 		 [format {o source [o path [s %s]] \
-			    sourceReference [i 0]} $path]]
-    if { $obj != "" } {
-	set text [dict get [lindex $obj 0] body content]
-	gdb_assert {[string first "Distinguishing comment" $text] != -1}
+			      sourceReference [i 0]} $path]]
+    if { $obj == "" } {
+	return
     }
+
+    set text [dict get [lindex $obj 0] body content]
+    gdb_assert {[string first "Distinguishing comment" $text] != -1}
 }
 
+do_tests
 
 dap_shutdown

base-commit: a16034bf6417dc2259fef43fd5bcc2dd1dac562f
-- 
2.35.3


             reply	other threads:[~2024-02-13 16:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13 16:18 Tom de Vries [this message]
2024-02-13 18:08 ` Tom Tromey
2024-02-14  8:56   ` 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=20240213161823.25945-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --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).