Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/testsuite: show evaluation errors in gdb_assert
@ 2020-11-23 18:35 Simon Marchi via Gdb-patches
  2020-11-23 18:46 ` Luis Machado via Gdb-patches
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi via Gdb-patches @ 2020-11-23 18:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Let's say you put this gdb_assert in a test:

    gdb_assert "some invalid tcl code"

You just get:

    FAIL: gdb.base/template.exp: some invalid tcl code

That's not very easy to debug, since you don't know what's invalid in
your code.

Change gdb_assert to print the error message when catch's return code is
1 (TCL_ERROR).  The "warning" is shown both on stdout and in the log
file.  Mark the test as unresolved, because the evaluation error means
we couldn't reach a valid pass/fail conclusion.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (gdb_assert): Show error message on error.

Change-Id: Ie6477859554e909ed8d07fb2769c6f2f55e7cce6
---
 gdb/testsuite/lib/gdb.exp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index c42933b3f41e..f2954fd5192b 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1728,7 +1728,14 @@ proc gdb_assert { condition {message ""} } {
     }
 
     set code [catch {uplevel 1 expr $condition} res]
-    if {$code != 0 || !$res} {
+    if {$code == 1} {
+	# If code is 1 (TCL_ERROR), it means evaluation failed and res contains
+	# an error message.  Print the error message, and set res to 0 since we
+	# want to return a boolean.
+	warning "While evaluating expression in gdb_assert: $res"
+	unresolved $message
+	set res 0
+    } elseif { !$res } {
 	fail $message
     } else {
 	pass $message
-- 
2.26.2


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

* Re: [PATCH] gdb/testsuite: show evaluation errors in gdb_assert
  2020-11-23 18:35 [PATCH] gdb/testsuite: show evaluation errors in gdb_assert Simon Marchi via Gdb-patches
@ 2020-11-23 18:46 ` Luis Machado via Gdb-patches
  2020-11-23 22:27   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Luis Machado via Gdb-patches @ 2020-11-23 18:46 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 11/23/20 3:35 PM, Simon Marchi via Gdb-patches wrote:
> Let's say you put this gdb_assert in a test:
> 
>      gdb_assert "some invalid tcl code"
> 
> You just get:
> 
>      FAIL: gdb.base/template.exp: some invalid tcl code
> 
> That's not very easy to debug, since you don't know what's invalid in
> your code.
> 
> Change gdb_assert to print the error message when catch's return code is
> 1 (TCL_ERROR).  The "warning" is shown both on stdout and in the log
> file.  Mark the test as unresolved, because the evaluation error means
> we couldn't reach a valid pass/fail conclusion.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* lib/gdb.exp (gdb_assert): Show error message on error.
> 
> Change-Id: Ie6477859554e909ed8d07fb2769c6f2f55e7cce6
> ---
>   gdb/testsuite/lib/gdb.exp | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index c42933b3f41e..f2954fd5192b 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -1728,7 +1728,14 @@ proc gdb_assert { condition {message ""} } {
>       }
>   
>       set code [catch {uplevel 1 expr $condition} res]
> -    if {$code != 0 || !$res} {
> +    if {$code == 1} {
> +	# If code is 1 (TCL_ERROR), it means evaluation failed and res contains
> +	# an error message.  Print the error message, and set res to 0 since we
> +	# want to return a boolean.
> +	warning "While evaluating expression in gdb_assert: $res"
> +	unresolved $message
> +	set res 0
> +    } elseif { !$res } {
>   	fail $message
>       } else {
>   	pass $message
> 

Looks OK to me. That's good to have more meaningful output.

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

* Re: [PATCH] gdb/testsuite: show evaluation errors in gdb_assert
  2020-11-23 18:46 ` Luis Machado via Gdb-patches
@ 2020-11-23 22:27   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2020-11-23 22:27 UTC (permalink / raw)
  To: Luis Machado, Simon Marchi, gdb-patches

On 2020-11-23 1:46 p.m., Luis Machado via Gdb-patches wrote:
> On 11/23/20 3:35 PM, Simon Marchi via Gdb-patches wrote:
>> Let's say you put this gdb_assert in a test:
>>
>>      gdb_assert "some invalid tcl code"
>>
>> You just get:
>>
>>      FAIL: gdb.base/template.exp: some invalid tcl code
>>
>> That's not very easy to debug, since you don't know what's invalid in
>> your code.
>>
>> Change gdb_assert to print the error message when catch's return code is
>> 1 (TCL_ERROR).  The "warning" is shown both on stdout and in the log
>> file.  Mark the test as unresolved, because the evaluation error means
>> we couldn't reach a valid pass/fail conclusion.
>>
>> gdb/testsuite/ChangeLog:
>>
>>     * lib/gdb.exp (gdb_assert): Show error message on error.
>>
>> Change-Id: Ie6477859554e909ed8d07fb2769c6f2f55e7cce6
>> ---
>>   gdb/testsuite/lib/gdb.exp | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index c42933b3f41e..f2954fd5192b 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -1728,7 +1728,14 @@ proc gdb_assert { condition {message ""} } {
>>       }
>>         set code [catch {uplevel 1 expr $condition} res]
>> -    if {$code != 0 || !$res} {
>> +    if {$code == 1} {
>> +    # If code is 1 (TCL_ERROR), it means evaluation failed and res contains
>> +    # an error message.  Print the error message, and set res to 0 since we
>> +    # want to return a boolean.
>> +    warning "While evaluating expression in gdb_assert: $res"
>> +    unresolved $message
>> +    set res 0
>> +    } elseif { !$res } {
>>       fail $message
>>       } else {
>>       pass $message
>>
> 
> Looks OK to me. That's good to have more meaningful output.

Thanks for the review, I pushed it.

Simon

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

end of thread, other threads:[~2020-11-23 22:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-23 18:35 [PATCH] gdb/testsuite: show evaluation errors in gdb_assert Simon Marchi via Gdb-patches
2020-11-23 18:46 ` Luis Machado via Gdb-patches
2020-11-23 22:27   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox