GDB 디 버 깅 인쇄 STL 개체
본문 을 기록 하 다
0. 비고
1.gdb_stl_utils
2. 인 스 턴 스 소스 코드
3. 디 버 깅 과정의 입 출력
0 >> 비고
참고:http://staff.science.uva.nl/~gilad/stl/stl_gdb.html
.gdbinit: http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt
gdb: http://www.yolinux.com/TUTORIALS/GDB-Commands.html
注意:这里的操作在32位linux机器上没有问题,但是在64位就杯具了,囧里个囧.我也不知道为啥呢
如果在64位机器上运行,会出这样的问题:(gdb) pmap map_str char* char*elem[0]->left: $1 = 0x14000000 <Address 0x14000000 out of bounds>elem[0]->right: $2 = 0xbfc2f7 <Address 0xbfc2f7 out of bounds>Attempt to dereference a generic pointer.
1 >>gdb_stl_utils
wet http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt
mv dbinit_stl_views-1.03.txt .gdbinit
2 >> 인 스 턴 스 소스 코드:
/********************************** 实例源码 start@peterguo ***************************/
#include <string>
#include <vector>
#include <map>
#include <iostream>
int main ()
{
cout << "map ........" << endl;
map <string, string> map_ctr;
map_ctr.insert(pair<string, string> (string("key1"), string("value1")));
map_ctr.insert(pair<string, string> (string("key2"), string("value2")));
map_ctr.insert(pair<string, string> (string("key3"), string("value3")));
map <string, string>::iterator it = map_ctr.begin();
for (;it != map_ctr.end(); it++)
{
cout << it->first << " -> " << it->second << endl;
}
map <int, string> map_int2str;
map_int2str.insert(pair<int, string> (9527, "shit"));
map_int2str.insert(pair<int, string> (9528, "shit2"));
map <int, int> map_int2int;
map_int2int.insert(pair<int, int> (9527, 9528));
map_int2int.insert(pair<int, int> (9528, 9529));
cout << "vectors ........" << endl;
vector <int> vector_int;
vector_int.push_back(9527);
vector_int.push_back(9528);
vector <string> vecotr_str;
vecotr_str.push_back("value1");
vecotr_str.push_back("value2");
cout << "pvector [vector_int] [vecotr_str]" << endl;
cout << "pmap [map_ctr] [map_int2str] [map_int2int]" << endl;
cout << "Set break point here at [" << __FILE__ << ":" << __LINE__ << "]" << endl;
return 0;
}
/********************************** 实例源码 end@peterguo ***************************/
1 >>调试过程:
root@XXX:/tmp/peterguo# gdb ./test_stl_gdb.exe
GNU gdb 6.4
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) b test_stl_gdb.cpp:43
Breakpoint 1 at 0x80499d8: file test_stl_gdb.cpp, line 43.
(gdb) r
Starting program: /tmp/peterguo/test_stl_gdb.exe
map ........
key1 -> value1
key2 -> value2
key3 -> value3
vectors ........
pvector [vector_int] [vecotr_str]
pmap [map_ctr] [map_int2str] [map_int2int]
Breakpoint 1, main () at test_stl_gdb.cpp:43
43 cout << "Set break point here at [" << __FILE__ << ":" << __LINE__ << "]" << endl;
(gdb) pvector vector_int
elem[0]: $1 = 9527
elem[1]: $2 = 9528
Vector size = 2
Vector capacity = 2
Element type = int *
(gdb) pvector vecotr_str
elem[0]: $3 = {static npos = 4294967295,
_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x80501f4 "value1"}}
elem[1]: $4 = {static npos = 4294967295,
_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x805020c "value2"}}
Vector size = 2
Vector capacity = 2
Element type = std::basic_string<char,std::char_traits<char>,std::allocator<char> > *
(gdb) pmap map_ctr char* char*
elem[0]->left: $5 = 0x805004c "key1"
elem[0]->right: $6 = 0x8050034 "value1"
elem[1]->left: $7 = 0x805009c "key2"
elem[1]->right: $8 = 0x8050084 "value2"
elem[2]->left: $9 = 0x80500ec "key3"
elem[2]->right: $10 = 0x80500d4 "value3"
Map size = 3
(gdb) pmap map_int2str int char*
elem[0]->left: $11 = 9527
elem[0]->right: $12 = 0x8050124 "shit"
elem[1]->left: $13 = 9528
elem[1]->right: $14 = 0x805015c "shit2"
Map size = 2
(gdb) pmap map_int2int int int
elem[0]->left: $15 = 9527
elem[0]->right: $16 = 9528
elem[1]->left: $17 = 9528
elem[1]->right: $18 = 9529
Map size = 2
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.