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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [doc/] [gdb.info-2] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
This is ./gdb.info, produced by makeinfo version 4.0 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, April 2001, of `Debugging with GDB: the
11
GNU Source-Level Debugger' for GDB Version 20010707.
12
 
13
   Copyright (C)
14
1988,1989,1990,1991,1992,1993,1994,1995,1996,1998,1999,2000,2001
15
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 "A Sample GDB Session" and "Free Software",
21
with the Front-Cover texts being "A GNU Manual," and with the
22
Back-Cover Texts as in (a) below.
23
 
24
   (a) The FSF's Back-Cover Text is: "You have freedom to copy and
25
modify this GNU Manual, like GNU software.  Copies published by the Free
26
Software Foundation raise funds for GNU development."
27
 
28

29
File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
30
 
31
Your program's environment
32
==========================
33
 
34
   The "environment" consists of a set of environment variables and
35
their values.  Environment variables conventionally record such things
36
as your user name, your home directory, your terminal type, and your
37
search path for programs to run.  Usually you set up environment
38
variables with the shell and they are inherited by all the other
39
programs you run.  When debugging, it can be useful to try running your
40
program with a modified environment without having to start GDB over
41
again.
42
 
43
`path DIRECTORY'
44
     Add DIRECTORY to the front of the `PATH' environment variable (the
45
     search path for executables) that will be passed to your program.
46
     The value of `PATH' used by GDB does not change.  You may specify
47
     several directory names, separated by whitespace or by a
48
     system-dependent separator character (`:' on Unix, `;' on MS-DOS
49
     and MS-Windows).  If DIRECTORY is already in the path, it is moved
50
     to the front, so it is searched sooner.
51
 
52
     You can use the string `$cwd' to refer to whatever is the current
53
     working directory at the time GDB searches the path.  If you use
54
     `.' instead, it refers to the directory where you executed the
55
     `path' command.  GDB replaces `.' in the DIRECTORY argument (with
56
     the current path) before adding DIRECTORY to the search path.
57
 
58
`show paths'
59
     Display the list of search paths for executables (the `PATH'
60
     environment variable).
61
 
62
`show environment [VARNAME]'
63
     Print the value of environment variable VARNAME to be given to
64
     your program when it starts.  If you do not supply VARNAME, print
65
     the names and values of all environment variables to be given to
66
     your program.  You can abbreviate `environment' as `env'.
67
 
68
`set environment VARNAME [=VALUE]'
69
     Set environment variable VARNAME to VALUE.  The value changes for
70
     your program only, not for GDB itself.  VALUE may be any string;
71
     the values of environment variables are just strings, and any
72
     interpretation is supplied by your program itself.  The VALUE
73
     parameter is optional; if it is eliminated, the variable is set to
74
     a null value.
75
 
76
     For example, this command:
77
 
78
          set env USER = foo
79
 
80
     tells the debugged program, when subsequently run, that its user
81
     is named `foo'.  (The spaces around `=' are used for clarity here;
82
     they are not actually required.)
83
 
84
`unset environment VARNAME'
85
     Remove variable VARNAME from the environment to be passed to your
86
     program.  This is different from `set env VARNAME ='; `unset
87
     environment' removes the variable from the environment, rather
88
     than assigning it an empty value.
89
 
90
   _Warning:_ On Unix systems, GDB runs your program using the shell
91
indicated by your `SHELL' environment variable if it exists (or
92
`/bin/sh' if not).  If your `SHELL' variable names a shell that runs an
93
initialization file--such as `.cshrc' for C-shell, or `.bashrc' for
94
BASH--any variables you set in that file affect your program.  You may
95
wish to move setting of environment variables to files that are only
96
run when you sign on, such as `.login' or `.profile'.
97
 
98

99
File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
100
 
101
Your program's working directory
102
================================
103
 
104
   Each time you start your program with `run', it inherits its working
105
directory from the current working directory of GDB.  The GDB working
106
directory is initially whatever it inherited from its parent process
107
(typically the shell), but you can specify a new working directory in
108
GDB with the `cd' command.
109
 
110
   The GDB working directory also serves as a default for the commands
111
that specify files for GDB to operate on.  *Note Commands to specify
112
files: Files.
113
 
114
`cd DIRECTORY'
115
     Set the GDB working directory to DIRECTORY.
116
 
117
`pwd'
118
     Print the GDB working directory.
119
 
120

121
File: gdb.info,  Node: Input/Output,  Next: Attach,  Prev: Working Directory,  Up: Running
122
 
123
Your program's input and output
124
===============================
125
 
126
   By default, the program you run under GDB does input and output to
127
the same terminal that GDB uses.  GDB switches the terminal to its own
128
terminal modes to interact with you, but it records the terminal modes
129
your program was using and switches back to them when you continue
130
running your program.
131
 
132
`info terminal'
133
     Displays information recorded by GDB about the terminal modes your
134
     program is using.
135
 
136
   You can redirect your program's input and/or output using shell
137
redirection with the `run' command.  For example,
138
 
139
     run > outfile
140
 
141
starts your program, diverting its output to the file `outfile'.
142
 
143
   Another way to specify where your program should do input and output
144
is with the `tty' command.  This command accepts a file name as
145
argument, and causes this file to be the default for future `run'
146
commands.  It also resets the controlling terminal for the child
147
process, for future `run' commands.  For example,
148
 
149
     tty /dev/ttyb
150
 
151
directs that processes started with subsequent `run' commands default
152
to do input and output on the terminal `/dev/ttyb' and have that as
153
their controlling terminal.
154
 
155
   An explicit redirection in `run' overrides the `tty' command's
