OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [gdb/] [doc/] [gdb.info-2] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1181 sfurman
This is gdb.info, produced by makeinfo version 4.1 from ./gdb.texinfo.
2
 
3
INFO-DIR-SECTION Programming & development tools.
4
START-INFO-DIR-ENTRY
5
* Gdb: (gdb).                     The GNU debugger.
6
END-INFO-DIR-ENTRY
7
 
8
   This file documents the GNU debugger GDB.
9
 
10
   This is the Ninth Edition, December 2001, of `Debugging with GDB:
11
the GNU Source-Level Debugger' for GDB Version 5.3.
12
 
13
   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
14
1998,
15
1999, 2000, 2001, 2002 Free Software Foundation, Inc.
16
 
17
   Permission is granted to copy, distribute and/or modify this document
18
under the terms of the GNU Free Documentation License, Version 1.1 or
19
any later version published by the Free Software Foundation; with the
20
Invariant Sections being "Free Software" and "Free Software Needs Free
21
Documentation", with the Front-Cover Texts being "A GNU Manual," and
22
with the Back-Cover Texts as in (a) below.
23
 
24
   (a) The Free Software Foundation's Back-Cover Text is: "You have
25
freedom to copy and modify this GNU Manual, like GNU software.  Copies
26
published by the Free Software Foundation raise funds for GNU
27
development."
28
 
29

30
File: gdb.info,  Node: Compilation,  Next: Starting,  Up: Running
31
 
32
Compiling for debugging
33
=======================
34
 
35
   In order to debug a program effectively, you need to generate
36
debugging information when you compile it.  This debugging information
37
is stored in the object file; it describes the data type of each
38
variable or function and the correspondence between source line numbers
39
and addresses in the executable code.
40
 
41
   To request debugging information, specify the `-g' option when you
42
run the compiler.
43
 
44
   Most compilers do not include information about preprocessor macros
45
in the debugging information if you specify the `-g' flag alone,
46
because this information is rather large.  Version 3.1 of GCC, the GNU
47
C compiler, provides macro information if you specify the options
48
`-gdwarf-2' and `-g3'; the former option requests debugging information
49
in the Dwarf 2 format, and the latter requests "extra information".  In
50
the future, we hope to find more compact ways to represent macro
51
information, so that it can be included with `-g' alone.
52
 
53
   Many C compilers are unable to handle the `-g' and `-O' options
54
together.  Using those compilers, you cannot generate optimized
55
executables containing debugging information.
56
 
57
   GCC, the GNU C compiler, supports `-g' with or without `-O', making
58
it possible to debug optimized code.  We recommend that you _always_
59
use `-g' whenever you compile a program.  You may think your program is
60
correct, but there is no sense in pushing your luck.
61
 
62
   When you debug a program compiled with `-g -O', remember that the
63
optimizer is rearranging your code; the debugger shows you what is
64
really there.  Do not be too surprised when the execution path does not
65
exactly match your source file!  An extreme example: if you define a
66
variable, but never use it, GDB never sees that variable--because the
67
compiler optimizes it out of existence.
68
 
69
   Some things do not work as well with `-g -O' as with just `-g',
70
particularly on machines with instruction scheduling.  If in doubt,
71
recompile with `-g' alone, and if this fixes the problem, please report
72
it to us as a bug (including a test case!).
73
 
74
   Older versions of the GNU C compiler permitted a variant option
75
`-gg' for debugging information.  GDB no longer supports this format;
76
if your GNU C compiler has this option, do not use it.
77
 
78

79
File: gdb.info,  Node: Starting,  Next: Arguments,  Prev: Compilation,  Up: Running
80
 
81
Starting your program
82
=====================
83
 
84
`run'
85
`r'
86
     Use the `run' command to start your program under GDB.  You must
87
     first specify the program name (except on VxWorks) with an
88
     argument to GDB (*note Getting In and Out of GDB: Invocation.), or
89
     by using the `file' or `exec-file' command (*note Commands to
90
     specify files: Files.).
91
 
92
   If you are running your program in an execution environment that
93
supports processes, `run' creates an inferior process and makes that
94
process run your program.  (In environments without processes, `run'
95
jumps to the start of your program.)
96
 
97
   The execution of a program is affected by certain information it
98
receives from its superior.  GDB provides ways to specify this
99
information, which you must do _before_ starting your program.  (You
100
can change it after starting your program, but such changes only affect
101
your program the next time you start it.)  This information may be
102
divided into four categories:
103
 
104
The _arguments._
105
     Specify the arguments to give your program as the arguments of the
106
     `run' command.  If a shell is available on your target, the shell
107
     is used to pass the arguments, so that you may use normal
108
     conventions (such as wildcard expansion or variable substitution)
109
     in describing the arguments.  In Unix systems, you can control
110
     which shell is used with the `SHELL' environment variable.  *Note
111
     Your program's arguments: Arguments.
112
 
113
The _environment._
114
     Your program normally inherits its environment from GDB, but you
115
     can use the GDB commands `set environment' and `unset environment'
116
     to change parts of the environment that affect your program.
117
     *Note Your program's environment: Environment.
118
 
119
The _working directory._
120
     Your program inherits its working directory from GDB.  You can set
121
     the GDB working directory with the `cd' command in GDB.  *Note
122
     Your program's working directory: Working Directory.
123
 
124
The _standard input and output._
125
     Your program normally uses the same device for standard input and
126
     standard output as GDB is using.  You can redirect input and output
127
     in the `run' command line, or you can use the `tty' command to set
128
     a different device for your program.  *Note Your program's input
129
     and output: Input/Output.
130
 
131
     _Warning:_ While input and output redirection work, you cannot use
132
     pipes to pass the output of the program you are debugging to
133
     another program; if you attempt this, GDB is likely to wind up
134
     debugging the wrong program.
135
 
