在Eclipse中调试全局变量(C/C ++) [英] debugging global variable in eclipse (C/C++)

查看:135
本文介绍了在Eclipse中调试全局变量(C/C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了这个示例C程序:

I wrote this sample C program:

#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,并且想要调试此代码. s zeroed 变量显示在变量"标签中.但是,此处未显示 g_s (这是一个全局变量).有没有办法让我查看其字段以及它们如何变化等?

I'm using Eclipse Mars IDE and I want to debug this code. the s and zeroed variables are shown in the variables tab. however, the g_s (which is a global variable) is not shown there. is there a way for me to see its fields and how they're changing etc.?

刚刚发现有一个添加全局变量"按钮,但是它是灰色的,所以我不能按它.

just figured out there's a "add global variables" button but it is grayed, so I can't press it.

推荐答案

好,因此在对其进行了更多搜索之后,我发现了

ok, so after some more googling about it I found this . tl;dr - the problem was that I was using the default GDB(DSF) process launcher. apparently this is a known issue (more details in the link above).

解决该怎么办:转到运行"->调试配置",然后在打开的窗口底部检查您正在使用的调试启动器.如果是GDB(DSF),则按下面的选择其他..."链接.在打开的窗口中标记使用特定于配置的设置",然后选择其他启动器(在我的情况下是旧版创建进程启动器").现在,添加全局变量不应为灰色,您可以单击它并选择要观看的变量.

what you should do to solve it: go to Run-->Debug Configurations and check at the bottom of the opened window which debug launcher you are using. if it is the GDB(DSF) then press the "Select other..." link below it. In the opened window mark "Use configuration specific settings" and then choose a different launcher (in my case it is "Legacy Create Process Launcher"). now the "add global variables should not be gray and you can click it and choose the variables you want to watch.

留下问题,以防万一有人遇到相同的问题.

leaving the question just in case someone will encounter the same problem.

这篇关于在Eclipse中调试全局变量(C/C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