1.5.3 Running/Debugging

Once you have the executable file, you can run the executable using the following command:

./test.out

The dot-slash (./) is needed because in Cygwin, the current directory is not one of the paths in which the operating system searches for executable files. Dot (.) is the current directory, and slash (/) is a separator for directories.

Of course, since this program doesn't do anything, running the program this way isn't very satisfying.

You can also execute a program using the debugger gdb. To start the debugger with our freshly linked executable, use the following command:

gdb test.out

Note that dot-slash is no longer needed here, because we are not executing the file directly.

Once you are in gdb, the prompt changes to (gdb) (including the parantheses). Now, you can use gdb commands. As usual, the first command you need to learn how to find more help. In gdb, help is the command to find more help.

To read the source code of the program, use the list command. You should see the source code of the program with line numbers next to each line.

Next, we are ready to execute the program. You can run the entire program at once using the run command. But that wouldn't be very exciting. Let us run the program instruction by instruction.

In order to do this, we need to set up a break point. When the program is executed to a break point, the debugger stops and waits for further instructions. For our simple program, let's put a break point on the first line of instruction. You can specify where to put a break point by line number. Here, we should put a break point on line 5, using the following command:

break 5

Now, we can use run to execute the program. The program stops before the line containing the break point executes. At this point, we can examine all sorts of data. At this point, let us simply look at the values of registers. This is done by the following command:

info registers

The leftmost column lists the registers, the middle column lists the value of each register in hexadecimal notation, whereas the right column lists the value of each register in decimal representation.

We can use the continue command to continue execution at full speed. However, we can also ask the debugger execute one line at a time. This is accomplished by the command step or next command. The difference between these two commands is not clear from our current example.

When you are ready to exit the debugging, use the command quit.

Copyright © 2009-04-16 by Tak Auyeung