public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/13111] New: "-var-update" command incorrect when using pretty printers
@ 2011-08-19 15:46 developer at audioranger dot com
  2012-11-17 19:16 ` [Bug python/13111] " poenitz at htwm dot de
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: developer at audioranger dot com @ 2011-08-19 15:46 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13111

             Bug #: 13111
           Summary: "-var-update" command incorrect when using pretty
                    printers
           Product: gdb
           Version: 7.3
            Status: NEW
          Severity: minor
          Priority: P2
         Component: python
        AssignedTo: unassigned@sourceware.org
        ReportedBy: developer@audioranger.com
    Classification: Unclassified


The gdb/mi command "-var-update" may return an incorrect value for
"type_changed" when pretty-printers are used.

Consider the following example. The struct "printMePretty" should be
pretty-printed by using the Python TestPrinter class from below. It should be
printed as an integer "array" (it doesn't actually makes sense here, it's just
for testing) if the structure's "printAsInt" member is true, and as a floating
point "array" otherwise.


****************** File: main.cpp *****************

struct printMePretty
{
    bool printAsInt;
    int intMember;
    float floatMember;

    printMePretty() :
        printAsInt(true),
        intMember(0xFF),
        floatMember(3.1415)
    { }
};

void main()
{
    printMePretty pretty;
    pretty.printAsInt = false;
}


****************** File: printer.py *****************

[...]

class TestPrinter:
    class _iterator:
        def __init__(self, val):
            self.val = val
            self.index = 0

        def __iter__(self):
            return self

        def next(self):
            if self.index == 1:
                raise StopIteration

            if self.val['printAsInt']:
                childValue = self.val['intMember']
            else:
                childValue = self.val['floatMember']

            self.index += 1
            return ('Value', childValue)

    def __init__(self, val):
        self.val = val

    def children(self):
        return self._iterator(self.val)

    def display_hint(self):
        return 'array'


****************** End of file *****************


Using Eclipse CDT to trace gdb/mi commands, one encounters the following until
the line "pretty.printAsInt = false;":


-var-create --thread 1 --frame 0 - * pretty
^done,name="var1",numchild="0",value="{...}",type="printMePretty",thread-id="1",displayhint="array",dynamic="1",has_more="1"

-var-list-children var1 0 1
^done,numchild="1",displayhint="array",children=[child={name="var1.Value",exp="Value",numchild="0",type="int",thread-id="1"}],has_more="0"


OK, so "var1.Value" has type "int". Now, stepping over the line
"pretty.printAsInt = false;" results in:


-var-update 1 var1
^done,changelist=[{name="var1.Value",value="3.1415",in_scope="true",type_changed="false",displayhint="array",dynamic="1",has_more="0"}]


It now says that "var1.Value" would have a "value" of "3.1415" - that's
obviously a strange value for an "int" (since "type_changed" reports "false" -
I suppose it should actually report that the type has changed to "float").

This seems like a bug within gdb to me. The same problem may also apply if a
pretty-printer's toString() method returns gdb.Values which have different
gdb.Types, depending on the data members of the structure which should be
pretty-printed.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/13111] "-var-update" command incorrect when using pretty printers
  2011-08-19 15:46 [Bug python/13111] New: "-var-update" command incorrect when using pretty printers developer at audioranger dot com
@ 2012-11-17 19:16 ` poenitz at htwm dot de
  2012-12-10 19:23 ` developer at audioranger dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: poenitz at htwm dot de @ 2012-11-17 19:16 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13111

Andre' Poenitz <poenitz at htwm dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |poenitz at htwm dot de

--- Comment #1 from Andre' Poenitz <poenitz at htwm dot de> 2012-11-17 19:16:17 UTC ---
-var-update was created to keep track of standard situations, like watching
data members of C style structures.

They can conceptually not work for "complex" pretty-printing in the presence of
arbitrary changes to the environment like the value of global variables or the
return value of function calls.

The only safe approach for a gdb frontend is to not rely on -var-update (or
varobj at all for that matter) and re-run all pretty printers everytime
something could have changed.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/13111] "-var-update" command incorrect when using pretty printers
  2011-08-19 15:46 [Bug python/13111] New: "-var-update" command incorrect when using pretty printers developer at audioranger dot com
  2012-11-17 19:16 ` [Bug python/13111] " poenitz at htwm dot de
@ 2012-12-10 19:23 ` developer at audioranger dot com
  2012-12-11  6:45 ` poenitz at htwm dot de
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: developer at audioranger dot com @ 2012-12-10 19:23 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13111

--- Comment #2 from Mathias Kunter <developer at audioranger dot com> 2012-12-10 19:23:07 UTC ---
Well, the -var-update command apparently successfully recognizes the updated
pretty printer expression, since we can see the updated value "3.1415".

If -var-update can recognize the updated value of the gdb.Value returned from
the pretty printer, then it must also be able to recognize a type change of
that gdb.Value, correct?

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/13111] "-var-update" command incorrect when using pretty printers
  2011-08-19 15:46 [Bug python/13111] New: "-var-update" command incorrect when using pretty printers developer at audioranger dot com
  2012-11-17 19:16 ` [Bug python/13111] " poenitz at htwm dot de
  2012-12-10 19:23 ` developer at audioranger dot com
@ 2012-12-11  6:45 ` poenitz at htwm dot de
  2012-12-11 13:29 ` [Bug python/13111] -var-update doesn't handle type changes of array childs developer at audioranger dot com
  2012-12-11 13:33 ` developer at audioranger dot com
  4 siblings, 0 replies; 6+ messages in thread
From: poenitz at htwm dot de @ 2012-12-11  6:45 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13111

--- Comment #3 from Andre' Poenitz <poenitz at htwm dot de> 2012-12-11 06:45:44 UTC ---
Your particular problem might be indeed fixable, as all "state" is locally
available. However, this does not solve the general problem, see
http://sourceware.org/bugzilla/show_bug.cgi?id=14854

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/13111] -var-update doesn't handle type changes of array childs
  2011-08-19 15:46 [Bug python/13111] New: "-var-update" command incorrect when using pretty printers developer at audioranger dot com
                   ` (2 preceding siblings ...)
  2012-12-11  6:45 ` poenitz at htwm dot de
@ 2012-12-11 13:29 ` developer at audioranger dot com
  2012-12-11 13:33 ` developer at audioranger dot com
  4 siblings, 0 replies; 6+ messages in thread
From: developer at audioranger dot com @ 2012-12-11 13:29 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13111

Mathias Kunter <developer at audioranger dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|"-var-update" command       |-var-update doesn't handle
                   |incorrect when using pretty |type changes of array
                   |printers                    |childs

--- Comment #4 from Mathias Kunter <developer at audioranger dot com> 2012-12-11 13:29:12 UTC ---
I understand that -var-update can't work if the pretty printer depends on
non-local data, as described in bug 14854. However, I don't think this bug is
related to that problem.

The problem here is that -var-update apparently doesn't handle type changes of
childs of array-printed types, but only value changes. Note that this doesn't
apply to string types, as they can't change their types when pretty-printed. As
an example, printing the above "printMePretty" structure as string type results
in:

If printAsInt is true: Type is "printMePretty", value is "255"
If printAsInt is false: Type is "printMePretty", value is "3.1415"

Everything OK here, the type will always just be "printMePretty" and won't
change. However, printing the same structure in array form results in:

If printAsInt is true: Parent type is "printMePretty", child type is "int",
child value is "255"
If printAsInt is false: Parent type is "printMePretty", child type is "float",
child value is "3.1415"


-var-update recognizes a value change of the child, but fails to recognize the
type change.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug python/13111] -var-update doesn't handle type changes of array childs
  2011-08-19 15:46 [Bug python/13111] New: "-var-update" command incorrect when using pretty printers developer at audioranger dot com
                   ` (3 preceding siblings ...)
  2012-12-11 13:29 ` [Bug python/13111] -var-update doesn't handle type changes of array childs developer at audioranger dot com
@ 2012-12-11 13:33 ` developer at audioranger dot com
  4 siblings, 0 replies; 6+ messages in thread
From: developer at audioranger dot com @ 2012-12-11 13:33 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13111

--- Comment #5 from Mathias Kunter <developer at audioranger dot com> 2012-12-11 13:33:35 UTC ---
I've changed the bug title in order to improve the description of the problem.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

end of thread, other threads:[~2012-12-11 13:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-19 15:46 [Bug python/13111] New: "-var-update" command incorrect when using pretty printers developer at audioranger dot com
2012-11-17 19:16 ` [Bug python/13111] " poenitz at htwm dot de
2012-12-10 19:23 ` developer at audioranger dot com
2012-12-11  6:45 ` poenitz at htwm dot de
2012-12-11 13:29 ` [Bug python/13111] -var-update doesn't handle type changes of array childs developer at audioranger dot com
2012-12-11 13:33 ` developer at audioranger dot com

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).