Download presentation
1
GDB Introduction And Lab 2
CSE 351 GDB Introduction And Lab 2
2
Lab 2: Bomb Lab Lab 2 has been assigned as of yesterday
You will be disassembling programs and trying to defuse artificial “bombs” by determining certain codes You likely haven’t covered enough in lecture to do the entire lab right now Start early! You have a week and a half to complete it Some people finish it quickly, some people take a long time
3
Lab 2 Requires you to defuse “bombs” by entering a series of passcodes
Not real bombs/viruses/etc! Each passcode is validated by some function You only have access to the assembly code It’s your job to determine what passcodes will prevent the program from ever calling the explode_bomb() function Each student has a different bomb Show them how to download the files
4
Lab 2 Files bomb bomb.c defuser.txt The executable bomb program
This is the entry point for the bomb program, and it calls functions whose source code is not available to you defuser.txt Contains passcodes, each separated by a newline Place your passcodes here once you solve each phase Can be passed as an argument to prevent you from entering the passcodes manually each time Open bomb.c: show them the phases Defuser.txt : remind them to have a line break at the end or the grading script might go wrong
5
Loading the Program to GDB
In order to load a binary into GDB, you simply pass the name of the executable to the gdb program Try this on your machine gdb bomb You should see a bunch of version and license information The last line before the (gdb) prompt is always the symbol loading status If you ever see (no debugging symbols found) you may have a problem In this case, you should see no such message
6
Exiting GDB Before we go any further, it might be helpful to understand how to exit GDB There are a few ways to exit: Ctrl-D Typing quit Typing q Many GDB commands can simply be abbreviated to their first letter, as you will see If you ever want to stop the current GDB command, just use Ctrl-C Then run gdb again
7
Running the executable
There are a couple ways you can begin execution of a program in GDB The run command will start your program and keep running until it hits a critical error or the program finishes Try entering run, or just r Run the program Input some strings when asked. Watch the world burn (exploded) Next set up the breakpoint
8
Setting breakpoints In order to step through code, we need to be able to stop our code first GDB allows you to set breakpoints, just like when you debugged Java programs in Eclipse, for example The break command will set breakpoints for you (b for short) Let’s set a breakpoint at the entry to phase_1() to prevent explosion Each breakpoint is given a number Our breakpoint is given the number 1 To disable our breakpoint temporarily, enter disable 1 To enable our breakpoint again, enter enable 1 To delete our breakpoint, enter delete 1 If you ever want to see a summary of all your breakpoints, just enter info break Set some more breakpoints, clear some breakpoints, get them comfortable with the concept
9
Disassemble your program
Dump the assembly code of the current function we are in Use disas command Can also passed in a specific function name disas function_name It will dump the assembly code of the given function name Try disas main for example
10
Stepping through code There are next and step
Stepping through one line of C code What is the difference? For this lab, you want to step through each line of assembly Use stepi or nexti Can also mention how many steps: stepi 2 If you have halted execution and wish to continue running the program, use the continue command Use that now to run the program to completion Explain difference between next and step : step get inside the function
11
Examining Register/Memory
x/[NUM][SIZE][FORMAT] [Register/Memory] NUM = number of objects to display SIZE = size of each object (b=byte, h=half-word, w=word, g=giant (quad- word)) FORMAT = how to display each object (d=decimal, x=hex, o=octal, etc.) Show an example: Try to examine the Answer string
12
Examining Register/Memory
13
Lab 2 Notes The bomb uses sscanf, which parses a string into values
Example: int a, b; sscanf(“123, 456”, “%d, %d”, &a, &b); The first argument is parsed according to the format string After this code is run, a = 123 and b = 456
14
Lab 2 Tips Print out the disassembled phases
To disassemble a program, run objdump -d bomb > bomb.s You can then print out bomb.s Mark the printouts up with notes Try to work backwards from the “success” case of each phase Remember that some addresses are pointing to strings located elsewhere in memory Print them out in GDB
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.