136
   When you issue the `run' command, your program begins to execute
137
immediately.  *Note Stopping and continuing: Stopping, for discussion
138
of how to arrange for your program to stop.  Once your program has
139
stopped, you may call functions in your program, using the `print' or
140
`call' commands.  *Note Examining Data: Data.
141
 
142
   If the modification time of your symbol file has changed since the
143
last time GDB read its symbols, GDB discards its symbol table, and
144
reads it again.  When it does this, GDB tries to retain your current
145
breakpoints.
146
 
147

148
File: gdb.info,  Node: Arguments,  Next: Environment,  Prev: Starting,  Up: Running
149
 
150
Your program's arguments
151
========================
152
 
153
   The arguments to your program can be specified by the arguments of
154
the `run' command.  They are passed to a shell, which expands wildcard
155
characters and performs redirection of I/O, and thence to your program.
156
Your `SHELL' environment variable (if it exists) specifies what shell
157
GDB uses.  If you do not define `SHELL', GDB uses the default shell
158
(`/bin/sh' on Unix).
159
 
160
   On non-Unix systems, the program is usually invoked directly by GDB,
161
which emulates I/O redirection via the appropriate system calls, and
162
the wildcard characters are expanded by the startup code of the
163
program, not by the shell.
164
 
165
   `run' with no arguments uses the same arguments used by the previous
166
`run', or those set by the `set args' command.
167
 
168
`set args'
169
     Specify the arguments to be used the next time your program is
170
     run.  If `set args' has no arguments, `run' executes your program
171
     with no arguments.  Once you have run your program with arguments,
172
     using `set args' before the next `run' is the only way to run it
173
     again without arguments.
174
 
175
`show args'
176
     Show the arguments to give your program when it is started.
177
 
178

179
File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
180
 
181
Your program's environment
182
==========================
183
 
184
   The "environment" consists of a set of environment variables and
185
their values.  Environment variables conventionally record such things
186
as your user name, your home directory, your terminal type, and your
187
search path for programs to run.  Usually you set up environment
188
variables with the shell and they are inherited by all the other
189
programs you run.  When debugging, it can be useful to try running your
190
program with a modified environment without having to start GDB over
191
again.
192
 
193
`path DIRECTORY'
194
     Add DIRECTORY to the front of the `PATH' environment variable (the
195
     search path for executables) that will be passed to your program.
196
     The value of `PATH' used by GDB does not change.  You may specify
197
     several directory names, separated by whitespace or by a
198
     system-dependent separator character (`:' on Unix, `;' on MS-DOS
199
     and MS-Windows).  If DIRECTORY is already in the path, it is moved
200
     to the front, so it is searched sooner.
201
 
202
     You can use the string `$cwd' to refer to whatever is the current
203
     working directory at the time GDB searches the path.  If you use
204
     `.' instead, it refers to the directory where you executed the
205
     `path' command.  GDB replaces `.' in the DIRECTORY argument (with
206
     the current path) before adding DIRECTORY to the search path.
207
 
208
`show paths'
209
     Display the list of search paths for executables (the `PATH'
210
     environment variable).
211
 
212
`show environment [VARNAME]'
213
     Print the value of environment variable VARNAME to be given to
214
     your program when it starts.  If you do not supply VARNAME, print
215
     the names and values of all environment variables to be given to
216
     your program.  You can abbreviate `environment' as `env'.
217
 
218
`set environment VARNAME [=VALUE]'
219
     Set environment variable VARNAME to VALUE.  The value changes for
220
     your program only, not for GDB itself.  VALUE may be any string;
221
     the values of environment variables are just strings, and any
222
     interpretation is supplied by your program itself.  The VALUE
223
     parameter is optional; if it is eliminated, the variable is set to
224
     a null value.
225
 
226
     For example, this command:
227
 
228
          set env USER = foo
229
 
230
     tells the debugged program, when subsequently run, that its user
231
     is named `foo'.  (The spaces around `=' are used for clarity here;
232
     they are not actually required.)
233
 
234
`unset environment VARNAME'
235
     Remove variable VARNAME from the environment to be passed to your
236
     program.  This is different from `set env VARNAME ='; `unset
237
     environment' removes the variable from the environment, rather
238
     than assigning it an empty value.
239
 
240
   _Warning:_ On Unix systems, GDB runs your program using the shell
241
indicated by your `SHELL' environment variable if it exists (or
242
`/bin/sh' if not).  If your `SHELL' variable names a shell that runs an
243
initialization file--such as `.cshrc' for C-shell, or `.bashrc' for
244
BASH--any variables you set in that file affect your program.  You may
245
wish to move setting of environment variables to files that are only
246
run when you sign on, such as `.login' or `.profile'.
247
 
248

249
File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
250
 
251
Your program's working directory
252
================================
253
 
254
   Each time you start your program with `run', it inherits its working
255
directory from the current working directory of GDB.  The GDB working
256
directory is initially whatever it inherited from its parent process
257
(typically the shell), but you can specify a new working directory in
258
GDB with the `cd' command.
259
 
260
   The GDB working directory also serves as a default for the commands
261
that specify files for GDB to operate on.  *Note Commands to specify
262
files: Files.
263
 
264
`cd DIRECTORY'
265
     Set the GDB working directory to DIRECTORY.
266
 
267
`pwd'
268
     Print the GDB working directory.
269
 
270

271
File: gdb.info,  Node: Input/Output,  Next: Attach,  Prev: Working Directory,  Up: Running
272
 
273
Your program's input and output
274
===============================
275
 
276
   By default, the program you run under GDB does input and output to
277
the same terminal that GDB uses.  GDB switches the terminal to its own
278
terminal modes to interact with you, but it records the terminal modes
279
your program was using and switches back to them when you continue
280
running your program.
281
 
282
`info terminal'
283
     Displays information recorded by GDB about the terminal modes your
284
     program is using.
285
 
286
   You can redirect your program's input and/or output using shell
287
redirection with the `run' command.  For example,
288
 
289
     run > outfile
290
 
291
starts your program, diverting its output to the file `outfile'.
292
 
293
   Another way to specify where your program should do input and output
294
is with the `tty' command.  This command accepts a file name as
295
argument, and causes this file to be the default for future `run'
296
commands.  It also resets the controlling terminal for the child
297
process, for future `run' commands.  For example,
298
 
