Bug 11738 - -var-evaluate-expression doesn't work after removing pretty printer
Summary: -var-evaluate-expression doesn't work after removing pretty printer
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: mi (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 14.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-22 19:11 UTC by seb.sfo
Modified: 2023-09-07 20:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2023-08-31 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description seb.sfo 2010-06-22 19:11:33 UTC
Here is an example with str_list which is a linked list having a corresponding
pretty printer:

-var-create - * str_list
^done,name="var1",numchild="3",value="0x9ae2c90",type="GList
*",thread-id="1",has_more="0"
(gdb)
-enable-pretty-printing
^done
(gdb)
-var-create - * str_list
^done,name="var2",numchild="0",value="{...}",type="GList
*",thread-id="1",displayhint="array",dynamic="1",has_more="1"
(gdb)
-var-evaluate-expression var2
^done,value="{...}"
(gdb)
-var-evaluate-expression var1
^done,value="0x9ae2c90"
(gdb)
-var-set-visualizer var2 None
^done
(gdb)
-var-evaluate-expression var2
^done,value="{...}"
(gdb) 

I expect to get value="0x9ae2c90" instead of value="{...}" as the pretty printer
has been removed.

Note that -var-list-children and -var-update returns the right value, the same
than for var1, without the pretty printer.

I can restore the pretty printer, using -var-set-visualizer var2
gdb.default_visualizer.

I'm run this test with gdb version 7.0.50.20091001-cvs
Comment 1 Tom Tromey 2022-05-25 19:54:16 UTC
I didn't set up a test case for a pointer pretty-printer,
but I wonder if invoking -var-update first would help.

I see this code in c-varobj.c:

	    /* If the specified format is the current one,
	       we can reuse print_value.  */
	    if (format == var->format)
	      return var->print_value;
	    else
	      return varobj_value_get_print_value (var->value.get (), format,
						   var);

So I suspect what's happening is that resetting the visualizer
does not change the print_value, and so then gdb thinks it
can just reuse the existing one.
Comment 2 Tom Tromey 2023-08-31 19:59:10 UTC
I have a somewhat hacky patch for this.
Comment 3 Sourceware Commits 2023-09-07 20:06:16 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d1369de649a9d19abae1012ef805aaa674314c0c

commit d1369de649a9d19abae1012ef805aaa674314c0c
Author: Tom Tromey <tromey@adacore.com>
Date:   Thu Aug 31 13:58:49 2023 -0600

    Fix bug in -var-evaluate-expression
    
    This bug points out that if one uses -var-set-visualizer with "None"
    -- to disable a pretty-printer for a varobj -- then
    -var-evaluate-expression will still use pretty-printing.
    
    This is a combination of bugs.  First, setting the visualizer does not
    update the display text; and second, computing the display text should
    use "raw" when Python is available but no visualizer is desired.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=11738
    Reviewed-by: Keith Seitz <keiths@redhat.com>
Comment 4 Tom Tromey 2023-09-07 20:06:53 UTC
Fixed.