GDB调试打印STL对象
生活随笔
收集整理的這篇文章主要介紹了
GDB调试打印STL对象
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
其實就gdb_stl_utils是定義的一些語句,就如同shell中的.bashrc一樣,可以在啟動gdb后把它source進取,也可以重命名到系統目錄或者當前路徑 .gdbinit 這樣gdb在啟動的時候就加載了這些所謂的語句(在gdb里設置斷點的輸入命令也可以加到.gdbinit中,如 b main)
本文做記錄,包含
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??.gdbinit2 >>實例源碼:?
/**********************************?實例源碼?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
轉載于:https://my.oschina.net/sanpeterguo/blog/207280
總結
以上是生活随笔為你收集整理的GDB调试打印STL对象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: awk工具的简单使用
- 下一篇: 25个CSS3 渐变和动画效果教程