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;
You could add a debugger script to parse the QStrings.
For more info see here: http://wiki.codeblocks.org/index.php?title=Debugger_scripts
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.
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
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
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>
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
Thanx a lot,
I really want to make this feature to me existant, cause this would save me a lot of time I think.
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...
Thanx a lot I will give it a try.
I give also a feedback....
thanks thanks thanks
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 ?
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
I use nightlies 5716
There is no show debugger pane.
Am I blind?
Check "Settings -> Compiler and debugger... -> Debugger settings -> Display debugger's debug log".
And don't forget the keyword "source" in the debugger command.
@ jens:
Do you mean like this :
source: X:\CODEBLOCKS\CB_DebuggerScripts\qstring.script
under Debugger initialization command
Yes, that is what he means :)
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]
This are my settings
[attachment deleted by admin]
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...
Thanks but I get an
Undefined command: "printqstring". Try "help".
Undefined command: "printqstring". Try "help".
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)
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).
Ok,
now I get this.
Attempt to extract a component of a value that is not a structure.
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"...
I really do not want to annoy you, but what does that mean now
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.
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
> 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....
The scripts are not run for the "Evaluate expression under cursor"
Ok but for int it is very nice. Isn´t it?
What about scrollability from those tooltips
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??
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:
QString str;
str = "hello world";
You should have get this output from gdb (using gdb 6.8 here), after typing 'printqstring str':
(QString)0x22ff50 (length=11): "hello world"
Is this still the case?
Eran
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:
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
printf "(%c)->(QString)0x%x (length=%i): \"",$arg0,&$arg0,$arg0.d->size
$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
Hmmm.. Ok ?!?!?!
Thanx a lot I learn alot in this post thanx to all