Page MenuHomePhabricator

[DWARF] Make llvm-dwarfdump display the .debug_loc.dwo section (fixes PR38991)
ClosedPublic

Authored by wolfgangp on Sep 24 2018, 4:21 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

wolfgangp created this revision.Sep 24 2018, 4:21 PM

Should the address size be required/used for parsing the debug_loc.dwo
section? I would think there shouldn't be any addresses, or otherwise
address-size-dependent there?

Should the address size be required/used for parsing the debug_loc.dwo
section? I would think there shouldn't be any addresses, or otherwise
address-size-dependent there?

Yes, but currently DWARFExpression is oblivious to DWO and insists on having a valid Address Size. This would have to be fixed before we can omit the address size.

Should the address size be required/used for parsing the debug_loc.dwo
section? I would think there shouldn't be any addresses, or otherwise
address-size-dependent there?

Yes, but currently DWARFExpression is oblivious to DWO and insists on having a valid Address Size. This would have to be fixed before we can omit the address size.

Is that sufficiently expensive to be worth doing this workaround in the interim?

What if the address size was hardcoded to 4 here, for example? What would go wrong in that case?

(could leave a fixit that this shouldn't be needed - maybe use Optional for the address size, so it asserts if someone doesn't provide an address size but it ends up being needed down the line)

Should the address size be required/used for parsing the debug_loc.dwo
section? I would think there shouldn't be any addresses, or otherwise
address-size-dependent there?

Yes, but currently DWARFExpression is oblivious to DWO and insists on having a valid Address Size. This would have to be fixed before we can omit the address size.

Is that sufficiently expensive to be worth doing this workaround in the interim?

The question is whether to bring it up to DWARF5 level right away or to just have it deal with DWO with what's currently supported. The former would certainly be more expensive.

What if the address size was hardcoded to 4 here, for example? What would go wrong in that case?

A DW_OP_addr or DW_OP_call_ref opcode with an 8-byte operand would cause the rest of the expression to be parsed incorrectly. That's unlikely to occur in a location list, but it would definitely fail.
As a matter of fact, DW_OP_call_ref uses AddrSize to decide whether to get 32 or 64 bits, when this should be dependent on the DWARF format (32 vs. 64). So instead of addrsize we should pass the format instead in a DWO context.

(could leave a fixit that this shouldn't be needed - maybe use Optional for the address size, so it asserts if someone doesn't provide an address size but it ends up being needed down the line)

I had originally thought to get location lists up to DWARF 5 level (i.e. just the table and range aspect), but deal with expressions later. Perhaps in the interim it's best to have what's currently there deal with DWO correctly so we don't have anything half-working out there.

One reason why we may still want addrsize is so we can skip the correct amount of bytes during parsing if we do find a DW_OP_addr in a DWO (and report an error).

Should the address size be required/used for parsing the debug_loc.dwo
section? I would think there shouldn't be any addresses, or otherwise
address-size-dependent there?

Yes, but currently DWARFExpression is oblivious to DWO and insists on having a valid Address Size. This would have to be fixed before we can omit the address size.

Is that sufficiently expensive to be worth doing this workaround in the interim?

The question is whether to bring it up to DWARF5 level right away or to just have it deal with DWO with what's currently supported. The former would certainly be more expensive.

Not sure I follow what you mean by that - what it has to do with DWARF5 or not. The pre-DWARF5 version of split-DWARF wouldn't've used addresses in the .dwo file - the addresses aren't known at that time, I think?

What if the address size was hardcoded to 4 here, for example? What would go wrong in that case?

A DW_OP_addr or DW_OP_call_ref opcode with an 8-byte operand would cause the rest of the expression to be parsed incorrectly. That's unlikely to occur in a location list, but it would definitely fail.

Those would be invalid OP kinds in location list in debug_loc.dwo though, right?

As a matter of fact, DW_OP_call_ref uses AddrSize to decide whether to get 32 or 64 bits, when this should be dependent on the DWARF format (32 vs. 64). So instead of addrsize we should pass the format instead in a DWO context.

(could leave a fixit that this shouldn't be needed - maybe use Optional for the address size, so it asserts if someone doesn't provide an address size but it ends up being needed down the line)

I had originally thought to get location lists up to DWARF 5 level (i.e. just the table and range aspect), but deal with expressions later. Perhaps in the interim it's best to have what's currently there deal with DWO correctly so we don't have anything half-working out there.

I think my general question is: What behavior of llvm-dwarfdump would be wrong if the address size was hardcoded to 4 (or 3? or any other number) for parsing debug_loc.dwo?

One reason why we may still want addrsize is so we can skip the correct amount of bytes during parsing if we do find a DW_OP_addr in a DWO (and report an error).

