On Wed, Jun 02, 2010 at 03:16:23PM +0200, Grego wrote:
> Hi,

Hi.
 
> I've been dabbling with python debugging helpers, trying to write some
> for my own custom classes.  The documentation is a bit raw, it is not
> always easy to find how to do simple things.

That's a very polite way to say it ;-)

> With lots of trial and error I've had some limited success.  I've looked at
> gdbmacros.py as reference.
> 
> Example of my current problem:
> 
> In a C++ source function I have local MyClass instance, and another comes in
> as a reference parameter
> 
> I can see the local value of MyClass instance with:
> 
> def qdump__MyClass(d, item):
>     data = call(item.value, 'chars()')
>     s = data.string('utf-8')  # Tells gdb that pointer is 'string like', in
> encoding utf-8
>     d.putValue(s)  # it would be nice to have a helper to quote this...
> gdbmacros.py way looks cryptic...
>     d.putNumChild(0)

This will not work in case of uninitialized or otherwise corrupted data
or data translating to characters breaking the MI protocol. The only
way to pass such "random" data is to encode it:

 def qdump__MyClass(d, item):
     data = call(item.value, 'chars()')
     d.putValue(encodedCharArray(data, 100), Hex2EncodedUtf8)
     d.putNumChild(0)

[Not tested, so this might be slightly off the mark]

In this case, a character array up to the first NUL char (but not more
than 100 characters) will be encoded as two hex digits per byte and the
frontend will try to interpret the result as UTF-8.

> But the reference type MyClass & does not show up.
> I tried the following hack:

That might be the bug that was fixed with b61e32371f055 about a week ago.
The fix is small, you can apply it locally:

-------------------------------- snip -----------------------------
    debugger: fix display of children of objects passed by reference.
    
    The value was adjusted to the referenced value but it was not used
    when dumping the members, basically leading to an empty child list
    in such cases.

diff --git a/share/qtcreator/gdbmacros/dumper.py
b/share/qtcreator/gdbmacros/dumper.py
index e31b154..2012cef 100644
--- a/share/qtcreator/gdbmacros/dumper.py
+++ b/share/qtcreator/gdbmacros/dumper.py
@@ -1366,7 +1366,8 @@ class Dumper:
                 if len(fields) == 1 and fields[0].name is None:
                     innerType = value.type.target()
                 with Children(self, 1, innerType):
-                    self.putFields(item)
+                    child = Item(value, item.iname, None, item.name)
+                    self.putFields(child)
 
     def putFields(self, item, innerType = None):
-------------------------------- snip -----------------------------

You debugging helper does not have to take care of references or
such, that's done by the "framework" in dumper.py.

Andre'
_______________________________________________
Qt-creator mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-creator

Reply via email to