LLVM API Documentation

DWARFDebugRangeList.cpp
Go to the documentation of this file.
00001 //===-- DWARFDebugRangesList.cpp ------------------------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "DWARFDebugRangeList.h"
00011 #include "llvm/Support/Format.h"
00012 #include "llvm/Support/raw_ostream.h"
00013 
00014 using namespace llvm;
00015 
00016 void DWARFDebugRangeList::clear() {
00017   Offset = -1U;
00018   AddressSize = 0;
00019   Entries.clear();
00020 }
00021 
00022 bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr) {
00023   clear();
00024   if (!data.isValidOffset(*offset_ptr))
00025     return false;
00026   AddressSize = data.getAddressSize();
00027   if (AddressSize != 4 && AddressSize != 8)
00028     return false;
00029   Offset = *offset_ptr;
00030   while (true) {
00031     RangeListEntry entry;
00032     uint32_t prev_offset = *offset_ptr;
00033     entry.StartAddress = data.getAddress(offset_ptr);
00034     entry.EndAddress = data.getAddress(offset_ptr);
00035     // Check that both values were extracted correctly.
00036     if (*offset_ptr != prev_offset + 2 * AddressSize) {
00037       clear();
00038       return false;
00039     }
00040     if (entry.isEndOfListEntry())
00041       break;
00042     Entries.push_back(entry);
00043   }
00044   return true;
00045 }
00046 
00047 void DWARFDebugRangeList::dump(raw_ostream &OS) const {
00048   for (const RangeListEntry &RLE : Entries) {
00049     const char *format_str = (AddressSize == 4
00050                               ? "%08x %08"  PRIx64 " %08"  PRIx64 "\n"
00051                               : "%08x %016" PRIx64 " %016" PRIx64 "\n");
00052     OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
00053   }
00054   OS << format("%08x <End of list>\n", Offset);
00055 }
00056 
00057 DWARFAddressRangesVector
00058 DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const {
00059   DWARFAddressRangesVector Res;
00060   for (const RangeListEntry &RLE : Entries) {
00061     if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
00062       BaseAddress = RLE.EndAddress;
00063     } else {
00064       Res.push_back(std::make_pair(BaseAddress + RLE.StartAddress,
00065                                    BaseAddress + RLE.EndAddress));
00066     }
00067   }
00068   return Res;
00069 }