I think it'd be reasonable to report an error and stop parsing - skipping the rest of the location list? The value is out of place in the DWO section, so I'm not sure it's reasonable to conclude what length it should be, etc.

Should the address size be required/used for parsing the debug_loc.dwo
section? I would think there shouldn't be any addresses, or otherwise
address-size-dependent there?

Yes, but currently DWARFExpression is oblivious to DWO and insists on having a valid Address Size. This would have to be fixed before we can omit the address size.

Is that sufficiently expensive to be worth doing this workaround in the interim?

The question is whether to bring it up to DWARF5 level right away or to just have it deal with DWO with what's currently supported. The former would certainly be more expensive.

Not sure I follow what you mean by that - what it has to do with DWARF5 or not. The pre-DWARF5 version of split-DWARF wouldn't've used addresses in the .dwo file - the addresses aren't known at that time, I think?

This was more about workflow. There are a few DWARF5 operands that are not supported yet, so I was just musing whether to implement DWARF5 first completely or just fix the DWO case and complete DWARF5 later.

What if the address size was hardcoded to 4 here, for example? What would go wrong in that case?

A DW_OP_addr or DW_OP_call_ref opcode with an 8-byte operand would cause the rest of the expression to be parsed incorrectly. That's unlikely to occur in a location list, but it would definitely fail.

Those would be invalid OP kinds in location list in debug_loc.dwo though, right?

I would think at least a DW_OP_call_ref could legally occur in a location description, even in a DWO, e.g in a memory location description. Unlikely anybody generates this, I would think.

As a matter of fact, DW_OP_call_ref uses AddrSize to decide whether to get 32 or 64 bits, when this should be dependent on the DWARF format (32 vs. 64). So instead of addrsize we should pass the format instead in a DWO context.

(could leave a fixit that this shouldn't be needed - maybe use Optional for the address size, so it asserts if someone doesn't provide an address size but it ends up being needed down the line)

I had originally thought to get location lists up to DWARF 5 level (i.e. just the table and range aspect), but deal with expressions later. Perhaps in the interim it's best to have what's currently there deal with DWO correctly so we don't have anything half-working out there.

I think my general question is: What behavior of llvm-dwarfdump would be wrong if the address size was hardcoded to 4 (or 3? or any other number) for parsing debug_loc.dwo?

If it's hard-coded to anything other than 4 or 8 the constructor for DWARFExpression would assert. If it's hard-coded to 4 it would work just fine (except for the DW_OP_call_ref example with an 8-byte operand mentioned above, and that would probably just report an obscure error and move on to the next list).

If it's hard-coded to anything other than 4 or 8 the constructor for DWARFExpression would assert. If it's hard-coded to 4 it would work just fine (except for the DW_OP_call_ref example with an 8-byte operand mentioned above, and that would probably just report an obscure error and move on to the next list).

In fact, the 8-byte operand would only be valid for DWARF64, which we don't support at the moment, so the bottom line is I can't see anything that would be incorrectly handled with a hard-coded 4.

wolfgangp updated this revision to Diff 167027.Sep 25 2018, 4:51 PM

Hardcoding address size to 4 as a workaround with a FIXME comment. DWARFExpression is unaware of DWO and requires it at the moment.

dblaikie accepted this revision.Oct 2 2018, 3:29 PM

You should be able to remove the condition on numDWOCompileUnits now that parsing debug_loc.dwo doesn't need a CU of any kind? Be good to have a/the test case validate that the dumping works in the absence of any debug_info(.dwo) sections. Just the debug_loc.dwo all by itself. (this is my main motivation with the line of questioning/discussion here - it's nice to be able to dump independent sections even if they appear alone and/or without parsing other (Possibly corrupt) debug info)

