Author Topic: A way to see wxString of wxWidgets 2.9.2 with gdb ?  (Read 16954 times)

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
A way to see wxString of wxWidgets 2.9.2 with gdb ?
« on: July 27, 2011, 01:30:04 pm »
Hello.

Since I began to work with wxWidgets 2.9.2 I cannot see wxString with the gdb debugger, it was working with wxWidgets 2.8.x but wxString code has changed and the gdb_types.script is not working with this new wxString code.

I have tryed to modify gdb_types.script but for the moment, I cannot found a way to make it work.
Any idea ?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: A way to see wxString of wxWidgets 2.9.2 with gdb ?
« Reply #1 on: July 27, 2011, 01:56:12 pm »
The best way should use a python enabled gdb, and use the pretty printer for wxString script.
Note the wx pretty printer should be available from:
http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/misc/gdb/print.py

see below as a reference:
http://code.google.com/p/qp-gcc/wiki/GDB
http://wxwidgets.blogspot.com/2009/01/pretty-printing-wxstuff-in-gdb.html

also, As I know, pcx's 4.6.1 mingw has the latest gdb
http://code.google.com/p/pcxprj/downloads/list
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: A way to see wxString of wxWidgets 2.9.2 with gdb ?
« Reply #2 on: July 27, 2011, 03:30:09 pm »
It's seems to be a litle bit more complex that I could read.
The video http://people.redhat.com/ebachalo/video/archer-pretty-printing-no-audio.swf is no more avalaible.
In downloaded file stdcxx_and_wx_pythonscript.7z, when I decompress, in wx folder I can see libwx\v28\: is this files are really working with wxWidgets 2.9 ?
I use gdb 7.2, should I use C:\MinGW\bin\gdb.exe or C:\MinGW\bin\gdb-python27.exe as debugger ?
gdb-python27.exe cannot be run because python dll is missing, so I have download and install python-2.7.2.msi here,  gdb-python27.exe could now be run.
In settings/compiler and debugger/debugger settings I put 2 lines :
Quote
source C:\MinGW\bin\stl.gdb
source C:\MinGW\bin\wx.gdb

Where should I put the file print.py ?

Will test and try to make it work. Will edit this message each time I'll make a step to explain exactly what I need to do to make it work.
« Last Edit: July 27, 2011, 03:49:10 pm by Feneck91 »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: A way to see wxString of wxWidgets 2.9.2 with gdb ?
« Reply #3 on: July 27, 2011, 04:10:02 pm »
In downloaded file stdcxx_and_wx_pythonscript.7z, when I decompress, in wx folder I can see libwx\v28\: is this files are really working with wxWidgets 2.9 ?
I have never used wx 2.9, so I can't say much, as I said before, you need the wx python script from the wx trunk:
http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/misc/gdb/print.py
I suggest you can just put the contents of the print.py to PathToYourMinGw\bin\libwx\v28\printers.py

the last change is just use pcx's new 4.6.1 packages. and put the code:

Code
source $(TARGET_COMPILER_DIR)bin\stl.gdb
source $(TARGET_COMPILER_DIR)bin\wx.gdb
in your c::b's debugger's initial command edit control.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: A way to see wxString of wxWidgets 2.9.2 with gdb ?
« Reply #4 on: July 27, 2011, 04:57:34 pm »
When I load gdb-python27.exe in place of gdb.exe (in toolchain executable) it seems to change some things.
One example : on breakpoint in "bool wxXmlResource::Load(const wxString& filemask_)"
Code
bool wxXmlResource::Load(const wxString& filemask_)
{
    wxString filemask = ConvertFileNameToURL(filemask_);

    bool allOK = true;

#if wxUSE_FILESYSTEM
    wxFileSystem fsys;
#   define wxXmlFindFirst  fsys.FindFirst(filemask, wxFILE)
#   define wxXmlFindNext   fsys.FindNext()
#else
#   define wxXmlFindFirst  wxFindFirstFile(filemask, wxFILE)
#   define wxXmlFindNext   wxFindNextFile()
#endif
    wxString fnd = wxXmlFindFirst;
    if ( fnd.empty() )
    {
        wxLogError(_("Cannot load resources from '%s'."), filemask);
        return false;
    }
With tooltip on filemask_ indicate "m_impl = L<error reading variable>"
Tooltip on filemask indicate "No symbol "wxStringData" in current context"
Two wxString that not indicate the same thing, strange.
In debugger (add watch) filemask_ indicate : Attemps to take contents of a non-pointer value.
In debugger (add watch) filemask indicate : "" and it is not true.
 If I run GDB in place of gdb-python27.exe, the tooltip of filemask_ indicate the expand of all the class.

For the moment, it don't work !  :(
I'm sure some other developpers have already test and make debug with wxWidgets 2.9.x under gdb/CodeBlocks, or I am alone in the earth ?

print.py is automatically loaded ? Strange, I don't understand how it is loaded.
« Last Edit: July 27, 2011, 04:59:20 pm by Feneck91 »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: A way to see wxString of wxWidgets 2.9.2 with gdb ?
« Reply #5 on: July 28, 2011, 09:14:52 am »
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'

then, everything works fine.

here is my test debug log:

Quote
> p msg
$1 = "wxWidgets 2.9.2-Windows-Unicode build"
>>>>>>cb_gdb:

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

But I found that I need to manuall change the setup.h, and un-comment the line: (line 70)
Code
  #define wxDEBUG_LEVEL 0

otherwise, I will have a build error, something like:
Code
undefined reference to `wxTheAssertHandler'

more details can be found:
http://trac.wxwidgets.org/ticket/12626

So, I guess the option :DEBUG_FLAG=0 should not be used. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline theojk

  • Single posting newcomer
  • *
  • Posts: 2
Re: A way to see wxString of wxWidgets 2.9.2 with gdb ?
« Reply #6 on: August 23, 2011, 05:45:52 pm »
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;
}
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;
}
displays the String again.

Hope this helps a little bit.

P.S. dont overwrite the whole file, but only the function Evaluate_wxString.  :wink:



Offline Manolo

  • Multiple posting newcomer
  • *
  • Posts: 47
Re: A way to see wxString of wxWidgets 2.9.2 with gdb ?
« Reply #7 on: August 25, 2011, 07:13:47 pm »
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;
}

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
« Last Edit: August 25, 2011, 07:23:06 pm by Manolo »

Offline theojk

  • Single posting newcomer
  • *
  • Posts: 2
Re: A way to see wxString of wxWidgets 2.9.2 with gdb ?
« Reply #8 on: August 26, 2011, 09:19:44 am »
Its working.  :D 
And so it might be the better way, working on other platforms too.  :wink:

Thank You.

Offline Feneck91

  • Multiple posting newcomer
  • *
  • Posts: 112
Re: A way to see wxString of wxWidgets 2.9.2 with gdb ?
« Reply #9 on: October 02, 2012, 01:49:40 pm »
It's seems that it doesn't work in wxWidgets 2.9.4 in unicode. Another way ?