At 14:18 12/10/01 -0400, Oldham, Adam wrote:
Yes, I saw some of these threads, but nothing seemed to shed light on fixes for the scoping of this. It is good to know Ada does this as well so that maybe us Ada/Pascal people can get together and come up with a fix.
I submitted code that demonstrates this with my bug report as well....
After some testing on both GNU C and GNU Pascal I discovered that they both use the same method (on djgpp i386 target)
The calling frame pointer is passed to the nested function in %ecx register and stored in -4(%ebp) in the function prologue (which does not seem to be handled by skip_prologue function, at least I didn't find anything in version 5.0 sources)
So the parent frame is placed in %ecx and stored at offset -4 for GNU gcc or gpc while it is pushed at offset 8 in Free Pascal code.
Using -gstabs+ I saw nothing generated to explain the meaning of the %ecx parameter or the -4(%ebp) location.
Checking the prologue for this movl %ecx,offset(%ebp) isn't probably sufficient to tell that we are in a nested proc... Moreover this is processor specific, which is bad...
Stabs does give info about nesting in the stabs concerning the
Consider the following source: int test () { int i = 1; int j;
int local () { return j+1; };
j = i+1; return local (); }
int main () { printf(" result of test() is %d \n",test()); return 0; }
This generates .stabs "local:f(0,1),local,test",36,0,8,_local.3 The ,local,test indicates that local is nested inside test function.
But this is not enough as I don't know what happens for instance if parameters are passed by registers...
Adding some debug info concerning the location of the parent frame seems like a good idea, no ? The Free Pascal approach to use a pseudo parameter called 'parent_ebp' seems to not be applicable to C as this would be a valid C local variable name. Maybe something beginning with a dollar like for the classes?
A similar problem exists for With statements in pascal. Stabs defines even a specific stab number for this but this is also unsupported for now.