简体   繁体   中英

eclipse CDT view struct in debug

In eclipse with CDT, I would like to view the values of a struct's members, similar to the way in which I can use the "variables view" to look at the values of variables. Below is a very simple example where I would like to be able to examine the values of test.val1 and test.val2. The program runs fine, but I can't use gdb to view struct test.

#include <cstdio>

struct test {
    int val1;
    int val2;
} test;

int main () {
    test.val1 = 3;
    test.val2 = test.val1*4;
    printf("val1 = %d, val2 = %d\n", test.val1, test.val2);

    return 1;
}

After I achieve this, my next question will be is there any difference is test is

extern "C" struct struct test {
    int val1;
    int val2;
} test;

I am running: Eclipse IDE for Java Developers Version: Luna Service Release 2 (4.4.2) with CDT, CDT SDK and Photran

Thanks for your help on this probably very simple question

Paul

In your sample code you declared struct (type) named test and a struct variable of type test also named test. GDB seems to have an issue with this.

Modify your code, so type and variable have different name (so something like this):

struct Test {
    int val1;
    int val2;
} test;

Then start the debugger. In expressions view add new expression "test" and that is it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM