0
votes

I'm in an enterprise environment (which means there's no possibility a priori to add pretty printers or change software at any level) using GDB (gdbserver) to debug an app using Qt on a different device.

While I'm debugging, I usually need to check the values of a Qt structure like a QMap, which has a QString as key.

Guess I have a map like this one:

QVariantMap map;

Now, while debugging, that happens:

(gdb) p dataMap.value()
Too few arguments in function call.
(gdb) p dataMap.value("first")
Cannot resolve method QVariantMap::value to any overloaded instance
(gdb) p dataMap.value("first", QVariant(""))
A syntax error in expression, near `(""))'.

According to QMap documentation, both 2nd and 3rd options should work.

That's pretty annoying, since I'd love to be able to check map's values without modifying my code.

It seems to me that there's some kind of missunderstanding between GDB and Qt.

Any help would be appreciated.


EDIT:

As pointed out by Mohammed, gdb doesn't have to understand conversion from const char * to QString.

It doesn't make any difference however, since I get the same error when I use QString("") than this one seen in the third command of the original part with QVariant("").

(gdb) p params.value(QString("deliveryLimit"))
A syntax error in expression, near `"deliveryLimit"))'

In this case, it is a QHash, but this shouldn't be important since I'm looking for a way to debug Qt's value-key containers in general.

1
Take a while and check this page with some info about the different ways to print a QString in GDB: silmor.de/qtstuff.printqstring.php & use QVariant().toString() to print QVariant as String.mohabouje
Sorry @MohammedB.B. but I don't get why you link that. In any case, if GDB doesn't accept a const char * (QString(const char *)), how will I insert the key I want to debug? Thanksjjimenezg93
What is interesting everything is debuggable with Qt Creator which uses gdb. I guess that Qt Creator does additional tricks. There might be an effort but it worth to make it work with remote GDB in case of device debug.Alexander V
@AlexanderVX I have no doubt of it and it's something beeing considered, but there must be a way to achieve this "manually", isn't it? Thank youjjimenezg93
@jjimenezg93 Qt is for GUI, right? And debug GUI stuff with command-line gdb? Way too cumbersome for me. If no IDE debugger then tat max logsAlexander V

1 Answers

0
votes

First of all, lets use QVariantMap for QMap<QString, QVariant>.

Posible issues: gdb is not a compiler, so let's avoid user-defined type conversions for you. Function wich wants a QString, lets give it a QString, not a const char*.

(gdb) p dataMap.value(QString("first"))

To avoid future problem, use a little helper function to your program, that would take a const char* and return an QString&, something like:

QString& toQString(const char* s)
{
       return *(new QString(s));
}

Then in gdb

gdb> p dataMap.value(toQString("domain"));

Fast solution, use QMap<const char*, QVariant>