Code::Blocks/dgb Unicode debugging for wxString

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
ubit
Knows some wx things
Knows some wx things
Posts: 30
Joined: Mon Dec 04, 2006 6:12 pm

Code::Blocks/dgb Unicode debugging for wxString

Post by ubit »

Hi,

currently i try to do some developement with wxWidgets. As an IDE i use CodeBlocks.
I have compiled wxWidgets in UNICODE-Mode. Can anyone tell me how i debug my application? Who am i able to see what values wxStrings have? What about wxChar? Can i convert the unicode Chars & Strings to human readable versions e.g. in the watchlist?

Ciao, Udo
bone
Experienced Solver
Experienced Solver
Posts: 74
Joined: Fri Nov 30, 2007 10:11 am
Location: Oz

Post by bone »

Perhaps you would get more response in the codeblocks forum at
http://forums.codeblocks.org/
Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil »

Hi!

Debugging is really a happy journey under Code::Blocks. Here is some major step:

1)Set up debug environment:

0. Open what ever a project
1. Debug->Start
2. Debug->Debugging Windows->
Call Stack,
Watches,
Breakpoints,
Memory,
CPU Register,
Disassembly

You can choose what windows you would like to see during debugging. Adapt the floating windows in the proper place(See the screenshot in the attachment).

3. Give the debugging Windows shortcuts. I use Alt-1 to Alt-6, it means when I hold Alt and press 1 to 6, all windows will come out or disappear in the arranged position.

4. Stop Debugging: Oh, all the windows are gone! Don't worry, they will appear again when you start debuging again.

2)Debugging...

1. Just place your breakpoint by clicking at the left side of the line.
2. Debug->Start (F8 for short cut)
3. Code::Blocks will stop at the breakpoint, and all the info you might need is in the windows.
4. Set a new breakpoint and Debug->Continue (Ctrl-F7 for shortcut)
5. You can observe more,try more or explorer more for what you want.
Who am i able to see what values wxStrings have? What about wxChar? Can i convert the unicode Chars & Strings to human readable versions e.g. in the watchlist?
Well, for wxChar, there is something we can do:

In the screenshot you can see I was watching the wxChar * buf. You can either watch it as an character array or access its memory in the Memory window.

Right click at the Watches window, ->Add Watch. You can find useful settings in it.

wxString is a little difficult, because it allocates the memory on the heap, it includes only a pointer itself. So you can only use the pointer m_pchData to access the corresponding memory. You can see what I do in the screenshot2.

As for the human readable version of the Unicode, you might have to copy the hex code to HexEdit etc. or pop out a messagebox showing the corresponding wxString...AFAIK, Code::Blocks can't do that for you.

What I say applies to Code::Blocks SVN Build 4845----the version I'm using. In the later versions, the operations are similar.

Regards,

Utensil Candel
Attachments
screen.png
screen2.png
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/
ubit
Knows some wx things
Knows some wx things
Posts: 30
Joined: Mon Dec 04, 2006 6:12 pm

Post by ubit »

Hi,

i generally know how to debug my application ;-)
The only problem is that gdb does not handle Unicode wxStrings in a readable way. There should be a way to debug wxStrings in Unicode, shouldn't it? Without beeing able to see the values of strings in the debugger debugging is a mess.

Ciao, Udo
Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil »

Well, I performede a search in Code::Blocks forum, I got a soluton to your question from Can't see value of unicode strings while debugging http://forums.codeblocks.org/index.php/ ... 587.0.html:
1. Open the gdb_types.script file in "C:\Program Files\CodeBlocks\share\CodeBlocks\scripts". Your installation dir may be different so change the above path if necessary.

2. Find the function "Evaluate_wxString".

3. Now find the line containing:
local result = _T("output /c ") + a_str + oper + _T("c_str()[") + start + _T("]@");

And change it to:
local result = _T("output /c ") + a_str + oper + _T("m_pchData[") + start + _T("]@");

Note we are only changing "c_str()" to "m_pchData".

4. Now save this file, start debugging.
1. Open the same gdb_types.script and find the same "Evaluate_wxString" function.

2. Locate and change the following line from this:
result = result + a_str + oper + _T("size()");

to this:
result = result + _T("((wxStringData*)") + a_str + oper + _T("m_pchData - 1)->nDataLength"
Hope it helps.

Regards,

Utensil Candel

EDIT:

I tried to edit the file and found out that in the latest nightly build(SVN 4893), it has already been modified as above.

And I used "a Shared Debug version of wxWidgets library" as guided.

But I have got nothing for return.....Still trying to figure out why.........
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/
eranif
Moderator
Moderator
Posts: 610
Joined: Tue Nov 29, 2005 7:10 pm
Location: Israel

Post by eranif »

The best way to view the wxString content under gdb when using unicode version of wxWidgets, is to use wxString methods, for example:

Code: Select all

wxString content(wxT("content"));
to view the content:

Code: Select all

(gdb)p content.ToAscii().m_str
this will present the value as ASCII text.

Eran
IDE: CodeLite + wxCrafter
OS: All
https://wxcrafter.codelite.org
https://codelite.org
Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil »

eranif wrote:

Code: Select all

(gdb)p content.ToAscii().m_str
this will present the value as ASCII text.

Eran
I guess what ubit needs is to view non-ASCII text.

According to Chapter 8.17 in info/gdb.info-1,
GDB currently includes support for the following character sets:

`ASCII'
Seven-bit U.S. ASCII. GDB can use this as its host character set.

`ISO-8859-1'
The ISO Latin 1 character set. This extends ASCII with accented
characters needed for French, German, and Spanish. GDB can use
this as its host character set.

`EBCDIC-US'
`IBM1047'
Variants of the EBCDIC character set, used on some of IBM's
mainframe operating systems. (GNU/Linux on the S/390 uses U.S.
ASCII.) GDB cannot use these as its host character set.


Note that these are all single-byte character sets. More work inside
GDB is needed to support multi-byte or variable-width character
encodings, like the UTF-8 and UCS-2 encodings of Unicode.
It seems gdb doesn't support printing Unicode itself. But there must be a way to hack it through Squirrel...Still trying...

-Utensil

EDIT:

ubit, if what you need is to view ASCII text in wxString, you only need to

1) watch it explicitly
or
2) check "Evaluate expression under cursor" in Settings->Compiler and Debugger...->Debugger Settings
and move cursor to the wxString variable in your Code and wait a second.
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/
Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil »

The folowing link has shown the ancient history of implementing this function in C::B:

Custom Watch Script Pluggins
http://forums.codeblocks.org/index.php/ ... 097.0.html

The following link has some instructions to write the debugging script:

http://wiki.codeblocks.org/index.php?ti ... er_scripts

The following link is the manual of Squirrel:

http://squirrel.sourceforge.net/doc/squirrel2.html

Further study will figure a way out...Still working on it...

-Utensil
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/
mandrav
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Jan 05, 2005 7:43 am

Post by mandrav »

Evaluating wxString in the watch list does not yet work.
But it works if you hover your mouse over the variable in the code (you must have enabled "Settings->Compiler & Debugger->Debugger->Evaluate expression under cursor"). That's when the aforementioned script is called currently :).

Yiannis.
Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil »

mandrav wrote:Evaluating wxString in the watch list does not yet work.
As far as I know, in versions later than SVN 4845, it all works fine if you watch it explicitly as "Undefined".
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/
Loaden
I live to help wx-kind
I live to help wx-kind
Posts: 177
Joined: Tue Feb 19, 2008 10:21 am
Location: China

Post by Loaden »

It's not work under CDB.
who can tell me: how do it use cdb?
thanks!
Post Reply