I am currently working on modifying an operating system kernel codebase and using Visual Studio Code as my primary IDE. I have successfully configured my environment to compile the kernel code and load it into a virtual machine using QEMU for debugging. However, I'm struggling to set breakpoints effectively in Visual Studio Code. Specifically, I want to know how to set breakpoints directly within the kernel code and debug it seamlessly within the Visual Studio Code environment. I have tried configuring launch configurations and attaching debuggers, but I haven't been successful so far. Any guidance on how to efficiently set breakpoints and debug modified kernel code in Visual Studio Code would be greatly appreciated.
I attempted to configure launch configurations in Visual Studio Code to connect to the QEMU debugger listening on port 1234, as specified in the provided makefile. I expected Visual Studio Code to seamlessly connect to the debugger and allow me to set breakpoints within the kernel code. However, upon launching the debugger, I encountered connection errors or breakpoints were not hit as expected. Despite adjusting various settings and configurations, I couldn't achieve the desired debugging experience. Instead, I had to resort to manually entering GDB commands within the integrated terminal.
Additionally, I tried modifying the launch.json file in Visual Studio Code to include configurations for connecting to the QEMU debugger, but I may not have configured it correctly. I expected Visual Studio Code to automatically detect the breakpoints I set in the kernel code and pause execution at those points when debugging. However, despite following online tutorials and documentation, I couldn't get this setup to work as expected.
Ideally, I was hoping to leverage the built-in debugging features of Visual Studio Code to streamline the debugging process and avoid the manual input of GDB commands. This would greatly improve my productivity and efficiency when working with the modified operating system kernel code.
If anyone has successfully configured Visual Studio Code for debugging modified kernel code, I would greatly appreciate any insights or guidance on how to achieve this setup effectively.
epos - Makefile
include Makefile.inc
.PHONY: all
all: hd.img
MODE = run
SUBDIRS = kernel userapp
.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@ $(MODE)
hd.img: subdirs
ifeq ($(OS),Windows_NT)
if [ ! -s $@ ]; then base64 -d [email protected] | bunzip2 >$@ ; fi
imgcpy kernel/eposkrnl.bin $@=C:\eposkrnl.bin
imgcpy userapp/a.out $@=C:\a.out
else
ifeq ($(shell uname -s),Linux)
if [ ! -s $@ ]; then base64 -d [email protected] | bunzip2 >$@ ; fi
sudo mount -o loop,offset=32256 -t vfat $@ /mnt
sudo cp kernel/eposkrnl.bin userapp/a.out /mnt
sudo umount /mnt
endif
ifeq ($(shell uname -s),Darwin)
if [ ! -s $@ ]; then base64 -D [email protected] | bunzip2 >$@ ; fi
hdiutil attach -imagekey diskimage-class=CRawDiskImage $@
cp kernel/eposkrnl.bin userapp/a.out /Volumes/EPOSDISK
hdiutil detach /Volumes/EPOSDISK
endif
endif
.PHONY: qemu
qemu: hd.img
ifeq ($(OS),Windows_NT)
-qemu-system-i386w -m 32 -boot order=c -vga std -hda $^ -L $(QEMUHOME)/Bios
else
-qemu-system-i386 -m 32 -boot order=c -vga std -hda $^
endif
.PHONY: qemudbg
qemudbg: MODE=debug
qemudbg: hd.img
ifeq ($(OS),Windows_NT)
-start $(GDB)
-qemu-system-i386w -S -gdb tcp::1234,nowait,nodelay,server,ipv4 -m 32 -boot order=c -vga std -hda $^ -L $(QEMUHOME)/Bios
else
ifeq ($(shell uname -s),Linux)
-/usr/bin/x-terminal-emulator -e $(GDB)
endif
ifeq ($(shell uname -s),Darwin)
-osascript -e 'on run argv' \
-e ' tell application "Terminal" to do script "cd $(shell pwd); $(GDB)"' \
-e 'end run'
endif
-qemu-system-i386 -S -gdb tcp::1234,nowait,nodelay,server,ipv4 -m 32 -boot order=c -vga std -hda $^
endif
.PHONY: bochs
bochs: hd.img
ifeq ($(OS),Windows_NT)
-bochs -q -f bochsrc-win.txt
else
-bochs -q -f bochsrc-unix.txt
endif
.PHONY: bochsdbg
bochsdbg: MODE=debug
bochsdbg: hd.img
ifeq ($(OS),Windows_NT)
-bochsdbg -q -f bochsrc-win.txt
else
-bochsdbg -q -f bochsrc-unix.txt
endif
.PHONY: vbox
vbox: hd.vmdk
@if ! VBoxManage -q list vms | grep epos >/dev/null; then \
VBoxManage -q createvm --name epos --ostype Other --register; \
else \
VBoxManage -q controlvm epos poweroff; \
sleep 1; \
VBoxManage -q storagectl epos --name IDE --remove; \
VBoxManage -q closemedium disk $^; \
fi
@VBoxManage -q modifyvm epos --cpus 1 --memory 32 --boot1 disk --nic1 bridged --nictype1 82540EM --bridgeadapter1 en0 --macaddress1 auto
@VBoxManage -q storagectl epos --add ide --name IDE
@VBoxManage -q storageattach epos --storagectl IDE --port 0 --device 0 --type hdd --medium $^
@VBoxManage startvm epos
.PHONY: tags
tags:
ctags -R *
hd.vmdk: hd.img
qemu-img convert -O vmdk $^ $@
.PHONY: run
run: qemu
.PHONY: debug
debug: qemudbg
.PHONY: clean
clean:
@for subdir in $(SUBDIRS); do $(MAKE) -C $${subdir} $@; done
$(RM) hd.img hd.vmdk tags
.PHONY: submit
submit: clean
@all=`svn status | grep '^[M?]' | cut -c9- | tr '\\\\' '/' | tr '\n' ' '`; \
if [ -z "$${all}" ]; then echo ">>> No files changed."; exit; fi; \
echo ">>> Files to be submitted: $${all}"; \
size=`tar -cjO $${all} | wc -c | tr -d '[:space:]'`; \
echo -n ">>> Total size of bytes $${size}"; \
if [ $${size} -gt $$((64*1024)) ]; then echo " exceeds the limit of 64KiB."; exit; else echo ""; fi; \
echo -n ">>> Enter student ID: "; \
read sid; \
if ! echo "$${sid}" | grep -qE '^[0-9]{8}$$'; then echo ">>> Student ID must be 8 digits."; exit; fi;\
tar -cjf $${sid}.tbz $${all}; \
trap "rm $${sid}.tbz; exit" 1 2 3 15; \
curl -isS -X POST -H "Content-Type: multipart/form-data" -F "myFile=@$${sid}.tbz" \
http://xgate.dhis.org/osexp/submit.php | sed -n 's@<div .*>\(.*\)<\/div>@>>> \1\'$$'\n@p'; \
$(RM) $${sid}.tbz