299
     tty /dev/ttyb
300
 
301
directs that processes started with subsequent `run' commands default
302
to do input and output on the terminal `/dev/ttyb' and have that as
303
their controlling terminal.
304
 
305
   An explicit redirection in `run' overrides the `tty' command's
306
effect on the input/output device, but not its effect on the controlling
307
terminal.
308
 
309
   When you use the `tty' command or redirect input in the `run'
310
command, only the input _for your program_ is affected.  The input for
311
GDB still comes from your terminal.
312
 
313

314
File: gdb.info,  Node: Attach,  Next: Kill Process,  Prev: Input/Output,  Up: Running
315
 
316
Debugging an already-running process
317
====================================
318
 
319
`attach PROCESS-ID'
320
     This command attaches to a running process--one that was started
321
     outside GDB.  (`info files' shows your active targets.)  The
322
     command takes as argument a process ID.  The usual way to find out
323
     the process-id of a Unix process is with the `ps' utility, or with
324
     the `jobs -l' shell command.
325
 
326
     `attach' does not repeat if you press  a second time after
327
     executing the command.
328
 
329
   To use `attach', your program must be running in an environment
330
which supports processes; for example, `attach' does not work for
331
programs on bare-board targets that lack an operating system.  You must
332
also have permission to send the process a signal.
333
 
334
   When you use `attach', the debugger finds the program running in the
335
process first by looking in the current working directory, then (if the
336
program is not found) by using the source file search path (*note
337
Specifying source directories: Source Path.).  You can also use the
338
`file' command to load the program.  *Note Commands to Specify Files:
339
Files.
340
 
341
   The first thing GDB does after arranging to debug the specified
342
process is to stop it.  You can examine and modify an attached process
343
with all the GDB commands that are ordinarily available when you start
344
processes with `run'.  You can insert breakpoints; you can step and
345
continue; you can modify storage.  If you would rather the process
346
continue running, you may use the `continue' command after attaching
347
GDB to the process.
348
 
349
`detach'
350
     When you have finished debugging the attached process, you can use
351
     the `detach' command to release it from GDB control.  Detaching
352
     the process continues its execution.  After the `detach' command,
353
     that process and GDB become completely independent once more, and
354
     you are ready to `attach' another process or start one with `run'.
355
     `detach' does not repeat if you press  again after executing
356
     the command.
357
 
358
   If you exit GDB or use the `run' command while you have an attached
359
process, you kill that process.  By default, GDB asks for confirmation
360
if you try to do either of these things; you can control whether or not
361
you need to confirm by using the `set confirm' command (*note Optional
362
warnings and messages: Messages/Warnings.).
363
 
364

365
File: gdb.info,  Node: Kill Process,  Next: Threads,  Prev: Attach,  Up: Running
366
 
367
Killing the child process
368
=========================
369
 
370
`kill'
371
     Kill the child process in which your program is running under GDB.
372
 
373
   This command is useful if you wish to debug a core dump instead of a
374
running process.  GDB ignores any core dump file while your program is
375
running.
376
 
377
   On some operating systems, a program cannot be executed outside GDB
378
while you have breakpoints set on it inside GDB.  You can use the
379
`kill' command in this situation to permit running your program outside
380
the debugger.
381
 
382
   The `kill' command is also useful if you wish to recompile and
383
relink your program, since on many systems it is impossible to modify an
384
executable file while it is running in a process.  In this case, when
385
you next type `run', GDB notices that the file has changed, and reads
386
the symbol table again (while trying to preserve your current
387
breakpoint settings).
388
 
389

390
File: gdb.info,  Node: Threads,  Next: Processes,  Prev: Kill Process,  Up: Running
391
 
392
Debugging programs with multiple threads
393
========================================
394
 
395
   In some operating systems, such as HP-UX and Solaris, a single
396
program may have more than one "thread" of execution.  The precise
397
semantics of threads differ from one operating system to another, but
398
in general the threads of a single program are akin to multiple
399
processes--except that they share one address space (that is, they can
400
all examine and modify the same variables).  On the other hand, each
401
thread has its own registers and execution stack, and perhaps private
402
memory.
403
 
404
   GDB provides these facilities for debugging multi-thread programs:
405
 
406
   * automatic notification of new threads
407
 
408
   * `thread THREADNO', a command to switch among threads
409
 
410
   * `info threads', a command to inquire about existing threads
411
 
412
   * `thread apply [THREADNO] [ALL] ARGS', a command to apply a command
413
     to a list of threads
414
 
415
   * thread-specific breakpoints
416
 
417
     _Warning:_ These facilities are not yet available on every GDB
418
     configuration where the operating system supports threads.  If
419
     your GDB does not support threads, these commands have no effect.
420
     For example, a system without thread support shows no output from
421
     `info threads', and always rejects the `thread' command, like this:
422
 
423
          (gdb) info threads
424
          (gdb) thread 1
425
          Thread ID 1 not known.  Use the "info threads" command to
426
          see the IDs of currently known threads.
427
 
428
   The GDB thread debugging facility allows you to observe all threads
429
while your program runs--but whenever GDB takes control, one thread in
430
particular is always the focus of debugging.  This thread is called the
431
"current thread".  Debugging commands show program information from the
432
perspective of the current thread.
433
 
434
   Whenever GDB detects a new thread in your program, it displays the
435
target system's identification for the thread with a message in the
436
form `[New SYSTAG]'.  SYSTAG is a thread identifier whose form varies
437
depending on the particular system.  For example, on LynxOS, you might
438
see
439
 
440
     [New process 35 thread 27]
441
 
442
when GDB notices a new thread.  In contrast, on an SGI system, the
443
SYSTAG is simply something like `process 368', with no further
444
qualifier.
445
 
446
   For debugging purposes, GDB associates its own thread number--always
447
a single integer--with each thread in your program.
448
 
