본문 바로가기

IT/프로그래밍

gdb stl의 list나 vector등 값 까보기

728x90

원글(이글루): 2010-06-11 18:05:47

gdb에서 define으로 함수처럼 정의해 쓸수있다.

첨부는 STL의 list나 vector등의 값을 따라 갈때 편리하게 하기 위해서 만들어 놓은 것이다.

원본은 plist가 하나의 함수로 되어 있는데, gdb버전이 낮은 경우 argc라는 변수가 없다.
그래서 인자 갯수별로 plist1 , plist2 이런식으로 함수 분리하는 작업을 한 파일도 첨부한다.

~/.gdbinit 파일을 첨부파일로 대체하면 된다.
개인적으론
“set print pretty on” 를 주석처리하는게 한줄에 나오고 더 좋은거 같다.

1) argc수정한 파일

gdbinit.argc.txt
0.02MB

2) 원본파일

dbinit_stl_views-1.03.txt
0.02MB

테스트
$ g++ -g3 a.cpp
$ ./a.out
NEW=0x89bf008
NEW=0x89bf0a8
NEW=0x89bf148
NEW=0x89bf1e8
NEW=0x89bf288
NEW=0x89bf328
NEW=0x89bf3c8
NEW=0x89bf468
NEW=0x89bf508
NEW=0x89bf5a8
MEM: A 0x89bf008 [BABO-0]
MEM: B 0x89bf0a8 [BABO-1]
MEM: C 0x89bf148 [BABO-2]
MEM: D 0x89bf1e8 [BABO-3]
MEM: E 0x89bf288 [BABO-4]
MEM: F 0x89bf328 [BABO-5]
MEM: G 0x89bf3c8 [BABO-6]
MEM: H 0x89bf468 [BABO-7]
MEM: I 0x89bf508 [BABO-8]
MEM: J 0x89bf5a8 [BABO-9]
Aborted (core dumped)
$ gdb a.out core.11356
GNU gdb (GDB) 7.0


(gdb) p m_cont
$1 = {
  _M_t = {
    _M_impl = {
      <std::allocator<std::_Rb_tree_node<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, char*> > >> = {
        <__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, char*> > >> = {<No data fields>}, <No data fields>},
      members of std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, char*>, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, char*> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, char*> > >::_Rb_tree_impl<std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, false>:
      _M_key_compare = {
        <std::binary_function<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool>> = {<No data fields>}, <No data fields>},
      _M_header = {
        _M_color = std::_S_red,
        _M_parent = 0x89bf268,
        _M_left = 0x89bf088,
        _M_right = 0x89bf628
      },
      _M_node_count = 10
    }
  }
}
(gdb) pmap m_cont
Map type = map_cont
Use pmap <variable_name> <left_element_type> <right_element_type> to see the elements in the map.
Map size = 10
(gdb) pmap m_cont void* char*
elem[0].left: $2 = (void *) 0x89bf07c
elem[0].right: $3 = 0x89bf008 “BABO-0”
elem[1].left: $4 = (void *) 0x89bf11c
elem[1].right: $5 = 0x89bf0a8 “BABO-1”
elem[2].left: $6 = (void *) 0x89bf1bc
elem[2].right: $7 = 0x89bf148 “BABO-2”
elem[3].left: $8 = (void *) 0x89bf25c
elem[3].right: $9 = 0x89bf1e8 “BABO-3”
elem[4].left: $10 = (void *) 0x89bf2fc
elem[4].right: $11 = 0x89bf288 “BABO-4”
elem[5].left: $12 = (void *) 0x89bf39c
elem[5].right: $13 = 0x89bf328 “BABO-5”
elem[6].left: $14 = (void *) 0x89bf43c
elem[6].right: $15 = 0x89bf3c8 “BABO-6”
elem[7].left: $16 = (void *) 0x89bf4dc
elem[7].right: $17 = 0x89bf468 “BABO-7”
elem[8].left: $18 = (void *) 0x89bf57c
elem[8].right: $19 = 0x89bf508 “BABO-8”
elem[9].left: $20 = (void *) 0x89bf61c
elem[9].right: $21 = 0x89bf5a8 “BABO-9”
Map size = 10

예제소스

a.cpp
0.00MB

참고자료:
http://www.yolinux.com/TUTORIALS/GDB-Commands.html
http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt

728x90