Part 1: SSH Keys to ieng6
Note: if you have a personal laptop you can set up ssh keys on it to be able to ssh to ieng6. If you're on windows, you’ll need a linux-like terminal, so use the terminal in VSCode, a program like git bash, or WSL for this.
If you don’t have a laptop or it isn’t set up with a linux terminal, work from your lab computer for today. You can set up ssh keys on your laptop at home on your own time.
- Generate a new pair of ssh keys (on your laptop, or on your lab computer)
cd
to your.ssh
directory, (if it doesn’t exist, first create it withmkdir ~/.ssh
)- IF YOU ALREADY HAVE AN 'id_rsa', SKIP THIS STEP (otherwise you'll overwrite your github keys)
- If you don't have an id_rsa, run:
ssh-keygen -t rsa -b 4096 -C YOUR_EMAIL_ADDRESS
- You'll be using the default filename and no password, so just press enter twice
- Copy the contents of your new public key (you can print out the contents with
cat
)
- Copy your public key onto ieng6, into the file
~/.ssh/authorized_keys
- On
ieng6
, in your.ssh
directory, create a file calledauthorized_keys
(or open it if it exists already) - Use
vim
to paste in the contents of the new public key into theauthorized_keys
file- (if your
authorized_keys
already existed, paste the new key on a new line at the end)
- (if your
- Log out from
ieng6
(useexit
), and make sure you can ssh into it without typing your password
Part 2: Debugging with -Wall
Clone the repository we’ll be using for this lab (you’ll need to get the ssh URL). You’ll be working with one of the three programs, depending on your group: https://classroom.github.com/a/X-DdsPq-
Many common errors can be caught by the compiler, but a lot of these checks aren't enabled by default. We can ask the compiler to warn us by adding the -Wall
flag ("- W(arn) all") when you compile:
$ gcc -Wall YOUR_CODE.c -o YOUR_CODE
Part 3: Debugging with gdb
Intro to gdb commands:
- To use gdb, make sure you’ve compiled your program with “debug symbols”
$ gcc -g YOUR_CODE.c
- Run your compiled code in gdb
$ gdb YOUR_BINARY
- This puts you into a gdb prompt: normal terminal commands don’t work here, and you can instead run gdb-specific commands
(gdb) run # starts running your program
- If your program stops running or segfaults in gdb, print out the backtrace (also called a “stack trace”)
(gdb) backtrace
or
(gdb) bt
Use the following commands to print out values at the point the program stopped:
(gdb) info locals
(gdb) info args
(gdb) print VALUE (or p VALUE)
- You can print any variable or expression, e.g.
print x
,p arr[5]
,p ((x & 0b1111) << 3)
- You can also specify a format to print in
print/t
(binary),print/x
(hex),print/d
(decimal)
- You can print any variable or expression, e.g.
(gdb) x ADDRESS
- This prints out memory at an address, e.g. strings / arrays / pointers
(gdb) x/16cb str1
- This prints the first 16 bytes of
str1
as characters
- This prints the first 16 bytes of
(gdb) x/20xb str2
- This prints 20 bytes of
str2
in hex
- This prints 20 bytes of
(gdb) x/4dw arr
- This prints 4 “words” (i.e. int32s) of
arr
, as decimal numbers
- This prints 4 “words” (i.e. int32s) of
- You can use the following reference card for reference on gdb commands, and format commands for x and print.
If you’re done early, use the reference card to try exploring other gdb commands!
Lab 3 Work Check-Off (due Monday, Oct 20):
In your copy of the lab3-buggy repo: fix the bugs in your assigned program, then commit and push your changes so they show up on GitHub.