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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [gdb-5.3/] [gdb/] [doc/] [gdb.info-6] - Blame information for rev 1181

Go to most recent revision | 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: Checks,  Next: Support,  Prev: Show,  Up: Languages
31
 
32
Type and range checking
33
=======================
34
 
35
     _Warning:_ In this release, the GDB commands for type and range
36
     checking are included, but they do not yet have any effect.  This
37
     section documents the intended facilities.
38
 
39
   Some languages are designed to guard you against making seemingly
40
common errors through a series of compile- and run-time checks.  These
41
include checking the type of arguments to functions and operators, and
42
making sure mathematical overflows are caught at run time.  Checks such
43
as these help to ensure a program's correctness once it has been
44
compiled by eliminating type mismatches, and providing active checks
45
for range errors when your program is running.
46
 
47
   GDB can check for conditions like the above if you wish.  Although
48
GDB does not check the statements in your program, it can check
49
expressions entered directly into GDB for evaluation via the `print'
50
command, for example.  As with the working language, GDB can also
51
decide whether or not to check automatically based on your program's
52
source language.  *Note Supported languages: Support, for the default
53
settings of supported languages.
54
 
55
* Menu:
56
 
57
* Type Checking::               An overview of type checking
58
* Range Checking::              An overview of range checking
59
 
60

61
File: gdb.info,  Node: Type Checking,  Next: Range Checking,  Up: Checks
62
 
63
An overview of type checking
64
----------------------------
65
 
66
   Some languages, such as Modula-2, are strongly typed, meaning that
67
the arguments to operators and functions have to be of the correct type,
68
otherwise an error occurs.  These checks prevent type mismatch errors
69
from ever causing any run-time problems.  For example,
70
 
71
     1 + 2 => 3
72
but
73
     error--> 1 + 2.3
74
 
75
   The second example fails because the `CARDINAL' 1 is not
76
type-compatible with the `REAL' 2.3.
77
 
78
   For the expressions you use in GDB commands, you can tell the GDB
79
type checker to skip checking; to treat any mismatches as errors and
80
abandon the expression; or to only issue warnings when type mismatches
81
occur, but evaluate the expression anyway.  When you choose the last of
82
these, GDB evaluates expressions like the second example above, but
83
also issues a warning.
84
 
85
   Even if you turn type checking off, there may be other reasons
86
related to type that prevent GDB from evaluating an expression.  For
87
instance, GDB does not know how to add an `int' and a `struct foo'.
88
These particular type errors have nothing to do with the language in
89
use, and usually arise from expressions, such as the one described
90
above, which make little sense to evaluate anyway.
91
 
92
   Each language defines to what degree it is strict about type.  For
93
instance, both Modula-2 and C require the arguments to arithmetical
94
operators to be numbers.  In C, enumerated types and pointers can be
95
represented as numbers, so that they are valid arguments to mathematical
96
operators.  *Note Supported languages: Support, for further details on
97
specific languages.
98
 
99
   GDB provides some additional commands for controlling the type
100
checker:
101
 
102
`set check type auto'
103
     Set type checking on or off based on the current working language.
104
     *Note Supported languages: Support, for the default settings for
105
     each language.
106
 
107
`set check type on'
108
`set check type off'
109
     Set type checking on or off, overriding the default setting for the
110
     current working language.  Issue a warning if the setting does not
111
     match the language default.  If any type mismatches occur in
112
     evaluating an expression while type checking is on, GDB prints a
113
     message and aborts evaluation of the expression.
114
 
115
`set check type warn'
116
     Cause the type checker to issue warnings, but to always attempt to
117
     evaluate the expression.  Evaluating the expression may still be
118
     impossible for other reasons.  For example, GDB cannot add numbers
119
     and structures.
120
 
121
`show type'
122
     Show the current setting of the type checker, and whether or not
123
     GDB is setting it automatically.
124
 
125

126
File: gdb.info,  Node: Range Checking,  Prev: Type Checking,  Up: Checks
127
 
128
An overview of range checking
129
-----------------------------
130
 
131
   In some languages (such as Modula-2), it is an error to exceed the
132
bounds of a type; this is enforced with run-time checks.  Such range
133
checking is meant to ensure program correctness by making sure
134
computations do not overflow, or indices on an array element access do
135
not exceed the bounds of the array.
136
 
137
   For expressions you use in GDB commands, you can tell GDB to treat
138
range errors in one of three ways: ignore them, always treat them as
139
errors and abandon the expression, or issue warnings but evaluate the
140
expression anyway.
141
 
142
   A range error can result from numerical overflow, from exceeding an
143
array index bound, or when you type a constant that is not a member of
144
any type.  Some languages, however, do not treat overflows as an error.
145
In many implementations of C, mathematical overflow causes the result
146
to "wrap around" to lower values--for example, if M is the largest
147
integer value, and S is the smallest, then
148
 
149
     M + 1 => S
150
 
151
   This, too, is specific to individual languages, and in some cases
152
specific to individual compilers or machines.  *Note Supported
153
languages: Support, for further details on specific languages.
154
 
155
   GDB provides some additional commands for controlling the range
156
checker:
157
 
158
`set check range auto'
159
     Set range checking on or off based on the current working language.
160
     *Note Supported languages: Support, for the default settings for
161
     each language.
162
 
163
`set check range on'
164
`set check range off'
165
     Set range checking on or off, overriding the default setting for
166
     the current working language.  A warning is issued if the setting
167
     does not match the language default.  If a range error occurs and
168
     range checking is on, then a message is printed and evaluation of
169
     the expression is aborted.
170
 
171
`set check range warn'
172
     Output messages when the GDB range checker detects a range error,
173
     but attempt to evaluate the expression anyway.  Evaluating the
174
     expression may still be impossible for other reasons, such as
175
     accessing memory that the process does not own (a typical example
176
     from many Unix systems).
177
 
178
`show range'
179
     Show the current setting of the range checker, and whether or not
180
     it is being set automatically by GDB.
181
 
182

183
File: gdb.info,  Node: Support,  Prev: Checks,  Up: Languages
184
 
