public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/testsuite] Fix error handling in _dap_read_json
@ 2024-02-14 16:22 Tom de Vries
  2024-02-21 13:27 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2024-02-14 16:22 UTC (permalink / raw)
  To: gdb-patches

In _dap_read_json we have a gdb_expect with clauses that generate errors:
...
        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.
.....

When a timeout triggers, it generates a timeout error, which is reported by
gdb_expect, after which it runs the timeout/eof/default clauses, which
generates an eof error, which is reported by runtest.

I think the intention here is to generate just a one error, a timeout error.

Fix this by postponing generating the error until after gdb_expect.

Tested on x86_64-linux, by:
- running all the DAP test-cases and observing no regressions, and
- modifying the gdb.dap/eof.exp test-case to trigger a timeout error, and
  observing only a timeout error.

PR testsuite/31382
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31382
---
 gdb/testsuite/lib/dap-support.exp | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp
index 979dfa2cd73..42c1491e507 100644
--- a/gdb/testsuite/lib/dap-support.exp
+++ b/gdb/testsuite/lib/dap-support.exp
@@ -137,6 +137,8 @@ proc dap_send_request {command {obj {}}} {
 # "last_ton" will be set to the TON form of the result.
 proc _dap_read_json {} {
     set length ""
+    set seen_timeout 0
+    set seen_eof 0
     gdb_expect {
 	-re "^Content-Length: (\[0-9\]+)\r\n" {
 	    set length $expect_out(1,string)
@@ -150,13 +152,20 @@ proc _dap_read_json {} {
 	    # Done.
 	}
 	timeout {
-	    error "timeout reading json header"
+	    set seen_timeout 1
 	}
 	eof {
-	    error "eof reading json header"
+	    set seen_eof 1
 	}
     }
 
+    if {$seen_timeout} {
+	error "timeout reading json header"	
+    }
+    if {$seen_eof} {
+	error "eof reading json header"
+    }
+
     if {$length == ""} {
 	error "didn't find content-length"
     }
@@ -166,17 +175,27 @@ proc _dap_read_json {} {
 	# Tcl only allows up to 255 characters in a {} expression in a
 	# regexp, so we may need to read in chunks.
 	set this_len [expr {min ($length, 255)}]
+	set seen_timeout 0
+	set seen_eof 0
 	gdb_expect {
 	    -re "^.{$this_len}" {
 		append json $expect_out(0,string)
 	    }
 	    timeout {
-		error "timeout reading json body"
+		set seen_timeout 1
 	    }
 	    eof {
-		error "eof reading json body"
+		set seen_eof 1
 	    }
 	}
+
+	if {$seen_timeout} {
+	    error "timeout reading json header"	
+	}
+	if {$seen_eof} {
+	    error "eof reading json header"
+	}
+
 	incr length -$this_len
     }
 

base-commit: b235e90e740aa486e6bbe8243eedf109fed41a5c
-- 
2.35.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [gdb/testsuite] Fix error handling in _dap_read_json
  2024-02-14 16:22 [PATCH] [gdb/testsuite] Fix error handling in _dap_read_json Tom de Vries
@ 2024-02-21 13:27 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2024-02-21 13:27 UTC (permalink / raw)
  To: gdb-patches

On 2/14/24 17:22, Tom de Vries wrote:
> In _dap_read_json we have a gdb_expect with clauses that generate errors:
> ...
>          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.
> .....
> 
> When a timeout triggers, it generates a timeout error, which is reported by
> gdb_expect, after which it runs the timeout/eof/default clauses, which
> generates an eof error, which is reported by runtest.
> 
> I think the intention here is to generate just a one error, a timeout error.
> 
> Fix this by postponing generating the error until after gdb_expect.
> 

Committed.

Thanks,
- Tom

> Tested on x86_64-linux, by:
> - running all the DAP test-cases and observing no regressions, and
> - modifying the gdb.dap/eof.exp test-case to trigger a timeout error, and
>    observing only a timeout error.
> 
> PR testsuite/31382
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31382
> ---
>   gdb/testsuite/lib/dap-support.exp | 27 +++++++++++++++++++++++----
>   1 file changed, 23 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp
> index 979dfa2cd73..42c1491e507 100644
> --- a/gdb/testsuite/lib/dap-support.exp
> +++ b/gdb/testsuite/lib/dap-support.exp
> @@ -137,6 +137,8 @@ proc dap_send_request {command {obj {}}} {
>   # "last_ton" will be set to the TON form of the result.
>   proc _dap_read_json {} {
>       set length ""
> +    set seen_timeout 0
> +    set seen_eof 0
>       gdb_expect {
>   	-re "^Content-Length: (\[0-9\]+)\r\n" {
>   	    set length $expect_out(1,string)
> @@ -150,13 +152,20 @@ proc _dap_read_json {} {
>   	    # Done.
>   	}
>   	timeout {
> -	    error "timeout reading json header"
> +	    set seen_timeout 1
>   	}
>   	eof {
> -	    error "eof reading json header"
> +	    set seen_eof 1
>   	}
>       }
>   
> +    if {$seen_timeout} {
> +	error "timeout reading json header"	
> +    }
> +    if {$seen_eof} {
> +	error "eof reading json header"
> +    }
> +
>       if {$length == ""} {
>   	error "didn't find content-length"
>       }
> @@ -166,17 +175,27 @@ proc _dap_read_json {} {
>   	# Tcl only allows up to 255 characters in a {} expression in a
>   	# regexp, so we may need to read in chunks.
>   	set this_len [expr {min ($length, 255)}]
> +	set seen_timeout 0
> +	set seen_eof 0
>   	gdb_expect {
>   	    -re "^.{$this_len}" {
>   		append json $expect_out(0,string)
>   	    }
>   	    timeout {
> -		error "timeout reading json body"
> +		set seen_timeout 1
>   	    }
>   	    eof {
> -		error "eof reading json body"
> +		set seen_eof 1
>   	    }
>   	}
> +
> +	if {$seen_timeout} {
> +	    error "timeout reading json header"	
> +	}
> +	if {$seen_eof} {
> +	    error "eof reading json header"
> +	}
> +
>   	incr length -$this_len
>       }
>   
> 
> base-commit: b235e90e740aa486e6bbe8243eedf109fed41a5c


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-21 13:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14 16:22 [PATCH] [gdb/testsuite] Fix error handling in _dap_read_json Tom de Vries
2024-02-21 13:27 ` Tom de Vries

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).