Issue 020712.1: New operator: DW_OP_call_frame_cfa

Author: Todd Allen
Champion: Todd Allen
Date submitted: 2002-07-12
Date revised:
Date closed:
Type: Extension
Status: Accepted
DWARF Version: 3
The .debug_frame section has the notion of a CFA defined by the state machine
at various points.  It seems likely that any producer of .debug_frame
information will endeavor to make the CFA accurate 100% of the time.

The .debug_info section has the notion of a "frame base" defined by the
DW_AT_frame_base attribute and referenced by variables, etc.  A lot of
implementations define it as a locdesc, which tends to be inaccurate during
parts of the prologue and epilogue(s).  The standard suggests that a robust
implementation might use a loclist to correct that.  (Does anyone?  I haven't
encountered an implementation that did, but I hardly have seen all.)

Using a loclist solution for the DW_AT_frame_base ought to work.  But it
seems that the "frame base" usually will be a simple offset from the CFA,
maybe even 0.  In gcc/i86-generated code with no weird options, we've
observed that frame_base = CFA - 8.  (Presumably the 8 bytes being the return
address and pushed %ebp register.)  So, describing the frame base with a
loclist seems like replication of information.

We think it would be nice to be able to describe the .debug_info's frame base
in terms of the .debug_frame's CFA.  To do that, we'd add a new locdesc
operator, like:

   DW_OP_call_frame_cfa

It would push the value of the CFA on the expression stack.  For the gcc/i86
case above, the locdesc for DW_AT_frame_base then would be:

   DW_AT_frame_base [ DW_OP_call_frame_cfa DW_OP_lit8 DW_OP_minus ]

And then DW_AT_frame_base is 100% accurate, and without having to pay the
cost of a loclist.

Obviously, it's only meaningful if the .debug_frame information is present.

Jim Blandy

todd.allen@ccur.com (Todd Allen) writes:
> Thoughts?

I think that sounds like a great idea!


PROPOSAL:

Add to section 2.4.1.2  Register Based Addressing

4. DW_OP_call_frame_cfa
   Pushes the current value of the CFA (see Call Frame
   Information) onto the expression stack.
   Can be useful when in the locdesc for a DW_AT_frame_base,
   for example.

Change the introductory sentence of the section to

"The following operations push a value onto the stack based
on register information."

Add the new operator into the relevant tables, assign the
next available number to it.

----------------------------------------------------------------

Revised proposal, May 31, 2005:

Add a new numbered item to the end of section 2.4.1.3:

n. DW_OP_call_frame_cfa

  The DW_OP_call_frame_cfa operation pushes the value of the CFA,
  obtained from the Call Frame Information (described in section 6.4).

  *Although the CFA can be computed using other Dwarf expression
  operators, in some cases this would require an extensive location list
  because the values of the registers used in computing the CFA change
  during a subroutine.  If the Call Frame Information is present, then it
  already encodes such changes, and it is space efficient to reference
  that.*

Add to Figure 23 (in section 7.1.1):

   DW_OP_call_frame_cfa   0x9c   0

   Add a DW_OP_call_frame_cfa index entry referencing those two positions.

---------------------------------------------------------

Accepted as revised.