This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Added support for dwarf expressions DW_OP_call2/DW_OP_call4
Needs RevisionPublic

Authored by Chirag on May 6 2019, 2:40 AM.

Details

Reviewers
jingham
clayborg
Summary

dwarf expression DW_OP_call2/DW_OP_call4 performs dwarf procedure calls during evaluation of a dwarf expression or location description. The 2-byte unsigned offset for DW_OP_call2 (4-byte unsigned offset for DW_OP_call4) is a die entry in the current compilation unit. These operations transfer control of DWARF expression evaluation to the DW_AT_location attribute of the referenced die entry. If there is no such attribute present then there is no effect. the evaluation stack is shared between caller/callee and callee may add to/remove from the value on stack.

Diff Detail

Event Timeline

Chirag created this revision.May 6 2019, 2:40 AM
clayborg requested changes to this revision.May 6 2019, 9:13 AM
clayborg added inline comments.
include/lldb/Expression/DWARFExpression.h
303–304

Do we need "initial_value_ptr" anymore? We should be able to remove it and just use the "stack" argument you added below. Probably best to just turn this value into:

std::vector<Value> &stack

And remove the "std::vector<Value> &stack" below.

source/Expression/DWARFExpression.cpp
2699

die_ref_offset us a CU relative offset. You must add "dwarf_cu->GetOffset()" to this to get the correct absolute DIE offset:

dw_offset_t die_ref_offset = opcodes.GetU16(&offset) + dwarf_cu->GetOffset();

Your example will work for the first compile unit and fail for any subsequent ones since the first CU is at offset zero.

2707–2727

Make these lines into a function of DWARFExpression and call it for call2 and call4:

... DWARFExpression::EvaluateCall(DWARFDie Die, ....)
2731

add CU offset like in call2 case.

2739–2759

call new DWARFExpression::EvaluateCall() function you created as noted in above inlined comment.

This revision now requires changes to proceed.May 6 2019, 9:13 AM

Need to add a test for this as well. And to cover all cases, you will need to test in a multi-compile unit example so we can ensure the relative CU offset of the call2 or call4 works in compile units that aren't the first one.

Chirag updated this revision to Diff 198439.May 7 2019, 5:00 AM

Fixed as per comments. passed proper execution/register context. for the time being DW_OP_piece is not allowed in call op. Working on testcase.

Chirag marked 5 inline comments as done.May 7 2019, 5:02 AM
clayborg requested changes to this revision.May 7 2019, 7:28 AM

A few nits and waiting for the test case.

source/Expression/DWARFExpression.cpp
2701–2704

Move these lines into EvaluateCall and pass "die_ref_offset" as the argument instead of "ref_die"

2704

include the calculated DIE offset in the error message

2733–2736

Move these lines into EvaluateCall and pass "die_ref_offset" as the argument instead of "ref_die"

2736

include the calculated DIE offset in the error message

This revision now requires changes to proceed.May 7 2019, 7:28 AM