浏览代码

:new: gdb源代码级别调试

fslongjin 2 年之前
父节点
当前提交
e667fff256
共有 5 个文件被更改,包括 14 次插入6 次删除
  1. 1 0
      .gitignore
  2. 4 1
      Makefile
  3. 3 3
      kernel/Makefile
  4. 2 2
      run.sh
  5. 4 0
      tools/.gdbinit

+ 1 - 0
.gitignore

@@ -2,6 +2,7 @@
 /bin/
 DragonOS.iso
 .idea/
+kernel/kernel
 
 *.o
 *.s

+ 4 - 1
Makefile

@@ -16,4 +16,7 @@ clean:
 		echo "Clean in dir: $$subdir";\
 		cd $$subdir && make clean;\
 		cd .. ;\
-	done
+	done
+
+gdb:
+	gdb -n -x tools/.gdbinit

+ 3 - 3
kernel/Makefile

@@ -7,7 +7,7 @@ DIR_LIB=lib
 lib_patterns := *.a
 LIB_FILES := $(foreach DIR,$(DIR_LIB),$(addprefix $(DIR)/,$(lib_patterns)))
 
-CFLAGS := -mcmodel=large -fno-builtin -m64
+CFLAGS := -mcmodel=large -fno-builtin -m64 -g
 
 # 控制操作系统使用的中断控制器 _INTR_8259A_ _INTR_APIC_
 PIC := _INTR_APIC_
@@ -16,8 +16,8 @@ CFLAGS += -D $(PIC)
 ASFLAGS := --64
 
 all: kernel
-	objcopy -I elf64-x86-64 -S -R ".comment" -R ".eh_frame" -O elf64-x86-64 kernel ../bin/kernel/kernel.elf
-
+	objcopy -I elf64-x86-64 -O elf64-x86-64 -R ".comment" -R ".eh_frame" kernel ../bin/kernel/kernel.elf
+#
 
 kernel: head.o entry.o main.o printk.o trap.o mm.o slab.o irq.o pic.o process.o syscall.o multiboot2.o cpu.o acpi.o ps2_keyboard.o ps2_mouse.o ata.o pci.o ahci.o
 	ld -b elf64-x86-64 -z muldefs -o kernel head.o exception/entry.o main.o common/printk.o exception/trap.o exception/irq.o mm/mm.o mm/slab.o process/process.o syscall/syscall.o driver/multiboot2/multiboot2.o \

+ 2 - 2
run.sh

@@ -92,8 +92,8 @@ if [ $flag_can_run -eq 1 ]; then
   if [ ${IA32_USE_QEMU} == 0 ]; then
         bochs -q -f ${bochsrc} -rc ./tools/bochsinit
     else
-        qemu-system-x86_64 -cdrom ${iso} -m 512M \
-        -monitor telnet::2333,server,nowait -serial stdio -s -cpu IvyBridge --enable-kvm \
+        qemu-system-x86_64 -cdrom ${iso} -m 512M -smp 2,cores=2,threads=1,sockets=1 \
+        -monitor telnet::2333,server,nowait -serial stdio -s -S -cpu IvyBridge --enable-kvm \
         -drive id=disk,file=bin/disk.img,if=none \
         -device ahci,id=ahci \
         -device ide-hd,drive=disk,bus=ahci.0    \

+ 4 - 0
tools/.gdbinit

@@ -0,0 +1,4 @@
+target remote localhost:1234
+file bin/kernel/kernel.elf
+set follow-fork-mode child 
+b Start_Kernel