156
effect on the input/output device, but not its effect on the controlling
157
terminal.
158
 
159
   When you use the `tty' command or redirect input in the `run'
160
command, only the input _for your program_ is affected.  The input for
161
GDB still comes from your terminal.
162
 
163

164
File: gdb.info,  Node: Attach,  Next: Kill Process,  Prev: Input/Output,  Up: Running
165
 
166
Debugging an already-running process
167
====================================
168
 
169
`attach PROCESS-ID'
170
     This command attaches to a running process--one that was started
171
     outside GDB.  (`info files' shows your active targets.)  The
172
     command takes as argument a process ID.  The usual way to find out
173
     the process-id of a Unix process is with the `ps' utility, or with
174
     the `jobs -l' shell command.
175
 
176
     `attach' does not repeat if you press  a second time after
177
     executing the command.
178
 
179
   To use `attach', your program must be running in an environment
180
which supports processes; for example, `attach' does not work for
181
programs on bare-board targets that lack an operating system.  You must
182
also have permission to send the process a signal.
183
 
184
   When you use `attach', the debugger finds the program running in the
185
process first by looking in the current working directory, then (if the
186
program is not found) by using the source file search path (*note
187
Specifying source directories: Source Path.).  You can also use the
188
`file' command to load the program.  *Note Commands to Specify Files:
189
Files.
190
 
191
   The first thing GDB does after arranging to debug the specified
192
process is to stop it.  You can examine and modify an attached process
193
with all the GDB commands that are ordinarily available when you start
194
processes with `run'.  You can insert breakpoints; you can step and
195
continue; you can modify storage.  If you would rather the process
196
continue running, you may use the `continue' command after attaching
197
GDB to the process.
198
 
199
`detach'
200
     When you have finished debugging the attached process, you can use
201
     the `detach' command to release it from GDB control.  Detaching
202
     the process continues its execution.  After the `detach' command,
203
     that process and GDB become completely independent once more, and
204
     you are ready to `attach' another process or start one with `run'.
205
     `detach' does not repeat if you press  again after executing
206
     the command.
207
 
208
   If you exit GDB or use the `run' command while you have an attached
209
process, you kill that process.  By default, GDB asks for confirmation
210
if you try to do either of these things; you can control whether or not
211
you need to confirm by using the `set confirm' command (*note Optional
212
warnings and messages: Messages/Warnings.).
213
 
214

215
File: gdb.info,  Node: Kill Process,  Next: Threads,  Prev: Attach,  Up: Running
216
 
217
Killing the child process
218
=========================
219
 
220
`kill'
221
     Kill the child process in which your program is running under GDB.
222
 
223
   This command is useful if you wish to debug a core dump instead of a
224
running process.  GDB ignores any core dump file while your program is
225
running.
226
 
227
   On some operating systems, a program cannot be executed outside GDB
228
while you have breakpoints set on it inside GDB.  You can use the
229
`kill' command in this situation to permit running your program outside
230
the debugger.
231
 
232
   The `kill' command is also useful if you wish to recompile and
233
relink your program, since on many systems it is impossible to modify an
234
executable file while it is running in a process.  In this case, when
235
you next type `run', GDB notices that the file has changed, and reads
236
the symbol table again (while trying to preserve your current
237
breakpoint settings).
238
 
239

240
File: gdb.info,  Node: Threads,  Next: Processes,  Prev: Kill Process,  Up: Running
241
 
242
Debugging programs with multiple threads
243
========================================
244
 
245
   In some operating systems, such as HP-UX and Solaris, a single
246
program may have more than one "thread" of execution.  The precise
247
semantics of threads differ from one operating system to another, but
248
in general the threads of a single program are akin to multiple
249
processes--except that they share one address space (that is, they can
250
all examine and modify the same variables).  On the other hand, each
251
thread has its own registers and execution stack, and perhaps private
252
memory.
253
 
254
   GDB provides these facilities for debugging multi-thread programs:
255
 
256
   * automatic notification of new threads
257
 
258
   * `thread THREADNO', a command to switch among threads
259
 
260
   * `info threads', a command to inquire about existing threads
261
 
262
   * `thread apply [THREADNO] [ALL] ARGS', a command to apply a command
263
     to a list of threads
264
 
265
   * thread-specific breakpoints
266
 
267
     _Warning:_ These facilities are not yet available on every GDB
268
     configuration where the operating system supports threads.  If
269
     your GDB does not support threads, these commands have no effect.
270
     For example, a system without thread support shows no output from
271
     `info threads', and always rejects the `thread' command, like this:
272
 
273
          (gdb) info threads
274
          (gdb) thread 1
275
          Thread ID 1 not known.  Use the "info threads" command to
276
          see the IDs of currently known threads.
277
 
278
   The GDB thread debugging facility allows you to observe all threads
279
while your program runs--but whenever GDB takes control, one thread in
280
particular is always the focus of debugging.  This thread is called the
281
"current thread".  Debugging commands show program information from the
282
perspective of the current thread.
283
 
284
   Whenever GDB detects a new thread in your program, it displays the
285
target system's identification for the thread with a message in the
286
form `[New SYSTAG]'.  SYSTAG is a thread identifier whose form varies
287
depending on the particular system.  For example, on LynxOS, you might
288
see
289
 
290
     [New process 35 thread 27]
291
 
292
when GDB notices a new thread.  In contrast, on an SGI system, the
293
SYSTAG is simply something like `process 368', with no further
294
qualifier.
295
 
296
   For debugging purposes, GDB associates its own thread number--always
297
a single integer--with each thread in your program.
298
 
