LLDB  mainline
ClangExternalASTSourceCommon.cpp
Go to the documentation of this file.
1 //===-- ClangExternalASTSourceCommon.cpp ------------------------*- 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 
10 #include "lldb/Utility/Stream.h"
11 
12 #include <mutex>
13 
14 using namespace lldb_private;
15 
16 uint64_t g_TotalSizeOfMetadata = 0;
17 
18 typedef llvm::DenseMap<clang::ExternalASTSource *,
21 
22 static ASTSourceMap &GetSourceMap(std::unique_lock<std::mutex> &guard) {
23  // Intentionally leaked to avoid problems with global destructors.
24  static ASTSourceMap *s_source_map = new ASTSourceMap;
25  static std::mutex s_mutex;
26  std::unique_lock<std::mutex> locked_guard(s_mutex);
27  guard.swap(locked_guard);
28  return *s_source_map;
29 }
30 
32 ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source) {
33  std::unique_lock<std::mutex> guard;
34  ASTSourceMap &source_map = GetSourceMap(guard);
35 
36  ASTSourceMap::iterator iter = source_map.find(source);
37 
38  if (iter != source_map.end()) {
39  return iter->second;
40  } else {
41  return nullptr;
42  }
43 }
44 
46  : clang::ExternalASTSource() {
47  g_TotalSizeOfMetadata += m_metadata.size();
48  std::unique_lock<std::mutex> guard;
49  GetSourceMap(guard)[this] = this;
50 }
51 
53  std::unique_lock<std::mutex> guard;
54  GetSourceMap(guard).erase(this);
55  g_TotalSizeOfMetadata -= m_metadata.size();
56 }
57 
60  if (HasMetadata(object))
61  return &m_metadata[object];
62  else
63  return nullptr;
64 }
65 
67  ClangASTMetadata &metadata) {
68  uint64_t orig_size = m_metadata.size();
69  m_metadata[object] = metadata;
70  uint64_t new_size = m_metadata.size();
71  g_TotalSizeOfMetadata += (new_size - orig_size);
72 }
73 
75  return m_metadata.find(object) != m_metadata.end();
76 }
77 
79  lldb::user_id_t uid = GetUserID();
80 
81  if (uid != LLDB_INVALID_UID) {
82  s->Printf("uid=0x%" PRIx64, uid);
83  }
84 
85  uint64_t isa_ptr = GetISAPtr();
86  if (isa_ptr != 0) {
87  s->Printf("isa_ptr=0x%" PRIx64, isa_ptr);
88  }
89 
90  const char *obj_ptr_name = GetObjectPtrName();
91  if (obj_ptr_name) {
92  s->Printf("obj_ptr_name=\"%s\" ", obj_ptr_name);
93  }
94 
95  if (m_is_dynamic_cxx) {
96  s->Printf("is_dynamic_cxx=%i ", m_is_dynamic_cxx);
97  }
98  s->EOL();
99 }
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void SetMetadata(const void *object, ClangASTMetadata &metadata)
#define LLDB_INVALID_UID
Definition: lldb-defines.h:91
static ASTSourceMap & GetSourceMap(std::unique_lock< std::mutex > &guard)
uint64_t user_id_t
Definition: lldb-types.h:84
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:127
ClangASTMetadata * GetMetadata(const void *object)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
llvm::DenseMap< clang::ExternalASTSource *, ClangExternalASTSourceCommon * > ASTSourceMap
uint64_t g_TotalSizeOfMetadata
static ClangExternalASTSourceCommon * Lookup(clang::ExternalASTSource *source)