If you're reading this, then you're probably an 18-349 student in the midst of debugging your real time kernel. If that's the case, then you're one of these 3 people:
- You're a cracked genius and you're already done. In that case, you probably don't even need to follow the guide because you're quite literally a human debugger with wireless
JTAGbuilt into your brain, interfacing with yourSTM32Nucleo board. - This lab is giving you a hard time. We know, we're sorry kernel lab is back. It only gets worse from here (or better, you get to build a car!! woah!!).
- You want to use your
gdbdebugger, but you're tired of keeping track of your breakpoints, and having to reinsert them after building your project again. You're also tired of doingi rto examine your register contents or some weird stuff likex/3uh 0x54320.
If you're 2 and/or 3 (or 1 🤔), keep reading! This is a guide about how to set up a graphical version of your gdb debugger using VS Code and how to make your debugging journey a little bit less chaotic.
Note: If you're using vim or emacs (oh god, emacs in 2025 😭) or some cool JetBrains IDE (ur a chill guy if this u tho 😪), then I'm sorry, I've got nothing for you.
- Open VS Code and open just the directory containing your lab files/folders. You probably already have this
.vscodedirectory as shown below in there. If not, then create it. Inside it, create 3 files:
launch.json: Configuration file that defines how the debugger should behave when running and debugging your code.tasks.json: Allows you to define custom tasks and configure how they should be executed.settings.json: This contains your editor's configuration and preferences. I provided a sample file, but you can include whatever you want in here.
- Copy the
launch.jsonandtasks.jsonfile contents from the repository onto your own (optional: add any other configurations you'd deem necessary). - Download the shell (
.sh) script and add it to the.vscodedirectory as shown above. Don't worry about copying thelatest.elffile, that's a binary generated by the build when you runmake flash. Thelink_latest_elf.shscript will look for theELFfile based on the test you want to build (e.g.test_0_0ortest_8_1). - Finally, insert this snippet of code into your
MakeFileright underneath the block of code for theflash: buildcommand. This preventsgdbfrom being launched from the command line when we're trying to launch it from VS Code. I uploaded my Makefile under thebuild-updatedirectory of the repository for your reference.
flash-nogdb: build
cp util/init_template.nc /tmp/init.nc
sed -i -e 's|<template>|$(BINARY)|g' /tmp/init.nc
cp util/init_template.gdb /tmp/init.gdb
sed -i -e 's|<template>|$(BINARY)|g' /tmp/init.gdb
@printf "\n"
@printf "$y***************************************************************\n$n"
@printf "$yFlashing $(BINARY) to board...\n$n"
@printf "$y***************************************************************\n$n"
cat /tmp/init.nc | nc localhost 4444 $(NC_FLAGS)
@echo "Flashing complete (without launching GDB)."
You can watch a video of me going over the basics of the debugger located in this Google Drive link. If that wasn't too helpful, I'm sorry lol. Please reach out on Piazza though if you have any questions or issues. There's also a couple of good videos on YouTube going over clever debugging tips with GDB, so those might be worth going over. Good luck!