299
`info threads'
300
     Display a summary of all threads currently in your program.  GDB
301
     displays for each thread (in this order):
302
 
303
       1. the thread number assigned by GDB
304
 
305
       2. the target system's thread identifier (SYSTAG)
306
 
307
       3. the current stack frame summary for that thread
308
 
309
     An asterisk `*' to the left of the GDB thread number indicates the
310
     current thread.
311
 
312
     For example,
313
 
314
     (gdb) info threads
315
       3 process 35 thread 27  0x34e5 in sigpause ()
316
       2 process 35 thread 23  0x34e5 in sigpause ()
317
     * 1 process 35 thread 13  main (argc=1, argv=0x7ffffff8)
318
         at threadtest.c:68
319
 
320
   On HP-UX systems:
321
 
322
   For debugging purposes, GDB associates its own thread number--a
323
small integer assigned in thread-creation order--with each thread in
324
your program.
325
 
326
   Whenever GDB detects a new thread in your program, it displays both
327
GDB's thread number and the target system's identification for the
328
thread with a message in the form `[New SYSTAG]'.  SYSTAG is a thread
329
identifier whose form varies depending on the particular system.  For
330
example, on HP-UX, you see
331
 
332
     [New thread 2 (system thread 26594)]
333
 
334
when GDB notices a new thread.
335
 
336
`info threads'
337
     Display a summary of all threads currently in your program.  GDB
338
     displays for each thread (in this order):
339
 
340
       1. the thread number assigned by GDB
341
 
342
       2. the target system's thread identifier (SYSTAG)
343
 
344
       3. the current stack frame summary for that thread
345
 
346
     An asterisk `*' to the left of the GDB thread number indicates the
347
     current thread.
348
 
349
     For example,
350
 
351
     (gdb) info threads
352
         * 3 system thread 26607  worker (wptr=0x7b09c318 "@") \
353
 
354
     at quicksort.c:137
355
           2 system thread 26606  0x7b0030d8 in __ksleep () \
356
 
357
     from /usr/lib/libc.2
358
           1 system thread 27905  0x7b003498 in _brk () \
359
 
360
     from /usr/lib/libc.2
361
 
362
`thread THREADNO'
363
     Make thread number THREADNO the current thread.  The command
364
     argument THREADNO is the internal GDB thread number, as shown in
365
     the first field of the `info threads' display.  GDB responds by
366
     displaying the system identifier of the thread you selected, and
367
     its current stack frame summary:
368
 
369
          (gdb) thread 2
370
          [Switching to process 35 thread 23]
371
          0x34e5 in sigpause ()
372
 
373
     As with the `[New ...]' message, the form of the text after
374
     `Switching to' depends on your system's conventions for identifying
375
     threads.
376
 
377
`thread apply [THREADNO] [ALL]  ARGS'
378
     The `thread apply' command allows you to apply a command to one or
379
     more threads.  Specify the numbers of the threads that you want
380
     affected with the command argument THREADNO.  THREADNO is the
381
     internal GDB thread number, as shown in the first field of the
382
     `info threads' display.  To apply a command to all threads, use
383
     `thread apply all' ARGS.
384
 
385
   Whenever GDB stops your program, due to a breakpoint or a signal, it
386
automatically selects the thread where that breakpoint or signal
387
happened.  GDB alerts you to the context switch with a message of the
388
form `[Switching to SYSTAG]' to identify the thread.
389
 
390
   *Note Stopping and starting multi-thread programs: Thread Stops, for
391
more information about how GDB behaves when you stop and start programs
392
with multiple threads.
393
 
394
   *Note Setting watchpoints: Set Watchpoints, for information about
395
watchpoints in programs with multiple threads.
396
 
397

398
File: gdb.info,  Node: Processes,  Prev: Threads,  Up: Running
399
 
400
Debugging programs with multiple processes
401
==========================================
402
 
403
   On most systems, GDB has no special support for debugging programs
404
which create additional processes using the `fork' function.  When a
405
program forks, GDB will continue to debug the parent process and the
406
child process will run unimpeded.  If you have set a breakpoint in any
407
code which the child then executes, the child will get a `SIGTRAP'
408
signal which (unless it catches the signal) will cause it to terminate.
409
 
410
   However, if you want to debug the child process there is a workaround
411
which isn't too painful.  Put a call to `sleep' in the code which the
412
child process executes after the fork.  It may be useful to sleep only
413
if a certain environment variable is set, or a certain file exists, so
414
that the delay need not occur when you don't want to run GDB on the
415
child.  While the child is sleeping, use the `ps' program to get its
416
process ID.  Then tell GDB (a new invocation of GDB if you are also
417
debugging the parent process) to attach to the child process (*note
418
Attach::).  From that point on you can debug the child process just
419
like any other process which you attached to.
420
 
421
   On HP-UX (11.x and later only?), GDB provides support for debugging
422
programs that create additional processes using the `fork' or `vfork'
423
function.
424
 
425
   By default, when a program forks, GDB will continue to debug the
426
parent process and the child process will run unimpeded.
427
 
428
   If you want to follow the child process instead of the parent
429
process, use the command `set follow-fork-mode'.
430
 
431
`set follow-fork-mode MODE'
432
     Set the debugger response to a program call of `fork' or `vfork'.
433
     A call to `fork' or `vfork' creates a new process.  The MODE can
434
     be:
435
 
436
    `parent'
437
          The original process is debugged after a fork.  The child
438
          process runs unimpeded.  This is the default.
439
 
440
    `child'
441
          The new process is debugged after a fork.  The parent process
442
          runs unimpeded.
443
 
