This is an archive of the discontinued LLVM Phabricator instance.

[LLDB] - Add support for DW_FORM_implicit_const.
ClosedPublic

Authored by grimar on Sep 29 2018, 7:38 AM.

Details

Summary

LLDB does not support this DWARF5 form atm.
At least gcc emits it in some cases when doing optimization
for abbreviations.

As far I can tell, clang does not support it yet, though
the rest LLVM code already knows about it.

The patch adds the support.

Diff Detail

Event Timeline

grimar created this revision.Sep 29 2018, 7:38 AM
vsk added a subscriber: vsk.Oct 2 2018, 3:02 PM

Could you describe how the test exercises DW_FORM_implicit_const support? It's not immediately clear to me.

grimar added a comment.Oct 3 2018, 2:48 AM
In D52689#1253175, @vsk wrote:

Could you describe how the test exercises DW_FORM_implicit_const support? It's not immediately clear to me.

The abbreviation for foo1 and foo2 subprograms use it for DW_AT_decl_file and DW_AT_decl_column:

[1] DW_TAG_subprogram	DW_CHILDREN_no
	DW_AT_external	DW_FORM_flag_present
	DW_AT_name	DW_FORM_strp
	DW_AT_decl_file	DW_FORM_implicit_const	1
	DW_AT_decl_line	DW_FORM_data1
	DW_AT_decl_column	DW_FORM_implicit_const	5
	DW_AT_linkage_name	DW_FORM_strp
	DW_AT_type	DW_FORM_ref4
	DW_AT_low_pc	DW_FORM_addr
	DW_AT_high_pc	DW_FORM_data8
	DW_AT_frame_base	DW_FORM_exprloc
	DW_AT_call_all_calls	DW_FORM_flag_present
clayborg requested changes to this revision.Oct 9 2018, 7:43 AM

See inline comments.

source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
41

Switch to using a "DWARFFormValue *form_value_ptr" so the form value can be filled in automatically, not just the DWARFFormValue::ValueType. See comments below where this is called.

source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
387

Remove this as it won't be needed if we do the work of filling in the form value in GetAttrAndFormByIndexUnchecked

426

Remove? See inlined comment below.

428–435

Maybe switch the order here and pass "form_value" to GetAttrAndFormByIndexUnchecked?:

DWARFFormValue form_value(cu, form);
abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form, &form_value);
501

Revert this if we do the work inside "GetAttrAndFormByIndexUnchecked" as form_value will be correct

506

You changed the logic here incorrectly from == to !=

507

Revert this if we do the work inside "GetAttrAndFormByIndexUnchecked" as form_value will be correct

511

You changed the logic here incorrectly from == to !=

512

Revert this if we do the work inside "GetAttrAndFormByIndexUnchecked" as form_value will be correct

516

You changed the logic here incorrectly from == to !=

517

Revert this if we do the work inside "GetAttrAndFormByIndexUnchecked" as form_value will be correct

521

Revert this if we do the work inside "GetAttrAndFormByIndexUnchecked" as form_value will be correct

source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
158–159

Revert this if we do the work inside "GetAttrAndFormByIndexUnchecked" as form_value will be filled in by that call

source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
59–60

Revert this if we do the work inside "GetAttrAndFormByIndexUnchecked" as form_value will be filled in by that call

This revision now requires changes to proceed.Oct 9 2018, 7:43 AM
grimar updated this revision to Diff 169005.Oct 10 2018, 7:08 AM
grimar marked 12 inline comments as done.
  • Addressed review comments.
source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
41

Answered below.

source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
387

Answered below.

428–435

DWARFFormValue form_value(cu, form);

We can not do this because at this point form is not yet known.
I changed the code in a bit different way though.

501

The problem I see here is the following:

DWARF5 spec says (2.14 Declaration Coordinates, p50):
"Any debugging information entry representing the declaration of an object,
module, subprogram or type may have DW_AT_decl_file, DW_AT_decl_line and
DW_AT_decl_column attributes, each of whose value is an unsigned integer
constant
."