449
`info threads'
450
     Display a summary of all threads currently in your program.  GDB
451
     displays for each thread (in this order):
452
 
453
       1. the thread number assigned by GDB
454
 
455
       2. the target system's thread identifier (SYSTAG)
456
 
457
       3. the current stack frame summary for that thread
458
 
459
     An asterisk `*' to the left of the GDB thread number indicates the
460
     current thread.
461
 
462
     For example,
463
 
464
     (gdb) info threads
465
       3 process 35 thread 27  0x34e5 in sigpause ()
466
       2 process 35 thread 23  0x34e5 in sigpause ()
467
     * 1 process 35 thread 13  main (argc=1, argv=0x7ffffff8)
468
         at threadtest.c:68
469
 
470
   On HP-UX systems:
471
 
472
   For debugging purposes, GDB associates its own thread number--a
473
small integer assigned in thread-creation order--with each thread in
474
your program.
475
 
476
   Whenever GDB detects a new thread in your program, it displays both
477
GDB's thread number and the target system's identification for the
478
thread with a message in the form `[New SYSTAG]'.  SYSTAG is a thread
479
identifier whose form varies depending on the particular system.  For
480
example, on HP-UX, you see
481
 
482
     [New thread 2 (system thread 26594)]
483
 
484
when GDB notices a new thread.
485
 
486
`info threads'
487
     Display a summary of all threads currently in your program.  GDB
488
     displays for each thread (in this order):
489
 
490
       1. the thread number assigned by GDB
491
 
492
       2. the target system's thread identifier (SYSTAG)
493
 
494
       3. the current stack frame summary for that thread
495
 
496
     An asterisk `*' to the left of the GDB thread number indicates the
497
     current thread.
498
 
499
     For example,
500
 
501
     (gdb) info threads
502
         * 3 system thread 26607  worker (wptr=0x7b09c318 "@") \
503
 
504
     at quicksort.c:137
505
           2 system thread 26606  0x7b0030d8 in __ksleep () \
506
 
507
     from /usr/lib/libc.2
508
           1 system thread 27905  0x7b003498 in _brk () \
509
 
510
     from /usr/lib/libc.2
511
 
512
`thread THREADNO'
513
     Make thread number THREADNO the current thread.  The command
514
     argument THREADNO is the internal GDB thread number, as shown in
515
     the first field of the `info threads' display.  GDB responds by
516
     displaying the system identifier of the thread you selected, and
517
     its current stack frame summary:
518
 
519
          (gdb) thread 2
520
          [Switching to process 35 thread 23]
521
          0x34e5 in sigpause ()
522
 
523
     As with the `[New ...]' message, the form of the text after
524
     `Switching to' depends on your system's conventions for identifying
525
     threads.
526
 
527
`thread apply [THREADNO] [ALL]  ARGS'
528
     The `thread apply' command allows you to apply a command to one or
529
     more threads.  Specify the numbers of the threads that you want
530
     affected with the command argument THREADNO.  THREADNO is the
531
     internal GDB thread number, as shown in the first field of the
532
     `info threads' display.  To apply a command to all threads, use
533
     `thread apply all' ARGS.
534
 
535
   Whenever GDB stops your program, due to a breakpoint or a signal, it
536
automatically selects the thread where that breakpoint or signal
537
happened.  GDB alerts you to the context switch with a message of the
538
form `[Switching to SYSTAG]' to identify the thread.
539
 
540
   *Note Stopping and starting multi-thread programs: Thread Stops, for
541
more information about how GDB behaves when you stop and start programs
542
with multiple threads.
543
 
544
   *Note Setting watchpoints: Set Watchpoints, for information about
545
watchpoints in programs with multiple threads.
546
 
547

548
File: gdb.info,  Node: Processes,  Prev: Threads,  Up: Running
549
 
550
Debugging programs with multiple processes
551
==========================================
552
 
553
   On most systems, GDB has no special support for debugging programs
554
which create additional processes using the `fork' function.  When a
555
program forks, GDB will continue to debug the parent process and the
556
child process will run unimpeded.  If you have set a breakpoint in any
557
code which the child then executes, the child will get a `SIGTRAP'
558
signal which (unless it catches the signal) will cause it to terminate.
559
 
560
   However, if you want to debug the child process there is a workaround
561
which isn't too painful.  Put a call to `sleep' in the code which the
562
child process executes after the fork.  It may be useful to sleep only
563
if a certain environment variable is set, or a certain file exists, so
564
that the delay need not occur when you don't want to run GDB on the
565
child.  While the child is sleeping, use the `ps' program to get its
566
process ID.  Then tell GDB (a new invocation of GDB if you are also
567
debugging the parent process) to attach to the child process (*note
568
Attach::).  From that point on you can debug the child process just
569
like any other process which you attached to.
570
 
571
   On HP-UX (11.x and later only?), GDB provides support for debugging
572
programs that create additional processes using the `fork' or `vfork'
573
function.
574
 
575
   By default, when a program forks, GDB will continue to debug the
576
parent process and the child process will run unimpeded.
577
 
578
   If you want to follow the child process instead of the parent
579
process, use the command `set follow-fork-mode'.
580
 
581
`set follow-fork-mode MODE'
582
     Set the debugger response to a program call of `fork' or `vfork'.
583
     A call to `fork' or `vfork' creates a new process.  The MODE can
584
     be:
585
 
586
    `parent'
587
          The original process is debugged after a fork.  The child
588
          process runs unimpeded.  This is the default.
589
 
590
    `child'
591
          The new process is debugged after a fork.  The parent process
592
          runs unimpeded.
593
 
594
    `ask'
595
          The debugger will ask for one of the above choices.
596
 
597
`show follow-fork-mode'
598
     Display the current debugger response to a `fork' or `vfork' call.
599
 
600
   If you ask to debug a child process and a `vfork' is followed by an
601
`exec', GDB executes the new target up to the first breakpoint in the
602
new target.  If you have a breakpoint set on `main' in your original
603
program, the breakpoint will also be set on the child process's `main'.
604
 
