DWARFContext.h revision 249423
161452Sdfr//===-- DWARFContext.h ------------------------------------------*- C++ -*-===// 261452Sdfr// 361452Sdfr// The LLVM Compiler Infrastructure 461452Sdfr// 561452Sdfr// This file is distributed under the University of Illinois Open Source 661452Sdfr// License. See LICENSE.TXT for details. 761452Sdfr// 861452Sdfr//===----------------------------------------------------------------------===/ 961452Sdfr 1061452Sdfr#ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H 1161452Sdfr#define LLVM_DEBUGINFO_DWARFCONTEXT_H 1261452Sdfr 1361452Sdfr#include "DWARFCompileUnit.h" 1461452Sdfr#include "DWARFDebugAranges.h" 1561452Sdfr#include "DWARFDebugFrame.h" 1661452Sdfr#include "DWARFDebugLine.h" 1761452Sdfr#include "DWARFDebugRangeList.h" 1861452Sdfr#include "llvm/ADT/OwningPtr.h" 1961452Sdfr#include "llvm/ADT/SmallVector.h" 2061452Sdfr#include "llvm/DebugInfo/DIContext.h" 2161452Sdfr 2261452Sdfrnamespace llvm { 2361452Sdfr 2461452Sdfr/// DWARFContext 2561452Sdfr/// This data structure is the top level entity that deals with dwarf debug 2661452Sdfr/// information parsing. The actual data is supplied through pure virtual 27116192Sobrien/// methods that a concrete implementation provides. 28116192Sobrienclass DWARFContext : public DIContext { 29116192Sobrien SmallVector<DWARFCompileUnit, 1> CUs; 3061452Sdfr OwningPtr<DWARFDebugAbbrev> Abbrev; 3161452Sdfr OwningPtr<DWARFDebugAranges> Aranges; 3261452Sdfr OwningPtr<DWARFDebugLine> Line; 3361452Sdfr OwningPtr<DWARFDebugFrame> DebugFrame; 3461452Sdfr 3561452Sdfr SmallVector<DWARFCompileUnit, 1> DWOCUs; 36129878Sphk OwningPtr<DWARFDebugAbbrev> AbbrevDWO; 3761452Sdfr 3861452Sdfr DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION; 3976827Salfred DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION; 4079339Sjhb 4161452Sdfr /// Read compile units from the debug_info section and store them in CUs. 42119288Simp void parseCompileUnits(); 43119288Simp 4461452Sdfr /// Read compile units from the debug_info.dwo section and store them in 4561452Sdfr /// DWOCUs. 4661452Sdfr void parseDWOCompileUnits(); 4761452Sdfr 4861452Sdfrpublic: 4961452Sdfr DWARFContext() {} 5061452Sdfr virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All); 5161452Sdfr 5261452Sdfr /// Get the number of compile units in this context. 5361452Sdfr unsigned getNumCompileUnits() { 5461452Sdfr if (CUs.empty()) 5561452Sdfr parseCompileUnits(); 5661452Sdfr return CUs.size(); 5761452Sdfr } 5861452Sdfr 5961452Sdfr /// Get the number of compile units in the DWO context. 6061452Sdfr unsigned getNumDWOCompileUnits() { 6161452Sdfr if (DWOCUs.empty()) 6261452Sdfr parseDWOCompileUnits(); 6361452Sdfr return DWOCUs.size(); 6461452Sdfr } 6561452Sdfr 6661452Sdfr /// Get the compile unit at the specified index for this compile unit. 6761452Sdfr DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { 6861452Sdfr if (CUs.empty()) 6961452Sdfr parseCompileUnits(); 70129415Sanholt return &CUs[index]; 71129415Sanholt } 72129415Sanholt 73129415Sanholt /// Get the compile unit at the specified index for the DWO compile units. 74129415Sanholt DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) { 75129415Sanholt if (DWOCUs.empty()) 76129415Sanholt parseDWOCompileUnits(); 77129415Sanholt return &DWOCUs[index]; 78129415Sanholt } 79129415Sanholt 80129415Sanholt /// Get a pointer to the parsed DebugAbbrev object. 81129415Sanholt const DWARFDebugAbbrev *getDebugAbbrev(); 82129415Sanholt 83129415Sanholt /// Get a pointer to the parsed dwo abbreviations object. 84112184Ssos const DWARFDebugAbbrev *getDebugAbbrevDWO(); 85112184Ssos 86129415Sanholt /// Get a pointer to the parsed DebugAranges object. 87129415Sanholt const DWARFDebugAranges *getDebugAranges(); 88129415Sanholt 89129415Sanholt /// Get a pointer to the parsed frame information object. 90129415Sanholt const DWARFDebugFrame *getDebugFrame(); 91129415Sanholt 92129415Sanholt /// Get a pointer to a parsed line table corresponding to a compile unit. 93129415Sanholt const DWARFDebugLine::LineTable * 94129415Sanholt getLineTableForCompileUnit(DWARFCompileUnit *cu); 95129415Sanholt 96129415Sanholt virtual DILineInfo getLineInfoForAddress(uint64_t Address, 97129415Sanholt DILineInfoSpecifier Specifier = DILineInfoSpecifier()); 98129415Sanholt virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, 99129415Sanholt uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()); 100129415Sanholt virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, 101129415Sanholt DILineInfoSpecifier Specifier = DILineInfoSpecifier()); 102129415Sanholt 103129415Sanholt virtual bool isLittleEndian() const = 0; 104129415Sanholt virtual uint8_t getAddressSize() const = 0; 105129415Sanholt virtual const RelocAddrMap &infoRelocMap() const = 0; 10661452Sdfr virtual const RelocAddrMap &lineRelocMap() const = 0; 10761452Sdfr virtual StringRef getInfoSection() = 0; 10861452Sdfr virtual StringRef getAbbrevSection() = 0; 10961452Sdfr virtual StringRef getARangeSection() = 0; 11061452Sdfr virtual StringRef getDebugFrameSection() = 0; 11161452Sdfr virtual StringRef getLineSection() = 0; 11261452Sdfr virtual StringRef getStringSection() = 0; 11361452Sdfr virtual StringRef getRangeSection() = 0; 11461452Sdfr virtual StringRef getPubNamesSection() = 0; 11561452Sdfr 116127815Snjl // Sections for DWARF5 split dwarf proposal. 117127815Snjl virtual StringRef getInfoDWOSection() = 0; 11861452Sdfr virtual StringRef getAbbrevDWOSection() = 0; 11961452Sdfr virtual StringRef getStringDWOSection() = 0; 12061452Sdfr virtual StringRef getStringOffsetDWOSection() = 0; 121142398Simp virtual StringRef getRangeDWOSection() = 0; 12261452Sdfr virtual StringRef getAddrSection() = 0; 12361452Sdfr virtual const RelocAddrMap &infoDWORelocMap() const = 0; 12461452Sdfr 12561452Sdfr static bool isSupportedVersion(unsigned version) { 12661452Sdfr return version == 2 || version == 3; 12761452Sdfr } 12861452Sdfrprivate: 12961452Sdfr /// Return the compile unit that includes an offset (relative to .debug_info). 13061452Sdfr DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset); 13161452Sdfr 13261452Sdfr /// Return the compile unit which contains instruction with provided 13361452Sdfr /// address. 13461452Sdfr DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); 13561452Sdfr}; 13661452Sdfr 13761452Sdfr/// DWARFContextInMemory is the simplest possible implementation of a 13861452Sdfr/// DWARFContext. It assumes all content is available in memory and stores 13961452Sdfr/// pointers to it. 14061452Sdfrclass DWARFContextInMemory : public DWARFContext { 14161452Sdfr virtual void anchor(); 14261452Sdfr bool IsLittleEndian; 14361452Sdfr uint8_t AddressSize; 14461452Sdfr RelocAddrMap InfoRelocMap; 14561452Sdfr RelocAddrMap LineRelocMap; 14661452Sdfr StringRef InfoSection; 14761452Sdfr StringRef AbbrevSection; 14861452Sdfr StringRef ARangeSection; 14961452Sdfr StringRef DebugFrameSection; 15061452Sdfr StringRef LineSection; 15161452Sdfr StringRef StringSection; 15261452Sdfr StringRef RangeSection; 15361452Sdfr StringRef PubNamesSection; 15461452Sdfr 15561452Sdfr // Sections for DWARF5 split dwarf proposal. 15661452Sdfr RelocAddrMap InfoDWORelocMap; 15761452Sdfr StringRef InfoDWOSection; 15861452Sdfr StringRef AbbrevDWOSection; 15961452Sdfr StringRef StringDWOSection; 16061452Sdfr StringRef StringOffsetDWOSection; 16161452Sdfr StringRef RangeDWOSection; 16261452Sdfr StringRef AddrSection; 16361452Sdfr 16461452Sdfrpublic: 16561452Sdfr DWARFContextInMemory(object::ObjectFile *); 16661452Sdfr virtual bool isLittleEndian() const { return IsLittleEndian; } 16761452Sdfr virtual uint8_t getAddressSize() const { return AddressSize; } 16861452Sdfr virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; } 16961452Sdfr virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; } 17061452Sdfr virtual StringRef getInfoSection() { return InfoSection; } 17161452Sdfr virtual StringRef getAbbrevSection() { return AbbrevSection; } 17261452Sdfr virtual StringRef getARangeSection() { return ARangeSection; } 17361452Sdfr virtual StringRef getDebugFrameSection() { return DebugFrameSection; } 17461452Sdfr virtual StringRef getLineSection() { return LineSection; } 17561452Sdfr virtual StringRef getStringSection() { return StringSection; } 17661452Sdfr virtual StringRef getRangeSection() { return RangeSection; } 177173203Sjhb virtual StringRef getPubNamesSection() { return PubNamesSection; } 17861452Sdfr 17961452Sdfr // Sections for DWARF5 split dwarf proposal. 18061452Sdfr virtual StringRef getInfoDWOSection() { return InfoDWOSection; } 18161452Sdfr virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; } 18261452Sdfr virtual StringRef getStringDWOSection() { return StringDWOSection; } 18361452Sdfr virtual StringRef getStringOffsetDWOSection() { 18461452Sdfr return StringOffsetDWOSection; 18561452Sdfr } 18661452Sdfr virtual StringRef getRangeDWOSection() { return RangeDWOSection; } 18761452Sdfr virtual StringRef getAddrSection() { 18861452Sdfr return AddrSection; 18961452Sdfr } 190173203Sjhb virtual const RelocAddrMap &infoDWORelocMap() const { 19161452Sdfr return InfoDWORelocMap; 19261452Sdfr } 19361452Sdfr}; 19461452Sdfr 19561452Sdfr} 19661452Sdfr 19761452Sdfr#endif 19861452Sdfr