This is an archive of the discontinued LLVM Phabricator instance.

DW_OP_const* is invalid as a location
ClosedPublic

Authored by kromanova on Dec 8 2014, 11:53 AM.

Details

Reviewers
dblaikie
echristo
Summary

This is a fix for BZ #21776.
http://llvm.org/bugs/show_bug.cgi?id=21776

Before DW_OP_stack_value was introduced in DWARF4, llvm relied on heuristics to disambiguate the value vs. location status of the expression DW_OP_consts <const>.

The proper (compliant with DWARF) way to describe a location where a value is constant is "DW_OP_constu <const>, DW_OP_stack_value”.

I pushed DW_OP_stack_value on the stack, where DW_OP_consts or DW_OP_constu were used to describe location description with the DWARF expression that represents the actual value of the object rather than its location.

Diff Detail

Event Timeline

kromanova updated this revision to Diff 17045.Dec 8 2014, 11:53 AM
kromanova retitled this revision from to DW_OP_const* is invalid as a location.
kromanova updated this object.
kromanova edited the test plan for this revision. (Show Details)
kromanova added a subscriber: Unknown Object (MLST).
dblaikie added inline comments.
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
1721

Should this just go outside the if/else, so it's written once rather than twice?

1721

Do we need to conditionalize this based on whether we're emitting DWARF >= 4? And just leave it the old/broken way in DWARF < 4 for old consumers to keep guessing the way they have before (like LLDB)?

test/DebugInfo/incorrect-variable-debugloc1.ll
15

Can this example be simplified further? (do we need the loop, etc?)

kromanova updated this object.Dec 8 2014, 12:01 PM
kromanova removed a subscriber: dblaikie.
echristo added inline comments.
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
1721

Seems the most reasonable thing to do, yes.

friss added a subscriber: friss.Dec 8 2014, 1:52 PM

Did you confirm that the OP_stack_value is correctly handled by lldb and that this produces no regression?

And I agree with others that this should be conditional on Dwarf 4 output. This gives consumers at least some coarse grain switch to know how to interpret expressions.

kromanova added inline comments.Dec 8 2014, 2:37 PM
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
1721

Reasonable :)

1721

Good point. I will add the condition. When I submit a bug against the LLDB, I will make a note that "old/broken" expressions will still be generated for < DWARF 4.

test/DebugInfo/incorrect-variable-debugloc1.ll
15

I will simplify the test as much as I can.
BTW, thank you David for reviewing the patch so quickly!

15

Is there an elegant solution to test different Dwarf versions (Dwarf-2, Dwarf-3 and Dwarf-4) using .ll file, while avoiding creation of multiple copies of the same test with only one line difference in metadata representing Dwarf Version.

!12 = metadata !{i32 2, metadata !"Dwarf Version", i32 4} needed for dwarf-4 test
!12 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}
needed for dwarf-2 test

Or should I create a .cpp test instead of .ll test to avoid duplication of the test?

dblaikie added inline comments.Dec 8 2014, 2:40 PM
test/DebugInfo/incorrect-variable-debugloc1.ll
15

Yep - check the other test cases that have "-dwarf-version" in the llc command line.

kromanova updated this revision to Diff 17075.Dec 9 2014, 1:43 AM

I have updated the patch based on Eric, David, Paul and Frédéric's reviews.

Using a small testcase, I have checked that LLDB works as expected (at least on Unix) with an object file compiled at -gdwarf-4( new way) and an object file compiled at -gdwarf-3, -gdwarf-2 (old way). Is there anything else I need to modify/check?

friss added a comment.Dec 9 2014, 7:03 AM

This is mostly OK, just some small nits:

test/DebugInfo/incorrect-variable-debugloc1.ll
8

I'd say 'doesn't describe a constant value, but a value at a constant address'. AFAIK, the location is valid, it's just not what we want to describe :-)

28–29

We usually edit these out when the testcase is target independent (And otherwise it should go to a target specific directory)

kromanova updated this revision to Diff 17090.Dec 9 2014, 1:07 PM

Addressed Fred's comments.

dblaikie added inline comments.Dec 9 2014, 1:12 PM
test/DebugInfo/incorrect-variable-debugloc1.ll
23

You probably need a {{$}} at the end of this line, otherwise it'll pass even if we emit the DWARF4 form here (test this by removing the conditional in your fix and observing that this test doesn't fail where it should)

kromanova updated this revision to Diff 17093.Dec 9 2014, 1:16 PM

Please ignore the previous revision. I accidentally uploaded an old diff.

kromanova updated this revision to Diff 17102.Dec 9 2014, 4:38 PM

Modified testcase based on David's comment.
Verified what Dave have asked; i.e that after removing the conditional in DwarfDebug.cpp (i.e causing it always generate DWARF-4) the test fails where it is expected to fail (in DWARF23: check).

dblaikie accepted this revision.Dec 9 2014, 4:39 PM
dblaikie added a reviewer: dblaikie.

Looks good, apart from the minor comment improvement.

test/DebugInfo/incorrect-variable-debugloc1.ll
7

Usually we write this as "PR21176" (rather than "BZ #21176").

This revision is now accepted and ready to land.Dec 9 2014, 4:39 PM
kromanova added inline comments.Dec 9 2014, 9:37 PM
test/DebugInfo/incorrect-variable-debugloc1.ll
7

I will make this change in the comment before I commit. I guess, It might make the grep more consistent.
I don't see any benefit in uploading one more review for this reason only.

Is it OK to commit or should I wait to make sure that Fred and Eric don't have any additional comments?
Katya.

23

You are right. I'll fix it.

kromanova updated this revision to Diff 17188.Dec 11 2014, 1:38 PM
kromanova edited edge metadata.

Buildbots spotted a failure for PowerPC platform for the incorrect-variable-debugloc1.ll test that I added.
Uploading a diff once again.

(1) Eric asked me to add a comment with the explanation in the source file (for the patch itself). Done.
(2) David asked me to change BZ 21776 into PR21776 in the testcase's comment. Done.
(3) I added XFAIL condition (and a comment) for PowerPC platform.

Does it look good?

Couple of comments inline, otherwise LGTM.

-eric

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
1725

80-col?

test/DebugInfo/incorrect-variable-debugloc1.ll
4

"Temporarily marking this test as XFAIL..."

12

PR...

echristo accepted this revision.Dec 11 2014, 1:45 PM
echristo added a reviewer: echristo.
kromanova updated this revision to Diff 17194.Dec 11 2014, 2:44 PM
kromanova edited edge metadata.

Addressed Eric's comments.

kromanova added inline comments.Dec 11 2014, 2:46 PM
test/DebugInfo/incorrect-variable-debugloc1.ll
4

Overlooked "marking" comment. If everything else is OK, I will change it before I commit and not going to upload one more review.

Yep. LGTM with the comment wording change.

-eric

Looks like patch was not committed.

It was committed in r224098. However, I don't see traces of it anymore. I need to track down if it was moved, deleted or rewritten.
Katya.

This code was removed in 225734. I will subscribe Adrian since he did this change.

I just looked around more carefully.
DwarfExpression::AddSignedConstant and DwarfExpression::AddUnsignedConstant call DwarfExpression::AddStackValue(), which adds "DW_OP_stack_value".
I think the logic is still there, but was just moved/re-factored.

The test was moved to llvm/test/DebugInfo/Generic/incorrect-variable-debugloc1.ll

kromanova closed this revision.Oct 4 2016, 9:08 PM

Closed by commit r224098.