Author Topic: Help on a Pretty-Printer wxIPV4address  (Read 4888 times)

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 196
Help on a Pretty-Printer wxIPV4address
« on: April 08, 2022, 01:41:13 pm »
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().
Code
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

Code
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,
Code
 (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
« Last Edit: April 08, 2022, 01:44:45 pm by tigerbeard »

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Help on a Pretty-Printer wxIPV4address
« Reply #1 on: April 09, 2022, 02:13:28 am »
GDB 8.1.1 is old and I think this version9or 8.1 or 8.1.x of GDB had debugging issues. I would try with GDB 11.2. GDB 11.2 is available in MSYS2 and Cygwin and there are latter versions of MINGW than 8.1 that have later GDB versions.

As it does not work on the GDB command line you are better asking on a GDB forum or you could have a look at the lib stdcxx printers that come with GDB 11.2 to see if you can find anything to help you out.

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 196
Re: Help on a Pretty-Printer wxIPV4address
« Reply #2 on: April 09, 2022, 12:02:19 pm »
GDB 8.1.1 is old and I think this version9or 8.1 or 8.1.x of GDB had debugging issues.
I knew you would say that  ::). And you are right, of course but honestly at this point I would rather expect this to be a syntax issue in my code.
I have it on my list to check check gdb updates for another issue anyway (Breakpoints). Maybe the fact that I am getting regular gdb crashes as well helps to speed that up a little bit...

Quote
As it does not work on the GDB command line you are better asking on a GDB forum or you could have a look at the lib stdcxx printers that come with GDB 11.2 to see if you can find anything to help you out.
good advice, i have checked the stdcxx printers tough, but none has the problem of using a function.
« Last Edit: April 09, 2022, 05:27:32 pm by tigerbeard »

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 196
Re: Help on a Pretty-Printer wxIPV4address
« Reply #3 on: April 09, 2022, 05:31:25 pm »
Checked with the GDB from ppa.launchpad.net/ubuntu-toolchain-r/test/ which seemed to have gdb 10.2 as the latest for bionic.
Same result.