$ ./configure --enable-gdb-stub $ make # make install
gdbstub: enabled=1, port=1234, text_base=0, data_base=0, bss_base=0
$ bochs选择Begin simulation
$ ls bget.o idt.o kernel.bin kthread.o mem.o synch.o crc32.o int.o kernel.exe lowlevel.o screen.o timer.o fd_boot.bin io.o kernel.syms main.o segment.o trap.o gdt.o irq.o keyboard.o malloc.o setup.bin tss.o
kernel.exe: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped
$ gdb kernel.exe
Reading symbols from /home/user/work/geekos-0.3.0/src/project0/build/geekos/kernel.exe...done.
然后连接到远程端口,当然其实是本机端口:
(gdb) target remote localhost:1234 Remote debugging using localhost:1234 0x0000fff0 in ?? ()
(gdb) l 1 /* 2 * GeekOS IDT initialization code 3 * Copyright (c) 2001, David H. Hovemeyer <[email protected]> 4 * $Revision: 1.9 $ 5 * 6 * This is free software. You are permitted to use, 7 * redistribute, and modify it as specified in the file "COPYING". 8 */ 9 10 #include <geekos/kassert.h>
(gdb) l main.c:0 warning: Source file is more recent than executable. 1 /* 2 * GeekOS C code entry point 3 * Copyright (c) 2001,2003,2004 David H. Hovemeyer <[email protected]> 4 * Copyright (c) 2003, Jeffrey K. Hollingsworth <[email protected]> 5 * Copyright (c) 2004, Iulian Neamtiu <[email protected]> 6 * $Revision: 1.51 $ 7 * 8 * This is free software. You are permitted to use, 9 * redistribute, and modify it as specified in the file "COPYING". 10 */ (gdb) 11 12 #include <geekos/bootinfo.h> 13 #include <geekos/string.h> 14 #include <geekos/screen.h> 15 #include <geekos/mem.h> 16 #include <geekos/crc32.h> 17 #include <geekos/tss.h> 18 #include <geekos/int.h> 19 #include <geekos/kthread.h> 20 #include <geekos/trap.h>
(gdb) b main.c:58 Breakpoint 1 at 0x1647b: file ../src/geekos/main.c, line 58.
(gdb) c Continuing. Breakpoint 1, Main (bootInfo=0x101ff8) at ../src/geekos/main.c:58 58 Print("Welcome to GeekOS!\n");
(gdb) n 59 Set_Current_Attr(ATTRIB(BLACK, GRAY));
# apt-get install ddd启动调试器调试内核文件:
$ ddd kernel.exe