Author Topic: Debugging QString  (Read 33325 times)

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Debugging QString
« on: September 14, 2009, 03:19:48 pm »
Hello friends,

during programming with Qt in CB I watch QStrings in this manner during debugging

Code
QString qTest = qstrLine;
std::string strTest = qTest.toStdString();

Is there a more convinient way to do this. Is there a direct watch method.
I don´t like to insert code to watch some variables during debugging and it is more to do;

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #1 on: September 14, 2009, 04:32:16 pm »
You could add a debugger script to parse the QStrings.
For more info see here: http://wiki.codeblocks.org/index.php?title=Debugger_scripts
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #2 on: September 14, 2009, 05:03:28 pm »
Ok, ...
Code
function RegisterTypes(driver)
{
//    signature:
//    driver.RegisterType(type_name, regex, eval_func, parse_func);

// QString
    driver.RegisterType(
        _T("Qt String"),
        _T("[^[:alnum:]_]*QString[^[:alnum:]_]*"),
        _T("Evaluate_QString"),
        _T("Parse_QString")
    );

    Log(_T("RegisterTypes is being called"));
}
function Evaluate_QString(type, a_str, start, count)
{
//what to do???
    return a_str;
}


function Parse_QString(a_str, start)
{
//what to do???
    return a_str;
}

Hmm and now any suggestions...

where comes my qstring variable in. The a_str seems to be a std::string.
« Last Edit: September 14, 2009, 05:12:22 pm by LordCB »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #3 on: September 14, 2009, 05:51:47 pm »
Code
function Evaluate_QString(type, a_str, start, count)

a_str is the string you have written in the watch windows (my_string, str, my_struct.name, etc).
In this function you are supposed to generate a command that gdb can execute and produce some output you can parse in the
Parse_QString function.

Code
function Parse_QString(a_str, start)
Here a_str is the result of the gdb command, just executed.

For example if you have  'QString s = "test"', you want to execute something like "output s.m_pinternal_string" and if the result is "test" in the parse function you return the a_str directly because it doesn't need any parsing and conversion.
Look for file gdb_types.script, there you can see implementations for some types: std::string, wxstring and std::vector
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: Debugging QString
« Reply #4 on: September 14, 2009, 07:55:39 pm »
This is how I debug QString:

I add the following user function to the debugger on the startup:
Code
define printqstring
    printf "(QString)0x%x (length=%i): \"",&$arg0,$arg0.d->size
    set $i=0
    while $i < $arg0.d->size
        set $c=$arg0.d->data[$i++]
        if $c < 32 || $c > 127
                printf "\\u0x%04x", $c
        else
                printf "%c", (char)$c
        end
    end
    printf "\"\n"
end
Next, to view QString, I simply type:
Code
printqstring <variable_name>

I guess that CodeBlocks can automate this procedure for you (i.e. register the user function when debugging session starts and to choose the command 'printqstring' over 'print' when a tooltip is requested)

Eran

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #5 on: September 14, 2009, 10:39:43 pm »
dear eranif,
now I understand nothing........

you say
Quote
I add the following user function to the debugger on the startup:
where do you do this perhaps a screenshot may help a little bit

Where do you type

Quote
printqstring <variable_name>

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: Debugging QString
« Reply #6 on: September 14, 2009, 10:47:29 pm »
dear eranif,
now I understand nothing........

you say
Quote
I add the following user function to the debugger on the startup:
where do you do this perhaps a screenshot may help a little bit

Where do you type

Quote
printqstring <variable_name>

I am sorry, I thought you understand that I meant gdb from the command line (I should have mentioned that more clear)
You just need to wait for one of the C::B experts here, that will answer the question: How to automate the process I described above in C::B

Sorry,
Eran

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #7 on: September 14, 2009, 11:44:03 pm »
Thanx a lot,

I really want to make this feature to me existant, cause this would save me a lot of time I think.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #8 on: September 15, 2009, 10:51:53 am »
LordCB,

Quick look at the script bindings reveals that there is no way to send commands to the debugger through scripting.
You have two variants for solving your issue:
1. Using the eranif gdb script:
   a). Put the gdb script eranif posted in a file
   b). then in the Settings -> Compiler & Debugger -> Debugger -> Initial commands put "source path_to_file"
   c). Add
