[1/2] Use common_val_print_checked in print_variable_and_value

Message ID 20210401175831.3373671-2-tromey@adacore.com
State New
Headers show
Series
  • Fix crash in 'bt' with Ada
Related show

Commit Message

Tom Tromey April 1, 2021, 5:58 p.m.
GDB was crashing in "bt full" for a large Ada program.  I tracked this
down to a combination of bugs.

The first bug, fixed here, is that print_variable_and_value calls
common_val_print.  Normally only the value-printing implementation
should call this; from the top level, common_val_print_checked is
preferred, because it correctly handles values that are wholly
optimized out.

I wasn't able to write a test case for this.

gdb/ChangeLog
2021-04-01  Tom Tromey  <tromey@adacore.com>

	* printcmd.c (print_variable_and_value): Use
	common_val_print_checked.
---
 gdb/ChangeLog  | 5 +++++
 gdb/printcmd.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

-- 
2.26.2

Comments

Tom de Vries April 16, 2021, 10:45 a.m. | #1
On 4/1/21 7:58 PM, Tom Tromey wrote:
> GDB was crashing in "bt full" for a large Ada program.  I tracked this

> down to a combination of bugs.

> 

> The first bug, fixed here, is that print_variable_and_value calls

> common_val_print.  Normally only the value-printing implementation

> should call this; from the top level, common_val_print_checked is

> preferred, because it correctly handles values that are wholly

> optimized out.

> 

> I wasn't able to write a test case for this.

> 


Caused:
...
FAIL: gdb.opt/inline-locals.exp: info locals above bar 2
FAIL: gdb.opt/inline-locals.exp: info locals above bar 3
...
filed as https://sourceware.org/bugzilla/show_bug.cgi?id=27742 .

Thanks,
- Tom

> gdb/ChangeLog

> 2021-04-01  Tom Tromey  <tromey@adacore.com>

> 

> 	* printcmd.c (print_variable_and_value): Use

> 	common_val_print_checked.

> ---

>  gdb/ChangeLog  | 5 +++++

>  gdb/printcmd.c | 2 +-

>  2 files changed, 6 insertions(+), 1 deletion(-)

> 

> diff --git a/gdb/printcmd.c b/gdb/printcmd.c

> index c82f709136f..a4f62f207d0 100644

> --- a/gdb/printcmd.c

> +++ b/gdb/printcmd.c

> @@ -2387,7 +2387,7 @@ print_variable_and_value (const char *name, struct symbol *var,

>        val = read_var_value (var, NULL, frame);

>        get_user_print_options (&opts);

>        opts.deref_ref = 1;

> -      common_val_print (val, stream, indent, &opts, current_language);

> +      common_val_print_checked (val, stream, indent, &opts, current_language);

>  

>        /* common_val_print invalidates FRAME when a pretty printer calls inferior

>  	 function.  */

>
Tom Tromey April 16, 2021, 8:11 p.m. | #2
Tom> Caused:
Tom> ...
Tom> FAIL: gdb.opt/inline-locals.exp: info locals above bar 2
Tom> FAIL: gdb.opt/inline-locals.exp: info locals above bar 3
Tom> ...
Tom> filed as https://sourceware.org/bugzilla/show_bug.cgi?id=27742 .

I don't have the compiler needed to reproduce.
Could you try the appended?

thanks,
Tom

commit 0d00bb54e39ae86c9344ea3a509720255fb6f147
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri Apr 16 14:08:49 2021 -0600

    Fix kfail patterns in inline-locals.exp
    
    PR gdb/27742 points out that my recent change to
    print_variable_and_value caused a regression in inline-locals.exp.  I
    can't reproduce this, but I came up with this patch based on the
    output shown in the bug.
    
    gdb/testsuite/ChangeLog
    2021-04-16  Tom Tromey  <tromey@adacore.com>
    
            PR gdb/27742:
            * gdb.opt/inline-locals.exp: Update kfail patterns.

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 212f2ae0c5b..2fa302cf338 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-16  Tom Tromey  <tromey@adacore.com>
+
+	PR gdb/27742:
+	* gdb.opt/inline-locals.exp: Update kfail patterns.
+
 2021-04-16  Simon Marchi  <simon.marchi@efficios.com>
 
 	* boards/simavr.exp: Set debug_flags.
diff --git a/gdb/testsuite/gdb.opt/inline-locals.exp b/gdb/testsuite/gdb.opt/inline-locals.exp
index d0acb4ae8b5..ff9dd1b49ed 100644
--- a/gdb/testsuite/gdb.opt/inline-locals.exp
+++ b/gdb/testsuite/gdb.opt/inline-locals.exp
@@ -45,7 +45,7 @@ if { ! $no_frames } {
     gdb_test "info frame" ".*inlined into frame.*" "func1 inlined 2"
     set pass_re "array = \\{0 <repeats 64 times>\\}"
     set kfail_re [multi_line $pass_re \
-		      "array = {<optimized out> <repeats 64 times>}"]
+		      "array = <optimized out>"]
     gdb_test_multiple "info locals" "info locals above bar 2" {
 	-re -wrap $pass_re {
 	    pass $gdb_test_name
@@ -94,7 +94,7 @@ if { ! $no_frames } {
     gdb_test "info frame" ".*inlined into frame.*" "func1 inlined 3"
     set pass_re "array = {$decimal, \[^\r\n\]*}"
     set kfail_re [multi_line $pass_re \
-		      "array = {<optimized out> <repeats 64 times>}"]
+		      "array = <optimized out>"]
     gdb_test_multiple "info locals" "info locals above bar 3" {
 	-re -wrap $pass_re {
 	    pass $gdb_test_name
Tom de Vries April 17, 2021, 12:38 p.m. | #3
On 4/16/21 10:11 PM, Tom Tromey wrote:
> Tom> Caused:

> Tom> ...

> Tom> FAIL: gdb.opt/inline-locals.exp: info locals above bar 2

> Tom> FAIL: gdb.opt/inline-locals.exp: info locals above bar 3

> Tom> ...

> Tom> filed as https://sourceware.org/bugzilla/show_bug.cgi?id=27742 .

> 

> I don't have the compiler needed to reproduce.

> Could you try the appended?

> 


Ack, that fixes it.

Thanks,
- Tom

Patch

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index c82f709136f..a4f62f207d0 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2387,7 +2387,7 @@  print_variable_and_value (const char *name, struct symbol *var,
       val = read_var_value (var, NULL, frame);
       get_user_print_options (&opts);
       opts.deref_ref = 1;
-      common_val_print (val, stream, indent, &opts, current_language);
+      common_val_print_checked (val, stream, indent, &opts, current_language);
 
       /* common_val_print invalidates FRAME when a pretty printer calls inferior
 	 function.  */