But about DW_FORM_implicit_const it says (p207):

"The attribute form DW_FORM_implicit_const is another special case. For
attributes with this form, the attribute specification contains a third part, which is
a signed LEB128 number. The value of this number is used as the value of the
attribute, and no value is stored in the .debug_info section."

So I read DW_FORM_implicit_const to value.sval and I think we can not
use form_value.Unsigned(); in that case because it reads from uval.
Writing to one union field and reading from the another is undefined behavior in C++ I believe.
Though it works with the modern compilers I think.

DWARFFormValue.h contains dead enum (it is unused)
https://github.com/llvm-mirror/lldb/blob/master/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h#L51
which intention seems was about to keep the value type information.
Should we start to set and check the type of form value?

I removed the helper for now, but this UB should be addressed somehow I think?

Should we create`DWARFFormValue::GetSignedOrUnsigned` may be? It perhaps will be consistent
with DWARFFormValue::Address/AsCStringwhich check the form type and returned value depends
on that.

clayborg requested changes to this revision.Oct 10 2018, 9:55 AM

A few things inlined. Very close. DumpAttribute will need to take a DWARFFormValue in order to dump the value correctly.

source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
43–44

It would be nice to be able to access the dw_form_t and DWARFFormValue::ValueType within "form_value" without having to create a temp variables here for both "form" and "val". Fine to add accessors that return references for the form_t and DWARFFormValue::ValueType to DWARFFormValue.

45–46

If we are able to follow my last inline comment, then these go away.

source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
23

Do we need to use a "DWARFFormValue::ValueType" here? Right now we only need a int64_t and DWARFFormValue::ValueType is larger than that. It does future proof us a bit and there aren't all that many abbreviations, even in a large DWARF file. Just thinking out loud here

source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
630–631

DumpAttribute will need to take the full form_value in order to dump DW_FORM_implicit_const forms correctly. Change DumpAttribute to take a "form_value"

This revision now requires changes to proceed.Oct 10 2018, 9:55 AM
grimar updated this revision to Diff 169177.Oct 11 2018, 2:57 AM
grimar marked 4 inline comments as done.
  • Addressed review comments.
source/Plugins/SymbolFile/DWARF/DWARFAttribute.h
23

My thoughts to use DWARFFormValue::ValueType were that it seems a bit more generic,
as standard can add other kinds of values rather than int64_t perhaps in future.
And it seems to be a bit cleaner because DWARFFormValue::ValueType is already
existent class representing the form value while int64_t would be kind of exception/special case.
I agree that for now, it is a bit excessive to have DWARFFormValue::ValueType here though.

source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
630–631

Done. I had to make it non-const DWARFFormValue &form_value because ExtractValue call inside DumpAttribute is not const.
As an alternative, we could probably use pass it by value here. But since there is a only one DumpAttribute call, I think its ok.

Down to just modifying the DWARFFormValue constructor to be able to take a CU only. Looks good.

source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
241–242

Make either a constructor that takes just a CU or provide a default value for the dw_form_t form? Then this code will be:

DWARFFormValue form_value(cu);
429–430

Make either a constructor that takes just a CU or provide a default value for the dw_form_t form? Then this code will be:

DWARFFormValue form_value(cu);
625–626

Make either a constructor that takes just a CU or provide a default value for the dw_form_t form? Then this code will be:

DWARFFormValue form_value(cu);
803–804

Make either a constructor that takes just a CU or provide a default value for the dw_form_t form? Then this code will be:

DWARFFormValue form_value(cu);
grimar updated this revision to Diff 169209.Oct 11 2018, 7:47 AM
  • Addressed review comments.
clayborg accepted this revision.Oct 11 2018, 8:52 AM

Thanks for making the changes. Looks good!

This revision is now accepted and ready to land.Oct 11 2018, 8:52 AM
This revision was automatically updated to reflect the committed changes.