444
    `ask'
445
          The debugger will ask for one of the above choices.
446
 
447
`show follow-fork-mode'
448
     Display the current debugger response to a `fork' or `vfork' call.
449
 
450
   If you ask to debug a child process and a `vfork' is followed by an
451
`exec', GDB executes the new target up to the first breakpoint in the
452
new target.  If you have a breakpoint set on `main' in your original
453
program, the breakpoint will also be set on the child process's `main'.
454
 
455
   When a child process is spawned by `vfork', you cannot debug the
456
child or parent until an `exec' call completes.
457
 
458
   If you issue a `run' command to GDB after an `exec' call executes,
459
the new target restarts.  To restart the parent process, use the `file'
460
command with the parent executable name as its argument.
461
 
462
   You can use the `catch' command to make GDB stop whenever a `fork',
463
`vfork', or `exec' call is made.  *Note Setting catchpoints: Set
464
Catchpoints.
465
 
466

467
File: gdb.info,  Node: Stopping,  Next: Stack,  Prev: Running,  Up: Top
468
 
469
Stopping and Continuing
470
***********************
471
 
472
   The principal purposes of using a debugger are so that you can stop
473
your program before it terminates; or so that, if your program runs into
474
trouble, you can investigate and find out why.
475
 
476
   Inside GDB, your program may stop for any of several reasons, such
477
as a signal, a breakpoint, or reaching a new line after a GDB command
478
such as `step'.  You may then examine and change variables, set new
479
breakpoints or remove old ones, and then continue execution.  Usually,
480
the messages shown by GDB provide ample explanation of the status of
481
your program--but you can also explicitly request this information at
482
any time.
483
 
484
`info program'
485
     Display information about the status of your program: whether it is
486
     running or not, what process it is, and why it stopped.
487
 
488
* Menu:
489
 
490
* Breakpoints::                 Breakpoints, watchpoints, and catchpoints
491
* Continuing and Stepping::     Resuming execution
492
* Signals::                     Signals
493
* Thread Stops::                Stopping and starting multi-thread programs
494
 
495

496
File: gdb.info,  Node: Breakpoints,  Next: Continuing and Stepping,  Up: Stopping
497
 
498
Breakpoints, watchpoints, and catchpoints
499
=========================================
500
 
501
   A "breakpoint" makes your program stop whenever a certain point in
502
the program is reached.  For each breakpoint, you can add conditions to
503
control in finer detail whether your program stops.  You can set
504
breakpoints with the `break' command and its variants (*note Setting
505
breakpoints: Set Breaks.), to specify the place where your program
506
should stop by line number, function name or exact address in the
507
program.
508
 
509
   In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can
510
set breakpoints in shared libraries before the executable is run.
511
There is a minor limitation on HP-UX systems: you must wait until the
512
executable is run in order to set breakpoints in shared library
513
routines that are not called directly by the program (for example,
514
routines that are arguments in a `pthread_create' call).
515
 
516
   A "watchpoint" is a special breakpoint that stops your program when
517
the value of an expression changes.  You must use a different command
518
to set watchpoints (*note Setting watchpoints: Set Watchpoints.), but
519
aside from that, you can manage a watchpoint like any other breakpoint:
520
you enable, disable, and delete both breakpoints and watchpoints using
521
the same commands.
522
 
523
   You can arrange to have values from your program displayed
524
automatically whenever GDB stops at a breakpoint.  *Note Automatic
525
display: Auto Display.
526
 
527
   A "catchpoint" is another special breakpoint that stops your program
528
when a certain kind of event occurs, such as the throwing of a C++
529
exception or the loading of a library.  As with watchpoints, you use a
530
different command to set a catchpoint (*note Setting catchpoints: Set
531
Catchpoints.), but aside from that, you can manage a catchpoint like any
532
other breakpoint.  (To stop when your program receives a signal, use the
533
`handle' command; see *Note Signals: Signals.)
534
 
535
   GDB assigns a number to each breakpoint, watchpoint, or catchpoint
536
when you create it; these numbers are successive integers starting with
537
one.  In many of the commands for controlling various features of
538
breakpoints you use the breakpoint number to say which breakpoint you
539
want to change.  Each breakpoint may be "enabled" or "disabled"; if
540
disabled, it has no effect on your program until you enable it again.
541
 
542
   Some GDB commands accept a range of breakpoints on which to operate.
543
A breakpoint range is either a single breakpoint number, like `5', or
544
two such numbers, in increasing order, separated by a hyphen, like
545
`5-7'.  When a breakpoint range is given to a command, all breakpoint
546
in that range are operated on.
547
 
548
* Menu:
549
 
550
* Set Breaks::                  Setting breakpoints
551
* Set Watchpoints::             Setting watchpoints
552
* Set Catchpoints::             Setting catchpoints
553
* Delete Breaks::               Deleting breakpoints
554
* Disabling::                   Disabling breakpoints
555
* Conditions::                  Break conditions
556
* Break Commands::              Breakpoint command lists
557
* Breakpoint Menus::            Breakpoint menus
558
* Error in Breakpoints::        ``Cannot insert breakpoints''
559
 
560

561
File: gdb.info,  Node: Set Breaks,  Next: Set Watchpoints,  Up: Breakpoints
562
 
563
Setting breakpoints
564
-------------------
565
 
566
   Breakpoints are set with the `break' command (abbreviated `b').  The
567
debugger convenience variable `$bpnum' records the number of the
568
breakpoint you've set most recently; see *Note Convenience variables:
569
Convenience Vars, for a discussion of what you can do with convenience
570
variables.
571
 
572
   You have several ways to say where the breakpoint should go.
573
 
574
`break FUNCTION'
575
     Set a breakpoint at entry to function FUNCTION.  When using source
