This is an archived copy of a previous semester's site.
Please see the current semester's site.
This is not a full MP; it is primarily testing your setup and ensuring you are ready for subsequent MPs. It is dramatically easier than other MPs. Don’t plan your time on other MPs based on this one.
Follow the MP page directions to set up VSCode and class-specific github.
We have some initial code for your mp0
for you to get started. Use the following command in your cs340/netid
directory to merge
our initial mp0
directory into your local repository:
git fetch release
git merge release/mp0 --allow-unrelated-histories -m "Merging release repository"
A goal of this MP is to help you feel comfortable with using Visual Studio Code. You should try out the following:
Opening a Project Folder: Most of Visual Studio Code’s project-related features are based on the root of the current folder you have open within Visual Studio Code. Make sure to open the mp0
folder in Visual Studio Code. (You cannot open your cs340
directory, or your netid
directory, it must be your mp0
directory.)
From a terminal, you can run code .
to open up VS Code from that folder.
Inside of VS Code, you can use File -> Open Folder to open a new folder.
Opening the Integrated Terminal: The keyboard shortcut Ctrl
+ ~
will open/close the integrated terminal inside of Visual Studio Code. Using the integrated terminal, let’s verify you are all set up for running C programs by doing the following:
make
to compile the provided code.Running a Visual Debugger: As part of the provided code, we have provided .vscode/launch.json
. This configuration file is used by Visual Studio Code to understand the steps needed to run
your project. It will compile your code using make
and then run ./main
inside of a debugger connected to VS Code. Use Visual Studio Code to run
your project:
Run and DebugInterface (#1).
Run and Debuginterface, find the green
Debugarrow to start your program with a visual debugger (#2).
<Enter>
to accept tay.gif
as the input file. You’ll use your own gif later.Some users of M1 and M2 Macs report that they are unable to run the visual debugger with the provided launch.json
.
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
ERROR: Unable to start debugging. Unexpected LLDB output from command "-exec-run". Command 'exec-run'. Invalid process during debug session
The program ‘/path/to/file/mp0/main' has exited with code 42 (0x0000002a).
To fix this
CodeLLDB
extension on VSCodetypefield in your
launch.json
to reflect this: "type": "lldb"
You may need to make similar changes to the launch.json
of subsequent MPs as well.
The purpose of this MP is to get comfortable with Visual Studio Code and viewing C code. The gif.c
file provided is based off of Marcel Rodrigues’ ultra-small GIF encoding and decoding library, but then modified to allow us to Illinify
any GIF animation.
Unfortunately, there are several bugs in the code that prevent it from running. You will need to use the Visual Studio Code debugger to help find the bugs.
gif.c
to resolve the bug.Fixing the bug is a tool to help you learn to use the debugger. To optimize your learning, use the follow common debugging patterns:
When you run the provided code, you will immediately have a segmentation fault. When using an interactive debugger, you will see the exact position in code when the segmentation fault occurs.
A segmentation fault is an access to a memory address that is not allocated to your process. Often, the line of code where the segmentation fault occurs is valid code. You may need to inspect the code executed in the lines prior to the segmentation fault.
Other errors in the code, like infinite recursion, can cause a segmentation fault when the process runs out of available memory allocated to the process to add a new stack frame.
You will fix several segmentation faults throughout mp0
.
A segmentation fault is only one type of exception that can occur in your code. Other exceptions will provide additional information in stdout
or stderr
reported on your integrated VS Code terminal.
In this bug you will find that the debugger reports *** stack smashing detected ***
:
Stack smashing occurs when you write onto stack frame of a function, which is the memory immediately following the local variables to the function. Check the code to find out where we might have written a few too many bytes. (This is the one and only place in mp0
where you don’t comment a line to fix a bug, but modify it.)
You will find additional output in the terminal when finding other bugs throughout mp0
.
lldb
, was not able to give a useable stack trace on this stack smashing bug. To fix this bug, figure out the error on Line 61 – where read
is called inside of the read_num
function.
When your program is paused (due to an exception, you pressing pause, a breakpoint you set, or any other reason), the Run and Debug
window shows a wealth of useful debugging information.
One panel is labeled Call Stack
. It will list the function calls that were called leading to where your program is currently paused. You can click on them to jump to their location in code.
In a call stack, the top is the most recent function called. Specifically, the above call stack shows the read_image
function located in gif.c
was called and the current line being executed is Line 449
. This function was invoked by the function below (gd_get_frame
), which itself was invoked by the function below that (main
), which is the starting point of this execution.
The call stack is very useful for finding infinite recursion if you see the same function name again and again and again. You will want to reference the call stack for several bugs in mp0
.
A common programming error is in accidental infinite loop, where no exception occurs but your program is stuck. A common debugging pattern is to pause the execution and examine the code where your program is stuck.
When Visual Studio Code is running your code, you will see the control window:
Pressing the left-most Pause
button will pause the execution of the program and provide you information about the current point of execution. When the program is paused:
Instead of pausing the program manually, programmers will set a breakpoint to have the program automatically pause immediately before running the line of code where the breakpoint is set.
To set a breakpoint, click on the space immediately to the left of the line number. A bright red dot will appear to indicate that an active breakpoint is set:
In the example above, execution will pause after running Line 834 but before running Line 835. Since it’s paused, you can inspect all of the variables at the exact moment before running Line 835. If you resume the program and the breakpoint is encountered again, it will pause again.
The primary CS 340 virtual space is the CS 340 Discord server. I want to see your favorite GIF, and make sure you’re all set up with Discord so you can be part of the CS 340 community.
luthertychonievich
to privately share your username/identity association so we can give you points.safe for work: nothing offensive, abusive, hate-based, or lewd.
#mp0-gifs
Discord channel.When you are finished working on the MP, you can run a local copy of the same test suite that you will use for grading. To run the test suite:
make test
../test
and everything should pass!Once you have locally passed all the tests, you will need to submit and grade your code. First commit using the standard git commands:
git add -A
git commit -m "MP submission"
git push
The initial grading is done via a manual GitHub Action. You MUST complete this step before the deadline to earn any points for the MP:
ActionTab
mp0 autograding
Run Workflowbutton (located on the blue bar)
Run Workflow
The test suit is given 75% weight in this MP
Posting an Illinified gif to Discord is given 25% weight for this MP
re-authorize the OAuth Application?GitHub CLI
gh auth login
.