To edit the lines in a source file, use the
The editing program of your choice
is invoked with the current line set to
the active line in the program.
Alternatively, there are several ways to specify what part of the file you
want to print if you want to see other parts of the program:
Edit the source file of the code location that results from resolving
locspec. Editing starts at the source file and source line
locspec resolves to.
See Location Specifications, for all the possible forms of the
locspec resolves to more than one source line in your
program, then the command prints the list of resolved source lines and
does not proceed with the editing.
Here are the forms of the
edit command most commonly used:
Edit the current source file with number as the active line number.
Edit the file containing function at the beginning of its definition.
You can customize GDB to use any editor you want
By default, it is /bin/ex, but you can change this
by setting the environment variable
EDITOR before using
GDB. For example, to configure GDB to use the
vi editor, you could use these commands with the
EDITOR=/usr/bin/vi export EDITOR gdb …
or in the
setenv EDITOR /usr/bin/vi gdb …
The only restriction is that your editor (say
ex), recognizes the
following command-line syntax:
ex +number file
The optional numeric value +number specifies the number of the line in the file where to start editing.