This is an archive of the discontinued LLVM Phabricator instance.

[macho2yaml] Refactor the DWARF section dumpers.
ClosedPublic

Authored by Higuoxing on Aug 7 2020, 12:55 AM.

Details

Summary

This patch refactors the DWARF section dumpers. When dumping a DWARF
section, if the DWARF parser fails to parse the section, we will dump it
as a raw content section. This patch also fixes a bug in
DWARFYAML::Data::isEmpty(). Finally, a test case that tests dumping the
__debug_aranges section is added.

Diff Detail

Event Timeline

Higuoxing created this revision.Aug 7 2020, 12:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2020, 12:55 AM
Higuoxing requested review of this revision.Aug 7 2020, 12:55 AM
grimar added inline comments.Aug 7 2020, 1:30 AM
llvm/tools/obj2yaml/macho2yaml.cpp
29

Probably, std::unique_ptr<MachOYAML::Object> &Y -> const MachOYAML::Object &Y
would express the intention better (doesn't seem you need the ability to really access/change the std::unique_ptr<...> holder of Y).

154

Why not just something like the following?

if (SecName == "__debug_abbrev")
  return dumpDebugAbbrev(DCtx, DWARF);
if (SecName == "__debug_aranges")
  return dumpDebugARanges(DCtx, DWARF);
Higuoxing updated this revision to Diff 283844.Aug 7 2020, 2:13 AM
Higuoxing marked an inline comment as done.

Address review comments.

Thanks for reviewing!

llvm/tools/obj2yaml/macho2yaml.cpp
29

Y.DWARF is modified in dumpDebugSection(), so I change it to MachOYAML::Object &Y.

grimar added inline comments.Aug 7 2020, 2:19 AM
llvm/tools/obj2yaml/macho2yaml.cpp
153

Perhaps we need a test for an unknown debug section to test this?
E.g. a test for an arbitrary "__debug_foo" that shows that we are able to and actually emit a raw content for it.

Higuoxing updated this revision to Diff 283857.Aug 7 2020, 3:01 AM

Add two test cases.

debug-aranges.yaml (e)
unrecognized-debug-section.yaml

Higuoxing added inline comments.Aug 7 2020, 3:03 AM
llvm/tools/obj2yaml/macho2yaml.cpp
153

The implementation of yaml2macho is buggy, we cannot specify the content of a section whose segname is __DWARF.

if (Sec.segname == "__DWARF") {
  if (Sec.sectname == "__debug_str")
    Err = emitDebugStr();
  else if (Sec.sectname == "__debug_info")
    Err = emitDebugInfo();
  ...
  else if (Sec.sectname == "__debug_line")
    Err = emitDebugLine();

  if (Err)
    return Err;
  continue;              // Emitting the custom content is unreachable.
}

if (Sec.content)
  emitContent();

So I create a section whose segname is __FOO and sectname is __debug_foo to bypass the ec.segname == "__DWARF" checking.

I also add a test case e) to test dumping a __debug_aranges section whose segname is __FOO. This is to prove that when the segname isn't __DWARF but the sectname starts with __debug_, dumpDebugSection() is still called.

grimar accepted this revision.Aug 7 2020, 3:08 AM

OK, thanks. This LGTM, but please hold on a bit to give other people a chance to comment too.

This revision is now accepted and ready to land.Aug 7 2020, 3:08 AM

OK, thanks. This LGTM, but please hold on a bit to give other people a chance to comment too.

Thanks for reviewing! I will wait until other people accept this.

jhenderson added inline comments.Aug 10 2020, 2:42 AM
llvm/test/tools/obj2yaml/MachO/debug-aranges.yaml
3
79
99
llvm/test/tools/obj2yaml/MachO/unrecognized-debug-section.yaml
47

You might want to explain with a comment the unusual segment name.

Higuoxing updated this revision to Diff 284305.Aug 10 2020, 3:43 AM
Higuoxing marked 4 inline comments as done.

Address review comments.

jhenderson accepted this revision.Aug 10 2020, 3:47 AM

LGTM.

llvm/test/tools/obj2yaml/MachO/unrecognized-debug-section.yaml
4–7
Higuoxing updated this revision to Diff 284554.Aug 10 2020, 7:15 PM

Address review comments.

Higuoxing marked an inline comment as done.Aug 10 2020, 7:17 PM
This revision was landed with ongoing or failed builds.Aug 10 2020, 7:19 PM
This revision was automatically updated to reflect the committed changes.
llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml