.stabs
N_LSYM
In addition to describing types, the N_LSYM
stab type also
describes locally scoped automatic variables. Refer again to the body
of main
in `example2.c'. It allocates two automatic
variables: `times' is scoped to the body of main
, and
`inner' is scoped to the body of the for
loop.
`s_flap' is locally scoped but not automatic, and will be discussed
later.
20 { 21 static float s_flap; 22 int times; 23 for (times=0; times < s_g_repeat; times++){ 24 int inner; 25 printf ("Hello world\n"); 26 } 27 };
The N_LSYM
stab for an automatic variable is located just before the
N_LBRAC
stab describing the open brace of the block to which it is
scoped.
N_LSYM
(128): automatic variable, scoped locally tomain
.stabs "name: type-ref", N_LSYM, NIL, NIL, frame-pointer-offset 98 .stabs "times:1",128,0,0,-20 99 .stabn 192,0,0,LBB2 ## begin `main' N_LBRACN_LSYM
(128): automatic variable, scoped locally to thefor
loop .stabs "name: type-ref", N_LSYM, NIL, NIL, frame-pointer-offset 100 .stabs "inner:1",128,0,0,-24 101 .stabn 192,0,0,LBB3 ## begin `for' loop N_LBRAC
Since the character in the string field following the colon is not a
letter, there is no symbol descriptor. This means that the stab
describes a local variable, and that the number after the colon is a
type reference. In this case it a a reference to the basic type int
.
Notice also that the frame pointer offset is negative number for
automatic variables.
.stabs
N_GSYM
G
Global variables are represented by the N_GSYM
stab type. The symbol
descriptor, following the colon in the string field, is `G'. Following
the `G' is a type reference or type definition. In this example it is a
type reference to the basic C type, char
. The first source line in
`example2.c',
1 char g_foo = 'c';
yields the following stab. The stab immediately precedes the code that allocates storage for the variable it describes.
N_GSYM
(32): global symbol
.stabs "name:
descriptor
type-ref",
N_GSYM, NIL, NIL, NIL
21 .stabs "g_foo:G2",32,0,0,0
22 .global _g_foo
23 .data
24 _g_foo:
25 .byte 99
The address of the variable represented by the N_GSYM
is not contained
in the N_GSYM
stab. The debugger gets this information from the
external symbol for the global variable.
.stabs
N_RSYM
r
The following source line defines a global variable, g_bar
, which is
explicitly allocated in global register %g5
.
2 register int g_bar asm ("%g5");
Register variables have their own stab type, N_RSYM
, and their own
symbol descriptor, r
. The stab's value field contains the number of
the register where the variable data will be stored. Since the
variable was not initialized in this compilation unit, the stab is
emited at the end of the object file, with the stabs for other
uninitialized globals (bcc
).
N_RSYM
(64): register variable
.stabs "name:
descriptor
type-ref",
N_RSYM, NIL, NIL,
register
133 .stabs "g_bar:r1",64,0,0,5
.stabs
N_STSYM
S
(file scope), V
(procedure scope)
Initialized static variables are represented by the N_STSYM
stab
type. The symbol descriptor part of the string field shows if the
variable is file scope static (`S') or procedure scope static
(`V'). The source line
3 static int s_g_repeat = 2;
yields the following code. The stab is located immediately preceding the storage for the variable it represents. Since the variable in this example is file scope static the symbol descriptor is `S'.
N_STSYM
(38): initialized static variable (data seg w/internal linkage)
.stabs "name:
descriptor
type-ref",
N_STSYM,NIL,NIL,
address
26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
27 .align 4
28 _s_g_repeat:
29 .word 2
.stabs
N_LCSYM
S
(file scope), V
(procedure scope)
Un-initialized static variables are represented by the N_LCSYM
stab type. The symbol descriptor part of the string shows if the
variable is file scope static (`S') or procedure scope static
(`V'). In this example it is procedure scope static. The source
line allocating s_flap
immediately follows the open brace for the
procedure main
.
20 { 21 static float s_flap;
The code that reserves storage for the variable s_flap
precedes the
body of body of main
.
39 .reserve _s_flap.0,4,"bss",4
But since s_flap
is scoped locally to main
, its stab is
located with the other stabs representing symbols local to main
.
The stab for s_flap
is located just before the N_LBRAC
for
main
.
N_LCSYM
(40): uninitialized static var (BSS seg w/internal linkage)
.stabs "name:
descriptor
type-ref",
N_LCSYM, NIL, NIL,
address
97 .stabs "s_flap:V12",40,0,0,_s_flap.0
98 .stabs "times:1",128,0,0,-20
99 .stabn 192,0,0,LBB2 # N_LBRAC for main.
.stabs
N_PSYM
p
Procedure parameters are represented by the N_PSYM stab type. The following source lines show the parameters of the main routine.
17 main (argc, argv) 18 int argc; 19 char* argv[]; 20 {
The N_PSYM stabs describing parameters to a function directly follow the N_FUN stab that represents the procedure itself. The N_FUN stab immediately follows the code of the procedure it describes. Following the N_PSYM parameter stabs are any N_LSYM stabs representing local variables.
<36> N_FUN - describing the procedure main 94 .stabs "main:F1",36,0,0,_main <160> N_PSYM - parameters .stabs "name:sym_desc(value_param)type_ref(int)", N_PSYM, NIL, NIL, frame_ptr_offset 95 .stabs "argc:p1",160,0,0,68 <160> N_PSYM - parameter .stabs "name:sym_desc(value_param)type_def(20)=ptr_to type_def(21)= ptr_to type_ref(char) 96 .stabs "argv:p20=*21=*2",160,0,0,72
The type definition of argv is interesting because it defines two new types in terms of an existing one. The array argv contains character pointers. The type of the array name is a pointer to the type the array holds. Thus the type of argv is ptr to ptr to char. The stab for argv contains nested type_definitions. Type 21 is ptr to type 2 (char) and argv (type 20) is ptr to type 21.