This is an archive of the discontinued LLVM Phabricator instance.

[DWARF] Add a unit test for DWARFUnit::getLength().
ClosedPublic

Authored by ikudrin on Sep 6 2019, 7:18 AM.

Details

Summary

This is a follow-up of D66472, where the return value of DWARFUnit::getLength() was changed from uint32_t to uint64_t.
The test checks that a unit header with Length > 4G can be successfully parsed and the value of the Length field is not truncated.

Diff Detail

Repository
rL LLVM

Event Timeline

ikudrin created this revision.Sep 6 2019, 7:18 AM

As written, this will work only for little-endian. There are other unittests that are bi-endian that you ought to be able to use for examples; if nothing else, bail out after checking sys::IsLittleEndianHost (but a bi-endian test would be better).

As written, this will work only for little-endian. There are other unittests that are bi-endian that you ought to be able to use for examples; if nothing else, bail out after checking sys::IsLittleEndianHost (but a bi-endian test would be better).

I'm not sure the host endianness is relevant here, though - the input data is hardcoded & the parsing hardcodes the endianness when it constructs the DWARFDataExtractor (the "true" parameter specifies little endian). So I /think/ this will work correctly/pass on a little or big endian host.

Testing both endiannesses seems unnecessary to me - since that's part of DataExtractor that's already/otherwise tested.

unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
3169–3175 ↗(On Diff #219093)

This intermediate step seems unnecessary - DWARFContext is basically passing back the string you put into the map, right?

So maybe skipping all that and building the DWARFSEction around the StringRef around DebugInfoSecRaw and passing that into the DWARFDataExtractor.

ikudrin marked an inline comment as done.Sep 6 2019, 8:59 PM
ikudrin added inline comments.
unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
3169–3175 ↗(On Diff #219093)

But we still need a DWARFContext to pass to Header.extract(), and we also need a DWARFObject to pass to DWARFDataExtractor, right? So, we can eliminate only the call to Obj.forEachInfoSection(), replacing it with an artificial DWARFSection, which does not seem much.

dblaikie accepted this revision.Sep 9 2019, 2:03 PM

Looks good to me - thanks!

unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
3169–3175 ↗(On Diff #219093)

Ah, fair enough!

This revision is now accepted and ready to land.Sep 9 2019, 2:03 PM
This revision was automatically updated to reflect the committed changes.