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/Allocator.h" 16#include "llvm/Support/Format.h" 17#include "llvm/Support/raw_ostream.h" 18 19 20namespace lld { 21namespace mach_o { 22 23class DebugInfo { 24public: 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 36protected: 37 DebugInfo(Kind kind) : _kind(kind) {} 38 39private: 40 std::unique_ptr<llvm::BumpPtrAllocator> _allocator; 41 Kind _kind; 42}; 43 44struct TranslationUnitSource { 45 StringRef name; 46 StringRef path; 47}; 48 49class DwarfDebugInfo : public DebugInfo { 50public: 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 60private: 61 TranslationUnitSource _tu; 62}; 63 64struct 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 78inline 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 85class StabsDebugInfo : public DebugInfo { 86public: 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 99public: 100 StabsList _stabs; 101}; 102 103} // end namespace mach_o 104} // end namespace lld 105 106#endif // LLD_READER_WRITER_MACHO_DEBUGINFO_H 107