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;
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
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...
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 ?
@ jens:
Do you mean like this :
source: X:\CODEBLOCKS\CB_DebuggerScripts\qstring.script
under Debugger initialization command
Thanks but I get an
Undefined command: "printqstring". Try "help".
Undefined command: "printqstring". Try "help".
Ok,
now I get this.
Attempt to extract a component of a value that is not a structure.
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....
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