DWARFDebugRangeList.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //===-- DWARFDebugRangesList.cpp ------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
  10. #include "llvm/Support/Format.h"
  11. #include "llvm/Support/raw_ostream.h"
  12. using namespace llvm;
  13. void DWARFDebugRangeList::clear() {
  14. Offset = -1U;
  15. AddressSize = 0;
  16. Entries.clear();
  17. }
  18. bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr) {
  19. clear();
  20. if (!data.isValidOffset(*offset_ptr))
  21. return false;
  22. AddressSize = data.getAddressSize();
  23. if (AddressSize != 4 && AddressSize != 8)
  24. return false;
  25. Offset = *offset_ptr;
  26. while (true) {
  27. RangeListEntry entry;
  28. uint32_t prev_offset = *offset_ptr;
  29. entry.StartAddress = data.getAddress(offset_ptr);
  30. entry.EndAddress = data.getAddress(offset_ptr);
  31. // Check that both values were extracted correctly.
  32. if (*offset_ptr != prev_offset + 2 * AddressSize) {
  33. clear();
  34. return false;
  35. }
  36. if (entry.isEndOfListEntry())
  37. break;
  38. Entries.push_back(entry);
  39. }
  40. return true;
  41. }
  42. void DWARFDebugRangeList::dump(raw_ostream &OS) const {
  43. for (const RangeListEntry &RLE : Entries) {
  44. const char *format_str = (AddressSize == 4
  45. ? "%08x %08" PRIx64 " %08" PRIx64 "\n"
  46. : "%08x %016" PRIx64 " %016" PRIx64 "\n");
  47. OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
  48. }
  49. OS << format("%08x <End of list>\n", Offset);
  50. }
  51. DWARFAddressRangesVector
  52. DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const {
  53. DWARFAddressRangesVector Res;
  54. for (const RangeListEntry &RLE : Entries) {
  55. if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
  56. BaseAddress = RLE.EndAddress;
  57. } else {
  58. Res.push_back(std::make_pair(BaseAddress + RLE.StartAddress,
  59. BaseAddress + RLE.EndAddress));
  60. }
  61. }
  62. return Res;
  63. }