Skip to content

GDB:pretty-printing

GDB 에서 STL vector, map 과 같은 container class 의 데이터를 확인을 편하게 도와주는 Python도구 이다.

How to use

만약 GDB에 Python확장이 설치되어 있지 않다면 다시 컴파일 해야 한다.

그 후 svn을 사용하여 pretty-printing를 받은 후 GDB초기화 파일을 생성한다. 1

$ svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python pretty-printing
$ vi ~/.gdbinit

gdb 초기화 파일에 아래와 같이 Python코드를 입력한다.

python
import sys
sys.path.insert(0, 'pretty-printing/home/path/libstdcxx/v6')
from printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

이후 gdb명령어를 실행하여 에러가 없다면 성공한 것이다.

Eclipse에 설정할 경우 Window > Preferences > C/C++ > Debug > GDB > GDB command file항목에 ~/.gdbinit을 지정한다.

참고로 아래와 같이 환경변수를 활용할 수 있다.

printing_home = os.environ['PPRINTING_V6']
sys.path.insert(0, printing_home)
from printers import register_libstdcxx_printers
register_libstdcxx_printers(None)

Example

적용한 전체 코드는 아래와 같다.

python
print "[PYTHON] Python initialize begin."

import os
import sys

## pretty-printing
## svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
PPRINTING_HOME = os.environ["PPRINTING_HOME"]
PPRINTING_V6 = os.path.join(PPRINTING_HOME, "libstdcxx/v6")

if os.path.isdir(PPRINTING_V6):
    print "[PPRINTING] Register libstdcxx printers."
    sys.path.insert(0, PPRINTING_V6)
    from printers import register_libstdcxx_printers
    register_libstdcxx_printers(None)
else:
    print "[PPRINTING] Not found printers.py file."

print "[PYTHON] Python initialize end."
end

See also

Favorite site

References


  1. 참고로 /share/gdb/python/gdb/printing.py파일이 존재한다.