Code
function Evaluate_QString(type, a_str, start, count)
{
      return _T("printqstring ") + a_str;
}
function Parse_QString(a_str, start)
{
      return a_str;
}


2. Try to implement the same the eranif script does in C::B's script (squirrel), the way I've explained you on my previous post.
I can't help you more, because I don't have QT, sorry.

Some things to consider:
 a). Settings -> Compiler & Debugger -> Debugger -> check the debugger log (debug) (or something like that) - this one will add another log pane in the "Logs & Other" window, there you can see the communication between C::B and gdb...
 b). You can execute gdb commands - if you use relatively new nightly there is a text entry in the debugger logs pane, if not "debug -> send command to debugger"
 c). Read this http://wiki.codeblocks.org/index.php?title=Scripting_Code::Blocks so you'll understand how to script codeblocks (there is view -> script console window for errors and command execution).

Good luck...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #9 on: September 15, 2009, 03:58:12 pm »
Thanx a lot I will give it a try.

I give also a feedback....

thanks thanks thanks

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #10 on: September 16, 2009, 10:47:05 am »
Ok I have taken the first way.

I put the script from eranif in qstring.script than I put the path to the script under
Settings -> Compiler & Debugger -> Debugger settings
That means:
I put the string     X:\CODEBLOCKS\CB_DebuggerScripts\qstring.script
to Debugger initialization command

than I add (to the file gdb_types.script)

Code
	// QString
    driver.RegisterType(
        _T("QString"),
        _T("[^[:alnum:]_]*QString<.*"),
        _T("Evaluate_QString"),
        _T("Parse_QString")
    );

to the function
Code
function RegisterTypes(driver)

after that

I also add
Code
 Evaluate_QString(type, a_str, start, count)
{
      return _T("printqstring ") + a_str;
}
function Parse_QString(a_str, start)
{
      return a_str;
}

to the gdb_types.script file

But nothing is to see

Where should the the line
Code
printqstring <variable_name>

be placed ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #11 on: September 16, 2009, 10:51:17 am »
What version do you use?

Try "Settings -> Compiler & Debugger -> Debugger -> show debugger pane" or something like that.
There you can see the communication between C::B and the debugger
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #12 on: September 16, 2009, 11:00:44 am »
I use nightlies 5716

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #13 on: September 16, 2009, 11:03:36 am »
There is no show debugger pane.
Am I blind?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Debugging QString
« Reply #14 on: September 16, 2009, 11:27:18 am »
Check "Settings -> Compiler and debugger... -> Debugger settings -> Display debugger's debug log".
And don't forget the keyword "source" in the debugger command.

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #15 on: September 16, 2009, 11:59:07 am »
@ jens:

Do you mean like this :
Code
source: X:\CODEBLOCKS\CB_DebuggerScripts\qstring.script

under Debugger initialization command

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #16 on: September 16, 2009, 12:41:08 pm »
Yes, that is what he means :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #17 on: September 16, 2009, 04:08:30 pm »
Ok I have done it and now my question.

What changes?
What do I expect during debugging a QString or where I have to look at the content of the string, cause now I see nothing else than a adress to the string like 0x7c9291d5 this one

[attachment deleted by admin]
« Last Edit: September 16, 2009, 04:30:50 pm by LordCB »

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #18 on: September 16, 2009, 04:35:55 pm »
This are my settings

[attachment deleted by admin]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #19 on: September 16, 2009, 04:45:09 pm »
Where you see "command:" type "printqstring strstr" and hit enter :)
Also you can add some logging commands to your Evaluate_QString and Parse_QString functions.
Unfortunately this is the only way to debug it...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #20 on: September 16, 2009, 05:16:04 pm »
Thanks but I get an

Code

Undefined command: "printqstring".  Try "help".
Undefined command: "printqstring".  Try "help".

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #21 on: September 16, 2009, 05:25:02 pm »
The source command has failed...
Try to execute it from the command field, try different paths. Spaces in the path may cause problems (just a suggestion)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Debugging QString
« Reply #22 on: September 16, 2009, 05:59:30 pm »
if you really use "source:" as posted before, that's the cause.
No colon after the post (except for the one in the drive letter).

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #23 on: September 16, 2009, 10:33:15 pm »
Ok,