576
     languages that permit overloading of symbols, such as C++,
577
     FUNCTION may refer to more than one possible place to break.
578
     *Note Breakpoint menus: Breakpoint Menus, for a discussion of that
579
     situation.
580
 
581
`break +OFFSET'
582
`break -OFFSET'
583
     Set a breakpoint some number of lines forward or back from the
584
     position at which execution stopped in the currently selected
585
     "stack frame".  (*Note Frames: Frames, for a description of stack
586
     frames.)
587
 
588
`break LINENUM'
589
     Set a breakpoint at line LINENUM in the current source file.  The
590
     current source file is the last file whose source text was printed.
591
     The breakpoint will stop your program just before it executes any
592
     of the code on that line.
593
 
594
`break FILENAME:LINENUM'
595
     Set a breakpoint at line LINENUM in source file FILENAME.
596
 
597
`break FILENAME:FUNCTION'
598
     Set a breakpoint at entry to function FUNCTION found in file
599
     FILENAME.  Specifying a file name as well as a function name is
600
     superfluous except when multiple files contain similarly named
601
     functions.
602
 
603
`break *ADDRESS'
604
     Set a breakpoint at address ADDRESS.  You can use this to set
605
     breakpoints in parts of your program which do not have debugging
606
     information or source files.
607
 
608
`break'
609
     When called without any arguments, `break' sets a breakpoint at
610
     the next instruction to be executed in the selected stack frame
611
     (*note Examining the Stack: Stack.).  In any selected frame but the
612
     innermost, this makes your program stop as soon as control returns
613
     to that frame.  This is similar to the effect of a `finish'
614
     command in the frame inside the selected frame--except that
615
     `finish' does not leave an active breakpoint.  If you use `break'
616
     without an argument in the innermost frame, GDB stops the next
617
     time it reaches the current location; this may be useful inside
618
     loops.
619
 
620
     GDB normally ignores breakpoints when it resumes execution, until
621
     at least one instruction has been executed.  If it did not do
622
     this, you would be unable to proceed past a breakpoint without
623
     first disabling the breakpoint.  This rule applies whether or not
624
     the breakpoint already existed when your program stopped.
625
 
626
`break ... if COND'
627
     Set a breakpoint with condition COND; evaluate the expression COND
628
     each time the breakpoint is reached, and stop only if the value is
629
     nonzero--that is, if COND evaluates as true.  `...' stands for one
630
     of the possible arguments described above (or no argument)
631
     specifying where to break.  *Note Break conditions: Conditions,
632
     for more information on breakpoint conditions.
633
 
634
`tbreak ARGS'
635
     Set a breakpoint enabled only for one stop.  ARGS are the same as
636
     for the `break' command, and the breakpoint is set in the same
637
     way, but the breakpoint is automatically deleted after the first
638
     time your program stops there.  *Note Disabling breakpoints:
639
     Disabling.
640
 
641
`hbreak ARGS'
642
     Set a hardware-assisted breakpoint.  ARGS are the same as for the
643
     `break' command and the breakpoint is set in the same way, but the
644
     breakpoint requires hardware support and some target hardware may
645
     not have this support.  The main purpose of this is EPROM/ROM code
646
     debugging, so you can set a breakpoint at an instruction without
647
     changing the instruction.  This can be used with the new
648
     trap-generation provided by SPARClite DSU and some x86-based
649
     targets.  These targets will generate traps when a program
650
     accesses some data or instruction address that is assigned to the
651
     debug registers.  However the hardware breakpoint registers can
652
     take a limited number of breakpoints.  For example, on the DSU,
653
     only two data breakpoints can be set at a time, and GDB will
654
     reject this command if more than two are used.  Delete or disable
655
     unused hardware breakpoints before setting new ones (*note
656
     Disabling: Disabling.).  *Note Break conditions: Conditions.
657
 
658
`thbreak ARGS'
659
     Set a hardware-assisted breakpoint enabled only for one stop.  ARGS
660
     are the same as for the `hbreak' command and the breakpoint is set
661
     in the same way.  However, like the `tbreak' command, the
662
     breakpoint is automatically deleted after the first time your
663
     program stops there.  Also, like the `hbreak' command, the
664
     breakpoint requires hardware support and some target hardware may
665
     not have this support.  *Note Disabling breakpoints: Disabling.
666
     See also *Note Break conditions: Conditions.
667
 
668
`rbreak REGEX'
669
     Set breakpoints on all functions matching the regular expression
670
     REGEX.  This command sets an unconditional breakpoint on all
671
     matches, printing a list of all breakpoints it set.  Once these
672
     breakpoints are set, they are treated just like the breakpoints
673
     set with the `break' command.  You can delete them, disable them,
674
     or make them conditional the same way as any other breakpoint.
675
 
676
     The syntax of the regular expression is the standard one used with
677
     tools like `grep'.  Note that this is different from the syntax
678
     used by shells, so for instance `foo*' matches all functions that
679
     include an `fo' followed by zero or more `o's.  There is an
680
     implicit `.*' leading and trailing the regular expression you
681
     supply, so to match only functions that begin with `foo', use
682
     `^foo'.
683
 
684
     When debugging C++ programs, `rbreak' is useful for setting
685
     breakpoints on overloaded functions that are not members of any
686
     special classes.
687
 
688
`info breakpoints [N]'
689
`info break [N]'
690
`info watchpoints [N]'
691
     Print a table of all breakpoints, watchpoints, and catchpoints set
692
     and not deleted, with the following columns for each breakpoint:
693
 
694
    _Breakpoint Numbers_
695
 
696
    _Type_
697
          Breakpoint, watchpoint, or catchpoint.
698
 
699
    _Disposition_
700
          Whether the breakpoint is marked to be disabled or deleted
701
          when hit.
702
 
703
    _Enabled or Disabled_
704
          Enabled breakpoints are marked with `y'.  `n' marks
