[llvm-bugs] [Bug 32382] New: LLVM may create invalid DWARF 4+ expressions

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 22 14:36:50 PDT 2017


            Bug ID: 32382
           Summary: LLVM may create invalid DWARF 4+ expressions
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: DebugInfo
          Assignee: unassignedbugs at nondot.org
          Reporter: aprantl at apple.com
                CC: llvm-bugs at lists.llvm.org

As I recently confirmed on a thread on the dwarf-discuss mailing list
LLVM's DwarfExpression implementation can generate illegal DWARF 4+. This
hasn't been noticed thus far, because for relatively simple DWARF expressions
the difference doesn't matter, but as we get better about preserving debug
locations, this is becoming urgent.

To give a simplified overview, DWARF 4+ location descriptions come in multiple
- Register location descriptions
  - describe a variable in a register
  - consist of only a DW_OP_reg
- Memory location descriptions
  - describe the address of a variable
- Implicit location descriptions
  - describe the value of a variable
  - end with DW_OP_stack_value & friends
- Composite location descriptions
  - use DW_OP_piece & friends to combine multiple location
    descriptions of any of the previous kinds

Based on this, there are three main problems with LLVM's implementation:
1. DW_OP_reg is not allowed outside of register location descriptions.
2. We are sometimes missing a DW_OP_stack_value.
   2a. In DWARF 2&3 we should not emit anything that needs a
       DW_OP_stack_value that is not a constant.
3. LLVM uses DW_OP_breg when it means "deref the contents of that register",
   which is only correct if no arithmetic operators follow.
   Because of the missing DW_OP_stack_value the location will be classified as
   a memory location description and thus it usually works out.

In the last couple of days I refactored DwarfExpression to make fixing all of
these issues easy. We can now defer the decision on which kind of location
description to emit (and thus whether to use DW_OP_reg vs. DW_OP_breg
(+DW_OP_stack_value)) until we know the remainder of the expression.

The bugfixes won't affect any straightforward location descriptions (i.e.:
DW_OP_(b)reg without any operators, and DW_OP_breg DW_OP_deref will remain the
same) so I'm not expecting any dramatic fallout from fixing this PR, but please
do keep an eye on your debugger bots and let me know if your tools have come to
depend on LLVM bugs and we need to do some debugger tuning to make things work.
I will keep an eye on LLDB and make sure that it doesn't suffer from the same
problems as LLVM.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170322/d29875f7/attachment.html>

More information about the llvm-bugs mailing list