beautypg.com

1 a sample gdb session, 1 loading the executable – HP gnu source-level debugger 5992-4701 User Manual

Page 19

background image

1 A Sample GDB Session

This chapter describes the most common GDB commands with the help of an example.

The following topics are discussed:

Loading the Executable

Setting the Display Width

Setting Breakpoints

Running the Executable under GDB

Stepping to the next line

Stepping into a Subroutine

Examining the Stack

Printing Variable Values

Listing the Source Code

Setting Variable Values During a Debug Session

In this sample session, we emphasize user input like this: input, to make it easier to
pick out from the surrounding output.

One of the preliminary versions of GNU m4 (a generic macro processor) exhibits the
following bug: sometimes, when we change its quote strings from the default, the
commands used to capture one macro definition within another stop working. In the
following short m4 session, we define a macro foo which expands to 0000; we then
use the m4 built-in defn to define bar as the same thing. However, when we
change the open quote string to and the close quote string to ,
the same procedure fails to define a new synonym baz:

$ cd gnu/m4 //change your current directory to the location where the m4 executable is stored.
$ ./m4 //run the m4 application
define(foo,0000)

foo
0000
define (bar,defn('foo'))

bar
0000
changequote(,)

define(baz,defn(foo))
baz
C-d

m4: End of input: 0: fatal error: EOF in string

1.1 Loading the Executable

Let us use GDB to try to see what is going on.

1.1 Loading the Executable

19