185
Supported languages
186
===================
187
 
188
   GDB supports C, C++, Fortran, Java, assembly, and Modula-2.  Some
189
GDB features may be used in expressions regardless of the language you
190
use: the GDB `@' and `::' operators, and the `{type}addr' construct
191
(*note Expressions: Expressions.) can be used with the constructs of
192
any supported language.
193
 
194
   The following sections detail to what degree each source language is
195
supported by GDB.  These sections are not meant to be language
196
tutorials or references, but serve only as a reference guide to what the
197
GDB expression parser accepts, and what input and output formats should
198
look like for different languages.  There are many good books written
199
on each of these languages; please look to these for a language
200
reference or tutorial.
201
 
202
* Menu:
203
 
204
* C::           C and C++
205
* Modula-2::    Modula-2
206
 
207

208
File: gdb.info,  Node: C,  Next: Modula-2,  Up: Support
209
 
210
C and C++
211
---------
212
 
213
   Since C and C++ are so closely related, many features of GDB apply
214
to both languages.  Whenever this is the case, we discuss those
215
languages together.
216
 
217
   The C++ debugging facilities are jointly implemented by the C++
218
compiler and GDB.  Therefore, to debug your C++ code effectively, you
219
must compile your C++ programs with a supported C++ compiler, such as
220
GNU `g++', or the HP ANSI C++ compiler (`aCC').
221
 
222
   For best results when using GNU C++, use the stabs debugging format.
223
You can select that format explicitly with the `g++' command-line
224
options `-gstabs' or `-gstabs+'.  See *Note Options for Debugging Your
225
Program or GNU CC: (gcc.info)Debugging Options, for more information.
226
 
227
* Menu:
228
 
229
* C Operators::                 C and C++ operators
230
* C Constants::                 C and C++ constants
231
* C plus plus expressions::     C++ expressions
232
* C Defaults::                  Default settings for C and C++
233
* C Checks::                    C and C++ type and range checks
234
* Debugging C::                 GDB and C
235
* Debugging C plus plus::       GDB features for C++
236
 
237

238
File: gdb.info,  Node: C Operators,  Next: C Constants,  Up: C
239
 
240
C and C++ operators
241
...................
242
 
243
   Operators must be defined on values of specific types.  For instance,
244
`+' is defined on numbers, but not on structures.  Operators are often
245
defined on groups of types.
246
 
247
   For the purposes of C and C++, the following definitions hold:
248
 
249
   * _Integral types_ include `int' with any of its storage-class
250
     specifiers; `char'; `enum'; and, for C++, `bool'.
251
 
252
   * _Floating-point types_ include `float', `double', and `long
253
     double' (if supported by the target platform).
254
 
255
   * _Pointer types_ include all types defined as `(TYPE *)'.
256
 
257
   * _Scalar types_ include all of the above.
258
 
259
 
260
The following operators are supported.  They are listed here in order
261
of increasing precedence:
262
 
263
`,'
264
     The comma or sequencing operator.  Expressions in a
265
     comma-separated list are evaluated from left to right, with the
266
     result of the entire expression being the last expression
267
     evaluated.
268
 
269
`='
270
     Assignment.  The value of an assignment expression is the value
271
     assigned.  Defined on scalar types.
272
 
273
`OP='
274
     Used in an expression of the form `A OP= B', and translated to
275
     `A = A OP B'.  `OP=' and `=' have the same precedence.  OP is any
276
     one of the operators `|', `^', `&', `<<', `>>', `+', `-', `*',
277
     `/', `%'.
278
 
279
`?:'
280
     The ternary operator.  `A ? B : C' can be thought of as:  if A
281
     then B else C.  A should be of an integral type.
282
 
283
`||'
284
     Logical OR.  Defined on integral types.
285
 
286
`&&'
287
     Logical AND.  Defined on integral types.
288
 
289
`|'
290
     Bitwise OR.  Defined on integral types.
291
 
292
`^'
293
     Bitwise exclusive-OR.  Defined on integral types.
294
 
295
`&'
296
     Bitwise AND.  Defined on integral types.
297
 
298
`==, !='
299
     Equality and inequality.  Defined on scalar types.  The value of
300
     these expressions is 0 for false and non-zero for true.
301
 
302
`<, >, <=, >='
303
     Less than, greater than, less than or equal, greater than or equal.
304
     Defined on scalar types.  The value of these expressions is 0 for
305
     false and non-zero for true.
306
 
307
`<<, >>'
308
     left shift, and right shift.  Defined on integral types.
309
 
310
`@'
311
     The GDB "artificial array" operator (*note Expressions:
312
     Expressions.).
313
 
314
`+, -'
315
     Addition and subtraction.  Defined on integral types,
316
     floating-point types and pointer types.
317
 
318
`*, /, %'
319
     Multiplication, division, and modulus.  Multiplication and
320
     division are defined on integral and floating-point types.
321
     Modulus is defined on integral types.
322
 
323
`++, --'
324
     Increment and decrement.  When appearing before a variable, the
325
     operation is performed before the variable is used in an
326
     expression; when appearing after it, the variable's value is used
327
     before the operation takes place.
328
 
329
`*'
330
     Pointer dereferencing.  Defined on pointer types.  Same precedence
331
     as `++'.
332
 
333
`&'
334
     Address operator.  Defined on variables.  Same precedence as `++'.
335
 
336
     For debugging C++, GDB implements a use of `&' beyond what is
337
     allowed in the C++ language itself: you can use `&(&REF)' (or, if
338
     you prefer, simply `&&REF') to examine the address where a C++
339
     reference variable (declared with `&REF') is stored.
340
 
341
`-'
342
     Negative.  Defined on integral and floating-point types.  Same
343
     precedence as `++'.
344
 
345
`!'
346
     Logical negation.  Defined on integral types.  Same precedence as
347
     `++'.
348
 
349
`~'
350
     Bitwise complement operator.  Defined on integral types.  Same
351
     precedence as `++'.
352
 
353
`., ->'
354
     Structure member, and pointer-to-structure member.  For
355
     convenience, GDB regards the two as equivalent, choosing whether
356
     to dereference a pointer based on the stored type information.
357
     Defined on `struct' and `union' data.
