본문 바로가기
Virtualization/[상용] vmware

VMware 에서 Metalkit app 디버깅하기

by blackcon 2021. 12. 16.
728x90

Debugging Metalkit Apps

이 글은 리눅스의 gdb로 Metalkit을 동적으로 분석할 수 있는 방법을 설명하며,

본 게시글은 vmware에서 제공하는 vmware-svga의 내용을 나름대로 해석한 글이다.

디버깅하고자 하는 vm 이미지의 설정파일(*.vmx)를 에디터로 오픈해서 아래의 내용을 한다.

debugStub.listen.guest32 = "TRUE"
debugStub.hideBreakpoints = "TRUE"
monitor.debugOnStartGuest32 = "TRUE"

 

이 후, VM 이미지를 실행하면 bios 화면이 뜨기전에 hang이 걸려있게 된다.
이번 단계에서 할 것이 gdb를 이용해서 attach를 하는것인데,
Metalkit에 심겨져있는 .elf 파일을 가지고 있어야지 디버깅을 할 수 있다.

micah@micah-64:~/metalkit/examples/apm-test$ gdb -q apm-test.elf
No symbol table is loaded.  Use the "file" command.
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) set arch i386
The target architecture is assumed to be i386
(gdb) target remote localhost:8832
Remote debugging using localhost:8832
[New Thread 1]
0x000ffff0 in ?? ()
(gdb) break main
Breakpoint 1 at 0x100ba2: file main.c, line 11.
(gdb) cont
Continuing.

 

이제 VM 부팅이 표시됩니다. 더 일찍 중지해야 하는 경우 디버깅하려면 대신 *0x7c00에서 중단점을 설정할 수 있습니다.

보통. main() 에서 시작하는 것으로 충분합니다.

Metalkit이 로딩되자마자 중단점에 합니다. 지금부터 모든 일반 gdb command 는 사용할 수 있게 됩니다.

Breakpoint 1, main () at main.c:11
11      {
(gdb) list
6       #include "keyboard.h"
7       #include "apm.h"
8
9       int
10      main(void)
11      {
12         ConsoleVGA_Init();
13         Intr_Init();
14         Intr_SetFaultHandlers(Console_UnhandledFault);
15         Keyboard_Init();
(gdb) next
main () at main.c:12
12         ConsoleVGA_Init();
(gdb)
13         Intr_Init();
(gdb)
14         Intr_SetFaultHandlers(Console_UnhandledFault);
(gdb)
15         Keyboard_Init();
(gdb) p gConsole
$1 = {beginPanic = 0x1005ef <ConsoleVGABeginPanic>,
      clear = 0x1004d2 <ConsoleVGAClear>,
      moveTo = 0x1004c1 <ConsoleVGAMoveTo>,
      writeChar = 0x100511 <ConsoleVGAWriteChar>,
      flush = 0x100482 <ConsoleVGAMoveHardwareCursor>}
(gdb)

 

728x90