I already put up a post in wxWidgets forum, but its an issue that also has a lot to do with C::B and its gdb itegration. And I have found more about the topic in the history of this forum and I know there are some gdb cracks on the foum as well, so please forgive me if I ask the question here as well.
I am using the standard pretty-printers of wxWifgets in misc/gdb/print.py and they work fine. Just recently I found out that I can use prettty printers also project-wise and use them for own classes as well. Also i found out that some printers only work when I compile with wx debug libs.
Since currently I have to work on a bit of code using quite a bit of wxIPV4address I wanted to add a pretty-printer for it, the default one does not incude this. This class is a bit difficult, since it does not have useful member variables so with a standard pretty-printer it would not work. But wx itself has an interesting workaround with their wxFileName that has a similar problem. The core
to_string(val) function uses the gdb function
parse_and_eval to basically to this
((wxFileName*)0xfff23124->GetFullPath().
return gdb.parse_and_eval('((wxFileName*)%s)->GetFullPath(0)' % self.val.address )
When you compile with the wxDebug version this works fine. I think that must also work the same way with wxIPV4address, but it does not for me.
Here is the code I used
import gdb
import sys
class wxIPV4addressPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
return gdb.parse_and_eval('((wxIPV4address*)%s)->Service(0)' % self.val.address ) # stolen from wxFilenName example
def GftPrettyPrinters(val):
if str(val.type) == 'wxIPV4address': return wxIPV4addressPrinter(val)
return None
gdb.pretty_printers.append(GftPrettyPrinters)
The to_string function is basically the same. I tried different functions: Service(), Hostname() and IPV4address() all should return the currently set IP address or port. The final version should print something like "IP=123.123.123, Port=711". I get the error
Python Exception <class 'gdb.error'> Cannot resolve method wxIPV4address::IPAddress to any overloaded function.
First I suspected this is because the system get confused by the multiple versions of Service() and Hostname() functions, that why I tried IPAddress() as well. All get the same error.
When calling the functions on a current code variable with gdb's 'p' command, it works fine,
(gdb) p pMyIpVar->Service()
$4 = 711
I think that should show that gdb has all information available to access the data, so it should be more a syntax or similar issue.
Any ideas?
I've tested it with gdb 8.1.1 and CB rev12765