358
 
359
`.*, ->*'
360
     Dereferences of pointers to members.
361
 
362
`[]'
363
     Array indexing.  `A[I]' is defined as `*(A+I)'.  Same precedence
364
     as `->'.
365
 
366
`()'
367
     Function parameter list.  Same precedence as `->'.
368
 
369
`::'
370
     C++ scope resolution operator.  Defined on `struct', `union', and
371
     `class' types.
372
 
373
`::'
374
     Doubled colons also represent the GDB scope operator (*note
375
     Expressions: Expressions.).  Same precedence as `::', above.
376
 
377
   If an operator is redefined in the user code, GDB usually attempts
378
to invoke the redefined version instead of using the operator's
379
predefined meaning.
380
 
381
* Menu:
382
 
383
* C Constants::
384
 
385

386
File: gdb.info,  Node: C Constants,  Next: C plus plus expressions,  Prev: C Operators,  Up: C
387
 
388
C and C++ constants
389
...................
390
 
391
   GDB allows you to express the constants of C and C++ in the
392
following ways:
393
 
394
   * Integer constants are a sequence of digits.  Octal constants are
395
     specified by a leading `0' (i.e. zero), and hexadecimal constants
396
     by a leading `0x' or `0X'.  Constants may also end with a letter
397
     `l', specifying that the constant should be treated as a `long'
398
     value.
399
 
400
   * Floating point constants are a sequence of digits, followed by a
401
     decimal point, followed by a sequence of digits, and optionally
402
     followed by an exponent.  An exponent is of the form:
403
     `e[[+]|-]NNN', where NNN is another sequence of digits.  The `+'
404
     is optional for positive exponents.  A floating-point constant may
405
     also end with a letter `f' or `F', specifying that the constant
406
     should be treated as being of the `float' (as opposed to the
407
     default `double') type; or with a letter `l' or `L', which
408
     specifies a `long double' constant.
409
 
410
   * Enumerated constants consist of enumerated identifiers, or their
411
     integral equivalents.
412
 
413
   * Character constants are a single character surrounded by single
