]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/lib/ReaderWriter/MachO/DebugInfo.h
Merge lld trunk r366426, and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / lib / ReaderWriter / MachO / DebugInfo.h
1 //===- lib/ReaderWriter/MachO/File.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 LLD_READER_WRITER_MACHO_DEBUGINFO_H
10 #define LLD_READER_WRITER_MACHO_DEBUGINFO_H
11
12 #include "lld/Core/Atom.h"
13 #include <vector>
14
15 #include "llvm/Support/Format.h"
16 #include "llvm/Support/raw_ostream.h"
17
18
19 namespace lld {
20 namespace mach_o {
21
22 class DebugInfo {
23 public:
24   enum class Kind {
25     Dwarf,
26     Stabs
27   };
28
29   Kind kind() const { return _kind; }
30
31   void setAllocator(std::unique_ptr<llvm::BumpPtrAllocator> allocator) {
32     _allocator = std::move(allocator);
33   }
34
35 protected:
36   DebugInfo(Kind kind) : _kind(kind) {}
37
38 private:
39   std::unique_ptr<llvm::BumpPtrAllocator> _allocator;
40   Kind _kind;
41 };
42
43 struct TranslationUnitSource {
44   StringRef name;
45   StringRef path;
46 };
47
48 class DwarfDebugInfo : public DebugInfo {
49 public:
50   DwarfDebugInfo(TranslationUnitSource tu)
51     : DebugInfo(Kind::Dwarf), _tu(std::move(tu)) {}
52
53   static inline bool classof(const DebugInfo *di) {
54     return di->kind() == Kind::Dwarf;
55   }
56
57   const TranslationUnitSource &translationUnitSource() const { return _tu; }
58
59 private:
60   TranslationUnitSource _tu;
61 };
62
63 struct Stab {
64   Stab(const Atom* atom, uint8_t type, uint8_t other, uint16_t desc,
65        uint32_t value, StringRef str)
66     : atom(atom), type(type), other(other), desc(desc), value(value),
67       str(str) {}
68
69   const class Atom*   atom;
70   uint8_t             type;
71   uint8_t             other;
72   uint16_t            desc;
73   uint32_t            value;
74   StringRef           str;
75 };
76
77 inline raw_ostream& operator<<(raw_ostream &os, Stab &s) {
78   os << "Stab -- atom: " << llvm::format("%p", s.atom) << ", type: " << (uint32_t)s.type
79      << ", other: " << (uint32_t)s.other << ", desc: " << s.desc << ", value: " << s.value
80      << ", str: '" << s.str << "'";
81   return os;
82 }
83
84 class StabsDebugInfo : public DebugInfo {
85 public:
86
87   typedef std::vector<Stab> StabsList;
88
89   StabsDebugInfo(StabsList stabs)
90     : DebugInfo(Kind::Stabs), _stabs(std::move(stabs)) {}
91
92   static inline bool classof(const DebugInfo *di) {
93     return di->kind() == Kind::Stabs;
94   }
95
96   const StabsList& stabs() const { return _stabs; }
97
98 public:
99   StabsList _stabs;
100 };
101
102 } // end namespace mach_o
103 } // end namespace lld
104
105 #endif // LLD_READER_WRITER_MACHO_DEBUGINFO_H