This is an archive of the discontinued LLVM Phabricator instance.

Fix DW_OP_convert to resolve the CU relative offset correctly.
ClosedPublic

Authored by clayborg on Sep 9 2022, 4:48 PM.

Details

Summary

Debugging some DWARF5 binaries was causing errors to appear when DWARFExpression::Evaluate was called:

error: GetDIE for DIE 0x31 is outside of its CU 0x123450

The issue is in the DWARF expression evaluator. Fixed with this.

Diff Detail

Event Timeline

clayborg created this revision.Sep 9 2022, 4:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 4:48 PM
clayborg requested review of this revision.Sep 9 2022, 4:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 4:48 PM

Adrian: not sure how to test this. This all seems to be unit tested with your unit tests. If you have any ideas of how to modify the tests to verify this let me know.

You would need to modify or clone the existing test https://github.com/llvm/llvm-project/blob/38ffa2bb963714cd117b6d4534d328fa6a0fb875/lldb/unittests/Expression/DWARFExpressionTest.cpp#L153 and add a second CU to it. The inlined text is just the output of obj2yaml.

tschuett added inline comments.
lldb/source/Expression/DWARFExpression.cpp
2379

Do you need to give up the const or:

descriptive_offset = die_offset + dwarf_cu->GetOffset();

You would need to modify or clone the existing test https://github.com/llvm/llvm-project/blob/38ffa2bb963714cd117b6d4534d328fa6a0fb875/lldb/unittests/Expression/DWARFExpressionTest.cpp#L153 and add a second CU to it. The inlined text is just the output of obj2yaml.

I believe you. The main question is how top get an object file to produce this file in a small and simple test case. Are you saying it would be easy to add another CU by just appending some yaml? Or do I need to come up with a binary first that already has this in two CUs and then try to obj2yaml the binary? If so, please let me know how to make code that does this.

You would need to modify or clone the existing test https://github.com/llvm/llvm-project/blob/38ffa2bb963714cd117b6d4534d328fa6a0fb875/lldb/unittests/Expression/DWARFExpressionTest.cpp#L153 and add a second CU to it. The inlined text is just the output of obj2yaml.

I believe you. The main question is how top get an object file to produce this file in a small and simple test case. Are you saying it would be easy to add another CU by just appending some yaml? Or do I need to come up with a binary first that already has this in two CUs and then try to obj2yaml the binary? If so, please let me know how to make code that does this.

Looking at the test, I think for someone familiar with the DWARF format ;-) manually extending yaml should be pretty straightforward.

unless yaml2obj doesn't support multi-CU .debug_info sections.

clayborg updated this revision to Diff 459551.Sep 12 2022, 1:56 PM
  • Added the ability to select a compile unit by index to YAMLModuleTester
  • Added an extra empty compile unit to the yaml for DWARFExpression::DW_OP_convert test to make sure we can trigger the previous bug
  • Select the second compile unit that contains the DW_TAG_base_type entries we need for testing so the DWARF expressions succeed

Adrian: I added an extra compile unit into the YAML and verified it would fail without the fix. I also added the ability to select a different compile unit by index in the YAMLModuleTester so it can select the second compile unit in the test. Should be good to go now!

clayborg marked an inline comment as done.Sep 12 2022, 1:58 PM
aprantl accepted this revision.Sep 12 2022, 2:57 PM
This revision is now accepted and ready to land.Sep 12 2022, 2:57 PM