605
   When a child process is spawned by `vfork', you cannot debug the
606
child or parent until an `exec' call completes.
607
 
608
   If you issue a `run' command to GDB after an `exec' call executes,
609
the new target restarts.  To restart the parent process, use the `file'
610
command with the parent executable name as its argument.
611
 
612
   You can use the `catch' command to make GDB stop whenever a `fork',
613
`vfork', or `exec' call is made.  *Note Setting catchpoints: Set
614
Catchpoints.
615
 
616

617
File: gdb.info,  Node: Stopping,  Next: Stack,  Prev: Running,  Up: Top
618
 
619
Stopping and Continuing
620
***********************
621
 
622
   The principal purposes of using a debugger are so that you can stop
623
your program before it terminates; or so that, if your program runs into
624
trouble, you can investigate and find out why.
625
 
626
   Inside GDB, your program may stop for any of several reasons, such
627
as a signal, a breakpoint, or reaching a new line after a GDB command
628
such as `step'.  You may then examine and change variables, set new
629
breakpoints or remove old ones, and then continue execution.  Usually,
630
the messages shown by GDB provide ample explanation of the status of
631
your program--but you can also explicitly request this information at
632
any time.
633
 
634
`info program'
635
     Display information about the status of your program: whether it is
636
     running or not, what process it is, and why it stopped.
637
 
638
* Menu:
639
 
640
* Breakpoints::                 Breakpoints, watchpoints, and catchpoints
641
* Continuing and Stepping::     Resuming execution
642
* Signals::                     Signals
643
* Thread Stops::                Stopping and starting multi-thread programs
644
 
645

646
File: gdb.info,  Node: Breakpoints,  Next: Continuing and Stepping,  Up: Stopping
647
 
648
Breakpoints, watchpoints, and catchpoints
649
=========================================
650
 
651
   A "breakpoint" makes your program stop whenever a certain point in
652
the program is reached.  For each breakpoint, you can add conditions to
653
control in finer detail whether your program stops.  You can set
654
breakpoints with the `break' command and its variants (*note Setting
655
breakpoints: Set Breaks.), to specify the place where your program
656
should stop by line number, function name or exact address in the
657
program.
658
 
659
   In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can
660
set breakpoints in shared libraries before the executable is run.
661
There is a minor limitation on HP-UX systems: you must wait until the
662
executable is run in order to set breakpoints in shared library
663
routines that are not called directly by the program (for example,
664
routines that are arguments in a `pthread_create' call).
665
 
666
   A "watchpoint" is a special breakpoint that stops your program when
667
the value of an expression changes.  You must use a different command
668
to set watchpoints (*note Setting watchpoints: Set Watchpoints.), but
669
aside from that, you can manage a watchpoint like any other breakpoint:
670
you enable, disable, and delete both breakpoints and watchpoints using
671
the same commands.
672
 
673
   You can arrange to have values from your program displayed
674
automatically whenever GDB stops at a breakpoint.  *Note Automatic
675
display: Auto Display.
676
 
677
   A "catchpoint" is another special breakpoint that stops your program
678
when a certain kind of event occurs, such as the throwing of a C++
679
exception or the loading of a library.  As with watchpoints, you use a
680
different command to set a catchpoint (*note Setting catchpoints: Set
681
Catchpoints.), but aside from that, you can manage a catchpoint like any
682
other breakpoint.  (To stop when your program receives a signal, use the
683
`handle' command; see *Note Signals: Signals.)
684
 
685
   GDB assigns a number to each breakpoint, watchpoint, or catchpoint
686
when you create it; these numbers are successive integers starting with
687
one.  In many of the commands for controlling various features of
688
breakpoints you use the breakpoint number to say which breakpoint you
689
want to change.  Each breakpoint may be "enabled" or "disabled"; if
690
disabled, it has no effect on your program until you enable it again.
691
 
692
   Some GDB commands accept a range of breakpoints on which to operate.
693
A breakpoint range is either a single breakpoint number, like `5', or
694
two such numbers, in increasing order, separated by a hyphen, like
695
`5-7'.  When a breakpoint range is given to a command, all breakpoint
696
in that range are operated on.
697
 
698
* Menu:
699
 
700
* Set Breaks::                  Setting breakpoints
701
* Set Watchpoints::             Setting watchpoints
702
* Set Catchpoints::             Setting catchpoints
703
* Delete Breaks::               Deleting breakpoints
704
* Disabling::                   Disabling breakpoints
705
* Conditions::                  Break conditions
706
* Break Commands::              Breakpoint command lists
707
* Breakpoint Menus::            Breakpoint menus
708
* Error in Breakpoints::        ``Cannot insert breakpoints''
709
 
710

711
File: gdb.info,  Node: Set Breaks,  Next: Set Watchpoints,  Up: Breakpoints
712
 
713
Setting breakpoints
714
-------------------
715
 
716
   Breakpoints are set with the `break' command (abbreviated `b').  The
717
debugger convenience variable `$bpnum' records the number of the
718
breakpoint you've set most recently; see *Note Convenience variables:
719
Convenience Vars, for a discussion of what you can do with convenience
720
variables.
721
 
722
   You have several ways to say where the breakpoint should go.
723
 
724
`break FUNCTION'
725
     Set a breakpoint at entry to function FUNCTION.  When using source
726
     languages that permit overloading of symbols, such as C++,
727
     FUNCTION may refer to more than one possible place to break.
728
     *Note Breakpoint menus: Breakpoint Menus, for a discussion of that
729
     situation.
730
 
731
`break +OFFSET'
732
`break -OFFSET'
733
     Set a breakpoint some number of lines forward or back from the
734
     position at which execution stopped in the currently selected
735
     "stack frame".  (*Note Frames: Frames, for a description of stack
736
     frames.)
737
 
738
`break LINENUM'
739
     Set a breakpoint at line LINENUM in the current source file.  The
740
     current source file is the last file whose source text was printed.
741
     The breakpoint will stop your program just before it executes any
742
     of the code on that line.
743
 
744
`break FILENAME:LINENUM'
745
     Set a breakpoint at line LINENUM in source file FILENAME.
