public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/testsuite: fix gdb.python/py-events.exp for finding process id
@ 2022-01-12  9:51 Tankut Baris Aktemur
  2022-01-12 14:50 ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Tankut Baris Aktemur @ 2022-01-12  9:51 UTC (permalink / raw)
  To: gdb-patches

When executed with --target_board=native-extended-gdbserver, the
gdb.python/py-events.exp test errors out with

  ERROR: tcl error sourcing /path/to/gdb/testsuite/gdb.python/py-events.exp.
  ERROR: can't read "process_id": no such variable
      while executing
  "lappend expected "ptid: \\($process_id, $process_id, 0\\)" "address: $addr""
      (file "/path/to/gdb/testsuite/gdb.python/py-events.exp" line 103)
      invoked from within
  "source /path/to/gdb/testsuite/gdb.python/py-events.exp"
      ("uplevel" body line 1)
      invoked from within
  "uplevel #0 source /path/to/gdb/testsuite/gdb.python/py-events.exp"
      invoked from within                                                                                                                                                                       "catch "uplevel #0 source $test_file_name""

There are multiple problems around this:

1. The process_id variable is not initialized to a default value.

2. The test attempts to find the PID of the current thread, but the
   regexp that it uses is not tailored for the output printed by the
   remote target.

3. The test uses "info threads" to find the current thread PID.
   Using the "thread" command instead is simpler.

Fix these problems.
---
 gdb/testsuite/gdb.python/py-events.exp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp
index 4df012b943b..4b411999588 100644
--- a/gdb/testsuite/gdb.python/py-events.exp
+++ b/gdb/testsuite/gdb.python/py-events.exp
@@ -81,12 +81,17 @@ delete_breakpoints
 
 # Test inferior call events
 
-gdb_test_multiple "info threads" "get current thread" {
-    -re -wrap "process ($decimal)\[^\n\r\]*do_nothing.*" {
+set process_id 0
+gdb_test_multiple "thread" "get current thread" {
+    -re -wrap "process ($decimal).*" {
 	set process_id $expect_out(1,string)
 	pass $gdb_test_name
     }
-    -re -wrap "Thread $hex \\(LWP ($decimal)\\)\[^\n\r\]*do_nothing.*" {
+    -re -wrap "Thread $hex \\(LWP ($decimal)\\).*" {
+	set process_id $expect_out(1,string)
+	pass $gdb_test_name
+    }
+    -re -wrap "Thread $decimal\.($decimal).*" {
 	set process_id $expect_out(1,string)
 	pass $gdb_test_name
     }
-- 
2.33.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

* Re: [PATCH] gdb/testsuite: fix gdb.python/py-events.exp for finding process id
  2022-01-12  9:51 [PATCH] gdb/testsuite: fix gdb.python/py-events.exp for finding process id Tankut Baris Aktemur
@ 2022-01-12 14:50 ` Andrew Burgess
  2022-01-12 15:22   ` Aktemur, Tankut Baris
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2022-01-12 14:50 UTC (permalink / raw)
  To: Tankut Baris Aktemur; +Cc: gdb-patches

* Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> [2022-01-12 10:51:51 +0100]:

> When executed with --target_board=native-extended-gdbserver, the
> gdb.python/py-events.exp test errors out with
> 
>   ERROR: tcl error sourcing /path/to/gdb/testsuite/gdb.python/py-events.exp.
>   ERROR: can't read "process_id": no such variable
>       while executing
>   "lappend expected "ptid: \\($process_id, $process_id, 0\\)" "address: $addr""
>       (file "/path/to/gdb/testsuite/gdb.python/py-events.exp" line 103)
>       invoked from within
>   "source /path/to/gdb/testsuite/gdb.python/py-events.exp"
>       ("uplevel" body line 1)
>       invoked from within
>   "uplevel #0 source /path/to/gdb/testsuite/gdb.python/py-events.exp"
>       invoked from within                                                                                                                                                                       "catch "uplevel #0 source $test_file_name""
> 
> There are multiple problems around this:
> 
> 1. The process_id variable is not initialized to a default value.
> 
> 2. The test attempts to find the PID of the current thread, but the
>    regexp that it uses is not tailored for the output printed by the
>    remote target.
> 
> 3. The test uses "info threads" to find the current thread PID.
>    Using the "thread" command instead is simpler.
> 
> Fix these problems.
> ---
>  gdb/testsuite/gdb.python/py-events.exp | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp
> index 4df012b943b..4b411999588 100644
> --- a/gdb/testsuite/gdb.python/py-events.exp
> +++ b/gdb/testsuite/gdb.python/py-events.exp
> @@ -81,12 +81,17 @@ delete_breakpoints
>  
>  # Test inferior call events
>  
> -gdb_test_multiple "info threads" "get current thread" {
> -    -re -wrap "process ($decimal)\[^\n\r\]*do_nothing.*" {
> +set process_id 0

This looks good.  My only suggestion would be don't initialise
process_id to a number.  I know it's pretty unlikely that `0` is ever
going to be a valid result, but it's not impossible.

If you instead initialise to something like "invalid" then there's
even less chance that this will match the actual output.

With that change this is good to apply.

Thanks,
Andrew


> +gdb_test_multiple "thread" "get current thread" {
> +    -re -wrap "process ($decimal).*" {
>  	set process_id $expect_out(1,string)
>  	pass $gdb_test_name
>      }
> -    -re -wrap "Thread $hex \\(LWP ($decimal)\\)\[^\n\r\]*do_nothing.*" {
> +    -re -wrap "Thread $hex \\(LWP ($decimal)\\).*" {
> +	set process_id $expect_out(1,string)
> +	pass $gdb_test_name
> +    }
> +    -re -wrap "Thread $decimal\.($decimal).*" {
>  	set process_id $expect_out(1,string)
>  	pass $gdb_test_name
>      }
> -- 
> 2.33.1
> 
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
> Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928
> 


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

* RE: [PATCH] gdb/testsuite: fix gdb.python/py-events.exp for finding process id
  2022-01-12 14:50 ` Andrew Burgess
@ 2022-01-12 15:22   ` Aktemur, Tankut Baris
  0 siblings, 0 replies; 3+ messages in thread
From: Aktemur, Tankut Baris @ 2022-01-12 15:22 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On Wednesday, January 12, 2022 3:50 PM, Andrew Burgess wrote:
> > diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-
> events.exp
> > index 4df012b943b..4b411999588 100644
> > --- a/gdb/testsuite/gdb.python/py-events.exp
> > +++ b/gdb/testsuite/gdb.python/py-events.exp
> > @@ -81,12 +81,17 @@ delete_breakpoints
> >
> >  # Test inferior call events
> >
> > -gdb_test_multiple "info threads" "get current thread" {
> > -    -re -wrap "process ($decimal)\[^\n\r\]*do_nothing.*" {
> > +set process_id 0
> 
> This looks good.  My only suggestion would be don't initialise
> process_id to a number.  I know it's pretty unlikely that `0` is ever
> going to be a valid result, but it's not impossible.
> 
> If you instead initialise to something like "invalid" then there's
> even less chance that this will match the actual output.
> 
> With that change this is good to apply.
> 
> Thanks,
> Andrew

Pushed with this fix.

Thanks.
-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

end of thread, other threads:[~2022-01-12 15:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12  9:51 [PATCH] gdb/testsuite: fix gdb.python/py-events.exp for finding process id Tankut Baris Aktemur
2022-01-12 14:50 ` Andrew Burgess
2022-01-12 15:22   ` Aktemur, Tankut Baris

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