This is an archive of the discontinued LLVM Phabricator instance.

Add line table verification to lldb-dwarfdump --verify.
AbandonedPublic

Authored by clayborg on May 2 2017, 9:54 AM.

Details

Summary

This patch verifies the .debug_line:

  • verify all addresses in a line table sequence have ascending addresses
  • verify that all line table file indexes are valid

Unit tests added for both cases.

Diff Detail

Event Timeline

clayborg created this revision.May 2 2017, 9:54 AM
dblaikie added inline comments.May 2 2017, 10:19 AM
lib/DebugInfo/DWARF/DWARFContext.cpp
404

FIXME to handle this as a verification failure too? (if stmt_list isn't usable as a section offset)

406

another verification failure possibility?

414–415

probably invert this to reduce indentation:

auto StmtFormValue = CU->getUnitDIE().find(DW_AT_stmt_list);
if (!StmtFormValue)
  continue;
...
449–450

maybe use set notation to be clear about open/closed range, etc: "[1,MaxFileIndex]"

453

Probably use '\n' rather than "\n" - so there's no need to go hunting for a null terminator, etc.

unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
1914

Declare as StringRef?

1984

Probably make this a StringRef

1992

StringRef?

2064–2065

Perhaps it's worthwhile to mention what the file index was? (doesn't look like it's in this error message)

clayborg updated this revision to Diff 97473.May 2 2017, 10:52 AM

Updates:

  • reflow code around StmtFormValue
  • comment that we don't need to create an error where things are already checked in the .debug_info to make things clear
  • Use StringRef where needed
  • clang-format
  • include bad file index in error message and update unit test
  • use '\n' instead of "\n"
clayborg marked 6 inline comments as done.May 2 2017, 10:53 AM

Marked things as done and commented where things weren't changed.

lib/DebugInfo/DWARF/DWARFContext.cpp
404

This is handled when verifying the .debug_info section. No need to duplicate this here.

406

This is handled when verifying the .debug_info section. No need to duplicate this here.

415

Yeah, I thought of that but have been asked to do the "if (auto StmtFormValue" way many times. The way you did it above is the way I wanted to do it. I will change it.

unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
1984

We search the std::string named "str" for this below and use must be a C string as part of the EXPECT_TRUE. No need for the StringRef here? Unless I wrap "str" into a StringRef. Let me know your preference here.

dblaikie added inline comments.May 2 2017, 2:31 PM
lib/DebugInfo/DWARF/DWARFContext.cpp
404

Should it be an assertion here, then? (is this verification still run, even if the debug_info section verification fails?)

415

Yeah, it depends - both are certainly used a lot.

Exactly how much code is unindented by inverting the condition makes it worthwhile is a bit subjective. All good.

unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
1914

Prefer copy-init over direct init where possible. ie:

T v = u;

rather than

T v(u);

(so 'StringRef yamldata = R"(... ' here)

1984

Could use SmallString instead of std::string (with raw_svector_ostream (SmallString is a StringVector)) & then SmallString's got a find(StringRef).

2056

can this be 'const auto &'? (or skip the variable and pass '*ErrOrSections' to the DWARFContextInMemory ctor directly)

probinson edited edge metadata.May 2 2017, 3:05 PM

Can you verify that each CU (that has DW_AT_stmt_list) points to a different place in .debug_line?

probinson added inline comments.May 2 2017, 3:11 PM
lib/DebugInfo/DWARF/DWARFContext.cpp
460

Can you verify that the address is in-range for the CU?
(which might be sufficient for my comment about each CU having a unique contribution to the line table.)

Can you verify that each CU (that has DW_AT_stmt_list) points to a different place in .debug_line?

That is a good idea. Maybe we emit a warning? I say that because it seems like a good way to save space for type unique style DWARF to share line tables since they only use the line tables for DW_AT_decl_file and DW_AT_call_file. Is it against the DWARF spec to share a line table? Let me know if you think this should be a warning or error.

lib/DebugInfo/DWARF/DWARFContext.cpp
404

No assertion. It will be handled by the .debug_info and reported there. We just want to get around it here.

clayborg abandoned this revision.May 2 2017, 3:32 PM

Lines have changed too much and a previous patch for llvm-dwarfdump --verify changed where verification happens. I will fix all requested items and make a new diff