705
          breakpoints that are not enabled.
706
 
707
    _Address_
708
          Where the breakpoint is in your program, as a memory address.
709
 
710
    _What_
711
          Where the breakpoint is in the source for your program, as a
712
          file and line number.
713
 
714
     If a breakpoint is conditional, `info break' shows the condition on
715
     the line following the affected breakpoint; breakpoint commands,
716
     if any, are listed after that.
717
 
718
     `info break' with a breakpoint number N as argument lists only
719
     that breakpoint.  The convenience variable `$_' and the default
720
     examining-address for the `x' command are set to the address of
721
     the last breakpoint listed (*note Examining memory: Memory.).
722
 
723
     `info break' displays a count of the number of times the breakpoint
724
     has been hit.  This is especially useful in conjunction with the
725
     `ignore' command.  You can ignore a large number of breakpoint
726
     hits, look at the breakpoint info to see how many times the
727
     breakpoint was hit, and then run again, ignoring one less than
728
     that number.  This will get you quickly to the last hit of that
729
     breakpoint.
730
 
731
   GDB allows you to set any number of breakpoints at the same place in
732
your program.  There is nothing silly or meaningless about this.  When
733
the breakpoints are conditional, this is even useful (*note Break
734
conditions: Conditions.).
735
 
736
   GDB itself sometimes sets breakpoints in your program for special
737
purposes, such as proper handling of `longjmp' (in C programs).  These
738
internal breakpoints are assigned negative numbers, starting with `-1';
739
`info breakpoints' does not display them.
740
 
741
   You can see these breakpoints with the GDB maintenance command
742
`maint info breakpoints'.
743
 
744
`maint info breakpoints'
745
     Using the same format as `info breakpoints', display both the
746
     breakpoints you've set explicitly, and those GDB is using for
747
     internal purposes.  Internal breakpoints are shown with negative
748
     breakpoint numbers.  The type column identifies what kind of
749
     breakpoint is shown:
750
 
751
    `breakpoint'
752
          Normal, explicitly set breakpoint.
753
 
754
    `watchpoint'
755
          Normal, explicitly set watchpoint.
756
 
757
    `longjmp'
758
          Internal breakpoint, used to handle correctly stepping through
759
          `longjmp' calls.
760
 
761
    `longjmp resume'
762
          Internal breakpoint at the target of a `longjmp'.
763
 
764
    `until'
765
          Temporary internal breakpoint used by the GDB `until' command.
766
 
767
    `finish'
768
          Temporary internal breakpoint used by the GDB `finish'
769
          command.
770
 
771
    `shlib events'
772
          Shared library events.
773
 
774

775
File: gdb.info,  Node: Set Watchpoints,  Next: Set Catchpoints,  Prev: Set Breaks,  Up: Breakpoints
776
 
777
Setting watchpoints
778
-------------------
779
 
780
   You can use a watchpoint to stop execution whenever the value of an
781
expression changes, without having to predict a particular place where
782
this may happen.
783
 
784
   Depending on your system, watchpoints may be implemented in software
785
or hardware.  GDB does software watchpointing by single-stepping your
786
program and testing the variable's value each time, which is hundreds of
787
times slower than normal execution.  (But this may still be worth it, to
788
catch errors where you have no clue what part of your program is the
789
culprit.)
790
 
791
   On some systems, such as HP-UX, Linux and some other x86-based
792
targets, GDB includes support for hardware watchpoints, which do not
793
slow down the running of your program.
794
 
795
`watch EXPR'
796
     Set a watchpoint for an expression.  GDB will break when EXPR is
797
     written into by the program and its value changes.
798
 
799
`rwatch EXPR'
800
     Set a watchpoint that will break when watch EXPR is read by the
801
     program.
802
 
803
`awatch EXPR'
804
     Set a watchpoint that will break when EXPR is either read or
805
     written into by the program.
806
 
807
`info watchpoints'
808
     This command prints a list of watchpoints, breakpoints, and
809
     catchpoints; it is the same as `info break'.
810
 
811
   GDB sets a "hardware watchpoint" if possible.  Hardware watchpoints
812
execute very quickly, and the debugger reports a change in value at the
813
exact instruction where the change occurs.  If GDB cannot set a
814
hardware watchpoint, it sets a software watchpoint, which executes more
815
slowly and reports the change in value at the next statement, not the
816
instruction, after the change occurs.
817
 
818
   When you issue the `watch' command, GDB reports
819
 
820
     Hardware watchpoint NUM: EXPR
821
 
822
if it was able to set a hardware watchpoint.
823
 
824
   Currently, the `awatch' and `rwatch' commands can only set hardware
825
watchpoints, because accesses to data that don't change the value of
826
the watched expression cannot be detected without examining every
827
instruction as it is being executed, and GDB does not do that
828
currently.  If GDB finds that it is unable to set a hardware breakpoint
829
with the `awatch' or `rwatch' command, it will print a message like
830
this:
831
 
832
     Expression cannot be implemented with read/access watchpoint.
833
 
834
   Sometimes, GDB cannot set a hardware watchpoint because the data
835
type of the watched expression is wider than what a hardware watchpoint
836
on the target machine can handle.  For example, some systems can only
837
watch regions that are up to 4 bytes wide; on such systems you cannot
838
set hardware watchpoints for an expression that yields a
839
double-precision floating-point number (which is typically 8 bytes
840
wide).  As a work-around, it might be possible to break the large region
841
into a series of smaller ones and watch them with separate watchpoints.
842
 