now I get this.

Code
Attempt to extract a component of a value that is not a structure.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #24 on: September 17, 2009, 10:03:31 am »
I think this's a gdb problem cause by the use of "source stl-views-1.0.3.script".
In the wxpropgrid_debugger branch I've implemented a workaround by calling "whatis &{watched_var}" instead of "whatis {watched_var}", when the plugin wants to understand the type of the watched variable.

The same problem happens when one tries to watch "const wxString &str"...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #25 on: September 17, 2009, 10:13:20 am »
I really do not want to annoy you, but what does that mean now

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #26 on: September 17, 2009, 10:25:30 am »
The only way to workaround the problem is to delete the stl-views-1.0.3.script file.
Or you could try the new wxpropgrid_debugger branch.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #27 on: September 17, 2009, 01:16:46 pm »
Ok, I have now a rudimentary. Using gdb 6.3 it works with gdb 6.8 not.
Observed for all who try it again  :)

one more thing I enable the option "Evaluate expression under cursor".

When I go over a qstring it popups a big popmenu with this content
Code
> output &strtrtr
(QString *) 0x22b78c>>>>>>cb_gdb:
> output strtrtr
{
  static null = {<No data fields>},
  static shared_null = {
    ref = {
      _q_value = 2148
    },
    alloc = 0,
    size = 0,
    data = 0x10203122,
    clean = 0,
    simpletext = 0,
    righttoleft = 0,
    asciiCache = 0,
    capacity = 0,
    reserved = 0,
    array = {0}
  },
  static shared_empty = {
    ref = {
      _q_value = 2
    },
    alloc = 0,
    size = 0,
    data = 0x10203136,
    clean = 0,
    simpletext = 0,
    righttoleft = 0,
    asciiCache = 0,
    capacity = 0,
    reserved = 0,
    array = {0}
  },
  d = 0x77e1da8,
  static codecForCStrings = 0x0
}>>>>>>cb_gdb:
down to the border of my screen.
Is it possible to make it scrollable or adjustable....

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugging QString
« Reply #28 on: September 17, 2009, 01:44:10 pm »
The scripts are not run for the "Evaluate expression under cursor"
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #29 on: September 17, 2009, 04:39:12 pm »
Ok but for int it is very nice. Isn´t it?

What about scrollability from those tooltips

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #30 on: September 17, 2009, 05:17:35 pm »
One more question.

When I type a command during debugging it seems CB stores the entered command somwhere.
Does aanybody knows in which file those commands are stored??

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: Debugging QString
« Reply #31 on: September 17, 2009, 07:03:07 pm »
I did not follow the entire discussion on this thread, but I assume that you are using the script I provided you with, and with it you should be able to view much short output..

for example, for this code:
Code
	QString str;
str = "hello world";

You should have get this output from gdb (using gdb 6.8 here), after typing 'printqstring str':

Code
(QString)0x22ff50 (length=11): "hello world"


Is this still the case?

Eran

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #32 on: September 17, 2009, 11:36:25 pm »
Yes I use your script you provided before.

But under gdb6.8 it doesnt work with gdb 6.3 it works.

I always search the gdb command to output the name of the variable. Perhaps like this:
Code
	QString str;
str = "hello world";

(str)->(QString)0x22ff50 (length=11): "hello world"

Is there a method for example $arg0.d->name or which methods are available in the script you provide.

I took the gdb reference but don´t find any command that gives me the name of the variable.

I try to add a third variable like this

Code
 printf "(%c)->(QString)0x%x (length=%i): \"",$arg0,&$arg0,$arg0.d->size
« Last Edit: September 17, 2009, 11:38:05 pm by LordCB »

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: Debugging QString
« Reply #33 on: September 18, 2009, 07:09:58 am »
$arg0 IS a QString
$arg0.d-> is part of the QString implementation and not related to gdb
using this:
printf "%c", $arg0 is equal to this:
printf ("%c", str) -> but as you can see, str is of type QString so it wont work...

You can not get the name of the argument, the same way you cant do it in C++/C

Eran

Offline LordCB

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Debugging QString
« Reply #34 on: September 18, 2009, 01:58:33 pm »
Hmmm.. Ok ?!?!?!

Thanx a lot I learn alot in this post thanx to all