지난일들/GDB

QEMU에서 remote gdb의 사용

바위맨 2012. 8. 16. 21:57
반응형

1. 일반적인 embedded linux를 타켓에 포팅하고 remote gdb를 통해서 debugging을 실행할 경우

  1. GDB cross debugger 를  build 하고 install한다. 
  2. gdbserver를 build하고 install한다. 
    (몇몇 linux에서는 gdbserver를 rootfs의 어플리케이션처럼 구분하고, 어떤 경우에는 toolchain의 package의 의 일부로 들어가는 경우도 있다. 만약 포함이 되어있지 않다면 cross compile을 통해서 추가해주어야 한다.)
  3. application을 적절한 CFLAGS와  LDFLAGS등으로 설정한다.
  4. gdbserver와 컴파일된 application을 타겟으로 이동한다. 
  5. 타겟에서 gdbserver를 실행 시키고, 연결 설정을 실행한다.
    (serial port 3000사용할 경우= gdbserver :3000 application)
    (타겟은 serial port 3000을 listen하고 있다.)
  6. host에서 cross debugger gdb를 실행 시키고 , gdbserver와 연결을 실행한다. 
    (ex) mk68k-uclinux-gdb 192.168.1.100:3000 ./application)
    (192.168.1.100은 타겟의 가상 IP)

2. QEMU에서의 gdb 사용하기

http://aseemsethi.wordpress.com/article/debugging-linux-with-qemu-gdb-29fizhrip655z-17/

  1. GDB can be connected to QEMU by starting QEMU with the -s -S command line switches
  2. 동일 머신에서 qemu에 의해 실행되는 가상 머신의 stub와 통신한다. 
  3. 통신은 TCP/IP를 통해서 실행된다. 

3. QEMU를 통해서 gdb를 사용하게 되면 하드웨어 자체를 정지시키는 방식을 통해서 실행시키는것 같기도 하다?!!!!!??????? 확인해보자 확인

- 추가 정보 http://zoo.cs.yale.edu/classes/cs422/2011/lec/l2-hw

  1. 타겟에서 kernel이 직접적으로 실행이 이루어지고 있는 과정에도, GDB의 실행이 편리한 하드웨어, OS에서 GDB를 실행 시켜서 디버깅을 실행 할 수 있다. 이런 경우 타겟에서 디버깅에 필요한 모든 프로그램을 실행시킬 필요가 없다. 
  2. 이런 경우 일반적으로 작은 stub가 디버깅을 실행할 커널에서 실행이 이루어지게 된다. 
    (a small remote debugging stub is typically embedded into the kernel being debugged)
  3. gdb에 옵션을 입력하고 실행을 시키게 될경우에는 gdb_stub가 실행됨과 동시에 명령을 기다리는 대기 상태로 대기하는듯?!!


 $ make qemu-gdb

*** Now run 'gdb'.

qemu -parallel mon:stdio -smp 2 -hdb fs.img xv6.img -s -S -p 25501

QEMU 0.10.6 monitor - type 'help' for more information

(qemu)

You will notice that while a window appears representing the virtual machine's display, nothing appears on that display: that is because QEMU initialized the virtual machine but stopped it before executing the first instruction, and is now waiting for an instance of GDB to connect to its remote debugging stub and supervise the virtual machine's execution. In particular, QEMU is listening for connections on a TCP network socket, at port 25501 in this example, because of the '-p 25501' in the qemu command line above. You might see a different port number: this is because xv6's Makefile tries to compute a port number that is likely to be unique and available even if multiple users are debugging xv6 under QEMU on the same machine (see the GDBPORT variable in xv6's Makefile).


반응형