(also, I did go back and read the spec - and you're right that call_ref uses an address-width-sized value, and that it could be used in debug_loclists.dwo. Appendix B of DWARF5 even states specifically (in (fo)) that DW_OP_call_ref can be used to reference from somewhere in debug_info.dwo to somewhere else in debug_info.dwo - though interestingly it doesn't mention any chance of referencing debug_info.dwo from debug_loc.dwo - so maybe it isn't valid in debug_loclists.dwo (or debug_loc.dwo)?

And honestly I'm not sure it makes sense to use it in debug_info.dwo either - because DWP tools are meant to work without relocations - and this form would require a relocation)

This revision is now accepted and ready to land.Oct 2 2018, 3:29 PM

(also, I did go back and read the spec - and you're right that call_ref uses an address-width-sized value, and that it could be used in debug_loclists.dwo.

Where do you see that? In DWARF 5, section 2.5.1.5, item 4 (p.36) it says call_ref is a reference not an address; its size depends on format (32/64) not target address size.

Appendix B of DWARF5 even states specifically (in (fo)) that DW_OP_call_ref can be used to reference from somewhere in debug_info.dwo to somewhere else in debug_info.dwo - though interestingly it doesn't mention any chance of referencing debug_info.dwo from debug_loc.dwo - so maybe it isn't valid in debug_loclists.dwo (or debug_loc.dwo)?

And honestly I'm not sure it makes sense to use it in debug_info.dwo either - because DWP tools are meant to work without relocations - and this form would require a relocation)

This is probably a spec bug; DW_OP_call_ref (and DW_FORM_ref_addr) shouldn't be allowed in a .dwo section. I see call_ref is already prohibited in type units, and .dwo sections should follow the same reasoning, I think. I'll file this as a DWARF issue.

(also, I did go back and read the spec - and you're right that call_ref uses an address-width-sized value, and that it could be used in debug_loclists.dwo.

Where do you see that? In DWARF 5, section 2.5.1.5, item 4 (p.36) it says call_ref is a reference not an address; its size depends on format (32/64) not target address size.

sorry, yes, I meant format

Appendix B of DWARF5 even states specifically (in (fo)) that DW_OP_call_ref can be used to reference from somewhere in debug_info.dwo to somewhere else in debug_info.dwo - though interestingly it doesn't mention any chance of referencing debug_info.dwo from debug_loc.dwo - so maybe it isn't valid in debug_loclists.dwo (or debug_loc.dwo)?

And honestly I'm not sure it makes sense to use it in debug_info.dwo either - because DWP tools are meant to work without relocations - and this form would require a relocation)

This is probably a spec bug; DW_OP_call_ref (and DW_FORM_ref_addr) shouldn't be allowed in a .dwo section. I see call_ref is already prohibited in type units, and .dwo sections should follow the same reasoning, I think. I'll file this as a DWARF issue.

SGTM - thanks!

wolfgangp updated this revision to Diff 168182.Oct 3 2018, 3:29 PM
  • Removed the condition on the existence of compile units.
  • Added a test to check that llvm-dwarfdump can dump the .debug_loc.dwo section even without compile units present.
dblaikie accepted this revision.Oct 4 2018, 11:01 AM
dblaikie added inline comments.
test/tools/llvm-dwarfdump/X86/debug_loc_dwo.ll
5–6 ↗(On Diff #168182)

I think this is already tested - in, say, test/DebugInfo/X86/fission-ranges.ll

I think you can probably skip this test case - and just keep the other one that's testing the new functionality you're enabling?

test/tools/llvm-dwarfdump/X86/debug_loc_dwo.s
15 ↗(On Diff #168182)

What further interpretation of the address index could it do?

wolfgangp added inline comments.Oct 4 2018, 12:07 PM
test/tools/llvm-dwarfdump/X86/debug_loc_dwo.ll
5–6 ↗(On Diff #168182)

There is a subtle difference between the fission-ranges.ll and this one. In fission-ranges, the object file contains both the non-split and the split sections, which is why it was passing even before this fix.

The new test case demonstrates that it works also when the .dwo sections have been separated out into a separate .dwo file, which was not working.

I can fold this case into fission-ranges if you prefer.

test/tools/llvm-dwarfdump/X86/debug_loc_dwo.s
15 ↗(On Diff #168182)

What further interpretation of the address index could it do?

Theoretically, if you're dumping an object file where the fission sections haven't been separated out yet, you could refer to the skeleton unit's .debug_addr section through the index and dump the actual addresses. Don't know if that would be a common use-case, though.

dblaikie added inline comments.Oct 4 2018, 12:12 PM
test/tools/llvm-dwarfdump/X86/debug_loc_dwo.ll
5–6 ↗(On Diff #168182)

Ah, I see.

Not sure it's worth test coverage though - if it can be dumped without any other sections (demonstrated by the other test), then the fact that it can be dumped with some but not other sections present seems like it's not an interesting/distinct case to test for?

test/tools/llvm-dwarfdump/X86/debug_loc_dwo.s
15 ↗(On Diff #168182)

Fair enough - doesn't seem to be relevant to this test case (since there's no debug_addr section in this file), so might be confusing in a comment here?

wolfgangp updated this revision to Diff 168835.Oct 9 2018, 10:59 AM

Eliminated one of the test cases due to redundancy and adjusted a comment in the other one.

test/tools/llvm-dwarfdump/X86/debug_loc_dwo.ll
5–6 ↗(On Diff #168182)

True, the other test case covers the failing case as well. I'll remove it then.

test/tools/llvm-dwarfdump/X86/debug_loc_dwo.s
15 ↗(On Diff #168182)

OK I'll get rid of it.

dblaikie accepted this revision.Oct 9 2018, 11:03 AM

Great - thanks!

This revision was automatically updated to reflect the committed changes.