::

'::' allows you to specify a variable in terms of the file or function

 

where it is defined. See “Program variables” (page 84).

{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 in a

 

cast). This construct is allowed regardless of what kind of data is

 

normally supposed to reside at addr.

8.2 Program variables

The most common kind of expression to use is the name of a variable in your program.

Variables in expressions are understood in the selected stack frame (see “Selecting a frame” (page 73); they must be either:

global (or file-static)

or

visible according to the scope rules of the programming language from the point of execution in that frame

This means that in the function

foo (a) int a;

{

bar (a);

{

int b = test (); bar (b);

}

}

you can examine and use the variable a whenever your program is executing within the function foo, but you can only use or examine the variable b while your program is executing inside the block where b is declared.

However, you can refer to a variable or function whose scope is a single source file even if the current execution point is not in this file. But it is possible to have more than one such variable or function with the same name (in different source files). If that happens, 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::variable

function::variable

Here file or function is the name of the context for the static variable. In the case of file names, you can use quotes to make sure GDB parses the file name as a single word. For example, to print a global value of x defined in 'f2.c':

((gdb)) p 'f2.c'::x

84 Examining Data

Page 84
Image 84
HP gnu source-level debugger 5992-4701 manual Where it is defined. See Program variables, Type addr