746
 
747
`break FILENAME:FUNCTION'
748
     Set a breakpoint at entry to function FUNCTION found in file
749
     FILENAME.  Specifying a file name as well as a function name is
750
     superfluous except when multiple files contain similarly named
751
     functions.
752
 
753
`break *ADDRESS'
754
     Set a breakpoint at address ADDRESS.  You can use this to set
755
     breakpoints in parts of your program which do not have debugging
756
     information or source files.
757
 
758
`break'
759
     When called without any arguments, `break' sets a breakpoint at
760
     the next instruction to be executed in the selected stack frame
761
     (*note Examining the Stack: Stack.).  In any selected frame but the
762
     innermost, this makes your program stop as soon as control returns
763
     to that frame.  This is similar to the effect of a `finish'
764
     command in the frame inside the selected frame--except that
765
     `finish' does not leave an active breakpoint.  If you use `break'
766
     without an argument in the innermost frame, GDB stops the next
767
     time it reaches the current location; this may be useful inside
768
     loops.
769
 
770
     GDB normally ignores breakpoints when it resumes execution, until
771
     at least one instruction has been executed.  If it did not do
772
     this, you would be unable to proceed past a breakpoint without
773
     first disabling the breakpoint.  This rule applies whether or not
774
     the breakpoint already existed when your program stopped.
775
 
776
`break ... if COND'
777
     Set a breakpoint with condition COND; evaluate the expression COND
778
     each time the breakpoint is reached, and stop only if the value is
779
     nonzero--that is, if COND evaluates as true.  `...' stands for one
780
     of the possible arguments described above (or no argument)
781
     specifying where to break.  *Note Break conditions: Conditions,
782
     for more information on breakpoint conditions.
783
 
784
`tbreak ARGS'
785
     Set a breakpoint enabled only for one stop.  ARGS are the same as
786
     for the `break' command, and the breakpoint is set in the same
787
     way, but the breakpoint is automatically deleted after the first
788
     time your program stops there.  *Note Disabling breakpoints:
789
     Disabling.
790
 
791
`hbreak ARGS'
792
     Set a hardware-assisted breakpoint.  ARGS are the same as for the
793
     `break' command and the breakpoint is set in the same way, but the
794
     breakpoint requires hardware support and some target hardware may
795
     not have this support.  The main purpose of this is EPROM/ROM code
796
     debugging, so you can set a breakpoint at an instruction without
797
     changing the instruction.  This can be used with the new
798
     trap-generation provided by SPARClite DSU and some x86-based
799
     targets.  These targets will generate traps when a program
800
     accesses some data or instruction address that is assigned to the
801
     debug registers.  However the hardware breakpoint registers can
802
     take a limited number of breakpoints.  For example, on the DSU,
803
     only two data breakpoints can be set at a time, and GDB will
804
     reject this command if more than two are used.  Delete or disable
805
     unused hardware breakpoints before setting new ones (*note
806
     Disabling: Disabling.).  *Note Break conditions: Conditions.
807
 
808
`thbreak ARGS'
809
     Set a hardware-assisted breakpoint enabled only for one stop.  ARGS
810
     are the same as for the `hbreak' command and the breakpoint is set
811
     in the same way.  However, like the `tbreak' command, the
812
     breakpoint is automatically deleted after the first time your
813
     program stops there.  Also, like the `hbreak' command, the
814
     breakpoint requires hardware support and some target hardware may
815
     not have this support.  *Note Disabling breakpoints: Disabling.
816
     See also *Note Break conditions: Conditions.
817
 
818
`rbreak REGEX'
819
     Set breakpoints on all functions matching the regular expression
820
     REGEX.  This command sets an unconditional breakpoint on all
821
     matches, printing a list of all breakpoints it set.  Once these
822
     breakpoints are set, they are treated just like the breakpoints
823
     set with the `break' command.  You can delete them, disable them,
824
     or make them conditional the same way as any other breakpoint.
825
 
826
     The syntax of the regular expression is the standard one used with
827
     tools like `grep'.  Note that this is different from the syntax
828
     used by shells, so for instance `foo*' matches all functions that
829
     include an `fo' followed by zero or more `o's.  There is an
830
     implicit `.*' leading and trailing the regular expression you
831
     supply, so to match only functions that begin with `foo', use
832
     `^foo'.
833
 
834
     When debugging C++ programs, `rbreak' is useful for setting
835
     breakpoints on overloaded functions that are not members of any
836
     special classes.
837
 
838
`info breakpoints [N]'
839
`info break [N]'
840
`info watchpoints [N]'
841
     Print a table of all breakpoints, watchpoints, and catchpoints set
842
     and not deleted, with the following columns for each breakpoint:
843
 
844
    _Breakpoint Numbers_
845
 
846
    _Type_
847
          Breakpoint, watchpoint, or catchpoint.
848
 
849
    _Disposition_
850
          Whether the breakpoint is marked to be disabled or deleted
851
          when hit.
852
 
853
    _Enabled or Disabled_
854
          Enabled breakpoints are marked with `y'.  `n' marks
855
          breakpoints that are not enabled.
856
 
857
    _Address_
858
          Where the breakpoint is in your program, as a memory address.
859
 
860
    _What_
861
          Where the breakpoint is in the source for your program, as a
862
          file and line number.
863
 
864
     If a breakpoint is conditional, `info break' shows the condition on
865
     the line following the affected breakpoint; breakpoint commands,
866
     if any, are listed after that.
867
 
868
     `info break' with a breakpoint number N as argument lists only
869
     that breakpoint.  The convenience variable `$_' and the default
870
     examining-address for the `x' command are set to the address of
871
     the last breakpoint listed (*note Examining memory: Memory.).
872
 
873
     `info break' displays a count of the number of times the breakpoint
874
     has been hit.  This is especially useful in conjunction with the
875
     `ignore' command.  You can ignore a large number of breakpoint
876
     hits, look at the breakpoint info to see how many times the
