public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] testsuite, mi: fix indentation in get_mi_thread_list
@ 2024-02-29 15:49 Tankut Baris Aktemur
  2024-02-29 15:49 ` [PATCH v2 2/2] testsuite, mi: prevent buffer overflow " Tankut Baris Aktemur
  0 siblings, 1 reply; 3+ messages in thread
From: Tankut Baris Aktemur @ 2024-02-29 15:49 UTC (permalink / raw)
  To: gdb-patches

The `get_mi_thread_list` procedure's body is incorrectly indented.
Fix it.

One line is still too long, but we don't care to break it.  The next
patch will change it.
---
 gdb/testsuite/lib/mi-support.exp | 58 ++++++++++++++++----------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index b3a27efb155..33a3a71b396 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -1953,40 +1953,40 @@ proc mi_run_inline_test { testcase } {
 }
 
 proc get_mi_thread_list {name} {
-  global expect_out
+    global expect_out
 
-  # MI will return a list of thread ids:
-  #
-  # -thread-list-ids
-  # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
-  # (gdb)
-  mi_gdb_test "-thread-list-ids" \
-    {.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
-    "-thread_list_ids ($name)"
+    # MI will return a list of thread ids:
+    #
+    # -thread-list-ids
+    # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
+    # (gdb)
+    mi_gdb_test "-thread-list-ids" \
+	{.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
+	"-thread_list_ids ($name)"
 
-  set output {}
-  if {[info exists expect_out(buffer)]} {
-    set output $expect_out(buffer)
-  }
+    set output {}
+    if {[info exists expect_out(buffer)]} {
+	set output $expect_out(buffer)
+    }
 
-  set thread_list {}
-  if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
-    fail "finding threads in MI output ($name)"
-  } else {
-    pass "finding threads in MI output ($name)"
-
-    # Make list of console threads
-    set start [expr {[string first \{ $threads] + 1}]
-    set end   [expr {[string first \} $threads] - 1}]
-    set threads [string range $threads $start $end]
-    foreach thread [split $threads ,] {
-      if {[scan $thread {thread-id="%d"} num]} {
-	lappend thread_list $num
-      }
+    set thread_list {}
+    if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
+	fail "finding threads in MI output ($name)"
+    } else {
+	pass "finding threads in MI output ($name)"
+
+	# Make list of console threads
+	set start [expr {[string first \{ $threads] + 1}]
+	set end   [expr {[string first \} $threads] - 1}]
+	set threads [string range $threads $start $end]
+	foreach thread [split $threads ,] {
+	    if {[scan $thread {thread-id="%d"} num]} {
+		lappend thread_list $num
+	    }
+	}
     }
-  }
 
-  return $thread_list
+    return $thread_list
 }
 
 # Check that MI and the console know of the same threads.
-- 
2.34.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

* [PATCH v2 2/2] testsuite, mi: prevent buffer overflow in get_mi_thread_list
  2024-02-29 15:49 [PATCH v2 1/2] testsuite, mi: fix indentation in get_mi_thread_list Tankut Baris Aktemur
@ 2024-02-29 15:49 ` Tankut Baris Aktemur
  2024-04-02  8:54   ` Aktemur, Tankut Baris
  0 siblings, 1 reply; 3+ messages in thread
From: Tankut Baris Aktemur @ 2024-02-29 15:49 UTC (permalink / raw)
  To: gdb-patches

For the first version of this patch, Linaro's bot reported regression:

  https://ci.linaro.org/job/tcwg_gdb_check--master-arm-precommit/1788/artifact/artifacts/artifacts.precommit/notify/mail-body.txt

I cannot reproduce the failure locally.  In this revision, I added the
"-prompt" flag to gdb_test_multiple.  Hopefully that will help address
the failure reported by the bot.

The first version is available at

  https://sourceware.org/pipermail/gdb-patches/2024-February/206885.html

Regards,
Baris

=================================

If there is a large number of threads in the input program, the
expect buffer in `get_mi_thread_list` would become full.  Prevent this
by consuming the buffer in small pieces.
---
 gdb/testsuite/lib/mi-support.exp | 52 +++++++++++++++++---------------
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 33a3a71b396..6862b831c07 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -1953,39 +1953,43 @@ proc mi_run_inline_test { testcase } {
 }
 
 proc get_mi_thread_list {name} {
-    global expect_out
+    global expect_out decimal mi_gdb_prompt
 
     # MI will return a list of thread ids:
     #
     # -thread-list-ids
-    # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
+    # ^done,thread-ids={thread-id="1",thread-id="2",...},number-of-threads="N"
     # (gdb)
-    mi_gdb_test "-thread-list-ids" \
-	{.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
-	"-thread_list_ids ($name)"
-
-    set output {}
-    if {[info exists expect_out(buffer)]} {
-	set output $expect_out(buffer)
-    }
-
+    #
+    # In case there are too many threads, the expect buffer would
+    # become full.  Process the buffer contents in small chunks.
     set thread_list {}
-    if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
-	fail "finding threads in MI output ($name)"
-    } else {
-	pass "finding threads in MI output ($name)"
-
-	# Make list of console threads
-	set start [expr {[string first \{ $threads] + 1}]
-	set end   [expr {[string first \} $threads] - 1}]
-	set threads [string range $threads $start $end]
-	foreach thread [split $threads ,] {
-	    if {[scan $thread {thread-id="%d"} num]} {
-		lappend thread_list $num
-	    }
+    set num_threads "unknown"
+    set test "$name: get mi thread list"
+    gdb_test_multiple "-thread-list-ids" $test -prompt "$mi_gdb_prompt" {
+	-re "done,thread-ids=\{" {
+	    exp_continue
+	}
+	-re "^thread-id=\"($decimal)\"(,|\})" {
+	    set num $expect_out(1,string)
+	    lappend thread_list $num
+	    exp_continue
+	}
+	-re "^,current-thread-id=\"$decimal\"" {
+	    exp_continue
+	}
+	-re "^,number-of-threads=\"($decimal)\"" {
+	    set num_threads $expect_out(1,string)
+	    exp_continue
+	}
+	-re "^\r\n$mi_gdb_prompt" {
+	    pass $gdb_test_name
 	}
     }
 
+    gdb_assert {[llength $thread_list] == $num_threads} \
+	"$name: found thread ids in MI output"
+
     return $thread_list
 }
 
-- 
2.34.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 v2 2/2] testsuite, mi: prevent buffer overflow in get_mi_thread_list
  2024-02-29 15:49 ` [PATCH v2 2/2] testsuite, mi: prevent buffer overflow " Tankut Baris Aktemur
