Improve release doc slightly.
[deliverable/binutils-gdb.git] / gdb / doc / gdb.run-m4
CommitLineData
9bcc06ef
RP
1_dnl__ -*- Texinfo -*-
2_dnl__ Copyright (c) 1988 1989 1990 1991 Free Software Foundation, Inc.
3_dnl__ This file is part of the source for the GDB manual.
27189593 4@c M4 FRAGMENT: $Id$
9bcc06ef
RP
5@node Running, Stopping, Commands, Top
6@chapter Running Programs Under _GDBN__
7
8@menu
9* Compilation:: Compiling for Debugging
10* Starting:: Starting your Program
11* Arguments:: Your Program's Arguments
12* Environment:: Your Program's Environment
13* Working Directory:: Your Program's Working Directory
14* Input/Output:: Your Program's Input and Output
15* Attach:: Debugging an Already-Running Process
16* Kill Process:: Killing the Child Process
17@end menu
18
19@node Compilation, Starting, Running, Running
20@section Compiling for Debugging
21
22In order to debug a program effectively, you need to generate
23debugging information when you compile it. This debugging information
24is stored in the object file; it describes the data type of each
25variable or function and the correspondence between source line numbers
26and addresses in the executable code.
27
28To request debugging information, specify the @samp{-g} option when you run
29the compiler.
30
31Many C compilers are unable to handle the @samp{-g} and @samp{-O}
32options together. Using those compilers, you cannot generate optimized
33executables containing debugging information.
34
35The GNU C compiler supports @samp{-g} with or without @samp{-O}, making it
36possible to debug optimized code. We recommend that you @emph{always} use
37@samp{-g} whenever you compile a program. You may think the program is
38correct, but there's no sense in pushing your luck.
39
40Some things do not work as well with @samp{-g -O} as with just
41@samp{-g}, particularly on machines with instruction scheduling. If in
42doubt, recompile with @samp{-g} alone, and if this fixes the problem,
43please report it as a bug (including a test case!).
44
45Older versions of the GNU C compiler permitted a variant option
46@samp{-gg} for debugging information. _GDBN__ no longer supports this
47format; if your GNU C compiler has this option, do not use it.
48
49@ignore
50@comment As far as I know, there are no cases in which _GDBN__ will
51@comment produce strange output in this case. (but no promises).
52If your program includes archives made with the @code{ar} program, and
53if the object files used as input to @code{ar} were compiled without the
54@samp{-g} option and have names longer than 15 characters, _GDBN__ will get
55confused reading the program's symbol table. No error message will be
56given, but _GDBN__ may behave strangely. The reason for this problem is a
57deficiency in the Unix archive file format, which cannot represent file
58names longer than 15 characters.
59
60To avoid this problem, compile the archive members with the @samp{-g}
61option or use shorter file names. Alternatively, use a version of GNU
62@code{ar} dated more recently than August 1989.
63@end ignore
64
65
66@node Starting, Arguments, Compilation, Running
67@section Starting your Program
68@cindex starting
69@cindex running
70@table @code
71@item run
72@itemx r
73@kindex run
74Use the @code{run} command to start your program under _GDBN__.
75_if__(_VXWORKS__)
76Except on VxWorks, you
77_fi__(_VXWORKS__)
78_if__(!_VXWORKS__)
79You
80_fi__(!_VXWORKS__)
81must first specify the program name with an argument to _GDBN__
82(@pxref{Invocation}), or using the @code{file} or @code{exec-file}
83command (@pxref{Files}).@refill
84@end table
85
86On targets that support processes, @code{run} creates an inferior
87process and makes that process run your program. On other targets,
88@code{run} jumps to the start of the program.
89
90The execution of a program is affected by certain information it
91receives from its superior. _GDBN__ provides ways to specify this
92information, which you must do @i{before} starting the program. (You
93can change it after starting the program, but such changes will only affect
94the program the next time you start it.) This information may be
95divided into four categories:
96
97@table @asis
98@item The @i{arguments.}
99You specify the arguments to give your program as the arguments of the
100@code{run} command. If a shell is available on your target, the shell
101is used to pass the arguments, so that you may use normal conventions
102(such as wildcard expansion or variable substitution) in
103describing the arguments. In Unix systems, you can control which shell
104is used with the @code{SHELL} environment variable. @xref{Arguments}.@refill
105
106@item The @i{environment.}
107Your program normally inherits its environment from _GDBN__, but you can
108use the _GDBN__ commands @code{set environment} and @code{unset
109environment} to change parts of the environment that will be given to
110the program. @xref{Environment}.@refill
111
112@item The @i{working directory.}
113Your program inherits its working directory from _GDBN__. You can set
114_GDBN__'s working directory with the @code{cd} command in _GDBN__.
115@xref{Working Directory}.
116
117@item The @i{standard input and output.}
118Your program normally uses the same device for standard input and
119standard output as _GDBN__ is using. You can redirect input and output
120in the @code{run} command line, or you can use the @code{tty} command to
121set a different device for your program.
122@xref{Input/Output}.
123@end table
124
125When you issue the @code{run} command, your program begins to execute
126immediately. @xref{Stopping}, for discussion of how to arrange for your
127program to stop. Once your program has been started by the @code{run}
128command (and then stopped), you may evaluate expressions that involve
129calls to functions in the inferior, using the @code{print} or
130@code{call} commands. @xref{Data}.
131
132If the modification time of your symbol file has changed since the last
133time _GDBN__ read its symbols, _GDBN__ will discard its symbol table and re-read
134it. In this process, it tries to retain your current breakpoints.
135
136@node Arguments, Environment, Starting, Running
137@section Your Program's Arguments
138
139@cindex arguments (to your program)
140The arguments to your program can be specified by the arguments of the
141@code{run} command. They are passed to a shell, which expands wildcard
142characters and performs redirection of I/O, and thence to the program.
143_GDBN__ uses the shell indicated by your environment variable
144@code{SHELL} if it exists; otherwise, _GDBN__ uses @code{/bin/sh}.
145
146@code{run} with no arguments uses the same arguments used by the previous
147@code{run}, or those set by the @code{set args} command.
148
149@kindex set args
150@table @code
151@item set args
152Specify the arguments to be used the next time your program is run. If
153@code{set args} has no arguments, @code{run} will execute your program
154with no arguments. Once you have run your program with arguments, this
155is the only way to run it again without arguments.
156
157@item show args
158@kindex show args
159Show the arguments to give your program when it is started.
160@end table
161
162@node Environment, Working Directory, Arguments, Running
163@section Your Program's Environment
164
165@cindex environment (of your program)
166The @dfn{environment} consists of a set of environment variables and
167their values. Environment variables conventionally record such things as
168your user name, your home directory, your terminal type, and your search
169path for programs to run. Usually you set up environment variables with
170the shell and they are inherited by all the other programs you run. When
171debugging, it can be useful to try running the program with a modified
172environment without having to start _GDBN__ over again.
173
174@table @code
175@item path @var{directory}
176@kindex path
177Add @var{directory} to the front of the @code{PATH} environment variable
178(the search path for executables), for both _GDBN__ and your program.
179You may specify several directory names, separated by @samp{:} or
180whitespace. If @var{directory} is already in the path, it is moved to
181the front, so it will be searched sooner. You can use the string
182@samp{$cwd} to refer to whatever is the current working directory at the
183time _GDBN__ searches the path. @footnote{If you use @samp{.} instead,
184it refers to the directory where you executed the @code{path} command.
185_GDBN__ fills in the current path where needed in the @var{directory}
186argument, before adding it to the search path.}
187@c 'path' is explicitly nonrepeatable, but RMS points out it's silly to
188@c document that, since repeating it would be a no-op.
189
190@item show paths
191@kindex show paths
192Display the list of search paths for executables (the @code{PATH}
193environment variable).
194
195@item show environment @var{varname}
196@kindex show environment
197Print the value of environment variable @var{varname} to be given to
198your program when it starts.
199
200@item show environment
201Print the names and values of all environment variables to be given to
202your program.
203
204@item set environment @var{varname} @var{value}
205@itemx set environment @var{varname} = @var{value}
206@kindex set environment
207Sets environment variable @var{varname} to @var{value}. The value
208changes for your program only, not for _GDBN__ itself. @var{value} may
209be any string; the values of environment variables are just strings, and
210any interpretation is supplied by your program itself. The @var{value}
211parameter is optional; if it is eliminated, the variable is set to a
212null value.
213@c "any string" here doesn't include leading, trailing
214@c blanks. Gnu asks: does anyone care?
215
216For example, this command:
217
218@example
219set env USER = foo
220@end example
221
222@noindent
223tells a Unix program, when subsequently run, that its user is named
224@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
225are not actually required.)
226
227@item unset environment @var{varname}
228@kindex unset environment
229Remove variable @var{varname} from the environment to be passed to your
230program. This is different from @samp{set env @var{varname} =};
231@code{unset environment} removes the variable from the environment,
232rather than assigning it an empty value.
233@end table
234
235@node Working Directory, Input/Output, Environment, Running
236@section Your Program's Working Directory
237
238@cindex working directory (of your program)
239Each time you start your program with @code{run}, it inherits its
240working directory from the current working directory of _GDBN__. _GDBN__'s
241working directory is initially whatever it inherited from its parent
242process (typically the shell), but you can specify a new working
243directory in _GDBN__ with the @code{cd} command.
244
245The _GDBN__ working directory also serves as a default for the commands
246that specify files for _GDBN__ to operate on. @xref{Files}.
247
248@table @code
249@item cd @var{directory}
250@kindex cd
251Set _GDBN__'s working directory to @var{directory}.
252
253@item pwd
254@kindex pwd
255Print _GDBN__'s working directory.
256@end table
257
258@node Input/Output, Attach, Working Directory, Running
259@section Your Program's Input and Output
260
261@cindex redirection
262@cindex i/o
263@cindex terminal
264@cindex controlling terminal
265By default, the program you run under _GDBN__ does input and output to
266the same terminal that _GDBN__ uses. _GDBN__ switches the terminal to
267its own terminal modes to interact with you, but it records the terminal
268modes your program was using and switches back to them when you continue
269running your program.
270
271@table @code
272@item info terminal
273@kindex info terminal
274Displays _GDBN__'s recorded information about the terminal modes your
275program is using.
276@end table
277
278You can redirect the program's input and/or output using shell
279redirection with the @code{run} command. For example,
280
281_0__@example
282run > outfile
283_1__@end example
284
285@noindent
286starts the program, diverting its output to the file @file{outfile}.
287
288@kindex tty
289Another way to specify where the program should do input and output is
290with the @code{tty} command. This command accepts a file name as
291argument, and causes this file to be the default for future @code{run}
292commands. It also resets the controlling terminal for the child
293process, for future @code{run} commands. For example,
294
295@example
296tty /dev/ttyb
297@end example
298
299@noindent
300directs that processes started with subsequent @code{run} commands
301default to do input and output on the terminal @file{/dev/ttyb} and have
302that as their controlling terminal.
303
304An explicit redirection in @code{run} overrides the @code{tty} command's
305effect on the input/output device, but not its effect on the controlling
306terminal.
307
308When you use the @code{tty} command or redirect input in the @code{run}
309command, only the input @emph{for your program} is affected. The input
310for _GDBN__ still comes from your terminal.
311
312@node Attach, Kill Process, Input/Output, Running
313@section Debugging an Already-Running Process
314@kindex attach
315@cindex attach
316
317@table @code
318@item attach @var{process-id}
319This command
320attaches to a running process---one that was started outside _GDBN__.
321(@code{info files} will show your active targets.) The command takes as
322argument a process ID. The usual way to find out the process-id of
323a Unix process is with the @code{ps} utility, or with the @samp{jobs -l}
324shell command.
325
326@code{attach} will not repeat if you press @key{RET} a second time after
327executing the command.
328@end table
329
330To use @code{attach}, you must be debugging in an environment which
331supports processes. You must also have permission to send the process a
332signal, and it must have the same effective user ID as the _GDBN__
333process.
334
335When using @code{attach}, you should first use the @code{file} command
336to specify the program running in the process and load its symbol table.
337@xref{Files}.
338
339The first thing _GDBN__ does after arranging to debug the specified
340process is to stop it. You can examine and modify an attached process
341with all the _GDBN__ commands that ordinarily available when you start
342processes with @code{run}. You can insert breakpoints; you can step and
343continue; you can modify storage. If you would rather the process
344continue running, you may use the @code{continue} command after
345attaching _GDBN__ to the process.
346
347@table @code
348@item detach
349@kindex detach
350When you have finished debugging the attached process, you can use the
351@code{detach} command to release it from _GDBN__'s control. Detaching
352the process continues its execution. After the @code{detach} command,
353that process and _GDBN__ become completely independent once more, and you
354are ready to @code{attach} another process or start one with @code{run}.
355@code{detach} will not repeat if you press @key{RET} again after
356executing the command.
357@end table
358
359If you exit _GDBN__ or use the @code{run} command while you have an attached
360process, you kill that process. By default, you will be asked for
361confirmation if you try to do either of these things; you can control
362whether or not you need to confirm by using the @code{set confirm} command
363(@pxref{Messages/Warnings}).
364
9bcc06ef 365@node Kill Process, , Attach, Running
27189593 366@c @group
9bcc06ef
RP
367@section Killing the Child Process
368
369@table @code
370@item kill
371@kindex kill
372Kill the child process in which your program is running under _GDBN__.
373@end table
374
375This command is useful if you wish to debug a core dump instead of a
376running process. _GDBN__ ignores any core dump file while your program
377is running.
27189593 378@c @end group
9bcc06ef
RP
379
380On some operating systems, you can't execute your program in another
381process while breakpoints are active inside _GDBN__. You can use the
382@code{kill} command in this situation to permit running the program
383outside the debugger.
384
385The @code{kill} command is also useful if you wish to recompile and
386relink the program, since on many systems it is impossible to modify an
387executable file which is running in a process. In this case, when you
388next type @code{run}, _GDBN__ will notice that the file has changed, and
389will re-read the symbol table (while trying to preserve your current
390breakpoint settings).
This page took 0.073193 seconds and 4 git commands to generate.