877
     breakpoint was hit, and then run again, ignoring one less than
878
     that number.  This will get you quickly to the last hit of that
879
     breakpoint.
880
 
881
   GDB allows you to set any number of breakpoints at the same place in
882
your program.  There is nothing silly or meaningless about this.  When
883
the breakpoints are conditional, this is even useful (*note Break
884
conditions: Conditions.).
885
 
886
   GDB itself sometimes sets breakpoints in your program for special
887
purposes, such as proper handling of `longjmp' (in C programs).  These
888
internal breakpoints are assigned negative numbers, starting with `-1';
889
`info breakpoints' does not display them.  You can see these
890
breakpoints with the GDB maintenance command `maint info breakpoints'
891
(*note maint info breakpoints::).
892
 
893

894
File: gdb.info,  Node: Set Watchpoints,  Next: Set Catchpoints,  Prev: Set Breaks,  Up: Breakpoints
895
 
896
Setting watchpoints
897
-------------------
898
 
899
   You can use a watchpoint to stop execution whenever the value of an
900
expression changes, without having to predict a particular place where
901
this may happen.
902
 
903
   Depending on your system, watchpoints may be implemented in software
904
or hardware.  GDB does software watchpointing by single-stepping your
905
program and testing the variable's value each time, which is hundreds of
906
times slower than normal execution.  (But this may still be worth it, to
907
catch errors where you have no clue what part of your program is the
908
culprit.)
909
 
910
   On some systems, such as HP-UX, GNU/Linux and some other x86-based
911
targets, GDB includes support for hardware watchpoints, which do not
912
slow down the running of your program.
913
 
914
`watch EXPR'
915
     Set a watchpoint for an expression.  GDB will break when EXPR is
916
     written into by the program and its value changes.
917
 
918
`rwatch EXPR'
919
     Set a watchpoint that will break when watch EXPR is read by the
920
     program.
921
 
922
`awatch EXPR'
923
     Set a watchpoint that will break when EXPR is either read or
924
     written into by the program.
925
 
926
`info watchpoints'
927
     This command prints a list of watchpoints, breakpoints, and
928
     catchpoints; it is the same as `info break'.
929
 
930
   GDB sets a "hardware watchpoint" if possible.  Hardware watchpoints
931
execute very quickly, and the debugger reports a change in value at the
932
exact instruction where the change occurs.  If GDB cannot set a
933
hardware watchpoint, it sets a software watchpoint, which executes more
934
slowly and reports the change in value at the next statement, not the
935
instruction, after the change occurs.
936
 
937
   When you issue the `watch' command, GDB reports
938
 
939
     Hardware watchpoint NUM: EXPR
940
 
941
if it was able to set a hardware watchpoint.
942
 
943
   Currently, the `awatch' and `rwatch' commands can only set hardware
944
watchpoints, because accesses to data that don't change the value of
945
the watched expression cannot be detected without examining every
946
instruction as it is being executed, and GDB does not do that
947
currently.  If GDB finds that it is unable to set a hardware breakpoint
948
with the `awatch' or `rwatch' command, it will print a message like
949
this:
950
 
951
     Expression cannot be implemented with read/access watchpoint.
952
 
953
   Sometimes, GDB cannot set a hardware watchpoint because the data
954
type of the watched expression is wider than what a hardware watchpoint
955
on the target machine can handle.  For example, some systems can only
956
watch regions that are up to 4 bytes wide; on such systems you cannot
957
set hardware watchpoints for an expression that yields a
958
double-precision floating-point number (which is typically 8 bytes
959
wide).  As a work-around, it might be possible to break the large region
960
into a series of smaller ones and watch them with separate watchpoints.
961
 
962
   If you set too many hardware watchpoints, GDB might be unable to
963
insert all of them when you resume the execution of your program.
964
Since the precise number of active watchpoints is unknown until such
965
time as the program is about to be resumed, GDB might not be able to
966
warn you about this when you set the watchpoints, and the warning will
967
be printed only when the program is resumed:
968
 
969
     Hardware watchpoint NUM: Could not insert watchpoint
970
 
971
If this happens, delete or disable some of the watchpoints.
972
 
973
   The SPARClite DSU will generate traps when a program accesses some
974
data or instruction address that is assigned to the debug registers.
975
For the data addresses, DSU facilitates the `watch' command.  However
976
the hardware breakpoint registers can only take two data watchpoints,
977
and both watchpoints must be the same kind.  For example, you can set
978
two watchpoints with `watch' commands, two with `rwatch' commands, *or*
979
two with `awatch' commands, but you cannot set one watchpoint with one
980
command and the other with a different command.  GDB will reject the
981
command if you try to mix watchpoints.  Delete or disable unused
982
watchpoint commands before setting new ones.
983
 
984
   If you call a function interactively using `print' or `call', any
985
watchpoints you have set will be inactive until GDB reaches another
986
kind of breakpoint or the call completes.
987
 
988
   GDB automatically deletes watchpoints that watch local (automatic)
989
variables, or expressions that involve such variables, when they go out
990
of scope, that is, when the execution leaves the block in which these
991
variables were defined.  In particular, when the program being debugged
992
terminates, _all_ local variables go out of scope, and so only
993
watchpoints that watch global variables remain set.  If you rerun the
994
program, you will need to set all such watchpoints again.  One way of
995
doing that would be to set a code breakpoint at the entry to the `main'
996
function and when it breaks, set all the watchpoints.
997
 
998
     _Warning:_ In multi-thread programs, watchpoints have only limited
999
     usefulness.  With the current watchpoint implementation, GDB can
1000
     only watch the value of an expression _in a single thread_.  If
1001
     you are confident that the expression can only change due to the
1002
     current thread's activity (and if you are also confident that no
1003
     other thread can become current), then you can use watchpoints as
1004
     usual.  However, GDB may not notice when a non-current thread's
1005
     activity changes the expression.
1006
 
1007
     _HP-UX Warning:_ In multi-thread programs, software watchpoints
1008
     have only limited usefulness.  If GDB creates a software
1009
     watchpoint, it can only watch the value of an expression _in a
1010
     single thread_.  If you are confident that the expression can only
1011
     change due to the current thread's activity (and if you are also
1012
     confident that no other thread can become current), then you can
1013
     use software watchpoints as usual.  However, GDB may not notice
1014
     when a non-current thread's activity changes the expression.
1015
     (Hardware watchpoints, in contrast, watch an expression in all
1016
     threads.)
1017
 
1018

1019
File: gdb.info,  Node: Set Catchpoints,  Next: Delete Breaks,  Prev: Set Watchpoints,  Up: Breakpoints
1020
 
1021
Setting catchpoints
1022
-------------------
1023
 
1024
   You can use "catchpoints" to cause the debugger to stop for certain
1025
kinds of program events, such as C++ exceptions or the loading of a
1026
shared library.  Use the `catch' command to set a catchpoint.
1027
 
