eclipse CDT中如何手动输入gdb命令

hc000 hc000 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在eclipse CDT中调试很不方便,主要是无法查看STL容器变量的值。查了下资料,发现可以通过如下方式查看vector(其它容器类似):

第一步: 定义打印输出每个元素的方法(甚至可以写成脚本放到特定的文件中,如.gdbinit):

void dump(const vector<string> & vec)
{
int i = 0;
for( vector<string>::const_iterator iter = vec.begin(); iter != vec.end(); ++ iter )
cerr << '[' << (i ++) << ']' << " = \"" << *iter << "\"" << endl;
}

第二步:在breakpoints处调用dump打印感兴趣的vector变量:

Breakpoint 1, MatchString::placeWords (this=0xbfe49633, matchString=@0xbfe495f0,
matchWords=@0xbfe495e4) at MatchString.cpp:120
120 int m = 51;
(gdb) call dump(matchWords)
[0] = "dog"
[1] = "cat"
[2] = "rat"
(gdb)



我的问题是:在eclipse CDT中如何输入gdb命令呢?请大家指教。

...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
hc000
Eclipse 58,439 成员 49,457 内容