Lab: debugging a multi-source-file C project with VS Code
In this lab, you'll set up VS Code debugging for your queues assignment.
Building and debugging qtest
- Make a clean copy of the queues-package folder somewhere on mantis.
- Open a new VS Code window, connect to mantis, and then open the new queues-package folder as your top-level folder.
- Open qtest.c for editing.
- Click the play button (upper right) and select Debug C/C++ File (This will try to build and run qtest.c, but it will fail because qtest.c calls a bunch of functions that are defined in other files.)
- In the terminal, do
ls -a
. See how there's now a folder named.vscode
? That's new, created during the previous step. Note that you can see .vscode in the VS Explorer, too. - Inside
.vscode
, there's a file named tasks.json. Open it. See under"args"
how there's a variable called${file}
? Change that to${workspaceFolder}/*.c
. (What do you think you just did? Why does it matter?) - Try the Debug C/C++ File thing again. You should (I hope) get the usual
qtest
cmd>
prompt for the qtest program in your terminal. (Note that there are a bunch of tabs over the bottom VS Code panel, so you might need to click on Terminal to see thecmd>
.) If that worked as predicted, now do:
cmd>new <-- to create an empty queue cmd>ih "goat" <-- to insert a "goat" node at the head of the queueThat
ih command
should crash qtest. But it will show you where it crashes, which can be very valuable information.- Open queue.c and put a breakpoint somewhere in your q_insert_head function. Try debugging the program again.
Now you're all set to use breakpoints, step through your code, check the function call stack when you crash, etc.