843
   If you set too many hardware watchpoints, GDB might be unable to
844
insert all of them when you resume the execution of your program.
845
Since the precise number of active watchpoints is unknown until such
846
time as the program is about to be resumed, GDB might not be able to
847
warn you about this when you set the watchpoints, and the warning will
848
be printed only when the program is resumed:
849
 
850
     Hardware watchpoint NUM: Could not insert watchpoint
851
 
852
If this happens, delete or disable some of the watchpoints.
853
 
854
   The SPARClite DSU will generate traps when a program accesses some
855
data or instruction address that is assigned to the debug registers.
856
For the data addresses, DSU facilitates the `watch' command.  However
857
the hardware breakpoint registers can only take two data watchpoints,
858
and both watchpoints must be the same kind.  For example, you can set
859
two watchpoints with `watch' commands, two with `rwatch' commands, *or*
860
two with `awatch' commands, but you cannot set one watchpoint with one
861
command and the other with a different command.  GDB will reject the
862
command if you try to mix watchpoints.  Delete or disable unused
863
watchpoint commands before setting new ones.
864
 
865
   If you call a function interactively using `print' or `call', any
866
watchpoints you have set will be inactive until GDB reaches another
867
kind of breakpoint or the call completes.
868
 
869
   GDB automatically deletes watchpoints that watch local (automatic)
870
variables, or expressions that involve such variables, when they go out
871
of scope, that is, when the execution leaves the block in which these
872
variables were defined.  In particular, when the program being debugged
873
terminates, _all_ local variables go out of scope, and so only
874
watchpoints that watch global variables remain set.  If you rerun the
875
program, you will need to set all such watchpoints again.  One way of
876
doing that would be to set a code breakpoint at the entry to the `main'
877
function and when it breaks, set all the watchpoints.
878
 
879
     _Warning:_ In multi-thread programs, watchpoints have only limited
880
     usefulness.  With the current watchpoint implementation, GDB can
881
     only watch the value of an expression _in a single thread_.  If
882
     you are confident that the expression can only change due to the
883
     current thread's activity (and if you are also confident that no
884
     other thread can become current), then you can use watchpoints as
885
     usual.  However, GDB may not notice when a non-current thread's
886
     activity changes the expression.
887
 
888
     _HP-UX Warning:_ In multi-thread programs, software watchpoints
889
     have only limited usefulness.  If GDB creates a software
890
     watchpoint, it can only watch the value of an expression _in a
891
     single thread_.  If you are confident that the expression can only
892
     change due to the current thread's activity (and if you are also
893
     confident that no other thread can become current), then you can
894
     use software watchpoints as usual.  However, GDB may not notice
895
     when a non-current thread's activity changes the expression.
896
     (Hardware watchpoints, in contrast, watch an expression in all
897
     threads.)
898
 
899

900
File: gdb.info,  Node: Set Catchpoints,  Next: Delete Breaks,  Prev: Set Watchpoints,  Up: Breakpoints
901
 
902
Setting catchpoints
903
-------------------
904
 
905
   You can use "catchpoints" to cause the debugger to stop for certain
906
kinds of program events, such as C++ exceptions or the loading of a
907
shared library.  Use the `catch' command to set a catchpoint.
908
 
909
`catch EVENT'
910
     Stop when EVENT occurs.  EVENT can be any of the following:
911
    `throw'
912
          The throwing of a C++ exception.
913
 
914
    `catch'
915
          The catching of a C++ exception.
916
 
917
    `exec'
918
          A call to `exec'.  This is currently only available for HP-UX.
919
 
920
    `fork'
921
          A call to `fork'.  This is currently only available for HP-UX.
922
 
923
    `vfork'
924
          A call to `vfork'.  This is currently only available for
925
          HP-UX.
926
 
927
    `load'
928
    `load LIBNAME'
929
          The dynamic loading of any shared library, or the loading of
930
          the library LIBNAME.  This is currently only available for
931
          HP-UX.
932
 
933
    `unload'
934
    `unload LIBNAME'
935
          The unloading of any dynamically loaded shared library, or
936
          the unloading of the library LIBNAME.  This is currently only
937
          available for HP-UX.
938
 
939
`tcatch EVENT'
940
     Set a catchpoint that is enabled only for one stop.  The
941
     catchpoint is automatically deleted after the first time the event
942
     is caught.
943
 
944
   Use the `info break' command to list the current catchpoints.
945
 
946
   There are currently some limitations to C++ exception handling
947
(`catch throw' and `catch catch') in GDB:
948
 
949
   * If you call a function interactively, GDB normally returns control
950
     to you when the function has finished executing.  If the call
951
     raises an exception, however, the call may bypass the mechanism
952
     that returns control to you and cause your program either to abort
953
     or to simply continue running until it hits a breakpoint, catches
954
     a signal that GDB is listening for, or exits.  This is the case
955
     even if you set a catchpoint for the exception; catchpoints on
956
     exceptions are disabled within interactive calls.
957
 
958
   * You cannot raise an exception interactively.
959
 
960
   * You cannot install an exception handler interactively.
961
 
962
   Sometimes `catch' is not the best way to debug exception handling:
963
if you need to know exactly where an exception is raised, it is better
964
to stop _before_ the exception handler is called, since that way you
965
can see the stack before any unwinding takes place.  If you set a
966
breakpoint in an exception handler instead, it may not be easy to find
967
out where the exception was raised.
968
 
969
   To stop just before an exception handler is called, you need some
970
knowledge of the implementation.  In the case of GNU C++, exceptions are
971
raised by calling a library function named `__raise_exception' which
972
has the following ANSI C interface:
973
 
