LLDB  mainline
ClangExternalASTSourceCommon.h
Go to the documentation of this file.
1 //===-- ClangExternalASTSourceCommon.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_ClangExternalASTSourceCommon_h
10 #define liblldb_ClangExternalASTSourceCommon_h
11 
12 // Clang headers like to use NDEBUG inside of them to enable/disable debug
13 // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing
14 // or another. This is bad because it means that if clang was built in release
15 // mode, it assumes that you are building in release mode which is not always
16 // the case. You can end up with functions that are defined as empty in header
17 // files when NDEBUG is not defined, and this can cause link errors with the
18 // clang .a files that you have since you might be missing functions in the .a
19 // file. So we have to define NDEBUG when including clang headers to avoid any
20 // mismatches. This is covered by rdar://problem/8691220
21 
22 #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
23 #define LLDB_DEFINED_NDEBUG_FOR_CLANG
24 #define NDEBUG
25 // Need to include assert.h so it is as clang would expect it to be (disabled)
26 #include <assert.h>
27 #endif
28 
29 #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
30 #undef NDEBUG
31 #undef LLDB_DEFINED_NDEBUG_FOR_CLANG
32 // Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
33 #include <assert.h>
34 #endif
35 
36 #include "clang/AST/ExternalASTSource.h"
37 
38 #include "lldb/Core/dwarf.h"
39 #include "lldb/lldb-defines.h"
40 #include "lldb/lldb-enumerations.h"
41 
42 namespace lldb_private {
43 
45 public:
47  : m_user_id(0), m_union_is_user_id(false), m_union_is_isa_ptr(false),
48  m_has_object_ptr(false), m_is_self(false), m_is_dynamic_cxx(true) {}
49 
50  bool GetIsDynamicCXXType() const { return m_is_dynamic_cxx; }
51 
52  void SetIsDynamicCXXType(bool b) { m_is_dynamic_cxx = b; }
53 
54  void SetUserID(lldb::user_id_t user_id) {
55  m_user_id = user_id;
56  m_union_is_user_id = true;
57  m_union_is_isa_ptr = false;
58  }
59 
61  if (m_union_is_user_id)
62  return m_user_id;
63  else
64  return LLDB_INVALID_UID;
65  }
66 
67  void SetISAPtr(uint64_t isa_ptr) {
68  m_isa_ptr = isa_ptr;
69  m_union_is_user_id = false;
70  m_union_is_isa_ptr = true;
71  }
72 
73  uint64_t GetISAPtr() const {
74  if (m_union_is_isa_ptr)
75  return m_isa_ptr;
76  else
77  return 0;
78  }
79 
80  void SetObjectPtrName(const char *name) {
81  m_has_object_ptr = true;
82  if (strcmp(name, "self") == 0)
83  m_is_self = true;
84  else if (strcmp(name, "this") == 0)
85  m_is_self = false;
86  else
87  m_has_object_ptr = false;
88  }
89 
91  if (m_has_object_ptr) {
92  if (m_is_self)
94  else
96  }
98  }
99 
100  const char *GetObjectPtrName() const {
101  if (m_has_object_ptr) {
102  if (m_is_self)
103  return "self";
104  else
105  return "this";
106  } else
107  return nullptr;
108  }
109 
110  bool HasObjectPtr() const { return m_has_object_ptr; }
111 
112  void Dump(Stream *s);
113 
114 private:
115  union {
117  uint64_t m_isa_ptr;
118  };
119 
120  bool m_union_is_user_id : 1, m_union_is_isa_ptr : 1, m_has_object_ptr : 1,
121  m_is_self : 1, m_is_dynamic_cxx : 1;
122 };
123 
124 class ClangExternalASTSourceCommon : public clang::ExternalASTSource {
125 public:
127  ~ClangExternalASTSourceCommon() override;
128 
129  ClangASTMetadata *GetMetadata(const void *object);
130  void SetMetadata(const void *object, ClangASTMetadata &metadata);
131  bool HasMetadata(const void *object);
132 
133  static ClangExternalASTSourceCommon *Lookup(clang::ExternalASTSource *source);
134 
135 private:
136  typedef llvm::DenseMap<const void *, ClangASTMetadata> MetadataMap;
137 
138  MetadataMap m_metadata;
139 };
140 
141 } // namespace lldb_private
142 
143 #endif // liblldb_ClangExternalASTSourceCommon_h
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
#define LLDB_INVALID_UID
Definition: lldb-defines.h:91
lldb::LanguageType GetObjectPtrLanguage() const
uint64_t user_id_t
Definition: lldb-types.h:84
LanguageType
Programming language type.
void SetUserID(lldb::user_id_t user_id)
Unknown or invalid language value.