Lang Hames | 436f7d6 | 2016-07-27 22:55:30 +0000 | [diff] [blame] | 1 | //===- lib/ReaderWriter/MachO/File.h ----------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLD_READER_WRITER_MACHO_DEBUGINFO_H |
| 11 | #define LLD_READER_WRITER_MACHO_DEBUGINFO_H |
| 12 | |
| 13 | #include "lld/Core/Atom.h" |
| 14 | #include <vector> |
| 15 | |
| 16 | #include "llvm/Support/Format.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
| 18 | |
| 19 | |
| 20 | namespace lld { |
| 21 | namespace mach_o { |
| 22 | |
| 23 | class DebugInfo { |
| 24 | public: |
| 25 | enum class Kind { |
| 26 | Dwarf, |
| 27 | Stabs |
| 28 | }; |
| 29 | |
| 30 | Kind kind() const { return _kind; } |
| 31 | |
| 32 | void setAllocator(std::unique_ptr<llvm::BumpPtrAllocator> allocator) { |
| 33 | _allocator = std::move(allocator); |
| 34 | } |
| 35 | |
| 36 | protected: |
| 37 | DebugInfo(Kind kind) : _kind(kind) {} |
| 38 | |
| 39 | private: |
| 40 | std::unique_ptr<llvm::BumpPtrAllocator> _allocator; |
| 41 | Kind _kind; |
| 42 | }; |
| 43 | |
| 44 | struct TranslationUnitSource { |
| 45 | StringRef name; |
| 46 | StringRef path; |
| 47 | }; |
| 48 | |
| 49 | class DwarfDebugInfo : public DebugInfo { |
| 50 | public: |
| 51 | DwarfDebugInfo(TranslationUnitSource tu) |
| 52 | : DebugInfo(Kind::Dwarf), _tu(std::move(tu)) {} |
| 53 | |
| 54 | static inline bool classof(const DebugInfo *di) { |
| 55 | return di->kind() == Kind::Dwarf; |
| 56 | } |
| 57 | |
| 58 | const TranslationUnitSource &translationUnitSource() const { return _tu; } |
| 59 | |
| 60 | private: |
| 61 | TranslationUnitSource _tu; |
| 62 | }; |
| 63 | |
| 64 | struct Stab { |
| 65 | Stab(const Atom* atom, uint8_t type, uint8_t other, uint16_t desc, |
| 66 | uint32_t value, StringRef str) |
| 67 | : atom(atom), type(type), other(other), desc(desc), value(value), |
| 68 | str(str) {} |
| 69 | |
| 70 | const class Atom* atom; |
| 71 | uint8_t type; |
| 72 | uint8_t other; |
| 73 | uint16_t desc; |
| 74 | uint32_t value; |
| 75 | StringRef str; |
| 76 | }; |
| 77 | |
| 78 | inline raw_ostream& operator<<(raw_ostream &os, Stab &s) { |
| 79 | os << "Stab -- atom: " << llvm::format("%p", s.atom) << ", type: " << (uint32_t)s.type |
| 80 | << ", other: " << (uint32_t)s.other << ", desc: " << s.desc << ", value: " << s.value |
| 81 | << ", str: '" << s.str << "'"; |
| 82 | return os; |
| 83 | } |
| 84 | |
| 85 | class StabsDebugInfo : public DebugInfo { |
| 86 | public: |
| 87 | |
| 88 | typedef std::vector<Stab> StabsList; |
| 89 | |
| 90 | StabsDebugInfo(StabsList stabs) |
| 91 | : DebugInfo(Kind::Stabs), _stabs(std::move(stabs)) {} |
| 92 | |
| 93 | static inline bool classof(const DebugInfo *di) { |
| 94 | return di->kind() == Kind::Stabs; |
| 95 | } |
| 96 | |
| 97 | const StabsList& stabs() const { return _stabs; } |
| 98 | |
| 99 | public: |
| 100 | StabsList _stabs; |
| 101 | }; |
| 102 | |
| 103 | } // end namespace mach_o |
| 104 | } // end namespace lld |
| 105 | |
| 106 | #endif // LLD_READER_WRITER_MACHO_DEBUGINFO_H |