News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Debugging QString

Started by LordCB, September 14, 2009, 03:19:48 PM

Previous topic - Next topic

LordCB

Hello friends,

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


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;

oBFusCATed

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!]

LordCB

#2
Ok, ...

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.

oBFusCATed


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.


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!]

eranif

This is how I debug QString:

I add the following user function to the debugger on the startup:
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:
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

LordCB

dear eranif,
now I understand nothing........

you say
QuoteI 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

Quoteprintqstring <variable_name>

eranif

Quote from: LordCB on September 14, 2009, 10:39:43 PM
dear eranif,
now I understand nothing........

you say
QuoteI 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

Quoteprintqstring <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

LordCB

Thanx a lot,

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

oBFusCATed

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

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!]

LordCB

Thanx a lot I will give it a try.

I give also a feedback....

thanks thanks thanks

LordCB

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)


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


to the function

function RegisterTypes(driver)


after that

I also add

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

printqstring <variable_name>


be placed ?

oBFusCATed

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!]

LordCB


LordCB

There is no show debugger pane.
Am I blind?

Jenna

Check "Settings -> Compiler and debugger... -> Debugger settings -> Display debugger's debug log".
And don't forget the keyword "source" in the debugger command.