开发者

Variable name conflict with GDB debugger

I'm debugging a C++ program with GDB on Linux, and I need to see the value of a member variable while the program is running. The member variable, unfortunately, is named list, which happens to be a GDB keyword. So when I try:

print m_operations.m_data[10].m_data.list

I get...

A syntax error in expression, near list'.

I tried all sorts of things to indicate 开发者_StackOverflow社区to GDB that I'm entering a literal expression, like putting double or single quotes around the variable name, but it just results in more syntax errors. I've looked in the GDB manual and can't find anything to resolve this. I can't rename the member variable because I'm not authorized to modify that class. Furthermore, list is a C++ object, not a regular integer or POD, so I can't simply use the x keyword to examine the memory there...at least not without spending some serious time deciphering what the raw binary represents.

So, any suggestions to resolve this?


The problem is not what you think it is - if i debug the following code:

int main() {
    int list = 666;
    while( list ) {
        list--;
    }
}

I can break on the third line and say:

(gdb) print list

which gives me:

$1 = 666

There must be something else wrong with the expression you are trying to print. Have you tried using a GUI debugger, like DDD, which will allow you to select the thing you want to print by clicking with the mouse?


Most likely this is a bug in GDB (or possibly in GCC).

First try the latest GDB (7.0.1).

If that fails, try to create a simple stand-alone test case, and file a bug in GDB bugzilla. If you do that, be sure to tell which version of GCC was used to compile your test.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