hide random home http://www.fmi.uni-passau.de/archive/doc/unix/gdb/gdb_4.html (Einblicke ins Internet, 10/1995)

Debugging with _GDBN__ - Getting In and Out of _GDBN__

Go to the previous, next section.

Getting In and Out of _GDBN__

This chapter discusses how to start _GDBN__, and how to get out of it. (The essentials: type `_GDBP__' to start GDB, and type quit or C-d to exit.)

Starting _GDBN__

_if__(_H8__) For details on starting up _GDBP__ as a remote debugger attached to a Hitachi H8/300 board, see @xref{Hitachi H8/300 Remote,,_GDBN__ and the Hitachi H8/300}. _fi__(_H8__) Start _GDBN__ by running the program _GDBP__. Once it's running, _GDBN__ reads commands from the terminal until you tell it to exit. You can also run _GDBP__ with a variety of arguments and options, to specify more of your debugging environment at the outset. _if__(_GENERIC__) The command-line options described here are designed to cover a variety of situations; in some environments, some of these options may effectively be unavailable. _fi__(_GENERIC__) The most usual way to start _GDBN__ is with one argument, specifying an executable program:
_GDBP__ program

_if__(!_BARE__) You can also start with both an executable program and a core file specified:

_GDBP__ program core

You can, instead, specify a process ID as a second argument, if you want to debug a running process:

_GDBP__ program 1234

would attach _GDBN__ to process 1234 (unless you also have a file named `1234'; _GDBN__ does check for a core file first).

Taking advantage of the second command-line argument requires a fairly complete operating system; when you use _GDBN__ as a remote debugger attached to a bare board, there may not be any notion of "process", and there is often no way to get a core dump. _fi__(!_BARE__)

You can further control how _GDBN__ starts up by using command-line options. _GDBN__ itself can remind you of the options available.

Type

_GDBP__ -help

to display all available options and briefly describe their use (`_GDBP__ -h' is a shorter equivalent).

All options and command line arguments you give are processed in sequential order. The order makes a difference when the `-x' option is used.

_if__(!_GENERIC__) _include__(gdbinv-s.m4) _fi__(!_GENERIC__)

Choosing Files

_if__(!_BARE__) When _GDBN__ starts, it reads any arguments other than options as specifying an executable file and core file (or process ID). This is the same as if the arguments were specified by the `-se' and `-c' options respectively. (_GDBN__ reads the first argument that does not have an associated option flag as equivalent to the `-se' option followed by that argument; and the second argument that does not have an associated option flag, if any, as equivalent to the `-c' option followed by that argument.) _fi__(!_BARE__) _if__(_BARE__) When _GDBN__ starts, it reads any argument other than options as specifying an executable file. This is the same as if the argument was specified by the `-se' option. _fi__(_BARE__)

Many options have both long and short forms; both are shown in the following list. _GDBN__ also recognizes the long forms if you truncate them, so long as enough of the option is present to be unambiguous. (If you prefer, you can flag option arguments with `--' rather than `-', though we illustrate the more usual convention.)

-symbols=file
-s file
Read symbol table from file file.

-exec=file
-e file
Use file file as the executable file to execute when appropriate, and for examining pure data in conjunction with a core dump.

-se=file
Read symbol table from file file and use it as the executable file.

_if__(!_BARE__)

-core=file
-c file
Use file file as a core dump to examine. _fi__(!_BARE__)

-command=file
-x file
Execute _GDBN__ commands from file file. See section Command Files.

-directory=directory
-d directory
Add directory to the path to search for source files.

_if__(!_BARE__)

-m
-mapped
Warning: this option depends on operating system facilities that are not supported on all systems. If memory-mapped files are available on your system through the mmap system call, you can use this option to have _GDBN__ write the symbols from your program into a reusable file in the current directory. If the program you are debugging is called `/tmp/fred', the mapped symbol file will be `./fred.syms'. Future _GDBN__ debugging sessions will notice the presence of this file, and will quickly map in symbol information from it, rather than reading the symbol table from the executable program.

The `.syms' file is specific to the host machine on which _GDBN__ is run. It holds an exact image of _GDBN__'s internal symbol table. It cannot be shared across multiple host platforms. _fi__(!_BARE__)

-r
-readnow
Read each symbol file's entire symbol table immediately, rather than the default, which is to read it incrementally as it is needed. This makes startup slower, but makes future operations faster.

_if__(!_BARE__) The -mapped and -readnow options are typically combined in order to build a `.syms' file that contains complete symbol information. A simple GDB invocation to do nothing but build a `.syms' file for future use is:

	gdb -batch -nx -mapped -readnow programname
_fi__(!_BARE__)

Choosing Modes

You can run _GDBN__ in various alternative modes--for example, in batch mode or quiet mode.

-nx
-n
Do not execute commands from any `_GDBINIT__' initialization files. Normally, the commands in these files are executed after all the command options and arguments have been processed. See section Command Files.

-quiet
-q
"Quiet". Do not print the introductory and copyright messages. These messages are also suppressed in batch mode.

-batch
Run in batch mode. Exit with status 0 after processing all the command files specified with `-x' (and `_GDBINIT__', if not inhibited). Exit with nonzero status if an error occurs in executing the _GDBN__ commands in the command files.

Batch mode may be useful for running _GDBN__ as a filter, for example to download and run a program on another computer; in order to make this more useful, the message

Program exited normally.

(which is ordinarily issued whenever a program running under _GDBN__ control terminates) is not issued when running in batch mode.

-cd=directory
Run _GDBN__ using directory as its working directory, instead of the current directory.

_if__(_LUCID__)

-context authentication
When the Energize programming system starts up _GDBN__, it uses this option to trigger an alternate mode of interaction. authentication is a pair of numeric codes that identify _GDBN__ as a client in the Energize environment. Avoid this option when you run _GDBN__ directly from the command line. See section Using _GDBN__ with Energize for more discussion of using _GDBN__ with Energize. _fi__(_LUCID__)

-fullname
-f
Emacs sets this option when it runs _GDBN__ as a subprocess. It tells _GDBN__ to output the full file name and line number in a standard, recognizable fashion each time a stack frame is displayed (which includes each time your program stops). This recognizable format looks like two `\032' characters, followed by the file name, line number and character position separated by colons, and a newline. The Emacs-to-_GDBN__ interface program uses the two `\032' characters as a signal to display the source code for the frame.

_if__(_GENERIC__ || !_H8__)

-b bps
Set the line speed (baud rate or bits per second) of any serial interface used by _GDBN__ for remote debugging.

-tty=device
Run using device for your program's standard input and output. _fi__(_GENERIC__ || !_H8__)

Leaving _GDBN__

quit
To exit _GDBN__, use the quit command (abbreviated q), or type an end-of-file character (usually C-d).

An interrupt (often C-c) will not exit from _GDBN__, but rather will terminate the action of any _GDBN__ command that is in progress and return to _GDBN__ command level. It is safe to type the interrupt character at any time because _GDBN__ does not allow it to take effect until a time when it is safe.

_if__(!_BARE__) If you have been using _GDBN__ to control an attached process or device, you can release it with the detach command; see section Debugging an Already-Running Process.. _fi__(!_BARE__)

_if__(!_BARE__)

Shell Commands

If you need to execute occasional shell commands during your debugging session, there is no need to leave or suspend _GDBN__; you can just use the shell command.

shell command string
Directs _GDBN__ to invoke an inferior shell to execute command string. If it exists, the environment variable SHELL is used for the name of the shell to run. Otherwise _GDBN__ uses /bin/sh.

The utility make is often needed in development environments. You do not have to use the shell command for this purpose in _GDBN__:

make make-args
Causes _GDBN__ to execute an inferior make program with the specified arguments. This is equivalent to `shell make make-args'.
_fi__(!_BARE__)

Go to the previous, next section.