1028
`catch EVENT'
1029
     Stop when EVENT occurs.  EVENT can be any of the following:
1030
    `throw'
1031
          The throwing of a C++ exception.
1032
 
1033
    `catch'
1034
          The catching of a C++ exception.
1035
 
1036
    `exec'
1037
          A call to `exec'.  This is currently only available for HP-UX.
1038
 
1039
    `fork'
1040
          A call to `fork'.  This is currently only available for HP-UX.
1041
 
1042
    `vfork'
1043
          A call to `vfork'.  This is currently only available for
1044
          HP-UX.
1045
 
1046
    `load'
1047
    `load LIBNAME'
1048
          The dynamic loading of any shared library, or the loading of
1049
          the library LIBNAME.  This is currently only available for
1050
          HP-UX.
1051
 
1052
    `unload'
1053
    `unload LIBNAME'
1054
          The unloading of any dynamically loaded shared library, or
1055
          the unloading of the library LIBNAME.  This is currently only
1056
          available for HP-UX.
1057
 
1058
`tcatch EVENT'
1059
     Set a catchpoint that is enabled only for one stop.  The
1060
     catchpoint is automatically deleted after the first time the event
1061
     is caught.
1062
 
1063
   Use the `info break' command to list the current catchpoints.
1064
 
1065
   There are currently some limitations to C++ exception handling
1066
(`catch throw' and `catch catch') in GDB:
1067
 
1068
   * If you call a function interactively, GDB normally returns control
1069
     to you when the function has finished executing.  If the call
1070
     raises an exception, however, the call may bypass the mechanism
1071
     that returns control to you and cause your program either to abort
1072
     or to simply continue running until it hits a breakpoint, catches
1073
     a signal that GDB is listening for, or exits.  This is the case
1074
     even if you set a catchpoint for the exception; catchpoints on
1075
     exceptions are disabled within interactive calls.
1076
 
1077
   * You cannot raise an exception interactively.
1078
 
1079
   * You cannot install an exception handler interactively.
1080
 
1081
   Sometimes `catch' is not the best way to debug exception handling:
1082
if you need to know exactly where an exception is raised, it is better
1083
to stop _before_ the exception handler is called, since that way you
1084
can see the stack before any unwinding takes place.  If you set a
1085
breakpoint in an exception handler instead, it may not be easy to find
1086
out where the exception was raised.
1087
 
1088
   To stop just before an exception handler is called, you need some
1089
knowledge of the implementation.  In the case of GNU C++, exceptions are
1090
raised by calling a library function named `__raise_exception' which
1091
has the following ANSI C interface:
1092
 
1093
         /* ADDR is where the exception identifier is stored.
1094
            ID is the exception identifier.  */
1095
         void __raise_exception (void **addr, void *id);
1096
 
1097
To make the debugger catch all exceptions before any stack unwinding
1098
takes place, set a breakpoint on `__raise_exception' (*note
1099
Breakpoints; watchpoints; and exceptions: Breakpoints.).
1100
 
1101
   With a conditional breakpoint (*note Break conditions: Conditions.)
1102
that depends on the value of ID, you can stop your program when a
1103
specific exception is raised.  You can use multiple conditional
1104
breakpoints to stop your program when any of a number of exceptions are
1105
raised.
1106
 
1107

1108
File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Set Catchpoints,  Up: Breakpoints
1109
 
1110
Deleting breakpoints
1111
--------------------
1112
 
1113
   It is often necessary to eliminate a breakpoint, watchpoint, or
1114
catchpoint once it has done its job and you no longer want your program
1115
to stop there.  This is called "deleting" the breakpoint.  A breakpoint
1116
that has been deleted no longer exists; it is forgotten.
1117
 
1118
   With the `clear' command you can delete breakpoints according to
1119
where they are in your program.  With the `delete' command you can
1120
delete individual breakpoints, watchpoints, or catchpoints by specifying
1121
their breakpoint numbers.
1122
 
1123
   It is not necessary to delete a breakpoint to proceed past it.  GDB
1124
automatically ignores breakpoints on the first instruction to be
1125
executed when you continue execution without changing the execution
1126
address.
1127
 
1128
`clear'
1129
     Delete any breakpoints at the next instruction to be executed in
1130
     the selected stack frame (*note Selecting a frame: Selection.).
1131
     When the innermost frame is selected, this is a good way to delete
1132
     a breakpoint where your program just stopped.
1133
 
1134
`clear FUNCTION'
1135
`clear FILENAME:FUNCTION'
1136
     Delete any breakpoints set at entry to the function FUNCTION.
1137
 
1138
`clear LINENUM'
1139
`clear FILENAME:LINENUM'
1140
     Delete any breakpoints set at or within the code of the specified
1141
     line.
1142
 
1143
`delete [breakpoints] [RANGE...]'
1144
     Delete the breakpoints, watchpoints, or catchpoints of the
1145
     breakpoint ranges specified as arguments.  If no argument is
1146
     specified, delete all breakpoints (GDB asks confirmation, unless
1147
     you have `set confirm off').  You can abbreviate this command as
1148
     `d'.
1149
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.