This is the mail archive of the gdb-patches@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: entryval tail call frames $sp adjustment vs. gdbarches [Re: New ARI warning Thu Oct 13 01:55:36 UTC 2011]


Jan Kratochvil wrote:
> On Thu, 13 Oct 2011 16:59:37 +0200, Ulrich Weigand wrote:
> > Generic code is not supposed to make the assumption that there *is*
> > a single "sp" (or "pc") register;
> 
> The current code does everything in a "best effort" mode.  If anything fails
> $sp in tail call frames is just not adjusted - it should not be such a problem.
> So far I would set such behavior for all gdbarches anyway (*).
> 
> (*) I guess the correct approach is to set it only for gdbarches where one
>     verifies it is correct.  Still if the code succeeds I believe the result is
>     always correct - so what is the point of gdbarch in such case?

It's just that some of those assumptions seem really unnecessary to me.
For example, the assumption that there is a fixed "PC" register:

      prev_gdbarch = frame_unwind_arch (this_frame);
      pc_regnum = gdbarch_pc_regnum (prev_gdbarch);
      if (pc_regnum == -1)
        break;

      /* Simulate frame_unwind_pc without setting this_frame->prev_pc.p.  */
      prev_pc = frame_unwind_register_unsigned (this_frame, pc_regnum);

Why don't you just do something like:

      prev_gdbarch = frame_unwind_arch (this_frame);

      /* Simulate frame_unwind_pc without setting this_frame->prev_pc.p.  */
      prev_pc = gdbarch_unwind_pc (prev_gdbarch, this_frame);


Similarly, when injecting the tailcall PC values, you hook into the
prev_register routine -- which assumes that unwind_pc will end up
doing an unwind_register of pc_regnum.  This assumptium would be
unnecessary if you just hooked into frame_unwind_pc directly instead.


Now as to SP, what happens is that you detect the rule for the CFA
at the entry point is
   CFA = <sp_register> + <some_offset>

Tailcall unwinding doesn't directly know the value of sp_register, but
it does know the CFA, so you hook into prev_register to return a value
of sp_register that is designed such that the above computation will
yield the desired CFA.

However -- nothing in that design depends on the CFA being relative to
the SP register in particular.  You could avoid this by detecting the
more general rule
  CFA = <some_register> + <some_offset>

and then remember both the register and the offset, and hook into 
prev_register for whatever the register is -- no need at all to
enforce that this must be gdbarch_sp_regnum ...

(You could then even generalize this to even more generic expressions
to compute the CFA, if necessary for certain platforms.)


> > For DWARF frames specifically, the convention is that ->stack_addr will
> > equal the CFA.  So if you are in DWARF-specific code, and need the CFA,
> > you can make use of that convention; but the best way to do that would
> > probably be to call dwarf2_frame_cfa instead of get_frame_base.
> 
> I see now dwarf2_frame_cfa is more appropriate by its name.  The detection
> code is based on CFA (CFA_REG_OFFSET, regs.cfa_reg etc.).
> And dwarf2_frame_cfa in such case effectively just calls get_frame_base.
> 
> Unless you advice me differently I will change it this way.

Yes, dwarf2_frame_cfa would be preferable here.

> > Note however, that even the CFA is not automatically equal to some "value
> > of a SP register"; for example, on s390(x), the CFA is always biased by 96
> > (or 160) bytes against the SP at function entry ...
> 
> On s390x the adjustment code in dwarf2_tailcall_prev_register_first (detected
> inside dwarf2_frame_cache, from .debug_frame) gets into effect but in fact it
> does not change the $sp value.  Which is correct, as "brasl" does not modify
> $sp.

I see that I misunderstood your code; it does take the offset between SP and
CFA into account correctly, so it will work on s390 too.

> > I'm afraid I'm not sure exactly what all this SP manipulation code is intended
> > to achieve; could you elaborate (or is there documentation somewhere that I
> > missed)?
> 
> I dd not think it needs to be documented in the manual as it just simulates
> the expected state of inferior.
> 
> In the x86_64 sample code below when we unwind function `f' the register set
> there should be already the unwound one - the same like in the function
> `main'.  `f' just stands on the jmp instruction so it does not have any its
> own register state to unwind.
> 
> Just there is the exception $sp - in function `f' the value of $sp should not
> be the same like in the function `main' as there is the return address there.
> The two lines `XXX' - the real register state should match the later unwound
> register state.

OK, thanks for the explanation.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


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