LLDB  mainline
DebugMacros.h
Go to the documentation of this file.
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 LLDB_SYMBOL_DEBUGMACROS_H
10 #define LLDB_SYMBOL_DEBUGMACROS_H
11 
12 #include <memory>
13 #include <vector>
14 
16 #include "lldb/lldb-private.h"
17 
18 namespace lldb_private {
19 
20 class CompileUnit;
22 typedef std::shared_ptr<DebugMacros> DebugMacrosSP;
23 
25 public:
26  enum EntryType : uint8_t {
28  };
29 
30 public:
31  static DebugMacroEntry CreateDefineEntry(uint32_t line, const char *str);
32 
33  static DebugMacroEntry CreateUndefEntry(uint32_t line, const char *str);
34 
36  uint32_t debug_line_file_idx);
37 
39 
40  static DebugMacroEntry
41  CreateIndirectEntry(const DebugMacrosSP &debug_macros_sp);
42 
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 
56  return m_debug_macros_sp.get();
57  }
58 
59 private:
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 
69  DebugMacrosSP m_debug_macros_sp;
70 };
71 
72 class DebugMacros {
73 public:
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 
91 private:
92  DebugMacros(const DebugMacros &) = delete;
93  const DebugMacros &operator=(const DebugMacros &) = delete;
94 
95  std::vector<DebugMacroEntry> m_macro_entries;
96 };
97 
98 } // namespace lldb_private
99 
100 #endif // LLDB_SYMBOL_DEBUGMACROS_H
DebugMacros * GetIndirectDebugMacros() const
Definition: DebugMacros.h:55
A class that represents a running process on the host machine.
static DebugMacroEntry CreateUndefEntry(uint32_t line, const char *str)
Definition: DebugMacros.cpp:34
static DebugMacroEntry CreateEndFileEntry()
Definition: DebugMacros.cpp:46
static DebugMacroEntry CreateStartFileEntry(uint32_t line, uint32_t debug_line_file_idx)
Definition: DebugMacros.cpp:40
ConstString GetMacroString() const
Definition: DebugMacros.h:51
A file utility class.
Definition: FileSpec.h:56
size_t GetNumMacroEntries() const
Definition: DebugMacros.h:82
A class that describes a compilation unit.
Definition: CompileUnit.h:37
static DebugMacroEntry CreateDefineEntry(uint32_t line, const char *str)
Definition: DebugMacros.cpp:29
uint64_t GetLineNumber() const
Definition: DebugMacros.h:49
std::shared_ptr< DebugMacros > DebugMacrosSP
Definition: DebugMacros.h:21
EntryType GetType() const
Definition: DebugMacros.h:47
const FileSpec & GetFileSpec(CompileUnit *comp_unit) const
Definition: DebugMacros.cpp:25
A uniqued constant string class.
Definition: ConstString.h:40
static DebugMacroEntry CreateIndirectEntry(const DebugMacrosSP &debug_macros_sp)
Definition: DebugMacros.cpp:51
std::vector< DebugMacroEntry > m_macro_entries
Definition: DebugMacros.h:95
DebugMacrosSP m_debug_macros_sp
Definition: DebugMacros.h:69
void AddMacroEntry(const DebugMacroEntry &entry)
Definition: DebugMacros.h:78
DebugMacroEntry GetMacroEntryAtIndex(const size_t index) const
Definition: DebugMacros.h:84