GDB调试C++类对象/C++B标准库STL

韦伊 2016-05-11 03:22:47
gdb调试C++类对象/标准库对象这些支持的程度是怎么样的?
看到网上有人调试vertor,map的结果服从直观。如图所示:
图1

图2


但是我自己机器上调试,结果就没那么直观了。源代码如下:
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

#define PI 3.1415926
const int WEEK= 7;
const string NAME= "weijl";
static double SCORE= 99.0;

class CMyData
{
public:
CMyData()
{
a = 0;
str = string("weijl");
c = 65;
}
~CMyData()
{

}
int a;
string str;
float c;

int GetA()
{
return a;
}

string GetStr()
{
return str;
}

float GetC()
{
return c;
}
void setmv()
{
m_v.push_back("weijl");
m_v.push_back("shenzhen");
m_v.push_back("nanning");
m_v.push_back("C++ Program");
}

public:
typedef vector<string> vs;
typedef vector<string>::iterator It;

vs m_v;
};

int main() {

cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!

CMyData data;
cout << data.a << endl << data.str << endl << data.c << endl;

data.setmv();
CMyData::vs v = data.m_v;
CMyData::It it = v.begin();
while( it != v.end())
{
string s = *it;
cout << s << endl;

it++;
}

int i1 = 32;
int i2 = 45;
double d = i1 + i2 / 3;

vector<string> vstr;
vstr.push_back("Hello");
vstr.push_back("World");
vstr.push_back("!");

map<string, int> m_si;
m_si["A"] = 12;
m_si["D"] = 93;
m_si["B"] = 77;

return 0;
}


调试结果如图所示:
图3

-----------------------------------------------------------------------------------------------------------------------------------------
图2 是我期望的结果,图3是我机器上调试的结果。
想知道图2是怎么做到的,我gdb的版本是7.4
...全文
559 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hijack00 2016-08-29
  • 打赏
  • 举报
回复
参考{GDB调试手册](http://www.programlife.net/gdb-manual.html)的Controlling GDB那一节。通过以下设置 set print array on set print array-indexes on set print pretty on set print union on set print demangle on 等等选项应该可以达到目的。
hijack00 2016-08-27
  • 打赏
  • 举报
回复
同问,我也遇到了这个问题
mewiteor 2016-05-12
  • 打赏
  • 举报
回复

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