I started to talk about GDB 64-bit and pretty printing at http://forums.codeblocks.org/index.php/topic,17495.0.html, but there were several subjects and it remains only one now : so, a new clear fresh thread !
Well, I'm under Windows 7 64-bit. My project is compiled using the compiler delivered with the TDM64GCC 4.7.1-3 package. The debugger in use is GDB 7.5 (x86_64-w64-mingw32) coming with this same package. This debugger is Python-enabled.
My project being wxWidgets-based, to be able to watch data like wxString, I've followed the guide at http://code.google.com/p/qp-gcc/wiki/GDB. Thus, I've added the wxWidgets-dedicated "print.py" Python script beside "gdb.exe" (under "C:\MinGW64\bin") and added the required initialization commands in CodeBlocks settings about debugger.
The problem is that the returned value look "undreadable" (directly I mean).
For example, watching this wxString :
wxString strTest = "C:/some/path/somewhere/test.txt";
I see :
L"C\000:\000/\000s\000o\000m\000e\000/\000p\000a\000t\000h\000/\000s\000o\000m\000e\000w\000h\000e\000r\000e\000/\000t\000e\000s\000t\000.\000t\000x\000t\000"
It's obvious the data are here : original "C" is shown as "C\000", ":" as ":\000", "/" as "/\000", etc. And the first idea is just to strip out these extra "\000" for every character, but the things are maybe more complex to manage others wx data classes covered by print.py (i.e. wxDateTime, wxFileName, wxPoint, wxSize, wxRect)...
So, is there a print.py script around which would be ready for 64-bit target ?
--
EDIT : OK, solved modifying the to_string() function of wxStringPrinter class in Python script like shown below.
Was :
def to_string(self):
return self.val['m_impl']['_M_dataplus']['_M_p']
And is now :
def to_string(self):
buff = self.val['m_impl']['_M_dataplus']['_M_p'].string()
return buff.decode('utf-16', 'ignore')
Also, at the beginning of script, I've added "import string". Now, wxString is displayed correctly in watching window.
I'm back on this subject. Yesterday, I've add to watch and follow a path (something like "E:\TMP\blah")under GDB (for 64-bit target) and the way I gave above (see the EDIT of previous post) didn't worked... I got this Python error :
Python Exception <type 'exceptions.UnicodeEncodeError'> 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256):
So, the status is that this "solution" seems to not cover all the cases :(
Do you have an idea of the reason why ?
Am I alone in wanting to be able to debug some wxWidgets 2.9.4 's wxString ?
Hi,
I am using this wxStringPrinter:
class wxStringPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
ret = ""
wx29 = 0
try:
# wx-28 has m_pchData
self.val['m_pchData']
except Exception:
wx29 = 1
try:
if wx29:
dataAsCharPointer = self.val['m_impl']['_M_dataplus']['_M_p']
else:
dataAsCharPointer = self.val['m_pchData']
ret = dataAsCharPointer
except Exception:
# swallow the exception and return empty string
pass
return ret
def display_hint (self):
return 'wxString'
With this printer, the script knows if you are running wx29 or wx28 which is useful on some cases
HTH,
Eran