[Dwarf-Discuss] Location list entries for caller-saved registers at time of call

Ron Brender ron.brender at gmail.com
Thu Dec 6 12:36:34 PST 2018


Comments are inline...

On Thu, Dec 6, 2018 at 7:40 AM David Stenberg via Dwarf-Discuss <
dwarf-discuss at lists.dwarfstd.org> wrote:

> Hi!
>
> When GDB and LLDB perform virtual unwinding, they subtract one byte
> from the return addresses of the outer frames. This is for example
> necessary when unwinding from a non-returning call that is placed last
> in the function, as the return address then can point to a different
> function. I assume that this is also necessary to get the variables
> that were in scope at the time of the call, and the right location
> expressions for the variables, etc.
>

Yes, I am aware of this practice--indeed, it is mentioned in Section 6.4.4
of both the
V4 and V5 standards.

Another perfectly good solution is for the compiler to assure that the
return PC is always in the
right scope to begin with. All it takes is to include a (never executed)
NOP following any non-returning
CALL at the last address of the routine.Such calls are not common, plus
many environments align
the beginning of (any subsequent) functions anyway so padding bytes are
likely to be available. As a
result, such "extra" bytes are not going to be a space issue.

As far as I have understood it, GCC utilizes this fact for location
> list entries that are expressed in caller-saved registers, by
> subtracting one from the (exclusive) ending address of the entries.
> This means that variables in outer frames that are located in caller-
> saved registers will be printed out as <optimized out> by GDB.
>

Here you lose me. Once you do what is described in your first paragraph,
there seems no need
to do anything special about location lists at all. You seem to be saying
that GCC somehow
mis-represents those ranges for some reason, but I don't follow how or why
or under what
circumstances?

I have not been able to find anything in the DWARF standard that
> describes this. Is this something that is defined by standard, or is it
> established praxis between GCC and GDB? If the latter, do you know of
> other producers and consumers that behave like this.
>

As mentioned, see Section 6.4.4 of both the V4 and V5 standards.

GCC (or other producers) has nothing to do with it. GCC (or other
producers) should just describe
the program as it exists. Only the debugger needs to know how to avoid this
quirk of no-return
optimization.


> The reason why I ask this is because Clang/LLVM at the moment ends
> location list entries expressed in caller-saved registers at the first
> instruction after the call. This means that variables in outer frames
> using such location list entries will incorrectly be evaluated using
> the inner-most frame's register values when debugging in GDB.
>

But if GDB does what you say in the first paragraph, this will not be a
problem.
I don't follow...

>
> (As a side note, as far as I have understood it, LLDB has fallback
> knowledge of the ABI, so caller-saved registers will be considered
> unavailable in outer frames, meaning that such location list entries
> are not an issue when combining Clang/LLVM and LLDB.)
>
> Best regards,
> David
> _______________________________________________
> Dwarf-Discuss mailing list
> Dwarf-Discuss at lists.dwarfstd.org
> http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dwarfstd.org/pipermail/dwarf-discuss-dwarfstd.org/attachments/20181206/eca63579/attachment.html>


More information about the Dwarf-Discuss mailing list