DebugMacros.h revision 360784
1//===-- DebugMacros.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 liblldb_DebugMacros_h_ 10#define liblldb_DebugMacros_h_ 11 12#include <memory> 13#include <vector> 14 15#include "lldb/Utility/ConstString.h" 16#include "lldb/lldb-private.h" 17 18namespace lldb_private { 19 20class CompileUnit; 21class DebugMacros; 22typedef std::shared_ptr<DebugMacros> DebugMacrosSP; 23 24class DebugMacroEntry { 25public: 26 enum EntryType : uint8_t { 27 INVALID, DEFINE, UNDEF, START_FILE, END_FILE, INDIRECT 28 }; 29 30public: 31 static DebugMacroEntry CreateDefineEntry(uint32_t line, const char *str); 32 33 static DebugMacroEntry CreateUndefEntry(uint32_t line, const char *str); 34 35 static DebugMacroEntry CreateStartFileEntry(uint32_t line, 36 uint32_t debug_line_file_idx); 37 38 static DebugMacroEntry CreateEndFileEntry(); 39 40 static DebugMacroEntry 41 CreateIndirectEntry(const DebugMacrosSP &debug_macros_sp); 42 43 DebugMacroEntry() : m_type(INVALID) {} 44 45 ~DebugMacroEntry() = default; 46 47 EntryType GetType() const { return static_cast<EntryType>(m_type); } 48 49 uint64_t GetLineNumber() const { return m_line; } 50 51 ConstString GetMacroString() const { return m_str; } 52 53 const FileSpec &GetFileSpec(CompileUnit *comp_unit) const; 54 55 DebugMacros *GetIndirectDebugMacros() const { 56 return m_debug_macros_sp.get(); 57 } 58 59private: 60 DebugMacroEntry(EntryType type, uint32_t line, uint32_t debug_line_file_idx, 61 const char *str); 62 63 DebugMacroEntry(EntryType type, const DebugMacrosSP &debug_macros_sp); 64 65 uint32_t m_type : 3; 66 uint32_t m_line : 29; 67 uint32_t m_debug_line_file_idx; 68 ConstString m_str; 69 DebugMacrosSP m_debug_macros_sp; 70}; 71 72class DebugMacros { 73public: 74 DebugMacros() = default; 75 76 ~DebugMacros() = default; 77 78 void AddMacroEntry(const DebugMacroEntry &entry) { 79 m_macro_entries.push_back(entry); 80 } 81 82 size_t GetNumMacroEntries() const { return m_macro_entries.size(); } 83 84 DebugMacroEntry GetMacroEntryAtIndex(const size_t index) const { 85 if (index < m_macro_entries.size()) 86 return m_macro_entries[index]; 87 else 88 return DebugMacroEntry(); 89 } 90 91private: 92 DISALLOW_COPY_AND_ASSIGN(DebugMacros); 93 94 std::vector<DebugMacroEntry> m_macro_entries; 95}; 96 97} // namespace lldb_private 98 99#endif // liblldb_DebugMacros_h_ 100