Author Topic: Debugging QString  (Read 33227 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.