1. Goals for this week:
-
Reminder of tools for examining binary files (gdb and ddd in particular)
-
Learn about man pages, and using man and apropos
2. Handy References
-
GDB Help
-
gdb for IA32 assembly debugging IA32 gdb debugging guide
-
GDB for Assembly (from the gdb Guide).
-
Sections 3.2 and 3.5 of textbook (assembly debugging, print, display, info and x commands)
-
Other useful pages
At the end of the lab today, please use the last 10 minutes to fill out the midterm evaluation survey
3. Starting Point Code
There is no starting point code this week. Instead, let’s revisit
the week 6 in-lab and review some IA32 debugging resources
using the mystery
program.
Start by cd’ing into your week06 subdirectory:
cd ~/cs31/labs/Lab5-user1-user2/warmup-code/
ls
Makefile README mystery* simplefuncs.c
4. Review of gdb and ddd for IA32 binaries
Let’s try out the mystery
program from last week and in ddd
again:
-
let’s run it and see what it does
-
next, lets run it in ddd and examine its code:
ddd ./mystery (gdb) break main (gdb) run (gdb) disass main
-
what does main control flow look like?
-
let’s add some break points around function calls and in functions
-
let’s examine some state around functions
-
we can print out values on the stack using x and a stack memory address
(gdb) x/a address # /a: "examine memory contents as an adress" (gdb) x/s address # /s: "examine memory contents as a string" (gdb) x/wd address # /wd: "examine memory contents as a 4byte decimal"
5. man and manpages
First, we are going to learn how to use man to read manual pages, and how to use apropos to find commands: man and apropos
Next, let’s look at the man page for strcmp and for scanf to see what they are telling us about these functions.
man scanf
man 3 scanf # or explictly specify the manual section:
# (C library function scanf is in section 3 of the manual)
man strcmp
apropos
is a command for finding the names of other commands or library
functions. It is useful if you cannot remember the name of a library
function or command but you know what it does. Suppose that we cannot
remember strcmp
, we could try to find it using apropos:
apropos compare