Next: , Previous: , Up: Parameters   [Contents][Index]


4.7.2 Storing Parameters as Local Variables

There is a case similar to an argument in a register, which is an argument that is actually stored as a local variable. Sometimes this happens when the argument was passed in a register and then the compiler stores it as a local variable. If possible, the compiler should claim that it’s in a register, but this isn’t always done.

If a parameter is passed as one type and converted to a smaller type by the prologue (for example, the parameter is declared as a float, but the calling conventions specify that it is passed as a double), then GCC2 (sometimes) uses a pair of symbols. The first symbol uses symbol descriptor ‘p’ and the type which is passed. The second symbol has the type and location which the parameter actually has after the prologue. For example, suppose the following C code appears with no prototypes involved:

void
subr (f)
     float f;
{

if f is passed as a double at stack offset 8, and the prologue converts it to a float in register number 0, then the stabs look like:

.stabs "f:p13",160,0,3,8   # 160 is N_PSYM, here 13 is double
.stabs "f:r12",64,0,3,0    # 64 is N_RSYM, here 12 is float

In both stabs 3 is the line number where f is declared (see Line Numbers).

GCC, at least on the 960, has another solution to the same problem. It uses a single ‘p’ symbol descriptor for an argument which is stored as a local variable but uses N_LSYM instead of N_PSYM. In this case, the value of the symbol is an offset relative to the local variables for that function, not relative to the arguments; on some machines those are the same thing, but not on all.

On the VAX or on other machines in which the calling convention includes the number of words of arguments actually passed, the debugger (GDB at least) uses the parameter symbols to keep track of whether it needs to print nameless arguments in addition to the formal parameters which it has printed because each one has a stab. For example, in

extern int fprintf (FILE *stream, char *format, …);
…
fprintf (stdout, "%d\n", x);

there are stabs for stream and format. On most machines, the debugger can only print those two arguments (because it has no way of knowing that additional arguments were passed), but on the VAX or other machines with a calling convention which indicates the number of words of arguments, the debugger can print all three arguments. To do so, the parameter symbol (symbol descriptor ‘p’) (not necessarily ‘r’ or symbol descriptor omitted symbols) needs to contain the actual type as passed (for example, double not float if it is passed as a double and converted to a float).


Next: Passing Parameters by Reference, Previous: Passing Parameters in Registers, Up: Parameters   [Contents][Index]