**Debugging (C and Assembly) Exercise** CS 105 You will complete this exercise in class, and you will not need to submit anything to gradescope. You will work in groups of two or three with only one student coding at a time. We might not all complete the exercise during class, but I am glad to help out during office hours if you want to continue working after class. You all will work fairly independently in your groups, but I will occasionally demonstrate each exercise on the projector. # Logging into the server If you are **not** on Pomona's WiFi or Ethernet, you will first need to connect to the Pomona VPN. If you do not already have the Pomona VPN set up on your machine, there are [instructions for how to set-up the VPN here](https://servicedesk.pomona.edu/support/solutions/articles/18000021757). Once you are on Pomona's network, you should `ssh` into the course VM using the following command and your Pomona CAS username and password ~~~bash ssh USERNAME@itbdcv-lnx04p.campus.pomona.edu ~~~ Here is [a nice reference for command line commands](https://cs.pomona.edu/classes/cs105/assignments/commandline.pdf). # Debugging with VSCode Steps in the video below: 1. Create a file called `~/.ssh/config` 2. Add a configuration for the course server: ~~~text Host NICKNAME HostName itbdcv-lnx04p.campus.pomona.edu User USERNAME ~~~ 3. Use "`ssh-keygen -t ed25519 -C "EMAIL"`" to create ssh keys (this is omitted in the video) 4. Use "`ssh-copy-id NICKNAME`" to copy your ssh key to the server Here is a quick video showing these steps, and a bit about how to start and use the debugger.
# Viewing Disassembly It is often useful to view the assembly code associated with some C. You can ask VSCode to show the disassembly by running the "Open Disassembly View" command while debugging your C file. To run the command, you will need to first open the "Command Palette" (View->Command Palette), and then search and run for the "Open Disassembly View" command. For this exercise, I want you to pick any **two** of your functions from assignment 2, and then trace through each assembly instruction and draw/write down the result and purpose of each instruction. You will need to understand a bit about the registers, operators/instructions, and operands. # Debugging `float2int` The `float2int` puzzle is typically the most challenging. Here, you'll learn a bit about how the debugger can help you solve the puzzle. Try the following: 1. Put a breakpoint at the top of the function. 2. Step through your code and print values using the "Debug Console" with the following formats (`sign` is used as an example, you should also print your other variables): Format | Specifier -----------------|---------- default | `p sign` hexadecimal | `p/x sign` signed decimal | `p/d sign` unsigned decimal | `p/u sign` binary | `p/t sign` address | `p/a sign` character | `p/c sign` floating point | `p/f sign` Make a prediction, what is printed when you type `-exec p/f f`? Some other features to try: - Use the "Watch" list to view a variable as it changes over time. - Jump up and down the call stack and few the address of different variables. Should a variable in `main` have a higher or lower memory address when compared with a variable in `float2int`? - View the registers and see how they change each time you step through an instruction or line of code. Which registers change after each instruction? How is each register typically used? Here is [a nice cheat-sheet for debugging functionality](../assignments/A03-Debugging/gdb-refcard.pdf). # After Once you complete the two tasks above, please start working on the assignment with your partner. If you and your partner have completed the assignment, then let me know and I can help you get checked off.