STABS: Stack Variables

Next: Global Variables, Up: Variables [Contents][Index]

### 4.1 Automatic Variables Allocated on the Stack

If a variable’s scope is local to a function and its lifetime is only as long as that function executes (C calls such variables automatic), it can be allocated in a register (see Register Variables) or on the stack.

Each variable allocated on the stack has a stab with the symbol descriptor omitted. Since type information should begin with a digit, ‘`-`’, or ‘`(`’, only those characters precluded from being used for symbol descriptors. However, the Acorn RISC machine (ARM) is said to get this wrong: it puts out a mere type definition here, without the preceding ‘`type-number=`’. This is a bad idea; there is no guarantee that type descriptors are distinct from symbol descriptors. Stabs for stack variables use the `N_LSYM` stab type, or `C_LSYM` for XCOFF.

The value of the stab is the offset of the variable within the local variables. On most machines this is an offset from the frame pointer and is negative. The location of the stab specifies which block it is defined in; see Block Structure.

For example, the following C code:

    int
    main ()
    {
      int x;
    }

produces the following stabs:

    .stabs "main:F1",36,0,0,_main   # 36 is N_FUN
    .stabs "x:1",128,0,0,-12        # 128 is N_LSYM
    .stabn 192,0,0,LBB2             # 192 is N_LBRAC
    .stabn 224,0,0,LBE2             # 224 is N_RBRAC

See Procedures for more information on the `N_FUN` stab, and Block Structure for more information on the `N_LBRAC` and `N_RBRAC` stabs.