414
     quotes (`''), or a number--the ordinal value of the corresponding
415
     character (usually its ASCII value).  Within quotes, the single
416
     character may be represented by a letter or by "escape sequences",
417
     which are of the form `\NNN', where NNN is the octal representation
418
     of the character's ordinal value; or of the form `\X', where `X'
419
     is a predefined special character--for example, `\n' for newline.
420
 
421
   * String constants are a sequence of character constants surrounded
422
     by double quotes (`"').  Any valid character constant (as described
423
     above) may appear.  Double quotes within the string must be
424
     preceded by a backslash, so for instance `"a\"b'c"' is a string of
425
     five characters.
426
 
427
   * Pointer constants are an integral value.  You can also write
428
     pointers to constants using the C operator `&'.
429
 
430
   * Array constants are comma-separated lists surrounded by braces `{'
431
     and `}'; for example, `{1,2,3}' is a three-element array of
432
     integers, `{{1,2}, {3,4}, {5,6}}' is a three-by-two array, and
433
     `{&"hi", &"there", &"fred"}' is a three-element array of pointers.
434
 
435
* Menu:
436
 
437
* C plus plus expressions::
438
* C Defaults::
439
* C Checks::
440
 
441
* Debugging C::
442
 
443

444
File: gdb.info,  Node: C plus plus expressions,  Next: C Defaults,  Prev: C Constants,  Up: C
445
 
446
C++ expressions
447
...............
448
 
449
   GDB expression handling can interpret most C++ expressions.
450
 
451
     _Warning:_ GDB can only debug C++ code if you use the proper
452
     compiler.  Typically, C++ debugging depends on the use of
453
     additional debugging information in the symbol table, and thus
454
     requires special support.  In particular, if your compiler
455
     generates a.out, MIPS ECOFF, RS/6000 XCOFF, or ELF with stabs
456
     extensions to the symbol table, these facilities are all
457
     available.  (With GNU CC, you can use the `-gstabs' option to
458
     request stabs debugging extensions explicitly.)  Where the object
459
     code format is standard COFF or DWARF in ELF, on the other hand,
460
     most of the C++ support in GDB does _not_ work.
461
 
462
  1. Member function calls are allowed; you can use expressions like
463
 
464
          count = aml->GetOriginal(x, y)
465
 
466
  2. While a member function is active (in the selected stack frame),
467
     your expressions have the same namespace available as the member
468
     function; that is, GDB allows implicit references to the class
469
     instance pointer `this' following the same rules as C++.
470
 
471
  3. You can call overloaded functions; GDB resolves the function call
472
     to the right definition, with some restrictions.  GDB does not
473
     perform overload resolution involving user-defined type
474
     conversions, calls to constructors, or instantiations of templates
475
     that do not exist in the program.  It also cannot handle ellipsis
476
     argument lists or default arguments.
477
 
478
     It does perform integral conversions and promotions, floating-point
479
     promotions, arithmetic conversions, pointer conversions,
480
     conversions of class objects to base classes, and standard
481
     conversions such as those of functions or arrays to pointers; it
482
     requires an exact match on the number of function arguments.
483
 
484
     Overload resolution is always performed, unless you have specified
485
     `set overload-resolution off'.  *Note GDB features for C++:
486
     Debugging C plus plus.
487
 
488
     You must specify `set overload-resolution off' in order to use an
489
     explicit function signature to call an overloaded function, as in
490
          p 'foo(char,int)'('x', 13)
491
 
492
     The GDB command-completion facility can simplify this; see *Note
493
     Command completion: Completion.
494
 
495
  4. GDB understands variables declared as C++ references; you can use
496
     them in expressions just as you do in C++ source--they are
497
     automatically dereferenced.
498
 
499
     In the parameter list shown when GDB displays a frame, the values
500
     of reference variables are not displayed (unlike other variables);
501
     this avoids clutter, since references are often used for large
502
     structures.  The _address_ of a reference variable is always
503
     shown, unless you have specified `set print address off'.
504
 
505
  5. GDB supports the C++ name resolution operator `::'--your
506
     expressions can use it just as expressions in your program do.
507
     Since one scope may be defined in another, you can use `::'
508
     repeatedly if necessary, for example in an expression like
509
     `SCOPE1::SCOPE2::NAME'.  GDB also allows resolving name scope by
510
     reference to source files, in both C and C++ debugging (*note
511
     Program variables: Variables.).
512
 
513
   In addition, when used with HP's C++ compiler, GDB supports calling
514
virtual functions correctly, printing out virtual bases of objects,
515
calling functions in a base subobject, casting objects, and invoking
516
user-defined operators.
517
 
518

519
File: gdb.info,  Node: C Defaults,  Next: C Checks,  Prev: C plus plus expressions,  Up: C
520
 
521
C and C++ defaults
522
..................
523
 
524
   If you allow GDB to set type and range checking automatically, they
525
both default to `off' whenever the working language changes to C or
526
C++.  This happens regardless of whether you or GDB selects the working
527
language.
528
 
529
   If you allow GDB to set the language automatically, it recognizes
530
source files whose names end with `.c', `.C', or `.cc', etc, and when
531
GDB enters code compiled from one of these files, it sets the working
532
language to C or C++.  *Note Having GDB infer the source language:
533
Automatically, for further details.
534
 
535

536
File: gdb.info,  Node: C Checks,  Next: Debugging C,  Prev: C Defaults,  Up: C
537
 
538
C and C++ type and range checks
539
...............................
540
 
541
   By default, when GDB parses C or C++ expressions, type checking is
542
not used.  However, if you turn type checking on, GDB considers two
543
variables type equivalent if:
544
 
545
   * The two variables are structured and have the same structure,
546
     union, or enumerated tag.
547
 
548
   * The two variables have the same type name, or types that have been
549
     declared equivalent through `typedef'.
550
 
551
 
552
   Range checking, if turned on, is done on mathematical operations.
553
Array indices are not checked, since they are often used to index a
554
pointer that is not itself an array.
555
 
556

557
File: gdb.info,  Node: Debugging C,  Next: Debugging C plus plus,  Prev: C Checks,  Up: C
558
 
559
GDB and C
560
.........
561
 
562
   The `set print union' and `show print union' commands apply to the
563
`union' type.  When set to `on', any `union' that is inside a `struct'
564
or `class' is also printed.  Otherwise, it appears as `{...}'.
565
 
566
   The `@' operator aids in the debugging of dynamic arrays, formed
567
with pointers and a memory allocation function.  *Note Expressions:
568
Expressions.
569
 
570
* Menu:
571
 
572
* Debugging C plus plus::
573
 
574

575
File: gdb.info,  Node: Debugging C plus plus,  Prev: Debugging C,  Up: C
576
 
577
GDB features for C++
578
....................
579
 
580
   Some GDB commands are particularly useful with C++, and some are
581
designed specifically for use with C++.  Here is a summary:
582
 
583
`breakpoint menus'
584
     When you want a breakpoint in a function whose name is overloaded,
585
     GDB breakpoint menus help you specify which function definition
586
     you want.  *Note Breakpoint menus: Breakpoint Menus.
587
 
588
`rbreak REGEX'
589
     Setting breakpoints using regular expressions is helpful for
590
     setting breakpoints on overloaded functions that are not members
591
     of any special classes.  *Note Setting breakpoints: Set Breaks.
592
 
593
`catch throw'
594
`catch catch'
595
     Debug C++ exception handling using these commands.  *Note Setting
596
     catchpoints: Set Catchpoints.
597
 
598
`ptype TYPENAME'
599
     Print inheritance relationships as well as other information for
600
     type TYPENAME.  *Note Examining the Symbol Table: Symbols.
601
 
602
`set print demangle'
603
`show print demangle'
604
`set print asm-demangle'
605
`show print asm-demangle'
606
     Control whether C++ symbols display in their source form, both when
607
     displaying code as C++ source and when displaying disassemblies.
608
     *Note Print settings: Print Settings.
609
 
610
`set print object'
611
`show print object'
612
     Choose whether to print derived (actual) or declared types of
613
     objects.  *Note Print settings: Print Settings.
614
 
615
`set print vtbl'
616
`show print vtbl'
617
     Control the format for printing virtual function tables.  *Note
618
     Print settings: Print Settings.  (The `vtbl' commands do not work
619
     on programs compiled with the HP ANSI C++ compiler (`aCC').)
620
 
621
`set overload-resolution on'
622
     Enable overload resolution for C++ expression evaluation.  The
623
     default is on.  For overloaded functions, GDB evaluates the
624
     arguments and searches for a function whose signature matches the
625
     argument types, using the standard C++ conversion rules (see *Note
626
     C++ expressions: C plus plus expressions, for details).  If it
627
     cannot find a match, it emits a message.
628
 
629
`set overload-resolution off'
630
     Disable overload resolution for C++ expression evaluation.  For
631
     overloaded functions that are not class member functions, GDB
632
     chooses the first function of the specified name that it finds in
633
     the symbol table, whether or not its arguments are of the correct
634
     type.  For overloaded functions that are class member functions,
635
     GDB searches for a function whose signature _exactly_ matches the
636
     argument types.
637
 
638
`Overloaded symbol names'
639
     You can specify a particular definition of an overloaded symbol,
640
     using the same notation that is used to declare such symbols in
641
     C++: type `SYMBOL(TYPES)' rather than just SYMBOL.  You can also
642
     use the GDB command-line word completion facilities to list the
643
     available choices, or to finish the type list for you.  *Note
644
     Command completion: Completion, for details on how to do this.
645
 
646

647
File: gdb.info,  Node: Modula-2,  Prev: C,  Up: Support
648
 
649
Modula-2
650
--------
651
 
652
   The extensions made to GDB to support Modula-2 only support output
653
from the GNU Modula-2 compiler (which is currently being developed).
654
Other Modula-2 compilers are not currently supported, and attempting to
655
debug executables produced by them is most likely to give an error as
656
GDB reads in the executable's symbol table.
657
 
658
* Menu:
659
 
660
* M2 Operators::                Built-in operators
661
* Built-In Func/Proc::          Built-in functions and procedures
662
* M2 Constants::                Modula-2 constants
663
* M2 Defaults::                 Default settings for Modula-2
664
* Deviations::                  Deviations from standard Modula-2
665
* M2 Checks::                   Modula-2 type and range checks
666
* M2 Scope::                    The scope operators `::' and `.'
667
* GDB/M2::                      GDB and Modula-2
668
 
669

670
File: gdb.info,  Node: M2 Operators,  Next: Built-In Func/Proc,  Up: Modula-2
671
 
672
Operators
673
.........
674
 
675
   Operators must be defined on values of specific types.  For instance,
676
`+' is defined on numbers, but not on structures.  Operators are often
677
defined on groups of types.  For the purposes of Modula-2, the
678
following definitions hold:
679
 
680
   * _Integral types_ consist of `INTEGER', `CARDINAL', and their
681
     subranges.
682
 
683
   * _Character types_ consist of `CHAR' and its subranges.
684
 
685
   * _Floating-point types_ consist of `REAL'.
686
 
687
   * _Pointer types_ consist of anything declared as `POINTER TO TYPE'.
688
 
689
   * _Scalar types_ consist of all of the above.
690
 
691
   * _Set types_ consist of `SET' and `BITSET' types.
692
 
693
   * _Boolean types_ consist of `BOOLEAN'.
694
 
695
The following operators are supported, and appear in order of
696
increasing precedence:
697
 
698
`,'
699
     Function argument or array index separator.
700
 
701
`:='
702
     Assignment.  The value of VAR `:=' VALUE is VALUE.
703
 
704
`<, >'
705
     Less than, greater than on integral, floating-point, or enumerated
706
     types.
707
 
708
`<=, >='
709
     Less than or equal to, greater than or equal to on integral,
710
     floating-point and enumerated types, or set inclusion on set
711
     types.  Same precedence as `<'.
712
 
713
`=, <>, #'
714
     Equality and two ways of expressing inequality, valid on scalar
715
     types.  Same precedence as `<'.  In GDB scripts, only `<>' is
716
     available for inequality, since `#' conflicts with the script
717
     comment character.
718
 
719
`IN'
720
     Set membership.  Defined on set types and the types of their
721
     members.  Same precedence as `<'.
722
 
723
`OR'
724
     Boolean disjunction.  Defined on boolean types.
725
 
726
`AND, &'
727
     Boolean conjunction.  Defined on boolean types.
728
 
729
`@'
730
     The GDB "artificial array" operator (*note Expressions:
731
     Expressions.).
732
 
733
`+, -'
734
     Addition and subtraction on integral and floating-point types, or
735
     union and difference on set types.
736
 
737
`*'
738
     Multiplication on integral and floating-point types, or set
739
     intersection on set types.
740
 
741
`/'
742
     Division on floating-point types, or symmetric set difference on
743
     set types.  Same precedence as `*'.
744
 
745
`DIV, MOD'
746
     Integer division and remainder.  Defined on integral types.  Same
747
     precedence as `*'.
748
 
749
`-'
750
     Negative. Defined on `INTEGER' and `REAL' data.
751
 
752
`^'
753
     Pointer dereferencing.  Defined on pointer types.
754
 
755
`NOT'
756
     Boolean negation.  Defined on boolean types.  Same precedence as
757
     `^'.
758
 
759
`.'
760
     `RECORD' field selector.  Defined on `RECORD' data.  Same
761
     precedence as `^'.
762
 
763
`[]'
764
     Array indexing.  Defined on `ARRAY' data.  Same precedence as `^'.
765
 
766
`()'
767
     Procedure argument list.  Defined on `PROCEDURE' objects.  Same
768
     precedence as `^'.
769
 
770
`::, .'
771
     GDB and Modula-2 scope operators.
772
 
773
     _Warning:_ Sets and their operations are not yet supported, so GDB
774
     treats the use of the operator `IN', or the use of operators `+',
775
     `-', `*', `/', `=', , `<>', `#', `<=', and `>=' on sets as an
776
     error.
777
 
778

779
File: gdb.info,  Node: Built-In Func/Proc,  Next: M2 Constants,  Prev: M2 Operators,  Up: Modula-2
780
 
781
Built-in functions and procedures
782
.................................
783
 
784
   Modula-2 also makes available several built-in procedures and
785
functions.  In describing these, the following metavariables are used:
786
 
787
A
788
     represents an `ARRAY' variable.
789
 
790
C
791
     represents a `CHAR' constant or variable.
792
 
793
I
794
     represents a variable or constant of integral type.
795
 
796
M
797
     represents an identifier that belongs to a set.  Generally used in
798
     the same function with the metavariable S.  The type of S should
799
     be `SET OF MTYPE' (where MTYPE is the type of M).
800
 
801
N
802
     represents a variable or constant of integral or floating-point
803
     type.
804
 
805
R
806
     represents a variable or constant of floating-point type.
807
 
808
T
809
     represents a type.
810
 
811
V
812
     represents a variable.
813
 
814
X
815
     represents a variable or constant of one of many types.  See the
816
     explanation of the function for details.
817
 
818
   All Modula-2 built-in procedures also return a result, described
819
below.
820
 
821
`ABS(N)'
822
     Returns the absolute value of N.
823
 
824
`CAP(C)'
825
     If C is a lower case letter, it returns its upper case equivalent,
826
     otherwise it returns its argument.
827
 
828
`CHR(I)'
829
     Returns the character whose ordinal value is I.
830
 
831
`DEC(V)'
832
     Decrements the value in the variable V by one.  Returns the new
833
     value.
834
 
835
`DEC(V,I)'
836
     Decrements the value in the variable V by I.  Returns the new
837
     value.
838
 
839
`EXCL(M,S)'
840
     Removes the element M from the set S.  Returns the new set.
841
 
842
`FLOAT(I)'
843
     Returns the floating point equivalent of the integer I.
844
 
845
`HIGH(A)'
846
     Returns the index of the last member of A.
847
 
848
`INC(V)'
849
     Increments the value in the variable V by one.  Returns the new
850
     value.
851
 
852
`INC(V,I)'
853
     Increments the value in the variable V by I.  Returns the new
854
     value.
855
 
856
`INCL(M,S)'
857
     Adds the element M to the set S if it is not already there.
858
     Returns the new set.
859
 
860
`MAX(T)'
861
     Returns the maximum value of the type T.
862
 
863
`MIN(T)'
864
     Returns the minimum value of the type T.
865
 
866
`ODD(I)'
867
     Returns boolean TRUE if I is an odd number.
868
 
869
`ORD(X)'
870
     Returns the ordinal value of its argument.  For example, the
871
     ordinal value of a character is its ASCII value (on machines
872
     supporting the ASCII character set).  X must be of an ordered
873
     type, which include integral, character and enumerated types.
874
 
875
`SIZE(X)'
876
     Returns the size of its argument.  X can be a variable or a type.
877
 
878
`TRUNC(R)'
879
     Returns the integral part of R.
880
 
881
`VAL(T,I)'
882
     Returns the member of the type T whose ordinal value is I.
883
 
884
     _Warning:_  Sets and their operations are not yet supported, so
885
     GDB treats the use of procedures `INCL' and `EXCL' as an error.
886
 
887

888
File: gdb.info,  Node: M2 Constants,  Next: M2 Defaults,  Prev: Built-In Func/Proc,  Up: Modula-2
889
 
890
Constants
891
.........
892
 
893
   GDB allows you to express the constants of Modula-2 in the following
894
ways:
895
 
896
   * Integer constants are simply a sequence of digits.  When used in an
897
     expression, a constant is interpreted to be type-compatible with
898
     the rest of the expression.  Hexadecimal integers are specified by
899
     a trailing `H', and octal integers by a trailing `B'.
900
 
901
   * Floating point constants appear as a sequence of digits, followed
902
     by a decimal point and another sequence of digits.  An optional
903
     exponent can then be specified, in the form `E[+|-]NNN', where
904
     `[+|-]NNN' is the desired exponent.  All of the digits of the
905
     floating point constant must be valid decimal (base 10) digits.
906
 
907
   * Character constants consist of a single character enclosed by a
908
     pair of like quotes, either single (`'') or double (`"').  They may
909
     also be expressed by their ordinal value (their ASCII value,
910
     usually) followed by a `C'.
911
 
912
   * String constants consist of a sequence of characters enclosed by a
913
     pair of like quotes, either single (`'') or double (`"').  Escape
914
     sequences in the style of C are also allowed.  *Note C and C++
915
     constants: C Constants, for a brief explanation of escape
916
     sequences.
917
 
918
   * Enumerated constants consist of an enumerated identifier.
919
 
920
   * Boolean constants consist of the identifiers `TRUE' and `FALSE'.
921
 
922
   * Pointer constants consist of integral values only.
923
 
924
   * Set constants are not yet supported.
925
 
926

927
File: gdb.info,  Node: M2 Defaults,  Next: Deviations,  Prev: M2 Constants,  Up: Modula-2
928
 
929
Modula-2 defaults
930
.................
931
 
932
   If type and range checking are set automatically by GDB, they both
933
default to `on' whenever the working language changes to Modula-2.
934
This happens regardless of whether you or GDB selected the working
935
language.
936
 
937
   If you allow GDB to set the language automatically, then entering
938
code compiled from a file whose name ends with `.mod' sets the working
939
language to Modula-2.  *Note Having GDB set the language automatically:
940
Automatically, for further details.
941
 
942

943
File: gdb.info,  Node: Deviations,  Next: M2 Checks,  Prev: M2 Defaults,  Up: Modula-2
944
 
945
Deviations from standard Modula-2
946
.................................
947
 
948
   A few changes have been made to make Modula-2 programs easier to
949
debug.  This is done primarily via loosening its type strictness:
950
 
951
   * Unlike in standard Modula-2, pointer constants can be formed by
952
     integers.  This allows you to modify pointer variables during
953
     debugging.  (In standard Modula-2, the actual address contained in
954
     a pointer variable is hidden from you; it can only be modified
955
     through direct assignment to another pointer variable or
956
     expression that returned a pointer.)
957
 
958
   * C escape sequences can be used in strings and characters to
959
     represent non-printable characters.  GDB prints out strings with
960
     these escape sequences embedded.  Single non-printable characters
961
     are printed using the `CHR(NNN)' format.
962
 
963
   * The assignment operator (`:=') returns the value of its right-hand
964
     argument.
965
 
966
   * All built-in procedures both modify _and_ return their argument.
967
 
968

969
File: gdb.info,  Node: M2 Checks,  Next: M2 Scope,  Prev: Deviations,  Up: Modula-2
970
 
971
Modula-2 type and range checks
972
..............................
973
 
974
     _Warning:_ in this release, GDB does not yet perform type or range
975
     checking.
976
 
977
   GDB considers two Modula-2 variables type equivalent if:
978
 
979
   * They are of types that have been declared equivalent via a `TYPE
980
     T1 = T2' statement
981
 
982
   * They have been declared on the same line.  (Note:  This is true of
983
     the GNU Modula-2 compiler, but it may not be true of other
984
     compilers.)
985
 
986
   As long as type checking is enabled, any attempt to combine variables
987
whose types are not equivalent is an error.
988
 
989
   Range checking is done on all mathematical operations, assignment,
990
array index bounds, and all built-in functions and procedures.
991
 
992

993
File: gdb.info,  Node: M2 Scope,  Next: GDB/M2,  Prev: M2 Checks,  Up: Modula-2
994
 
995
The scope operators `::' and `.'
996
................................
997
 
998
   There are a few subtle differences between the Modula-2 scope
999
operator (`.') and the GDB scope operator (`::').  The two have similar
1000
syntax:
1001
 
1002
 
1003
     MODULE . ID
1004
     SCOPE :: ID
1005
 
1006
where SCOPE is the name of a module or a procedure, MODULE the name of
1007
a module, and ID is any declared identifier within your program, except
1008
another module.
1009
 
1010
   Using the `::' operator makes GDB search the scope specified by
1011
SCOPE for the identifier ID.  If it is not found in the specified
1012
scope, then GDB searches all scopes enclosing the one specified by
1013
SCOPE.
1014
 
1015
   Using the `.' operator makes GDB search the current scope for the
1016
identifier specified by ID that was imported from the definition module
1017
specified by MODULE.  With this operator, it is an error if the
1018
identifier ID was not imported from definition module MODULE, or if ID
1019
is not an identifier in MODULE.
1020
 
1021

1022
File: gdb.info,  Node: GDB/M2,  Prev: M2 Scope,  Up: Modula-2
1023
 
1024
GDB and Modula-2
1025
................
1026
 
1027
   Some GDB commands have little use when debugging Modula-2 programs.
1028
Five subcommands of `set print' and `show print' apply specifically to
1029
C and C++: `vtbl', `demangle', `asm-demangle', `object', and `union'.
1030
The first four apply to C++, and the last to the C `union' type, which
1031
has no direct analogue in Modula-2.
1032
 
1033
   The `@' operator (*note Expressions: Expressions.), while available
1034
with any language, is not useful with Modula-2.  Its intent is to aid
1035
the debugging of "dynamic arrays", which cannot be created in Modula-2
1036
as they can in C or C++.  However, because an address can be specified
1037
by an integral constant, the construct `{TYPE}ADREXP' is still useful.
1038
 
1039
   In GDB scripts, the Modula-2 inequality operator `#' is interpreted
1040
as the beginning of a comment.  Use `<>' instead.
1041
 
1042

1043
File: gdb.info,  Node: Symbols,  Next: Altering,  Prev: Languages,  Up: Top
1044
 
1045
Examining the Symbol Table
1046
**************************
1047
 
1048
   The commands described in this chapter allow you to inquire about the
1049
symbols (names of variables, functions and types) defined in your
1050
program.  This information is inherent in the text of your program and
1051
does not change as your program executes.  GDB finds it in your
1052
program's symbol table, in the file indicated when you started GDB
1053
(*note Choosing files: File Options.), or by one of the file-management
1054
commands (*note Commands to specify files: Files.).
1055
 
1056
   Occasionally, you may need to refer to symbols that contain unusual
1057
characters, which GDB ordinarily treats as word delimiters.  The most
1058
frequent case is in referring to static variables in other source files
1059
(*note Program variables: Variables.).  File names are recorded in
1060
object files as debugging symbols, but GDB would ordinarily parse a
1061
typical file name, like `foo.c', as the three words `foo' `.' `c'.  To
1062
allow GDB to recognize `foo.c' as a single symbol, enclose it in single
1063
quotes; for example,
1064
 
1065
     p 'foo.c'::x
1066
 
1067
looks up the value of `x' in the scope of the file `foo.c'.
1068
 
1069
`info address SYMBOL'
1070
     Describe where the data for SYMBOL is stored.  For a register
1071
     variable, this says which register it is kept in.  For a
1072
     non-register local variable, this prints the stack-frame offset at
1073
     which the variable is always stored.
1074
 
1075
     Note the contrast with `print &SYMBOL', which does not work at all
1076
     for a register variable, and for a stack local variable prints the
1077
     exact address of the current instantiation of the variable.
1078
 
1079
`info symbol ADDR'
1080
     Print the name of a symbol which is stored at the address ADDR.
1081
     If no symbol is stored exactly at ADDR, GDB prints the nearest
1082
     symbol and an offset from it:
1083
 
1084
          (gdb) info symbol 0x54320
1085
          _initialize_vx + 396 in section .text
1086
 
1087
     This is the opposite of the `info address' command.  You can use
1088
     it to find out the name of a variable or a function given its
1089
     address.
1090
 
1091
`whatis EXPR'
1092
     Print the data type of expression EXPR.  EXPR is not actually
1093
     evaluated, and any side-effecting operations (such as assignments
1094
     or function calls) inside it do not take place.  *Note
1095
     Expressions: Expressions.
1096
 
1097
`whatis'
1098
     Print the data type of `$', the last value in the value history.
1099
 
1100
`ptype TYPENAME'
1101
     Print a description of data type TYPENAME.  TYPENAME may be the
1102
     name of a type, or for C code it may have the form `class
1103
     CLASS-NAME', `struct STRUCT-TAG', `union UNION-TAG' or `enum
1104
     ENUM-TAG'.
1105
 
1106
`ptype EXPR'
1107
`ptype'
1108
     Print a description of the type of expression EXPR.  `ptype'
1109
     differs from `whatis' by printing a detailed description, instead
1110
     of just the name of the type.
1111
 
1112
     For example, for this variable declaration:
1113
 
1114
          struct complex {double real; double imag;} v;
1115
 
1116
     the two commands give this output:
1117
 
1118
          (gdb) whatis v
1119
          type = struct complex
1120
          (gdb) ptype v
1121
          type = struct complex {
1122
              double real;
1123
              double imag;
1124
          }
1125
 
1126
     As with `whatis', using `ptype' without an argument refers to the
1127
     type of `$', the last value in the value history.
1128
 
1129
`info types REGEXP'
1130
`info types'
1131
     Print a brief description of all types whose names match REGEXP
1132
     (or all types in your program, if you supply no argument).  Each
1133
     complete typename is matched as though it were a complete line;
1134
     thus, `i type value' gives information on all types in your
1135
     program whose names include the string `value', but `i type
1136
     ^value$' gives information only on types whose complete name is
1137
     `value'.
1138
 
1139
     This command differs from `ptype' in two ways: first, like
1140
     `whatis', it does not print a detailed description; second, it
1141
     lists all source files where a type is defined.
1142
 
1143
`info scope ADDR'
1144
     List all the variables local to a particular scope.  This command
1145
     accepts a location--a function name, a source line, or an address
1146
     preceded by a `*', and prints all the variables local to the scope
1147
     defined by that location.  For example:
1148
 
1149
          (gdb) info scope command_line_handler
1150
          Scope for command_line_handler:
1151
          Symbol rl is an argument at stack/frame offset 8, length 4.
1152
          Symbol linebuffer is in static storage at address 0x150a18, length 4.
1153
          Symbol linelength is in static storage at address 0x150a1c, length 4.
1154
          Symbol p is a local variable in register $esi, length 4.
1155
          Symbol p1 is a local variable in register $ebx, length 4.
1156
          Symbol nline is a local variable in register $edx, length 4.
1157
          Symbol repeat is a local variable at frame offset -8, length 4.
1158
 
1159
     This command is especially useful for determining what data to
1160
     collect during a "trace experiment", see *Note collect: Tracepoint
1161
     Actions.
1162
 
1163
`info source'
1164
     Show information about the current source file--that is, the
1165
     source file for the function containing the current point of
1166
     execution:
1167
        * the name of the source file, and the directory containing it,
1168
 
1169
        * the directory it was compiled in,
1170
 
1171
        * its length, in lines,
1172
 
1173
        * which programming language it is written in,
1174
 
1175
        * whether the executable includes debugging information for
1176
          that file, and if so, what format the information is in
1177
          (e.g., STABS, Dwarf 2, etc.), and
1178
 
1179
        * whether the debugging information includes information about
1180
          preprocessor macros.
1181
 
1182
`info sources'
1183
     Print the names of all source files in your program for which
1184
     there is debugging information, organized into two lists: files
1185
     whose symbols have already been read, and files whose symbols will
1186
     be read when needed.
1187
 
1188
`info functions'
1189
     Print the names and data types of all defined functions.
1190
 
1191
`info functions REGEXP'
1192
     Print the names and data types of all defined functions whose
1193
     names contain a match for regular expression REGEXP.  Thus, `info
1194
     fun step' finds all functions whose names include `step'; `info
1195
     fun ^step' finds those whose names start with `step'.  If a
1196
     function name contains characters that conflict with the regular
1197
     expression language (eg.  `operator*()'), they may be quoted with
1198
     a backslash.
1199
 
1200
`info variables'
1201
     Print the names and data types of all variables that are declared
1202
     outside of functions (i.e. excluding local variables).
1203
 
1204
`info variables REGEXP'
1205
     Print the names and data types of all variables (except for local
1206
     variables) whose names contain a match for regular expression
1207
     REGEXP.
1208
 
1209
     Some systems allow individual object files that make up your
1210
     program to be replaced without stopping and restarting your
1211
     program.  For example, in VxWorks you can simply recompile a
1212
     defective object file and keep on running.  If you are running on
1213
     one of these systems, you can allow GDB to reload the symbols for
1214
     automatically relinked modules:
1215
 
1216
    `set symbol-reloading on'
1217
          Replace symbol definitions for the corresponding source file
1218
          when an object file with a particular name is seen again.
1219
 
1220
    `set symbol-reloading off'
1221
          Do not replace symbol definitions when encountering object
1222
          files of the same name more than once.  This is the default
1223
          state; if you are not running on a system that permits
1224
          automatic relinking of modules, you should leave
1225
          `symbol-reloading' off, since otherwise GDB may discard
1226
          symbols when linking large programs, that may contain several
1227
          modules (from different directories or libraries) with the
1228
          same name.
1229
 
1230
    `show symbol-reloading'
1231
          Show the current `on' or `off' setting.
1232
 
1233
`set opaque-type-resolution on'
1234
     Tell GDB to resolve opaque types.  An opaque type is a type
1235
     declared as a pointer to a `struct', `class', or `union'--for
1236
     example, `struct MyType *'--that is used in one source file
1237
     although the full declaration of `struct MyType' is in another
1238
     source file.  The default is on.
1239
 
1240
     A change in the setting of this subcommand will not take effect
1241
     until the next time symbols for a file are loaded.
1242
 
1243
`set opaque-type-resolution off'
1244
     Tell GDB not to resolve opaque types.  In this case, the type is
1245
     printed as follows:
1246
          {}
1247
 
1248
`show opaque-type-resolution'
1249
     Show whether opaque types are resolved or not.
1250
 
1251
`maint print symbols FILENAME'
1252
`maint print psymbols FILENAME'
1253
`maint print msymbols FILENAME'
1254
     Write a dump of debugging symbol data into the file FILENAME.
1255
     These commands are used to debug the GDB symbol-reading code.  Only
1256
     symbols with debugging data are included.  If you use `maint print
1257
     symbols', GDB includes all the symbols for which it has already
1258
     collected full details: that is, FILENAME reflects symbols for
1259
     only those files whose symbols GDB has read.  You can use the
1260
     command `info sources' to find out which files these are.  If you
1261
     use `maint print psymbols' instead, the dump shows information
1262
     about symbols that GDB only knows partially--that is, symbols
1263
     defined in files that GDB has skimmed, but not yet read
1264
     completely.  Finally, `maint print msymbols' dumps just the
1265
     minimal symbol information required for each object file from
1266
     which GDB has read some symbols.  *Note Commands to specify files:
1267
     Files, for a discussion of how GDB reads symbols (in the
1268
     description of `symbol-file').
1269
 
1270

1271
File: gdb.info,  Node: Altering,  Next: GDB Files,  Prev: Symbols,  Up: Top
1272
 
1273
Altering Execution
1274
******************
1275
 
1276
   Once you think you have found an error in your program, you might
1277
want to find out for certain whether correcting the apparent error
1278
would lead to correct results in the rest of the run.  You can find the
1279
answer by experiment, using the GDB features for altering execution of
1280
the program.
1281
 
1282
   For example, you can store new values into variables or memory
1283
locations, give your program a signal, restart it at a different
1284
address, or even return prematurely from a function.
1285
 
1286
* Menu:
1287
 
1288
* Assignment::                  Assignment to variables
1289
* Jumping::                     Continuing at a different address
1290
* Signaling::                   Giving your program a signal
1291
* Returning::                   Returning from a function
1292
* Calling::                     Calling your program's functions
1293
* Patching::                    Patching your program
1294
 

powered by: WebSVN 2.1.0

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