User forums > Using Code::Blocks
A way to see wxString of wxWidgets 2.9.2 with gdb ?
ollydbg:
I have just take several hours to build a wx 2.9.2 under pcx's mingw 4.6.1 then try to see whether it works on wxWidgets.
it seems that you need to change the file:
MinGW_gcc4.6.1release_static_win32\bin\libwx\v28\printers.py
Then use the content below for the wxString class:
--- Code: ---# shamelessly stolen from std::string example
@register_pretty_printer
class wxStringPrinter:
regex = re.compile('^wxString$$');
@static
def supports(typename):
return wxStringPrinter.regex.search(typename)
@static
def is_undefine(val):
try:
val['m_impl']['_M_dataplus']['_M_p'].string()
return True
except:
return False
def __init__(self, val):
self.val = val
def to_string(self):
return self.val['m_impl']['_M_dataplus']['_M_p'].string()
def display_hint(self):
return 'string'
--- End code ---
then, everything works fine.
here is my test debug log:
--- Quote ---> p msg
$1 = "wxWidgets 2.9.2-Windows-Unicode build"
>>>>>>cb_gdb:
--- End quote ---
my test code was just use wx wizard to generate a simple wx smith project.
BTW: I use you command to build the wx library. such as:
--- Code: ---echo Add MinGW path
set PATH=D:\code\MinGW_gcc4.6.1release_static_win32\bin;%PATH%
cd wxWidgets-2.9.2\build\msw
mingw32-make -f makefile.gcc MONOLITHIC=1 SHARED=1 UNICODE=1 BUILD=release USE_XRC=1 DEBUG_FLAG=0
--- End code ---
But I found that I need to manuall change the setup.h, and un-comment the line: (line 70)
--- Code: --- #define wxDEBUG_LEVEL 0
--- End code ---
otherwise, I will have a build error, something like:
--- Code: ---undefined reference to `wxTheAssertHandler'
--- End code ---
more details can be found:
http://trac.wxwidgets.org/ticket/12626
So, I guess the option :DEBUG_FLAG=0 should not be used. :D
theojk:
Hi,
for all those, who dont want to use python:
I have modified the small script from CodeBlocks (10.5) for displaying wxStrings.
The old code located in <path to C::B>/share/CodeBlocks/scripts/gdb_types.script
--- Code: ---function Evaluate_wxString(type, a_str, start, count)
{
local oper = _T(".");
if (type.Find(_T("*"), false) > 0)
oper = _T("->");
local result = _T("output /c ") + a_str + oper + _T("m_pchData[") + start + _T("]@");
if (count != 0)
result = result + count;
else
result = result + _T("((wxStringData*)") + a_str + oper + _T("m_pchData - 1)->nDataLength");
return result;
}
--- End code ---
doesnt work on wxWidgets 2.9.2 anymore
this code
--- Code: ---function Evaluate_wxString(type, a_str, start, count)
{
local oper = _T(".");
if (type.Find(_T("*"), false) > 0)
oper = _T("->");
local result = _T("output /c *((wxChar *)(") + a_str + oper + _T("fn_str()))@") + a_str + oper + _T("Length()");
return result;
}
--- End code ---
displays the String again.
Hope this helps a little bit.
P.S. dont overwrite the whole file, but only the function Evaluate_wxString. :wink:
Manolo:
Hi
Starting with wx 2.9, the wxString internal representation depends on the OS. See
http://docs.wxwidgets.org/trunk/overview_string.html
To get your own OS suitable type, use wxString::wx_str(), which returns a pointer of the needed type.
To get the length (in characters, not chars, no bytes, no etc.) there are three functions: Len(), Length() and length().
If you use Len(), then the compiler knows about it and can use it too. If your code does not, GDB neither.
In Squirrel language, I can't find a way for telling the size of an "external" array. So let's GDB manage it.
Because wxString is moving to use std::string, it seems length() (lower case letter) is available.
With all of this, the Evaluate_wxString function at gdb_types.script would look like:
--- Code: ---function Evaluate_wxString(type, a_str, start, count)
{
local oper = _T(".");
if (type.Find(_T("*"), false) > 0)
oper = _T("->");
local result = _T("output /c ") + a_str + oper + _T("wx_str()") + _T("[") + start + _T("]@");
if (count != 0)
result = result + count;
else
result = result + a_str + oper + _T("length()");
return result;
}
--- End code ---
Now, the C:B Watches window shows the contents of the wxString type var.
Note the GDB command 'output /c' will treat each character as an integer and display it in 7 bit ASCII or escaped sequences if value>127
So, if your wxString has some characters not representable in 7 bit ASCII, you'll see escaped sequences for them.
N.B.
Looking at wx2.8.12 wxWidgets string.h, I find both functions (wx_str & length) are defined. So this script should work also for [all?] wx 2.8 series.
Regards
Manolo
theojk:
Its working. :D
And so it might be the better way, working on other platforms too. :wink:
Thank You.
Feneck91:
It's seems that it doesn't work in wxWidgets 2.9.4 in unicode. Another way ?
Navigation
[0] Message Index
[*] Previous page
Go to full version