[Dwarf-Discuss] variable locations - safe use as lvalues

Cary Coutant ccoutant@gmail.com
Tue Jan 21 00:05:34 GMT 2020


> A debugger cannot currently be told that any particular variable
> location expression is safe to use as an lvalue, something roughly
> "exclusive, exhaustive, -O0-equivalent".  I believe most debuggers
> don't even handle the multiple-locations case for writes at all.  I
> don't know why - assume complications are rare?  or we have kind of
> papered over the problem?
>
> As a DWARF standard level matter, descriptive rather than prescriptive
> as it is, what might be the minimum extension required to communicate
> lvalue-safety to a debugger?  A DW_OP_lvalue_safe assertive wrapper
> around a real expression?

In DWARF 5, we added the concepts of bounded and default location
descriptions. I think it would generally be safe to modify a value
under the following conditions:

(a) The variable's location is covered by a single location
description, or by a location list with a default location description
but where no bounded location description matches the current pc.

(b) Such location description is a simple memory or register location.

(c) You're stopped at a suggested breakpoint location.

I'm sure there are circumstances where you could still get into
trouble (e.g., your third example), but I think it would be unusual,
and there we'd probably be talking about a quality of implementation
issue. The courteous thing for a compiler to do would be to at least
try to make this ok at suggested breakpoint locations, though I
wouldn't expect a compiler at -O2 to deliberately avoid an
optimization solely for the sake of being able to modify a variable
while stopped at a breakpoint.

In your third example, once the compiler has loaded a copy of the
variable into a register to use in a computation, it could (should?)
create a bounded location description, thus marking it unsafe under
the rules above. So, rather than mark lvalue-safe regions, a compiler
could instead use a bounded location descriptions to mark a region
unsafe that wouldn't already be deemed unsafe.

-cary



More information about the Dwarf-discuss mailing list