xref: /freebsd/contrib/llvm-project/lld/MachO/Dwarf.h (revision bdd1243d)
1e8d8bef9SDimitry Andric //===- DWARF.h -----------------------------------------------*- C++ -*-===//
2e8d8bef9SDimitry Andric //
3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric //
7e8d8bef9SDimitry Andric //===-------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric 
9e8d8bef9SDimitry Andric #ifndef LLD_MACHO_DWARF_H
10e8d8bef9SDimitry Andric #define LLD_MACHO_DWARF_H
11e8d8bef9SDimitry Andric 
12e8d8bef9SDimitry Andric #include "llvm/ADT/StringRef.h"
13e8d8bef9SDimitry Andric #include "llvm/DebugInfo/DWARF/DWARFObject.h"
14e8d8bef9SDimitry Andric 
15*bdd1243dSDimitry Andric namespace lld::macho {
16e8d8bef9SDimitry Andric 
17e8d8bef9SDimitry Andric class ObjFile;
18e8d8bef9SDimitry Andric 
19e8d8bef9SDimitry Andric // Implements the interface between LLVM's DWARF-parsing utilities and LLD's
20e8d8bef9SDimitry Andric // InputSection structures.
21e8d8bef9SDimitry Andric class DwarfObject final : public llvm::DWARFObject {
22e8d8bef9SDimitry Andric public:
isLittleEndian()23e8d8bef9SDimitry Andric   bool isLittleEndian() const override { return true; }
24e8d8bef9SDimitry Andric 
find(const llvm::DWARFSection & sec,uint64_t pos)25*bdd1243dSDimitry Andric   std::optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec,
26e8d8bef9SDimitry Andric                                            uint64_t pos) const override {
27e8d8bef9SDimitry Andric     // TODO: implement this
28*bdd1243dSDimitry Andric     return std::nullopt;
29e8d8bef9SDimitry Andric   }
30e8d8bef9SDimitry Andric 
forEachInfoSections(llvm::function_ref<void (const llvm::DWARFSection &)> f)31e8d8bef9SDimitry Andric   void forEachInfoSections(
32e8d8bef9SDimitry Andric       llvm::function_ref<void(const llvm::DWARFSection &)> f) const override {
33e8d8bef9SDimitry Andric     f(infoSection);
34e8d8bef9SDimitry Andric   }
35e8d8bef9SDimitry Andric 
getAbbrevSection()36e8d8bef9SDimitry Andric   llvm::StringRef getAbbrevSection() const override { return abbrevSection; }
getStrSection()37e8d8bef9SDimitry Andric   llvm::StringRef getStrSection() const override { return strSection; }
38e8d8bef9SDimitry Andric 
getLineSection()3981ad6265SDimitry Andric   llvm::DWARFSection const &getLineSection() const override {
4081ad6265SDimitry Andric     return lineSection;
4181ad6265SDimitry Andric   }
4281ad6265SDimitry Andric 
getStrOffsetsSection()43*bdd1243dSDimitry Andric   llvm::DWARFSection const &getStrOffsetsSection() const override {
44*bdd1243dSDimitry Andric     return strOffsSection;
45*bdd1243dSDimitry Andric   }
46*bdd1243dSDimitry Andric 
47e8d8bef9SDimitry Andric   // Returns an instance of DwarfObject if the given object file has the
48e8d8bef9SDimitry Andric   // relevant DWARF debug sections.
49e8d8bef9SDimitry Andric   static std::unique_ptr<DwarfObject> create(ObjFile *);
50e8d8bef9SDimitry Andric 
51e8d8bef9SDimitry Andric private:
52e8d8bef9SDimitry Andric   llvm::DWARFSection infoSection;
5381ad6265SDimitry Andric   llvm::DWARFSection lineSection;
54*bdd1243dSDimitry Andric   llvm::DWARFSection strOffsSection;
55e8d8bef9SDimitry Andric   llvm::StringRef abbrevSection;
56e8d8bef9SDimitry Andric   llvm::StringRef strSection;
57e8d8bef9SDimitry Andric };
58e8d8bef9SDimitry Andric 
59*bdd1243dSDimitry Andric } // namespace lld::macho
60e8d8bef9SDimitry Andric 
61e8d8bef9SDimitry Andric #endif
62