[PATCH] D85085: Fix debug_loc offset difference with basic block sections

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 21:47:13 PDT 2020


dblaikie added a comment.

In D85085#2225426 <https://reviews.llvm.org/D85085#2225426>, @tmsriram wrote:

> In D85085#2225425 <https://reviews.llvm.org/D85085#2225425>, @dblaikie wrote:
>
>> In D85085#2225420 <https://reviews.llvm.org/D85085#2225420>, @tmsriram wrote:
>>
>>> @amharc
>>>
>>> When basic block sections are on and the debug_loc entries span multiple sections, emit entries for each section.  This keeps the fidelity and there is no loss of debug information.
>>>
>>> To summarize, by default there is only one entry which is collapsed into a DW_AT_const_value.
>>>
>>> WIth basic block sections, this one entry spans multiple sections and must be split into an entry for each section.
>>
>> if the location is valid for the entire range of the enclosing scope, it could still be described with a single DW_AT_const_value, I think?
>>
>> DWARFv5 spec: "[single (non-loclist) location descriptions] are sufficient for describing the location of any object as long as its lifetime is either static or the same as the lexical block that owns it, and it does not move during its lifetime"
>
> I am not sure I fully understood what you meant here, could you please elaborate?  With sections, since the individual sections could be separated and can become disjoint you need one per section right?  Maybe you meant something else.

Ah, sure, sorry - if a variable only has one location, and that location is valid for the entire range of its enclosing scope (even if that enclosing scope is fragmented/uses ranges (rather than high/low) to describe its valid set of addresses) then the variable can use a simple/single location description.

Take for example this code:

  void f1();
  void f2() {
    {
      int i = 7;
      f1();
      f1();
    }
    f1();
  }

compiled to LLVM IR with optimizations, then manually modified to reorder the 2nd and 3rd calls to f1 (to cause the valid set of addresses for the explicit lexical scope that contains `i` to become fragmented, and need a DW_AT_ranges to describe its valid addresses (the first f1 call, then the interleaved (originally 3rd, now second) f1 call which isn't part of tnhe scope, then more scope with the last call to f1)), this produces the following DWARF:

  DW_TAG_subprogram
    DW_AT_low_pc    (0x0000000000000000)
    DW_AT_high_pc   (0x0000000000000011)
    DW_AT_name      ("f2")
    ...
  
    DW_TAG_lexical_block
      DW_AT_ranges  (0x00000000
        [0x0000000000000001, 0x0000000000000006)
        [0x000000000000000b, 0x0000000000000011))
  
      DW_TAG_variable
        DW_AT_const_value   (7)
        DW_AT_name  ("i")
        ...
      NULL

Despite 'i' having a disjoint valid range (it's only valid in the [1, 6)+[b, 11) instructions) - it doesn't need to use a loclist to describe its location, because its location is the same for the entire life of its enclosing scope, which is the implicit range that the location is valid over if no location list is used.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85085/new/

https://reviews.llvm.org/D85085



More information about the llvm-commits mailing list