Lab 2 Extension: Debugging A Multi-Source C Project With VS Code

In this lab, you’ll set up VS Code debugging for the 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 the file qtest.c for editing.

  • Click the play button (in the upper right) and select Debug C/C++ File. (This will try to build and run qtest.c, but it should fail because qtest.c calls a bunch of functions that are defined in other files.)

  • Open a new terminal and type the command ls -a. This will display hidden files/folders as well as the rest, and you should now see a folder named .vscode. This was created in the previous step. You can see this folder in VS Code as well.

  • In VS Code, open the file tasks.json in the folder .vscode. Look at "args" – you’ll see a variable named ${file}. Change it instead to be ${workspaceFolder}/*.c. (What do you think this change does? Why does it matter?)

  • Try to debug qtest.c again. You should (hopefully) get the usual qtest cmd> prompt for the qtest program in your terminal. (Make sure that you are in the Terminal tab on the bottom.)

  • If that worked as predicted, try this:

    cmd>new
    cmd>ih cat
    

That ih command should crash the qtest program. However, you will now see where it crashes, which can be very valuable information.

  • Now, open the queue.c file in VS Code and put a breakpoint somewhere in the q_insert_head function. Try debugging the program again. You should hit your breakpoint.

Now you’re all set to use breakpoints, step through your code, check the function call stack when you crash. etc.

Disabling timeouts

Note that the coding harness has a time limit for your code, and will stop a process if it’s taking too long. You can change the timeout by modifying line 53 of harness.c, for example as follows:

static int time_limit = 1000; // was previously 1

Note: Your submission will not include harness.c; your code will be tested against an original version of harness.c, so make sure that you change it back to 1 to test your performance for the last few traces!