@ 2024-04-02  8:54   ` Aktemur, Tankut Baris
  0 siblings, 0 replies; 3+ messages in thread
From: Aktemur, Tankut Baris @ 2024-04-02  8:54 UTC (permalink / raw)
  To: gdb-patches

Kindly pinging.

Thanks
-Baris

On Thursday, February 29, 2024 4:49 PM, Aktemur, Tankut Baris wrote:
> For the first version of this patch, Linaro's bot reported regression:
> 
>   https://ci.linaro.org/job/tcwg_gdb_check--master-arm-
> precommit/1788/artifact/artifacts/artifacts.precommit/notify/mail-body.txt
> 
> I cannot reproduce the failure locally.  In this revision, I added the
> "-prompt" flag to gdb_test_multiple.  Hopefully that will help address
> the failure reported by the bot.
> 
> The first version is available at
> 
>   https://sourceware.org/pipermail/gdb-patches/2024-February/206885.html
> 
> Regards,
> Baris
> 
> =================================
> 
> If there is a large number of threads in the input program, the
> expect buffer in `get_mi_thread_list` would become full.  Prevent this
> by consuming the buffer in small pieces.
> ---
>  gdb/testsuite/lib/mi-support.exp | 52 +++++++++++++++++---------------
>  1 file changed, 28 insertions(+), 24 deletions(-)
> 
> diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
> index 33a3a71b396..6862b831c07 100644
> --- a/gdb/testsuite/lib/mi-support.exp
> +++ b/gdb/testsuite/lib/mi-support.exp
> @@ -1953,39 +1953,43 @@ proc mi_run_inline_test { testcase } {
>  }
> 
>  proc get_mi_thread_list {name} {
> -    global expect_out
> +    global expect_out decimal mi_gdb_prompt
> 
>      # MI will return a list of thread ids:
>      #
>      # -thread-list-ids
> -    # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
> +    # ^done,thread-ids={thread-id="1",thread-id="2",...},number-of-threads="N"
>      # (gdb)
> -    mi_gdb_test "-thread-list-ids" \
> -	{.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-
> of-threads="[0-9]+"} \
> -	"-thread_list_ids ($name)"
> -
> -    set output {}
> -    if {[info exists expect_out(buffer)]} {
> -	set output $expect_out(buffer)
> -    }
> -
> +    #
> +    # In case there are too many threads, the expect buffer would
> +    # become full.  Process the buffer contents in small chunks.
>      set thread_list {}
> -    if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
> -	fail "finding threads in MI output ($name)"
> -    } else {
> -	pass "finding threads in MI output ($name)"
> -
> -	# Make list of console threads
> -	set start [expr {[string first \{ $threads] + 1}]
> -	set end   [expr {[string first \} $threads] - 1}]
> -	set threads [string range $threads $start $end]
> -	foreach thread [split $threads ,] {
> -	    if {[scan $thread {thread-id="%d"} num]} {
> -		lappend thread_list $num
> -	    }
> +    set num_threads "unknown"
> +    set test "$name: get mi thread list"
> +    gdb_test_multiple "-thread-list-ids" $test -prompt "$mi_gdb_prompt" {
> +	-re "done,thread-ids=\{" {
> +	    exp_continue
> +	}
> +	-re "^thread-id=\"($decimal)\"(,|\})" {
> +	    set num $expect_out(1,string)
> +	    lappend thread_list $num
> +	    exp_continue
> +	}
> +	-re "^,current-thread-id=\"$decimal\"" {
> +	    exp_continue
> +	}
> +	-re "^,number-of-threads=\"($decimal)\"" {
> +	    set num_threads $expect_out(1,string)
> +	    exp_continue
> +	}
> +	-re "^\r\n$mi_gdb_prompt" {
> +	    pass $gdb_test_name
>  	}
>      }
> 
> +    gdb_assert {[llength $thread_list] == $num_threads} \
> +	"$name: found thread ids in MI output"
> +
>      return $thread_list
>  }
> 
> --
> 2.34.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

end of thread, other threads:[~2024-04-02  8:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 15:49 [PATCH v2 1/2] testsuite, mi: fix indentation in get_mi_thread_list Tankut Baris Aktemur
2024-02-29 15:49 ` [PATCH v2 2/2] testsuite, mi: prevent buffer overflow " Tankut Baris Aktemur
2024-04-02  8:54   ` 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).