public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug testsuite/31382] New: [gdb/testsuite] 2 errors instead of 1 reported by _dap_read_json
Date: Wed, 14 Feb 2024 13:56:43 +0000	[thread overview]
Message-ID: <bug-31382-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=31382

            Bug ID: 31382
           Summary: [gdb/testsuite] 2 errors instead of 1 reported by
                    _dap_read_json
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: testsuite
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider test-case gdb.dap/eof.exp, modified like so:
...
diff --git a/gdb/testsuite/gdb.dap/eof.exp b/gdb/testsuite/gdb.dap/eof.exp
index 9c17725c0d0..26bad3eeb3f 100644
--- a/gdb/testsuite/gdb.dap/eof.exp
+++ b/gdb/testsuite/gdb.dap/eof.exp
@@ -30,6 +30,9 @@ if {[dap_initialize] == ""} {
     return
 }

+_dap_wait_for_event "initialized"
+return
+
 catch "close -i $gdb_spawn_id"
 catch "wait -i $gdb_spawn_id"
 unset gdb_spawn_id
...

That works fine (well, unless we run into PR31306).

Now, if we add another _dap_wait_for_event line like it, we run into a timeout
error followed by an eof error:
...
Running /data/vries/gdb/src/gdb/testsuite/gdb.dap/eof.exp ...
ERROR: timeout reading json header
    while executing
"error "timeout reading json header""
    invoked from within
"expect {
-i exp9 -timeout 10 
        -re "^Content-Length: (\[0-9\]+)\r\n" {
            set length $expect_out(1,string)
            exp_continue
        }
        -re "^(\[^\r\n\]+)\..."
    ("uplevel" body line 1)
    invoked from within
"uplevel $body" NONE timeout reading json header
ERROR: tcl error sourcing /data/vries/gdb/src/gdb/testsuite/gdb.dap/eof.exp.
ERROR: eof reading json header
    while executing
"error "eof reading json header""
    ("uplevel" body line 2)
    invoked from within
"uplevel $error_sect"
    invoked from within
"remote_expect host 10 {
        -re "^Content-Length: (\[0-9\]+)\r\n" {
            set length $expect_out(1,string)
            exp_continue
        }
        -re "^(\[^\r\n\]+)\r\n" {..."
    ("uplevel" body line 1)
    invoked from within
"uplevel remote_expect host $tmt $expcode"
    invoked from within
"gdb_expect {
        -re "^Content-Length: (\[0-9\]+)\r\n" {
            set length $expect_out(1,string)
            exp_continue
        }
        -re "^(\[^\r\n\]+)\r\n" {
            # Any..."
    (procedure "_dap_read_json" line 3)
    invoked from within
"_dap_read_json"
    (procedure "_dap_wait_for_event" line 7)
    invoked from within
"_dap_wait_for_event "initialized""
    (file "/data/vries/gdb/src/gdb/testsuite/gdb.dap/eof.exp" line 34)
    invoked from within
"source /data/vries/gdb/src/gdb/testsuite/gdb.dap/eof.exp"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 source /data/vries/gdb/src/gdb/testsuite/gdb.dap/eof.exp"
    invoked from within
"catch "uplevel #0 source $test_file_name""
...

This is caused by using calls to error in these gdb_expect clauses in
_dap_read_json:
...
        timeout {
            error "timeout reading json header"
        }
        eof {
            error "eof reading json header"
        }
...

Proc gdb_expect uses dejagnu's remote_expect, which has some peculiar semantics
related to errors:
...
# remote_expect works basically the same as standard expect, but it             
# also takes care of getting the file descriptor from the specified             
# host and also calling the timeout/eof/default section if there is an          
# error on the expect call.                                                     
#                                                                               
...

So, the timeout error is caught by gdb_expect, and then printed, after which
the "timeout/eof/default" is called, which triggers the eof error.

I'm not sure how that proc is supposed to work, so this may or may not be
correct behaviour.

Either way, it's questionable whether it's a good idea to use error directly in
gdb_expect clauses.

I ran into this when trying to catch the timeout error:
...
catch {_dap_wait_for_event initialized}
...
which didn't work because the timeout error is caught and printed by
remote_expect.  Instead, we catch the eof error.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2024-02-14 13:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 13:56 vries at gcc dot gnu.org [this message]
2024-02-14 14:00 ` [Bug testsuite/31382] " vries at gcc dot gnu.org
2024-02-14 16:23 ` vries at gcc dot gnu.org
2024-02-21 13:25 ` cvs-commit at gcc dot gnu.org
2024-02-21 13:26 ` vries at gcc dot gnu.org
2024-02-21 13:26 ` vries at gcc dot gnu.org

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-31382-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@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).