在eclipse中调试全局变量(C / C ++)

时间:2016-09-01 07:42:55

标签: c eclipse

我写了这个示例C程序:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define SIZE 10

typedef struct _sampleStruct{
    int f1;
    double f2;
    int f3[SIZE];
}sampleStruct;

sampleStruct g_s;

int main() {

    sampleStruct s;
    sampleStruct zeroed = {0};
    s.f1 = g_s.f1 = 1;
    s.f2 = g_s.f2 = 2.0;
    for (int i = 0; i < SIZE; ++i) {
        s.f3[i] = g_s.f3[i] = i*10;

    }
    memset(&s, 0, sizeof(sampleStruct));
    printf("s: %d, g_s: %lf, zeroed: %d", s.f1, g_s.f2, zeroed.f3[3]);

    return 0;
}

我正在使用Eclipse Mars IDE,我想调试此代码。 szeroed变量显示在变量选项卡中。 但是,g_s(这是一个全局变量)没有在那里显示。 有没有办法让我看到它的领域以及它们如何改变等等?

编辑:只是想出了一个&#34;添加全局变量&#34;按钮但它是灰色的,所以我无法按下它。

2 个答案:

答案 0 :(得分:0)

好的,所以经过一些谷歌搜索后,我找到了this。 tl; dr - 问题在于我使用的是默认的GDB(DSF)进程启动器。显然这是一个已知问题(上面链接中的更多细节)。

你应该怎么做才能解决它: 转到Run - &gt; Debug Configurations并在打开的窗口底部检查您正在使用哪个调试启动器。如果是GDB(DSF),请按下面的“选择其他...”链接。在打开的窗口中标记“使用配置特定设置”,然后选择其他启动器(在我的情况下,它是“Legacy Create Process Launcher”)。 现在,“添加全局变量不应该是灰色的,您可以单击它并选择要监视的变量。

留下问题以防有人遇到同样的问题。

答案 1 :(得分:0)

我希望您觉得这个视觉描述很有帮助。

点击Variables图标(上面带有眼镜的绿点):

enter image description here

位于@Html.DisplayFor(i => Model.Single(m => m.Id == 1).question) 标签下的

enter image description here

以下是两者的缩小:

enter image description here