본문 바로가기

reversing

gdb child process debugging

GDB 에서는 fork()이후에도 디버깅할 수 있는 기능을 제공한다.

 

기본적으로 fork() 이후에는 parent process 만 계속 디버깅 된다. 만약, child process 에 bp 를 설정할 경우 SIGTRAP 시그널을 받고 종료된다. 이러한 문제점을 해결하기 위한 방법은 child process 에 sleep 을 걸고 pid 를 얻어 attach 하는 방법이 있다.

하지만, Linux Kernel 2.5.46 이상에서는 gdb를 사용하여 fork 또는 vpork 에 대한 디버깅 기능을 지원한다.

 

 

set follow-fork-mode child

위와 같이 설정할 경우 fork() 후에 child process 가 디버깅 되어진다. parent process 는 계속 실행된다.

기본 값은 parent 이다.

 

show follow-fork-mode

위 명령을 통해 fork() 에 대한 현재 디버거 응답 상태를 나타내 준다.

 

set detach-on-fork [on|off]

fork() 후 프로세스 중 하나를 detach 할 것인지 아니면 parent, child process 둘 다 제어할 것인지 알려준다.

기본 값은 set detach-on-fork on 이다.

set detach-on-fork off 명령을 통해 두 개의 프로세스는 GDB 제어 아래 디버깅 할 수 있다.

 

show detach-on-fork

detach-on-fork 모드가 on 인지 off 인지 나타내준다.

 

 

ref https://sourceware.org/gdb/onlinedocs/gdb/Forks.html

'reversing' 카테고리의 다른 글

code injection  (0) 2018.01.09
angr  (0) 2017.02.18
IDA remote gdb debugging with gdbserver  (0) 2016.04.10
예외 처리를 이용한 Anti-Debugging  (0) 2016.03.12
windbg kernel debugging  (0) 2016.01.31