Bug 11335 - -var-evaluate-expression should return the pretty printer's to_string result
Summary: -var-evaluate-expression should return the pretty printer's to_string result
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:
: 25153 28201 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-03-01 11:44 UTC by Jens Elmenthaler
Modified: 2023-03-28 18:38 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Patch to always call to_string for pretty-printers (926 bytes, patch)
2017-05-25 02:53 UTC, Peter Linss
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Elmenthaler 2010-03-01 11:44:59 UTC
The only way to obtain the value of a dynamic variable objects (= the return 
value of the pretty printer) is -data-evaluate-expresssion. However, -data-
evaluate-expresion cannot be used for children of dynamic variable objects, 
since it is impossible to provide the required expression.

The same should possibly returned in the results of -var-update and -var-list-
children.
Comment 1 Vladimir Prus 2010-03-06 08:14:14 UTC
Could you clarify why you even want to use -data-evaluate-expression? Is that
because you're adding pretty-printing to CDT and CDT, for some unknown reason,
wants to display "variable details" for selected node in the variables tree?

I am opposed to bloating the output of -var-update and or -var-list-children
with full text (=CLI) rendering of that varobj, because such a design would
require that GDB, fetches entire value from memory, always. It might be
possible to introduce a separate command, or add --varobj option to -data-
Comment 2 Jens Elmenthaler 2010-03-07 13:34:12 UTC
Ok, I know it again. The problem was for pretty printers returning children.

For instance, I have a collection and the pretty printer has a to_string 
method returning a summary (like "vector of lenght 2"). I would like to show 
this summary in the value column. -var-evaluate-expression only 
returns "{...}", probably since it has children. The only way of retrieving 
the summary, then, is to ask -data-evaluate-expression. But this works only as 
long as I'm able to provide the required expression, which I can only do as 
long as the variable of interest is not a child of another dynamic variable.

So my request simply was that -var-evaluate-expression returns the result of 
the to_string method if it is backed by a pretty printer, regardless of 
whether it has children or not.
Comment 3 Vladimir Prus 2010-03-29 20:42:49 UTC
I actually though that this summary is both too huge and not particularly
useful in a frontend. Say, the type of container is already knows, so all
the summary say is report the size. Maybe, for containers, we want to show
[N] as opposed to {...}?
Comment 4 Jens Elmenthaler 2010-03-30 07:20:44 UTC
(In reply to comment #3)
> I actually though that this summary is both too huge and not particularly
> useful in a frontend. Say, the type of container is already knows, so all
> the summary say is report the size. Maybe, for containers, we want to show
> [N] as opposed to {...}?
Yes, from the requirements point, this is what I miss most. Currently, I have 
to expand the collection variable, if I just want to see how many elements it 
contains. And this doesn't work well, because in a large collection I also 
have to scroll to the end.

Lets assume your proposal, how would you decide it's a collection? You take 
the display hint and if it's map or vector, it's collection. Next, how will 
you determine the number of childen? You cannot use the children method and 
use the iterate over all elements. If the collection is uninitialized, it may 
never return. Alternatively, you could add a new method to the pretty printers.

It all boyls down to what our understanding of the to_string method is. Shall 
it just provide a short summary to identify an object, or shall it be used to 
dump all members in a string? I always interpreted as the first.
Comment 5 Kevin Funk 2014-02-05 00:14:17 UTC
Hey Vladimir.

I'm curious if this issue has been solved in one or the other way up to now. I was wondering if we could resolve those '{...}' for non-simple types in KDevelop's GDB support, and stumbled upon this bug entry. 

I think it's valid request to get some 'short summary' of non-simple types. Containers are the best example, it'd be good to know how many items they contain, without requesting the individual child items.

Given the documentation about the pretty printer's to_string() method:
"When printing from the CLI, if the to_string method exists, then gdb will prepend its result to the values returned by children. Exactly how this formatting is done is dependent on the display hint, and may change as more hints are added. Also, depending on the print settings (see Print Settings), the CLI may print just the result of to_string in a stack trace, omitting the result of children."
=> Here, to_string() is used unconditionally, children() is optional. Can't we transfer that kind of behavior to -var-evaluate-expression and friends as well?
Comment 6 Vladimir Prus 2014-02-05 06:11:51 UTC
Kevin,

I don't know the current status of this issue 100%, but I don't know of any changes here.

It is generally reasonable to see short summary of composite types, but still, what do we do if a composite type is big? Iterating over all children just to count them might be expensive.
Comment 7 Peter Linss 2017-05-25 02:53:09 UTC
Created attachment 10068 [details]
Patch to always call to_string for pretty-printers
Comment 8 Peter Linss 2017-05-25 02:53:32 UTC
Patch sumbitted
Comment 9 Tom Tromey 2022-05-25 18:24:52 UTC
*** Bug 28201 has been marked as a duplicate of this bug. ***
Comment 10 Tom Tromey 2022-05-25 18:25:51 UTC
*** Bug 25153 has been marked as a duplicate of this bug. ***
Comment 11 Tom Tromey 2022-05-26 16:49:43 UTC
Sending a patch.
Comment 12 Sourceware Commits 2023-03-28 18:36:36 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

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

commit 3e8154778baf4df222d95e43a2c8fefdb17305f7
Author: Tom Tromey <tromey@adacore.com>
Date:   Thu May 26 08:33:05 2022 -0600

    Put pretty-printers to_string output in varobj result
    
    PR mi/11335 points out that an MI varobj will not display the result
    of a pretty-printer's "to_string" method.  Instead, it always shows
    "{...}".
    
    This does not seem very useful, and there have been multiple
    complaints about it over the years.  This patch changes varobj to emit
    this string when possible, and updates the test suite.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=11335
Comment 13 Tom Tromey 2023-03-28 18:38:17 UTC
Fixed.