974
         /* ADDR is where the exception identifier is stored.
975
            ID is the exception identifier.  */
976
         void __raise_exception (void **addr, void *id);
977
 
978
To make the debugger catch all exceptions before any stack unwinding
979
takes place, set a breakpoint on `__raise_exception' (*note
980
Breakpoints; watchpoints; and exceptions: Breakpoints.).
981
 
982
   With a conditional breakpoint (*note Break conditions: Conditions.)
983
that depends on the value of ID, you can stop your program when a
984
specific exception is raised.  You can use multiple conditional
985
breakpoints to stop your program when any of a number of exceptions are
986
raised.
987
 
988

989
File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Set Catchpoints,  Up: Breakpoints
990
 
991
Deleting breakpoints
992
--------------------
993
 
994
   It is often necessary to eliminate a breakpoint, watchpoint, or
995
catchpoint once it has done its job and you no longer want your program
996
to stop there.  This is called "deleting" the breakpoint.  A breakpoint
997
that has been deleted no longer exists; it is forgotten.
998
 
999
   With the `clear' command you can delete breakpoints according to
1000
where they are in your program.  With the `delete' command you can
1001
delete individual breakpoints, watchpoints, or catchpoints by specifying
1002
their breakpoint numbers.
1003
 
1004
   It is not necessary to delete a breakpoint to proceed past it.  GDB
1005
automatically ignores breakpoints on the first instruction to be
1006
executed when you continue execution without changing the execution
1007
address.
1008
 
1009
`clear'
1010
     Delete any breakpoints at the next instruction to be executed in
1011
     the selected stack frame (*note Selecting a frame: Selection.).
1012
     When the innermost frame is selected, this is a good way to delete
1013
     a breakpoint where your program just stopped.
1014
 
1015
`clear FUNCTION'
1016
`clear FILENAME:FUNCTION'
1017
     Delete any breakpoints set at entry to the function FUNCTION.
1018
 
1019
`clear LINENUM'
1020
`clear FILENAME:LINENUM'
1021
     Delete any breakpoints set at or within the code of the specified
1022
     line.
1023
 
1024
`delete [breakpoints] [RANGE...]'
1025
     Delete the breakpoints, watchpoints, or catchpoints of the
1026
     breakpoint ranges specified as arguments.  If no argument is
1027
     specified, delete all breakpoints (GDB asks confirmation, unless
1028
     you have `set confirm off').  You can abbreviate this command as
1029
     `d'.
1030
 
1031

1032
File: gdb.info,  Node: Disabling,  Next: Conditions,  Prev: Delete Breaks,  Up: Breakpoints
1033
 
1034
Disabling breakpoints
1035
---------------------
1036
 
1037
   Rather than deleting a breakpoint, watchpoint, or catchpoint, you
1038
might prefer to "disable" it.  This makes the breakpoint inoperative as
1039
if it had been deleted, but remembers the information on the breakpoint
1040
so that you can "enable" it again later.
1041
 
1042
   You disable and enable breakpoints, watchpoints, and catchpoints with
1043
the `enable' and `disable' commands, optionally specifying one or more
1044
breakpoint numbers as arguments.  Use `info break' or `info watch' to
1045
print a list of breakpoints, watchpoints, and catchpoints if you do not
1046
know which numbers to use.
1047
 
1048
   A breakpoint, watchpoint, or catchpoint can have any of four
1049
different states of enablement:
1050
 
1051
   * Enabled.  The breakpoint stops your program.  A breakpoint set
1052
     with the `break' command starts out in this state.
1053
 
1054
   * Disabled.  The breakpoint has no effect on your program.
1055
 
1056
   * Enabled once.  The breakpoint stops your program, but then becomes
1057
     disabled.
1058
 
1059
   * Enabled for deletion.  The breakpoint stops your program, but
1060
     immediately after it does so it is deleted permanently.  A
1061
     breakpoint set with the `tbreak' command starts out in this state.
1062
 
1063
   You can use the following commands to enable or disable breakpoints,
1064
watchpoints, and catchpoints:
1065
 
1066
`disable [breakpoints] [RANGE...]'
1067
     Disable the specified breakpoints--or all breakpoints, if none are
1068
     listed.  A disabled breakpoint has no effect but is not forgotten.
1069
     All options such as ignore-counts, conditions and commands are
1070
     remembered in case the breakpoint is enabled again later.  You may
1071
     abbreviate `disable' as `dis'.
1072
 
1073
`enable [breakpoints] [RANGE...]'
1074
     Enable the specified breakpoints (or all defined breakpoints).
1075
     They become effective once again in stopping your program.
1076
 
1077
`enable [breakpoints] once RANGE...'
1078
     Enable the specified breakpoints temporarily.  GDB disables any of
1079
     these breakpoints immediately after stopping your program.
1080
 
1081
`enable [breakpoints] delete RANGE...'
1082
     Enable the specified breakpoints to work once, then die.  GDB
1083
     deletes any of these breakpoints as soon as your program stops
1084
     there.
1085
 
1086
   Except for a breakpoint set with `tbreak' (*note Setting
1087
breakpoints: Set Breaks.), breakpoints that you set are initially
1088
enabled; subsequently, they become disabled or enabled only when you
1089
use one of the commands above.  (The command `until' can set and delete
1090
a breakpoint of its own, but it does not change the state of your other
1091
breakpoints; see *Note Continuing and stepping: Continuing and
1092
Stepping.)
1093
 

powered by: WebSVN 2.1.0

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