URL
https://opencores.org/ocsvn/or1k_old/or1k_old/trunk
Subversion Repositories or1k_old
[/] [or1k_old/] [trunk/] [insight/] [gdb/] [doc/] [gdb.info-4] - Rev 1782
Compare with Previous | Blame | View Log
This is ./gdb.info, produced by makeinfo version 4.0 from gdb.texinfo.INFO-DIR-SECTION Programming & development tools.START-INFO-DIR-ENTRY* Gdb: (gdb). The GNU debugger.END-INFO-DIR-ENTRYThis file documents the GNU debugger GDB.This is the Ninth Edition, April 2001, of `Debugging with GDB: theGNU Source-Level Debugger' for GDB Version 20010707.Copyright (C)1988,1989,1990,1991,1992,1993,1994,1995,1996,1998,1999,2000,2001Free Software Foundation, Inc.Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.1 orany later version published by the Free Software Foundation; with theInvariant Sections being "A Sample GDB Session" and "Free Software",with the Front-Cover texts being "A GNU Manual," and with theBack-Cover Texts as in (a) below.(a) The FSF's Back-Cover Text is: "You have freedom to copy andmodify this GNU Manual, like GNU software. Copies published by the FreeSoftware Foundation raise funds for GNU development."File: gdb.info, Node: Data, Next: Tracepoints, Prev: Source, Up: TopExamining Data**************The usual way to examine data in your program is with the `print'command (abbreviated `p'), or its synonym `inspect'. It evaluates andprints the value of an expression of the language your program iswritten in (*note Using GDB with Different Languages: Languages.).`print EXPR'`print /F EXPR'EXPR is an expression (in the source language). By default thevalue of EXPR is printed in a format appropriate to its data type;you can choose a different format by specifying `/F', where F is aletter specifying the format; see *Note Output formats: OutputFormats.`print'`print /F'If you omit EXPR, GDB displays the last value again (from the"value history"; *note Value history: Value History.). Thisallows you to conveniently inspect the same value in analternative format.A more low-level way of examining data is with the `x' command. Itexamines data in memory at a specified address and prints it in aspecified format. *Note Examining memory: Memory.If you are interested in information about types, or about how thefields of a struct or a class are declared, use the `ptype EXP' commandrather than `print'. *Note Examining the Symbol Table: Symbols.* Menu:* Expressions:: Expressions* Variables:: Program variables* Arrays:: Artificial arrays* Output Formats:: Output formats* Memory:: Examining memory* Auto Display:: Automatic display* Print Settings:: Print settings* Value History:: Value history* Convenience Vars:: Convenience variables* Registers:: Registers* Floating Point Hardware:: Floating point hardware* Memory Region Attributes:: Memory region attributesFile: gdb.info, Node: Expressions, Next: Variables, Up: DataExpressions===========`print' and many other GDB commands accept an expression and computeits value. Any kind of constant, variable or operator defined by theprogramming language you are using is valid in an expression in GDB.This includes conditional expressions, function calls, casts and stringconstants. It unfortunately does not include symbols defined bypreprocessor `#define' commands.GDB supports array constants in expressions input by the user. Thesyntax is {ELEMENT, ELEMENT...}. For example, you can use the command`print {1, 2, 3}' to build up an array in memory that is `malloc'ed inthe target program.Because C is so widespread, most of the expressions shown inexamples in this manual are in C. *Note Using GDB with DifferentLanguages: Languages, for information on how to use expressions in otherlanguages.In this section, we discuss operators that you can use in GDBexpressions regardless of your programming language.Casts are supported in all languages, not just in C, because it is souseful to cast a number into a pointer in order to examine a structureat that address in memory.GDB supports these operators, in addition to those common toprogramming languages:`@'`@' is a binary operator for treating parts of memory as arrays.*Note Artificial arrays: Arrays, for more information.`::'`::' allows you to specify a variable in terms of the file orfunction where it is defined. *Note Program variables: Variables.`{TYPE} ADDR'Refers to an object of type TYPE stored at address ADDR in memory.ADDR may be any expression whose value is an integer or pointer(but parentheses are required around binary operators, just as ina cast). This construct is allowed regardless of what kind ofdata is normally supposed to reside at ADDR.File: gdb.info, Node: Variables, Next: Arrays, Prev: Expressions, Up: DataProgram variables=================The most common kind of expression to use is the name of a variablein your program.Variables in expressions are understood in the selected stack frame(*note Selecting a frame: Selection.); they must be either:* global (or file-static)or* visible according to the scope rules of the programming languagefrom the point of execution in that frameThis means that in the functionfoo (a)int a;{bar (a);{int b = test ();bar (b);}}you can examine and use the variable `a' whenever your program isexecuting within the function `foo', but you can only use or examinethe variable `b' while your program is executing inside the block where`b' is declared.There is an exception: you can refer to a variable or function whosescope is a single source file even if the current execution point is notin this file. But it is possible to have more than one such variable orfunction with the same name (in different source files). If thathappens, referring to that name has unpredictable effects. If you wish,you can specify a static variable in a particular function or file,using the colon-colon notation:FILE::VARIABLEFUNCTION::VARIABLEHere FILE or FUNCTION is the name of the context for the staticVARIABLE. In the case of file names, you can use quotes to make sureGDB parses the file name as a single word--for example, to print aglobal value of `x' defined in `f2.c':(gdb) p 'f2.c'::xThis use of `::' is very rarely in conflict with the very similaruse of the same notation in C++. GDB also supports use of the C++scope resolution operator in GDB expressions._Warning:_ Occasionally, a local variable may appear to have thewrong value at certain points in a function--just after entry to anew scope, and just before exit.You may see this problem when you are stepping by machineinstructions. This is because, on most machines, it takes more thanone instruction to set up a stack frame (including local variabledefinitions); if you are stepping by machine instructions, variablesmay appear to have the wrong values until the stack frame is completelybuilt. On exit, it usually also takes more than one machineinstruction to destroy a stack frame; after you begin stepping throughthat group of instructions, local variable definitions may be gone.This may also happen when the compiler does significantoptimizations. To be sure of always seeing accurate values, turn offall optimization when compiling.Another possible effect of compiler optimizations is to optimizeunused variables out of existence, or assign variables to registers (asopposed to memory addresses). Depending on the support for such casesoffered by the debug info format used by the compiler, GDB might not beable to display values for such local variables. If that happens, GDBwill print a message like this:No symbol "foo" in current context.To solve such problems, either recompile without optimizations, oruse a different debug info format, if the compiler supports several suchformats. For example, GCC, the GNU C/C++ compiler usually supports the`-gstabs' option. `-gstabs' produces debug info in a format that issuperior to formats such as COFF. You may be able to use DWARF2(`-gdwarf-2'), which is also an effective form for debug info. See*Note Options for Debugging Your Program or GNU CC: (gcc.info)DebuggingOptions, for more information.File: gdb.info, Node: Arrays, Next: Output Formats, Prev: Variables, Up: DataArtificial arrays=================It is often useful to print out several successive objects of thesame type in memory; a section of an array, or an array of dynamicallydetermined size for which only a pointer exists in the program.You can do this by referring to a contiguous span of memory as an"artificial array", using the binary operator `@'. The left operand of`@' should be the first element of the desired array and be anindividual object. The right operand should be the desired length ofthe array. The result is an array value whose elements are all of thetype of the left argument. The first element is actually the leftargument; the second element comes from bytes of memory immediatelyfollowing those that hold the first element, and so on. Here is anexample. If a program saysint *array = (int *) malloc (len * sizeof (int));you can print the contents of `array' withp *array@lenThe left operand of `@' must reside in memory. Array values madewith `@' in this way behave just like other arrays in terms ofsubscripting, and are coerced to pointers when used in expressions.Artificial arrays most often appear in expressions via the value history(*note Value history: Value History.), after printing one out.Another way to create an artificial array is to use a cast. Thisre-interprets a value as if it were an array. The value need not be inmemory:(gdb) p/x (short[2])0x12345678$1 = {0x1234, 0x5678}As a convenience, if you leave the array length out (as in`(TYPE[])VALUE') GDB calculates the size to fill the value (as`sizeof(VALUE)/sizeof(TYPE)':(gdb) p/x (short[])0x12345678$2 = {0x1234, 0x5678}Sometimes the artificial array mechanism is not quite enough; inmoderately complex data structures, the elements of interest may notactually be adjacent--for example, if you are interested in the valuesof pointers in an array. One useful work-around in this situation isto use a convenience variable (*note Convenience variables: ConvenienceVars.) as a counter in an expression that prints the first interestingvalue, and then repeat that expression via <RET>. For instance,suppose you have an array `dtab' of pointers to structures, and you areinterested in the values of a field `fv' in each structure. Here is anexample of what you might type:set $i = 0p dtab[$i++]->fv<RET><RET>...File: gdb.info, Node: Output Formats, Next: Memory, Prev: Arrays, Up: DataOutput formats==============By default, GDB prints a value according to its data type. Sometimesthis is not what you want. For example, you might want to print anumber in hex, or a pointer in decimal. Or you might want to view datain memory at a certain address as a character string or as aninstruction. To do these things, specify an "output format" when youprint a value.The simplest use of output formats is to say how to print a valuealready computed. This is done by starting the arguments of the`print' command with a slash and a format letter. The format letterssupported are:`x'Regard the bits of the value as an integer, and print the integerin hexadecimal.`d'Print as integer in signed decimal.`u'Print as integer in unsigned decimal.`o'Print as integer in octal.`t'Print as integer in binary. The letter `t' stands for "two". (1)`a'Print as an address, both absolute in hexadecimal and as an offsetfrom the nearest preceding symbol. You can use this format usedto discover where (in what function) an unknown address is located:(gdb) p/a 0x54320$3 = 0x54320 <_initialize_vx+396>The command `info symbol 0x54320' yields similar results. *Noteinfo symbol: Symbols.`c'Regard as an integer and print it as a character constant.`f'Regard the bits of the value as a floating point number and printusing typical floating point syntax.For example, to print the program counter in hex (*noteRegisters::), typep/x $pcNote that no space is required before the slash; this is because commandnames in GDB cannot contain a slash.To reprint the last value in the value history with a differentformat, you can use the `print' command with just a format and noexpression. For example, `p/x' reprints the last value in hex.---------- Footnotes ----------(1) `b' cannot be used because these format letters are also usedwith the `x' command, where `b' stands for "byte"; see *Note Examiningmemory: Memory.File: gdb.info, Node: Memory, Next: Auto Display, Prev: Output Formats, Up: DataExamining memory================You can use the command `x' (for "examine") to examine memory in anyof several formats, independently of your program's data types.`x/NFU ADDR'`x ADDR'`x'Use the `x' command to examine memory.N, F, and U are all optional parameters that specify how much memoryto display and how to format it; ADDR is an expression giving theaddress where you want to start displaying memory. If you use defaultsfor NFU, you need not type the slash `/'. Several commands setconvenient defaults for ADDR.N, the repeat countThe repeat count is a decimal integer; the default is 1. Itspecifies how much memory (counting by units U) to display.F, the display formatThe display format is one of the formats used by `print', `s'(null-terminated string), or `i' (machine instruction). Thedefault is `x' (hexadecimal) initially. The default changes eachtime you use either `x' or `print'.U, the unit sizeThe unit size is any of`b'Bytes.`h'Halfwords (two bytes).`w'Words (four bytes). This is the initial default.`g'Giant words (eight bytes).Each time you specify a unit size with `x', that size becomes thedefault unit the next time you use `x'. (For the `s' and `i'formats, the unit size is ignored and is normally not written.)ADDR, starting display addressADDR is the address where you want GDB to begin displaying memory.The expression need not have a pointer value (though it may); itis always interpreted as an integer address of a byte of memory.*Note Expressions: Expressions, for more information onexpressions. The default for ADDR is usually just after the lastaddress examined--but several other commands also set the defaultaddress: `info breakpoints' (to the address of the last breakpointlisted), `info line' (to the starting address of a line), and`print' (if you use it to display a value from memory).For example, `x/3uh 0x54320' is a request to display three halfwords(`h') of memory, formatted as unsigned decimal integers (`u'), startingat address `0x54320'. `x/4xw $sp' prints the four words (`w') ofmemory above the stack pointer (here, `$sp'; *note Registers:Registers.) in hexadecimal (`x').Since the letters indicating unit sizes are all distinct from theletters specifying output formats, you do not have to remember whetherunit size or format comes first; either order works. The outputspecifications `4xw' and `4wx' mean exactly the same thing. (However,the count N must come first; `wx4' does not work.)Even though the unit size U is ignored for the formats `s' and `i',you might still want to use a count N; for example, `3i' specifies thatyou want to see three machine instructions, including any operands.The command `disassemble' gives an alternative way of inspectingmachine instructions; see *Note Source and machine code: Machine Code.All the defaults for the arguments to `x' are designed to make iteasy to continue scanning memory with minimal specifications each timeyou use `x'. For example, after you have inspected three machineinstructions with `x/3i ADDR', you can inspect the next seven with just`x/7'. If you use <RET> to repeat the `x' command, the repeat count Nis used again; the other arguments default as for successive uses of`x'.The addresses and contents printed by the `x' command are not savedin the value history because there is often too much of them and theywould get in the way. Instead, GDB makes these values available forsubsequent use in expressions as values of the convenience variables`$_' and `$__'. After an `x' command, the last address examined isavailable for use in expressions in the convenience variable `$_'. Thecontents of that address, as examined, are available in the conveniencevariable `$__'.If the `x' command has a repeat count, the address and contents savedare from the last memory unit printed; this is not the same as the lastaddress printed if several units were printed on the last line ofoutput.File: gdb.info, Node: Auto Display, Next: Print Settings, Prev: Memory, Up: DataAutomatic display=================If you find that you want to print the value of an expressionfrequently (to see how it changes), you might want to add it to the"automatic display list" so that GDB prints its value each time yourprogram stops. Each expression added to the list is given a number toidentify it; to remove an expression from the list, you specify thatnumber. The automatic display looks like this:2: foo = 383: bar[5] = (struct hack *) 0x3804This display shows item numbers, expressions and their current values.As with displays you request manually using `x' or `print', you canspecify the output format you prefer; in fact, `display' decideswhether to use `print' or `x' depending on how elaborate your formatspecification is--it uses `x' if you specify a unit size, or one of thetwo formats (`i' and `s') that are only supported by `x'; otherwise ituses `print'.`display EXPR'Add the expression EXPR to the list of expressions to display eachtime your program stops. *Note Expressions: Expressions.`display' does not repeat if you press <RET> again after using it.`display/FMT EXPR'For FMT specifying only a display format and not a size or count,add the expression EXPR to the auto-display list but arrange todisplay it each time in the specified format FMT. *Note Outputformats: Output Formats.`display/FMT ADDR'For FMT `i' or `s', or including a unit-size or a number of units,add the expression ADDR as a memory address to be examined eachtime your program stops. Examining means in effect doing `x/FMTADDR'. *Note Examining memory: Memory.For example, `display/i $pc' can be helpful, to see the machineinstruction about to be executed each time execution stops (`$pc' is acommon name for the program counter; *note Registers: Registers.).`undisplay DNUMS...'`delete display DNUMS...'Remove item numbers DNUMS from the list of expressions to display.`undisplay' does not repeat if you press <RET> after using it.(Otherwise you would just get the error `No display number ...'.)`disable display DNUMS...'Disable the display of item numbers DNUMS. A disabled displayitem is not printed automatically, but is not forgotten. It may beenabled again later.`enable display DNUMS...'Enable display of item numbers DNUMS. It becomes effective onceagain in auto display of its expression, until you specifyotherwise.`display'Display the current values of the expressions on the list, just asis done when your program stops.`info display'Print the list of expressions previously set up to displayautomatically, each one with its item number, but without showingthe values. This includes disabled expressions, which are markedas such. It also includes expressions which would not bedisplayed right now because they refer to automatic variables notcurrently available.If a display expression refers to local variables, then it does notmake sense outside the lexical context for which it was set up. Such anexpression is disabled when execution enters a context where one of itsvariables is not defined. For example, if you give the command`display last_char' while inside a function with an argument`last_char', GDB displays this argument while your program continues tostop inside that function. When it stops elsewhere--where there is novariable `last_char'--the display is disabled automatically. The nexttime your program stops where `last_char' is meaningful, you can enablethe display expression once again.File: gdb.info, Node: Print Settings, Next: Value History, Prev: Auto Display, Up: DataPrint settings==============GDB provides the following ways to control how arrays, structures,and symbols are printed.These settings are useful for debugging programs in any language:`set print address'`set print address on'GDB prints memory addresses showing the location of stack traces,structure values, pointer values, breakpoints, and so forth, evenwhen it also displays the contents of those addresses. The defaultis `on'. For example, this is what a stack frame display lookslike with `set print address on':(gdb) f#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")at input.c:530530 if (lquote != def_lquote)`set print address off'Do not print addresses when displaying their contents. Forexample, this is the same stack frame displayed with `set printaddress off':(gdb) set print addr off(gdb) f#0 set_quotes (lq="<<", rq=">>") at input.c:530530 if (lquote != def_lquote)You can use `set print address off' to eliminate all machinedependent displays from the GDB interface. For example, with`print address off', you should get the same text for backtraces onall machines--whether or not they involve pointer arguments.`show print address'Show whether or not addresses are to be printed.When GDB prints a symbolic address, it normally prints the closestearlier symbol plus an offset. If that symbol does not uniquelyidentify the address (for example, it is a name whose scope is a singlesource file), you may need to clarify. One way to do this is with`info line', for example `info line *0x4537'. Alternately, you can setGDB to print the source file and line number when it prints a symbolicaddress:`set print symbol-filename on'Tell GDB to print the source file name and line number of a symbolin the symbolic form of an address.`set print symbol-filename off'Do not print source file name and line number of a symbol. Thisis the default.`show print symbol-filename'Show whether or not GDB will print the source file name and linenumber of a symbol in the symbolic form of an address.Another situation where it is helpful to show symbol filenames andline numbers is when disassembling code; GDB shows you the line numberand source file that corresponds to each instruction.Also, you may wish to see the symbolic form only if the address beingprinted is reasonably close to the closest earlier symbol:`set print max-symbolic-offset MAX-OFFSET'Tell GDB to only display the symbolic form of an address if theoffset between the closest earlier symbol and the address is lessthan MAX-OFFSET. The default is 0, which tells GDB to alwaysprint the symbolic form of an address if any symbol precedes it.`show print max-symbolic-offset'Ask how large the maximum offset is that GDB prints in a symbolicaddress.If you have a pointer and you are not sure where it points, try `setprint symbol-filename on'. Then you can determine the name and sourcefile location of the variable where it points, using `p/a POINTER'.This interprets the address in symbolic form. For example, here GDBshows that a variable `ptt' points at another variable `t', defined in`hi2.c':(gdb) set print symbol-filename on(gdb) p/a ptt$4 = 0xe008 <t in hi2.c>_Warning:_ For pointers that point to a local variable, `p/a' doesnot show the symbol name and filename of the referent, even withthe appropriate `set print' options turned on.Other settings control how different kinds of objects are printed:`set print array'`set print array on'Pretty print arrays. This format is more convenient to read, butuses more space. The default is off.`set print array off'Return to compressed format for arrays.`show print array'Show whether compressed or pretty format is selected for displayingarrays.`set print elements NUMBER-OF-ELEMENTS'Set a limit on how many elements of an array GDB will print. IfGDB is printing a large array, it stops printing after it hasprinted the number of elements set by the `set print elements'command. This limit also applies to the display of strings. WhenGDB starts, this limit is set to 200. Setting NUMBER-OF-ELEMENTSto zero means that the printing is unlimited.`show print elements'Display the number of elements of a large array that GDB willprint. If the number is 0, then the printing is unlimited.`set print null-stop'Cause GDB to stop printing the characters of an array when thefirst NULL is encountered. This is useful when large arraysactually contain only short strings. The default is off.`set print pretty on'Cause GDB to print structures in an indented format with one memberper line, like this:$1 = {next = 0x0,flags = {sweet = 1,sour = 1},meat = 0x54 "Pork"}`set print pretty off'Cause GDB to print structures in a compact format, like this:$1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \meat = 0x54 "Pork"}This is the default format.`show print pretty'Show which format GDB is using to print structures.`set print sevenbit-strings on'Print using only seven-bit characters; if this option is set, GDBdisplays any eight-bit characters (in strings or character values)using the notation `\'NNN. This setting is best if you areworking in English (ASCII) and you use the high-order bit ofcharacters as a marker or "meta" bit.`set print sevenbit-strings off'Print full eight-bit characters. This allows the use of moreinternational character sets, and is the default.`show print sevenbit-strings'Show whether or not GDB is printing only seven-bit characters.`set print union on'Tell GDB to print unions which are contained in structures. Thisis the default setting.`set print union off'Tell GDB not to print unions which are contained in structures.`show print union'Ask GDB whether or not it will print unions which are contained instructures.For example, given the declarationstypedef enum {Tree, Bug} Species;typedef enum {Big_tree, Acorn, Seedling} Tree_forms;typedef enum {Caterpillar, Cocoon, Butterfly}Bug_forms;struct thing {Species it;union {Tree_forms tree;Bug_forms bug;} form;};struct thing foo = {Tree, {Acorn}};with `set print union on' in effect `p foo' would print$1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}and with `set print union off' in effect it would print$1 = {it = Tree, form = {...}}These settings are of interest when debugging C++ programs:`set print demangle'`set print demangle on'Print C++ names in their source form rather than in the encoded("mangled") form passed to the assembler and linker for type-safelinkage. The default is on.`show print demangle'Show whether C++ names are printed in mangled or demangled form.`set print asm-demangle'`set print asm-demangle on'Print C++ names in their source form rather than their mangledform, even in assembler code printouts such as instructiondisassemblies. The default is off.`show print asm-demangle'Show whether C++ names in assembly listings are printed in mangledor demangled form.`set demangle-style STYLE'Choose among several encoding schemes used by different compilersto represent C++ names. The choices for STYLE are currently:`auto'Allow GDB to choose a decoding style by inspecting yourprogram.`gnu'Decode based on the GNU C++ compiler (`g++') encodingalgorithm. This is the default.`hp'Decode based on the HP ANSI C++ (`aCC') encoding algorithm.`lucid'Decode based on the Lucid C++ compiler (`lcc') encodingalgorithm.`arm'Decode using the algorithm in the `C++ Annotated ReferenceManual'. *Warning:* this setting alone is not sufficient toallow debugging `cfront'-generated executables. GDB wouldrequire further enhancement to permit that.If you omit STYLE, you will see a list of possible formats.`show demangle-style'Display the encoding style currently in use for decoding C++symbols.`set print object'`set print object on'When displaying a pointer to an object, identify the _actual_(derived) type of the object rather than the _declared_ type, usingthe virtual function table.`set print object off'Display only the declared type of objects, without reference to thevirtual function table. This is the default setting.`show print object'Show whether actual, or declared, object types are displayed.`set print static-members'`set print static-members on'Print static members when displaying a C++ object. The default ison.`set print static-members off'Do not print static members when displaying a C++ object.`show print static-members'Show whether C++ static members are printed, or not.`set print vtbl'`set print vtbl on'Pretty print C++ virtual function tables. The default is off.(The `vtbl' commands do not work on programs compiled with the HPANSI C++ compiler (`aCC').)`set print vtbl off'Do not pretty print C++ virtual function tables.`show print vtbl'Show whether C++ virtual function tables are pretty printed, ornot.File: gdb.info, Node: Value History, Next: Convenience Vars, Prev: Print Settings, Up: DataValue history=============Values printed by the `print' command are saved in the GDB "valuehistory". This allows you to refer to them in other expressions.Values are kept until the symbol table is re-read or discarded (forexample with the `file' or `symbol-file' commands). When the symboltable changes, the value history is discarded, since the values maycontain pointers back to the types defined in the symbol table.The values printed are given "history numbers" by which you canrefer to them. These are successive integers starting with one.`print' shows you the history number assigned to a value by printing`$NUM = ' before the value; here NUM is the history number.To refer to any previous value, use `$' followed by the value'shistory number. The way `print' labels its output is designed toremind you of this. Just `$' refers to the most recent value in thehistory, and `$$' refers to the value before that. `$$N' refers to theNth value from the end; `$$2' is the value just prior to `$$', `$$1' isequivalent to `$$', and `$$0' is equivalent to `$'.For example, suppose you have just printed a pointer to a structureand want to see the contents of the structure. It suffices to typep *$If you have a chain of structures where the component `next' pointsto the next one, you can print the contents of the next one with this:p *$.nextYou can print successive links in the chain by repeating thiscommand--which you can do by just typing <RET>.Note that the history records values, not expressions. If the valueof `x' is 4 and you type these commands:print xset x=5then the value recorded in the value history by the `print' commandremains 4 even though the value of `x' has changed.`show values'Print the last ten values in the value history, with their itemnumbers. This is like `p $$9' repeated ten times, except that`show values' does not change the history.`show values N'Print ten history values centered on history item number N.`show values +'Print ten history values just after the values last printed. Ifno more values are available, `show values +' produces no display.Pressing <RET> to repeat `show values N' has exactly the same effectas `show values +'.File: gdb.info, Node: Convenience Vars, Next: Registers, Prev: Value History, Up: DataConvenience variables=====================GDB provides "convenience variables" that you can use within GDB tohold on to a value and refer to it later. These variables existentirely within GDB; they are not part of your program, and setting aconvenience variable has no direct effect on further execution of yourprogram. That is why you can use them freely.Convenience variables are prefixed with `$'. Any name preceded by`$' can be used for a convenience variable, unless it is one of thepredefined machine-specific register names (*note Registers:Registers.). (Value history references, in contrast, are _numbers_preceded by `$'. *Note Value history: Value History.)You can save a value in a convenience variable with an assignmentexpression, just as you would set a variable in your program. Forexample:set $foo = *object_ptrwould save in `$foo' the value contained in the object pointed to by`object_ptr'.Using a convenience variable for the first time creates it, but itsvalue is `void' until you assign a new value. You can alter the valuewith another assignment at any time.Convenience variables have no fixed types. You can assign aconvenience variable any type of value, including structures andarrays, even if that variable already has a value of a different type.The convenience variable, when used as an expression, has the type ofits current value.`show convenience'Print a list of convenience variables used so far, and theirvalues. Abbreviated `show conv'.One of the ways to use a convenience variable is as a counter to beincremented or a pointer to be advanced. For example, to print a fieldfrom successive elements of an array of structures:set $i = 0print bar[$i++]->contentsRepeat that command by typing <RET>.Some convenience variables are created automatically by GDB and givenvalues likely to be useful.`$_'The variable `$_' is automatically set by the `x' command to thelast address examined (*note Examining memory: Memory.). Othercommands which provide a default address for `x' to examine alsoset `$_' to that address; these commands include `info line' and`info breakpoint'. The type of `$_' is `void *' except when setby the `x' command, in which case it is a pointer to the type of`$__'.`$__'The variable `$__' is automatically set by the `x' command to thevalue found in the last address examined. Its type is chosen tomatch the format in which the data was printed.`$_exitcode'The variable `$_exitcode' is automatically set to the exit codewhen the program being debugged terminates.On HP-UX systems, if you refer to a function or variable name thatbegins with a dollar sign, GDB searches for a user or system namefirst, before it searches for a convenience variable.File: gdb.info, Node: Registers, Next: Floating Point Hardware, Prev: Convenience Vars, Up: DataRegisters=========You can refer to machine register contents, in expressions, asvariables with names starting with `$'. The names of registers aredifferent for each machine; use `info registers' to see the names usedon your machine.`info registers'Print the names and values of all registers except floating-pointregisters (in the selected stack frame).`info all-registers'Print the names and values of all registers, includingfloating-point registers.`info registers REGNAME ...'Print the "relativized" value of each specified register REGNAME.As discussed in detail below, register values are normallyrelative to the selected stack frame. REGNAME may be any registername valid on the machine you are using, with or without theinitial `$'.GDB has four "standard" register names that are available (inexpressions) on most machines--whenever they do not conflict with anarchitecture's canonical mnemonics for registers. The register names`$pc' and `$sp' are used for the program counter register and the stackpointer. `$fp' is used for a register that contains a pointer to thecurrent stack frame, and `$ps' is used for a register that contains theprocessor status. For example, you could print the program counter inhex withp/x $pcor print the instruction to be executed next withx/i $pcor add four to the stack pointer(1) withset $sp += 4Whenever possible, these four standard register names are availableon your machine even though the machine has different canonicalmnemonics, so long as there is no conflict. The `info registers'command shows the canonical names. For example, on the SPARC, `inforegisters' displays the processor status register as `$psr' but you canalso refer to it as `$ps'; and on x86-based machines `$ps' is an aliasfor the EFLAGS register.GDB always considers the contents of an ordinary register as aninteger when the register is examined in this way. Some machines havespecial registers which can hold nothing but floating point; theseregisters are considered to have floating point values. There is no wayto refer to the contents of an ordinary register as floating point value(although you can _print_ it as a floating point value with `print/f$REGNAME').Some registers have distinct "raw" and "virtual" data formats. Thismeans that the data format in which the register contents are saved bythe operating system is not the same one that your program normallysees. For example, the registers of the 68881 floating pointcoprocessor are always saved in "extended" (raw) format, but all Cprograms expect to work with "double" (virtual) format. In such cases,GDB normally works with the virtual format only (the format that makessense for your program), but the `info registers' command prints thedata in both formats.Normally, register values are relative to the selected stack frame(*note Selecting a frame: Selection.). This means that you get thevalue that the register would contain if all stack frames farther inwere exited and their saved registers restored. In order to see thetrue contents of hardware registers, you must select the innermostframe (with `frame 0').However, GDB must deduce where registers are saved, from the machinecode generated by your compiler. If some registers are not saved, or ifGDB is unable to locate the saved registers, the selected stack framemakes no difference.---------- Footnotes ----------(1) This is a way of removing one word from the stack, on machineswhere stacks grow downward in memory (most machines, nowadays). Thisassumes that the innermost stack frame is selected; setting `$sp' isnot allowed when other stack frames are selected. To pop entire framesoff the stack, regardless of machine architecture, use `return'; see*Note Returning from a function: Returning.File: gdb.info, Node: Floating Point Hardware, Next: Memory Region Attributes, Prev: Registers, Up: DataFloating point hardware=======================Depending on the configuration, GDB may be able to give you moreinformation about the status of the floating point hardware.`info float'Display hardware-dependent information about the floating pointunit. The exact contents and layout vary depending on thefloating point chip. Currently, `info float' is supported on theARM and x86 machines.File: gdb.info, Node: Memory Region Attributes, Prev: Floating Point Hardware, Up: DataMemory Region Attributes========================"Memory region attributes" allow you to describe special handlingrequired by regions of your target's memory. GDB uses attributes todetermine whether to allow certain types of memory accesses; whether touse specific width accesses; and whether to cache target memory.Defined memory regions can be individually enabled and disabled.When a memory region is disabled, GDB uses the default attributes whenaccessing memory in that region. Similarly, if no memory regions havebeen defined, GDB uses the default attributes when accessing all memory.When a memory region is defined, it is given a number to identify it;to enable, disable, or remove a memory region, you specify that number.`mem ADDRESS1 ADDRESS1 ATTRIBUTES...'Define memory region bounded by ADDRESS1 and ADDRESS2 withattributes ATTRIBUTES....`delete mem NUMS...'Remove memory region numbers NUMS.`disable mem NUMS...'Disable memory region numbers NUMS. A disabled memory region isnot forgotten. It may be enabled again later.`enable mem NUMS...'Enable memory region numbers NUMS.`info mem'Print a table of all defined memory regions, with the followingcolumns for each region._Memory Region Number__Enabled or Disabled._Enabled memory regions are marked with `y'. Disabled memoryregions are marked with `n'._Lo Address_The address defining the inclusive lower bound of the memoryregion._Hi Address_The address defining the exclusive upper bound of the memoryregion._Attributes_The list of attributes set for this memory region.Attributes----------Memory Access Mode..................The access mode attributes set whether GDB may make read or writeaccesses to a memory region.While these attributes prevent GDB from performing invalid memoryaccesses, they do nothing to prevent the target system, I/O DMA, etc.from accessing memory.`ro'Memory is read only.`wo'Memory is write only.`rw'Memory is read/write (default).Memory Access Size..................The acccess size attributes tells GDB to use specific sized accessesin the memory region. Often memory mapped device registers requirespecific sized accesses. If no access size attribute is specified, GDBmay use accesses of any size.`8'Use 8 bit memory accesses.`16'Use 16 bit memory accesses.`32'Use 32 bit memory accesses.`64'Use 64 bit memory accesses.Data Cache..........The data cache attributes set whether GDB will cache target memory.While this generally improves performance by reducing debug protocoloverhead, it can lead to incorrect results because GDB does not knowabout volatile variables or memory mapped device registers.`cache'Enable GDB to cache target memory.`nocache (default)'Disable GDB from caching target memory.File: gdb.info, Node: Tracepoints, Next: Languages, Prev: Data, Up: TopTracepoints***********In some applications, it is not feasible for the debugger tointerrupt the program's execution long enough for the developer to learnanything helpful about its behavior. If the program's correctnessdepends on its real-time behavior, delays introduced by a debuggermight cause the program to change its behavior drastically, or perhapsfail, even when the code itself is correct. It is useful to be able toobserve the program's behavior without interrupting it.Using GDB's `trace' and `collect' commands, you can specifylocations in the program, called "tracepoints", and arbitraryexpressions to evaluate when those tracepoints are reached. Later,using the `tfind' command, you can examine the values those expressionshad when the program hit the tracepoints. The expressions may alsodenote objects in memory--structures or arrays, for example--whosevalues GDB should record; while visiting a particular tracepoint, youmay inspect those objects as if they were in memory at that moment.However, because GDB records these values without interacting with you,it can do so quickly and unobtrusively, hopefully not disturbing theprogram's behavior.The tracepoint facility is currently available only for remotetargets. *Note Targets::.This chapter describes the tracepoint commands and features.* Menu:* Set Tracepoints::* Analyze Collected Data::* Tracepoint Variables::File: gdb.info, Node: Set Tracepoints, Next: Analyze Collected Data, Up: TracepointsCommands to Set Tracepoints===========================Before running such a "trace experiment", an arbitrary number oftracepoints can be set. Like a breakpoint (*note Set Breaks::), atracepoint has a number assigned to it by GDB. Like with breakpoints,tracepoint numbers are successive integers starting from one. Many ofthe commands associated with tracepoints take the tracepoint number astheir argument, to identify which tracepoint to work on.For each tracepoint, you can specify, in advance, some arbitrary setof data that you want the target to collect in the trace buffer when ithits that tracepoint. The collected data can include registers, localvariables, or global data. Later, you can use GDB commands to examinethe values these data had at the time the tracepoint was hit.This section describes commands to set tracepoints and associatedconditions and actions.* Menu:* Create and Delete Tracepoints::* Enable and Disable Tracepoints::* Tracepoint Passcounts::* Tracepoint Actions::* Listing Tracepoints::* Starting and Stopping Trace Experiment::File: gdb.info, Node: Create and Delete Tracepoints, Next: Enable and Disable Tracepoints, Up: Set TracepointsCreate and Delete Tracepoints-----------------------------`trace'The `trace' command is very similar to the `break' command. Itsargument can be a source line, a function name, or an address inthe target program. *Note Set Breaks::. The `trace' commanddefines a tracepoint, which is a point in the target program wherethe debugger will briefly stop, collect some data, and then allowthe program to continue. Setting a tracepoint or changing itscommands doesn't take effect until the next `tstart' command;thus, you cannot change the tracepoint attributes once a traceexperiment is running.Here are some examples of using the `trace' command:(gdb) trace foo.c:121 // a source file and line number(gdb) trace +2 // 2 lines forward(gdb) trace my_function // first source line of function(gdb) trace *my_function // EXACT start address of function(gdb) trace *0x2117c4 // an addressYou can abbreviate `trace' as `tr'.The convenience variable `$tpnum' records the tracepoint number ofthe most recently set tracepoint.`delete tracepoint [NUM]'Permanently delete one or more tracepoints. With no argument, thedefault is to delete all tracepoints.Examples:(gdb) delete trace 1 2 3 // remove three tracepoints(gdb) delete trace // remove all tracepointsYou can abbreviate this command as `del tr'.File: gdb.info, Node: Enable and Disable Tracepoints, Next: Tracepoint Passcounts, Prev: Create and Delete Tracepoints, Up: Set TracepointsEnable and Disable Tracepoints------------------------------`disable tracepoint [NUM]'Disable tracepoint NUM, or all tracepoints if no argument NUM isgiven. A disabled tracepoint will have no effect during the nexttrace experiment, but it is not forgotten. You can re-enable adisabled tracepoint using the `enable tracepoint' command.`enable tracepoint [NUM]'Enable tracepoint NUM, or all tracepoints. The enabledtracepoints will become effective the next time a trace experimentis run.File: gdb.info, Node: Tracepoint Passcounts, Next: Tracepoint Actions, Prev: Enable and Disable Tracepoints, Up: Set TracepointsTracepoint Passcounts---------------------`passcount [N [NUM]]'Set the "passcount" of a tracepoint. The passcount is a way toautomatically stop a trace experiment. If a tracepoint'spasscount is N, then the trace experiment will be automaticallystopped on the N'th time that tracepoint is hit. If thetracepoint number NUM is not specified, the `passcount' commandsets the passcount of the most recently defined tracepoint. If nopasscount is given, the trace experiment will run until stoppedexplicitly by the user.Examples:(gdb) passcount 5 2 // Stop on the 5th execution of tracepoint 2(gdb) passcount 12 // Stop on the 12th execution of the// most recently defined tracepoint.(gdb) trace foo(gdb) pass 3(gdb) trace bar(gdb) pass 2(gdb) trace baz(gdb) pass 1 // Stop tracing when foo has been// executed 3 times OR when bar has// been executed 2 times// OR when baz has been executed 1 time.
