wxString not shown in watch list under C::B with Unicode Build! Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

wxString not shown in watch list under C::B with Unicode Build!

Post by tomay3000 »

I am trying to debug a simple wxWidgets application with C::B using a Unicode Build.
The problem is that the values of any wxString in the watch list are incorrect.
I have debugged the value when it was in a wxChar[1024] variable, it was correct (visible in the watch list).
But when it has been transferred to the wxString one, then the troubles begin happening.

Code: Select all

wxChar  szValueName[1024];
<--- Good

Code: Select all

strValueName = szValueName;
<--- Bad (strValueName shows "" empty string)

what could be the cause?

Help me please. [-o<

Thank you for your understanding.

I am using Windows XP SP3 32bit under VMware Workstation, with C::B svn 11021 and TDM-GCC-32 v5.1.0 and wxWidgets 3.1.0
User avatar
marcelinux
Knows some wx things
Knows some wx things
Posts: 40
Joined: Thu Nov 07, 2013 9:59 pm
Location: Madrid, Spain

Re: wxString not shown in watch list under C::B with Unicode Build!

Post by marcelinux »

I just need learn a little bit more. Thank you for your help.
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: wxString not shown in watch list under C::B with Unicode Build!

Post by eranon »

To watch wxString in C::B, you need a Python enabled debugger and provide some commands of initialization in settings.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 550
Joined: Fri Nov 03, 2006 2:00 pm

Re: wxString not shown in watch list under C::B with Unicode Build!

Post by stahta01 »

On the Code::Blocks forum, they are always mentioning gdb pretty printers in relation to this type of debugger issue.
I do NOT use the CB Debugger; so, I never looked up what they meant.

Tim S.
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

Re: wxString not shown in watch list under C::B with Unicode Build!

Post by tomay3000 »

eranon wrote:To watch wxString in C::B, you need a Python enabled debugger and provide some commands of initialization in settings.
Could you please give me the pretty printer python script for wxString.

Thank you.
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: wxString not shown in watch list under C::B with Unicode Build!

Post by eranon »

tomay3000 wrote:Could you please give me the pretty printer python script for wxString.
Thank you.
I configured this long time ago and don't know if there's better since this date, but here is what's in my C::B settings (Settings->Debugger->Init commands) in Windows (on Mac, I don't use the debugger from C::B):

Code: Select all

python
import sys
import gdb
sys.path.insert(0,'C:/MinGW64/bin/wxprint')
import wxprint
end
set print pretty 1
My default (the one in PATH) Python is 2.7 and here is the referenced wxprint.py script in my MinGW64 (aka. TDM-GCC 86_64) tree:

Code: Select all

###############################################################################
# Name:         misc/gdb/print.py
# Purpose:      pretty-printers for wx data structures: this file is meant to
#               be sourced from gdb using "source -p" (or, better, autoloaded
#               in the future...)
# Author:       Vadim Zeitlin
# Created:      2009-01-04
# RCS-Id:       $Id$
# Copyright:    (c) 2009 Vadim Zeitlin
# Licence:      wxWindows licence
###############################################################################

# Define wxFooPrinter class implementing (at least) to_string() method for each
# wxFoo class we want to pretty print. Then just add wxFoo to the types array
# in wxLookupFunction at the bottom of this file.

# MODded by 'eranon' (name used on wxWidgets and C::B forums), 2013-02-11 :
# To be OK w/ 64-bit target linked w/ wxWidgets 2.9.4 & debugged w/ GDB x64,
# I've imported the string module and changed the wxStringPrinter::to_string()
# function to well decode the returned string
# REF : http://forums.codeblocks.org/index.php/topic,17502.0.html

import datetime
import gdb
import string

# shamelessly stolen from std::string example
class wxStringPrinter:
    def __init__(self, val):
        self.val = val

    def to_string(self):
        buff = self.val['m_impl']['_M_dataplus']['_M_p'].string()
        return buff.decode('utf-16', 'ignore')

    def display_hint(self):
        return 'string'

class wxDateTimePrinter:
    def __init__(self, val):
        self.val = val

    def to_string(self):
        # A value of type wxLongLong can't be used in Python arithmetic
        # expressions directly so we need to convert it to long long first and
        # then cast to int explicitly to be able to use it as a timestamp.
        msec = self.val['m_time'].cast(gdb.lookup_type('long long'))
        if msec == 0x8000000000000000:
            return 'NONE'
        sec = int(msec / 1000)
        return datetime.datetime.fromtimestamp(sec).isoformat(' ')

class wxFileNamePrinter:
    def __init__(self, val):
        self.val = val

    def to_string(self):
        # It is simpler to just call the internal function here than to iterate
        # over m_dirs array ourselves. The disadvantage of this approach is
        # that it requires a live inferior process and so doesn't work when
        # debugging using only a core file. If this ever becomes a serious
        # problem, this should be rewritten to use m_dirs and m_name and m_ext.
        return gdb.parse_and_eval('((wxFileName*)%s)->GetFullPath(0)' %
                                  self.val.address)

class wxXYPrinterBase:
    def __init__(self, val):
        self.x = val['x']
        self.y = val['y']

class wxPointPrinter(wxXYPrinterBase):
    def to_string(self):
        return '(%d, %d)' % (self.x, self.y)

class wxSizePrinter(wxXYPrinterBase):
    def to_string(self):
        return '%d*%d' % (self.x, self.y)

class wxRectPrinter(wxXYPrinterBase):
    def __init__(self, val):
        wxXYPrinterBase.__init__(self, val)
        self.width = val['width']
        self.height = val['height']

    def to_string(self):
        return '(%d, %d) %d*%d' % (self.x, self.y, self.width, self.height)


# The function looking up the pretty-printer to use for the given value.
def wxLookupFunction(val):
    # Using a list is probably ok for so few items but consider switching to a
    # set (or a dict and cache class types as the keys in it?) if needed later.
    types = ['wxString',
             'wxDateTime',
             'wxFileName',
             'wxPoint',
             'wxSize',
             'wxRect']

    for t in types:
        if val.type.tag == t:
            # Not sure if this is the best name to create the object of a class
            # by name but at least it beats eval()
            return globals()[t + 'Printer'](val)

    return None

gdb.pretty_printers.append(wxLookupFunction)
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Post Reply