Ex3_-_Console_Debugging
In most cases, youve written C/C++ code that was definitely broken, and it led to hours of hair pulling, and mundane searching for a simple issue that could have been easily identified by larger scaled debugging tools. Well thanks to GDB, theres less monotony! This exercise will teach you the fundamental, and very powerful tools that the GNU Debugger offers. You will analyze, deconstruct, and debug given programs to help you learn the necessary skills of using a console debugger that will help you with future projects, and any code that you will write. At the end of the exercise, youll submit several annotated screenshots.
Structure
This exercise will follow this basic structure:
- Install GDB 9.1 and its utilities
- Research on how to utilize GDB and its commands, a helpful link will be provided
- Create a simple program, and play around with GDBs features
- Debug c and explain the issue encountered / what it was trying to do 5) Analyze password by digging through its code in order to obtain the key
Installation (GDB)
Within Reptilian, use the apt-get command to update the Linux package list, and install GDB
$ sudo apt update
$ sudo apt install gdb
Test GDB to make sure that its the correct version by prompting it:
$ gdb -version
Your output should look something like this
Utilizing GDB
Utilizing the debugger is actually quite simple, in order to start up the debugger on a sample program myProgram we would type:
$ gdb myProgram
From there, we can learn more about GDB and how to use it by keying:
(gdb) help
We highly suggest you reference the bottom link to the GDB manual, and the help command if you ever get stuck, or want to learn more about its features. Using the debugging tool follows a simple guideline that will be outlined below:
- Run the program and analyze what its doing
- Set up necessary breakpoints, and step through the program
- Find the issues utilizing the various tools that GDB offers
Running
To run the code, simply key in:
(gdb) run
This will run the code as your normal shell would, except it will point out several helpful debugging hints whenever you compile your program with the -g flag.
Breaking
After running the code, you may choose an address, or function name in which you want to place your breakpoint:
(gdb)break main
This will place a breakpoint inside the program at the address of main, and from there, you will be able to step through the code, or run whatever code the method contains
Stepping
The most useful command next to creating breakpoints, stepping allows the user to step through each line of code to find what the outputs are, and what possible issues the code contains:
(gdb) step
After stepping through the program, you may delete the breakpoints that are not necessary to you
(gdb)delete
Useful Commands
- run
- break
- step
- delete
- next
- up
- down
- info
- quit
Application
Now that we have learned some basic commands, its time to apply our newfound knowledge to debug some programs that you will make, and that we provide
Part 1 Simple Program
Create your own Hello World program and play around with the capabilities of GDB. When youre done, take a screenshot of your program being run in GDB with a breakpoint being set in main.
Compiling your program uses these commands:
$ gcc -o myProggy.o myProggy.c
$ gcc -g -o myProggy.o myProggy.c
Part 2 Process Table
Download the process.c code from the source folder of the exercise and compile it with the commands given at the bottom of this page. This program emulates a (very) rudimentary process table, however, theres a catch. Inside the program is a bug, and you must use the GDB to find the issue.
When youre done, youre going to take a screenshot of the issue in GDB, explain why it broke the code (in a canvas submission comment), fix the code (only one line), and submit another screenshot of the working codes output.
To compile process.c
$ gcc -w -g -o process process.c -lpthread -lrt
Part 3 Password
Download the source file password from the same folder as process.c. As you will notice, this file is an output, and it was compiled without debugging symbols. In order to complete this part, you will need to use GDB to find a password that is hidden WITHIN the program itself (you should start by decompiling that code). Look into the info of the program to see what it contains. See if you can track its motion through compilation. You will take a screenshot of where you found the password before decoding it, and the message received after typing in the correct password.
Hint: Use a HEX translator, like the one provided at the bottom of the page
Reviews
There are no reviews yet.