🆕 gdb源代码级别调试

This commit is contained in:
fslongjin 2022-04-04 17:46:57 +08:00
parent e5274ce8e4
commit e667fff256
5 changed files with 14 additions and 6 deletions

1
.gitignore vendored
View File

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

View File

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

View File

@ -7,7 +7,7 @@ DIR_LIB=lib
lib_patterns := *.a lib_patterns := *.a
LIB_FILES := $(foreach DIR,$(DIR_LIB),$(addprefix $(DIR)/,$(lib_patterns))) 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_ # 控制操作系统使用的中断控制器 _INTR_8259A_ _INTR_APIC_
PIC := _INTR_APIC_ PIC := _INTR_APIC_
@ -16,8 +16,8 @@ CFLAGS += -D $(PIC)
ASFLAGS := --64 ASFLAGS := --64
all: kernel 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 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 \ 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 \

4
run.sh
View File

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

4
tools/.gdbinit Normal file
View File

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