This patch is motivated by the following observations:
- DWARF 4 rangelists are essentially a subset of DWARF 5 rangelists.
- We implemented DWARF5 largely independently (the consumer side, i.e. mostly llvm-dwarfdump). The DWARF 5 implementations are in DWARFDebugRnglists.*, the DWARF 4 implementations in DWARFDebugRangelists.* with a fair amount of duplication.
So I thought it should be possible to fold the DWARF 4 functionality into the newly implemented DWARF 5 functionality so that, at the expense of a bit more version-dependent code in dump and extract routines, we should be able to eliminate the DWARF4-only code (i.e. DWARFDebugRangeList.*) entirely.
This patch does attempt this in the following way:
- DWARF5 has range list tables, which of course don't exist in DWARF4, so for DWARF 4 (i.e. when we are extracting range lists from the .debug_ranges section) we create a fake table so we can use the same mechanisms as in DWARF 5.
- The extract and dump routines become version-aware so they can do what's expected both for DWARF4 and DWARF5.
The code in DWARFContext.cpp, DWARFUnit.cpp that arbiters between the different versions now just needs to set up the extractors correctly, set the correct section and pass the DWARF version, and should otherwise be version-oblivious to deal with ranges.
This is also prep for location list dumping, where it's possible to do the same thing, i.e. express DWARF4 functionality as a special case of DWARF5. This is why two routines in DWARFUnit.cpp that deal with the setup of range list tables are now templatized, so they can be used for location list tables as well.
One thing to note is that this change is almost, but not quite NFC. The difference is the following: In DWARF4 the range list table in .debug_ranges is dumped with the list offset preceding the entries:
00000000 00000000 0000abcd 00000000 ffffffff 0000deaf 00000000 00000010 00000020
etc. with the leading '00000000' being the list's section offset, which is repeated for every entry.
I didn't find this particularly useful, so the refactor now displays the list with the correct section offset for each entry, with the list offset simply being the first entry's offset.
00000000 00000000 0000abcd 00000008 ffffffff 0000deaf 00000010 00000010 00000020
Apologies for the size of the patch, but this will make the changes for location list dumping smaller.