LLVM API Documentation

DWARFDebugAranges.h
Go to the documentation of this file.
00001 //===-- DWARFDebugAranges.h -------------------------------------*- C++ -*-===//
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 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H
00011 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H
00012 
00013 #include "llvm/ADT/DenseSet.h"
00014 #include "llvm/Support/DataExtractor.h"
00015 #include <vector>
00016 
00017 namespace llvm {
00018 
00019 class DWARFContext;
00020 
00021 class DWARFDebugAranges {
00022 public:
00023   void generate(DWARFContext *CTX);
00024   uint32_t findAddress(uint64_t Address) const;
00025 
00026 private:
00027   void clear();
00028   void extract(DataExtractor DebugArangesData);
00029 
00030   // Call appendRange multiple times and then call construct.
00031   void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC);
00032   void construct();
00033 
00034   struct Range {
00035     explicit Range(uint64_t LowPC = -1ULL, uint64_t HighPC = -1ULL,
00036                    uint32_t CUOffset = -1U)
00037       : LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
00038 
00039     void setHighPC(uint64_t HighPC) {
00040       if (HighPC == -1ULL || HighPC <= LowPC)
00041         Length = 0;
00042       else
00043         Length = HighPC - LowPC;
00044     }
00045     uint64_t HighPC() const {
00046       if (Length)
00047         return LowPC + Length;
00048       return -1ULL;
00049     }
00050 
00051     bool containsAddress(uint64_t Address) const {
00052       return LowPC <= Address && Address < HighPC();
00053     }
00054     bool operator<(const Range &other) const {
00055       return LowPC < other.LowPC;
00056     }
00057 
00058     uint64_t LowPC; // Start of address range.
00059     uint32_t Length; // End of address range (not including this address).
00060     uint32_t CUOffset; // Offset of the compile unit or die.
00061   };
00062 
00063   struct RangeEndpoint {
00064     uint64_t Address;
00065     uint32_t CUOffset;
00066     bool IsRangeStart;
00067 
00068     RangeEndpoint(uint64_t Address, uint32_t CUOffset, bool IsRangeStart)
00069         : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {}
00070 
00071     bool operator<(const RangeEndpoint &Other) const {
00072       return Address < Other.Address;
00073     }
00074   };
00075 
00076 
00077   typedef std::vector<Range>              RangeColl;
00078   typedef RangeColl::const_iterator       RangeCollIterator;
00079 
00080   std::vector<RangeEndpoint> Endpoints;
00081   RangeColl Aranges;
00082   DenseSet<uint32_t> ParsedCUOffsets;
00083 };
00084 
00085 }
00086 
00087 #endif