Unix

GDB 스크립팅

ForceCore 2010. 3. 5. 22:49
아래 코드는 gdb -x gdb.scr (gdb.scr로 저장한 경우) 로 실행시킬 수 있다.
file bst               # bst라는 executable file을 대상으로 함.

define watchNode        # 나름의 subroutine을 정의했음;; 여기서 정의한 watchNode라는 명령어는 end가 나올때 까지 나오는 명령어를 순차적으로 실행하는 것임.
    set $me = this
    print this
    print area
    print ms
    print &area
    print &ms
    #watch area
    #watch ms
end

break bst_header.h:167    # 브레이크 포인트 걸기
commands 1      # break point 1이 걸리기만 하면 자동으로 수행할 명령어 set
    watchNode
    continue
end

# 이거저거 할거 다 했으면 이제 프로그램을 실행시킨다.
run -i r1 -B 100

나름... 알아내느라 시간 좀 걸렸음. 결과적으로 실패했지만 뭐 그래도 가치 있는 일이었다.
get/set 함수를 쓰지 않고는 member variable이 바뀌는 것을 추적하기 어렵구나!!

참고: get/set 을 왜 쓰나?
http://kldp.org/node/89756
ㅋㅋ