This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: The root cause for SEGV in evaluating fortran function call, any solution or suggestion?


On Fri, Nov 04, 2005 at 11:18:00AM +0800, Wu Zhou wrote:
> > Allocating memory on the stack is actually quite eazy.  Just
> > substract/add the amount of space you need from/to the stack pointer,
> > and use the new/old stack pointer as the address for the memory.
> > Whether you should substract or add depends on whether the stack grows
> > downward or upward.  Use gdbarch_inner_than(gdbarch, 1, 2) to check.
> > There's quite a bit of code in infcall.c that uses this trick.
> > 
> 
> Thanks.  I did some tests following this way.  But didn't get any success. 
> So I had to post here again to see if anybody can help me out.  
> 
> My basic idea is to create a value which hold the address to the original 
> argument. This is done in valur_addr for these argument which is not lval 
> and whose type is TYPE_CODE_INT.  Then I use the above method to get a new 
> value which hold the address to the original address.  Although it doesn't 
> report SEGV or "can not access memory" message, it didn't ouptut the 
> correct result I expected.  I expect 4 (which is 2 * 2), but it return 
> different number for me every time I run it.
> 
> Following is the changed I made to valur_arg_coerce and value_addr.  Could 
> anyone help me pointed out what is the reason why it fail.  Thanks a lot!

It's not quite as simple as Mark makes it out to be - in concept, sure,
but not in execution.  You have to _allocate_ the space on the stack;
not just find empty space off the side of the stack and write the
argument there.

By the type that we're calling value_arg_coerce, we've already
allocated some space on the stack, and saved the old stack pointer. 
But we'll allocate more space on the stack below, when we push
arguments.  And you have to be careful to keep the stack aligned
properly through all of this.  Read through the surrounding bits of
infcall.c to see how this works for struct returns; that is the closest
analogue we have today.

Maybe if you pass the sp value by reference to value_arg_coerce and
adjust it there...


-- 
Daniel Jacobowitz
CodeSourcery, LLC


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]