xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1 //===- DWARFObject.h --------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===-----------------------------------------------------------------------===/
8 
9 #ifndef LLVM_DEBUGINFO_DWARF_DWARFOBJECT_H
10 #define LLVM_DEBUGINFO_DWARF_DWARFOBJECT_H
11 
12 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
13 #include "llvm/DebugInfo/DWARF/DWARFSection.h"
14 #include "llvm/Object/ObjectFile.h"
15 #include <optional>
16 
17 namespace llvm {
18 // This is responsible for low level access to the object file. It
19 // knows how to find the required sections and compute relocated
20 // values.
21 // The default implementations of the get<Section> methods return dummy values.
22 // This is to allow clients that only need some of those to implement just the
23 // ones they need. We can't use unreachable for as many cases because the parser
24 // implementation is eager and will call some of these methods even if the
25 // result is not used.
26 class DWARFObject {
27   DWARFSection Dummy;
28 
29 public:
30   virtual ~DWARFObject() = default;
getFileName()31   virtual StringRef getFileName() const { llvm_unreachable("unimplemented"); }
getFile()32   virtual const object::ObjectFile *getFile() const { return nullptr; }
getSectionNames()33   virtual ArrayRef<SectionName> getSectionNames() const { return {}; }
34   virtual bool isLittleEndian() const = 0;
getAddressSize()35   virtual uint8_t getAddressSize() const { llvm_unreachable("unimplemented"); }
36   virtual void
forEachInfoSections(function_ref<void (const DWARFSection &)> F)37   forEachInfoSections(function_ref<void(const DWARFSection &)> F) const {}
38   virtual void
forEachTypesSections(function_ref<void (const DWARFSection &)> F)39   forEachTypesSections(function_ref<void(const DWARFSection &)> F) const {}
getAbbrevSection()40   virtual StringRef getAbbrevSection() const { return ""; }
getLocSection()41   virtual const DWARFSection &getLocSection() const { return Dummy; }
getLoclistsSection()42   virtual const DWARFSection &getLoclistsSection() const { return Dummy; }
getArangesSection()43   virtual StringRef getArangesSection() const { return ""; }
getFrameSection()44   virtual const DWARFSection &getFrameSection() const { return Dummy; }
getEHFrameSection()45   virtual const DWARFSection &getEHFrameSection() const { return Dummy; }
getLineSection()46   virtual const DWARFSection &getLineSection() const { return Dummy; }
getLineStrSection()47   virtual StringRef getLineStrSection() const { return ""; }
getStrSection()48   virtual StringRef getStrSection() const { return ""; }
getRangesSection()49   virtual const DWARFSection &getRangesSection() const { return Dummy; }
getRnglistsSection()50   virtual const DWARFSection &getRnglistsSection() const { return Dummy; }
getMacroSection()51   virtual const DWARFSection &getMacroSection() const { return Dummy; }
getMacroDWOSection()52   virtual StringRef getMacroDWOSection() const { return ""; }
getMacinfoSection()53   virtual StringRef getMacinfoSection() const { return ""; }
getMacinfoDWOSection()54   virtual StringRef getMacinfoDWOSection() const { return ""; }
getPubnamesSection()55   virtual const DWARFSection &getPubnamesSection() const { return Dummy; }
getPubtypesSection()56   virtual const DWARFSection &getPubtypesSection() const { return Dummy; }
getGnuPubnamesSection()57   virtual const DWARFSection &getGnuPubnamesSection() const { return Dummy; }
getGnuPubtypesSection()58   virtual const DWARFSection &getGnuPubtypesSection() const { return Dummy; }
getStrOffsetsSection()59   virtual const DWARFSection &getStrOffsetsSection() const { return Dummy; }
60   virtual void
forEachInfoDWOSections(function_ref<void (const DWARFSection &)> F)61   forEachInfoDWOSections(function_ref<void(const DWARFSection &)> F) const {}
62   virtual void
forEachTypesDWOSections(function_ref<void (const DWARFSection &)> F)63   forEachTypesDWOSections(function_ref<void(const DWARFSection &)> F) const {}
getAbbrevDWOSection()64   virtual StringRef getAbbrevDWOSection() const { return ""; }
getLineDWOSection()65   virtual const DWARFSection &getLineDWOSection() const { return Dummy; }
getLocDWOSection()66   virtual const DWARFSection &getLocDWOSection() const { return Dummy; }
getLoclistsDWOSection()67   virtual const DWARFSection &getLoclistsDWOSection() const { return Dummy; }
getStrDWOSection()68   virtual StringRef getStrDWOSection() const { return ""; }
getStrOffsetsDWOSection()69   virtual const DWARFSection &getStrOffsetsDWOSection() const {
70     return Dummy;
71   }
getRangesDWOSection()72   virtual const DWARFSection &getRangesDWOSection() const { return Dummy; }
getRnglistsDWOSection()73   virtual const DWARFSection &getRnglistsDWOSection() const { return Dummy; }
getAddrSection()74   virtual const DWARFSection &getAddrSection() const { return Dummy; }
getAppleNamesSection()75   virtual const DWARFSection &getAppleNamesSection() const { return Dummy; }
getAppleTypesSection()76   virtual const DWARFSection &getAppleTypesSection() const { return Dummy; }
getAppleNamespacesSection()77   virtual const DWARFSection &getAppleNamespacesSection() const {
78     return Dummy;
79   }
getNamesSection()80   virtual const DWARFSection &getNamesSection() const { return Dummy; }
getAppleObjCSection()81   virtual const DWARFSection &getAppleObjCSection() const { return Dummy; }
getCUIndexSection()82   virtual StringRef getCUIndexSection() const { return ""; }
getGdbIndexSection()83   virtual StringRef getGdbIndexSection() const { return ""; }
getTUIndexSection()84   virtual StringRef getTUIndexSection() const { return ""; }
85   virtual std::optional<RelocAddrEntry> find(const DWARFSection &Sec,
86                                              uint64_t Pos) const = 0;
87 };
88 
89 } // namespace llvm
90 #endif
91