LLDB  mainline
Type.cpp
Go to the documentation of this file.
1 //===-- Type.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 
9 #include <stdio.h>
10 
11 #include "lldb/Core/Module.h"
14 #include "lldb/Utility/Scalar.h"
16 
18 #include "lldb/Symbol/ObjectFile.h"
20 #include "lldb/Symbol/SymbolFile.h"
22 #include "lldb/Symbol/Type.h"
23 #include "lldb/Symbol/TypeList.h"
24 #include "lldb/Symbol/TypeSystem.h"
25 
27 #include "lldb/Target/Process.h"
28 #include "lldb/Target/Target.h"
29 
30 #include "llvm/ADT/StringRef.h"
31 
32 #include "clang/AST/Decl.h"
33 #include "clang/AST/DeclObjC.h"
34 
35 using namespace lldb;
36 using namespace lldb_private;
37 
38 void CompilerContext::Dump() const {
39  switch (type) {
40  case CompilerContextKind::Invalid:
41  printf("Invalid");
42  break;
43  case CompilerContextKind::TranslationUnit:
44  printf("TranslationUnit");
45  break;
46  case CompilerContextKind::Module:
47  printf("Module");
48  break;
49  case CompilerContextKind::Namespace:
50  printf("Namespace");
51  break;
52  case CompilerContextKind::Class:
53  printf("Class");
54  break;
55  case CompilerContextKind::Structure:
56  printf("Structure");
57  break;
58  case CompilerContextKind::Union:
59  printf("Union");
60  break;
61  case CompilerContextKind::Function:
62  printf("Function");
63  break;
64  case CompilerContextKind::Variable:
65  printf("Variable");
66  break;
67  case CompilerContextKind::Enumeration:
68  printf("Enumeration");
69  break;
70  case CompilerContextKind::Typedef:
71  printf("Typedef");
72  break;
73  }
74  printf("(\"%s\")\n", name.GetCString());
75 }
76 
78 public:
79  TypeAppendVisitor(TypeListImpl &type_list) : m_type_list(type_list) {}
80 
81  bool operator()(const lldb::TypeSP &type) {
82  m_type_list.Append(TypeImplSP(new TypeImpl(type)));
83  return true;
84  }
85 
86 private:
87  TypeListImpl &m_type_list;
88 };
89 
90 void TypeListImpl::Append(const lldb_private::TypeList &type_list) {
91  TypeAppendVisitor cb(*this);
92  type_list.ForEach(cb);
93 }
94 
95 SymbolFileType::SymbolFileType(SymbolFile &symbol_file,
96  const lldb::TypeSP &type_sp)
97  : UserID(type_sp ? type_sp->GetID() : LLDB_INVALID_UID),
98  m_symbol_file(symbol_file), m_type_sp(type_sp) {}
99 
101  if (!m_type_sp) {
102  Type *resolved_type = m_symbol_file.ResolveTypeUID(GetID());
103  if (resolved_type)
104  m_type_sp = resolved_type->shared_from_this();
105  }
106  return m_type_sp.get();
107 }
108 
110  ConstString name, llvm::Optional<uint64_t> byte_size,
111  SymbolContextScope *context, user_id_t encoding_uid,
112  EncodingDataType encoding_uid_type, const Declaration &decl,
113  const CompilerType &compiler_type,
114  ResolveState compiler_type_resolve_state)
115  : std::enable_shared_from_this<Type>(), UserID(uid), m_name(name),
116  m_symbol_file(symbol_file), m_context(context), m_encoding_type(nullptr),
117  m_encoding_uid(encoding_uid), m_encoding_uid_type(encoding_uid_type),
118  m_decl(decl), m_compiler_type(compiler_type) {
119  if (byte_size) {
120  m_byte_size = *byte_size;
121  m_byte_size_has_value = true;
122  } else {
123  m_byte_size = 0;
124  m_byte_size_has_value = false;
125  }
127  (compiler_type ? compiler_type_resolve_state : eResolveStateUnresolved);
129 }
130 
132  : std::enable_shared_from_this<Type>(), UserID(0), m_name("<INVALID TYPE>"),
133  m_symbol_file(nullptr), m_context(nullptr), m_encoding_type(nullptr),
136  m_compiler_type() {
139 }
140 
141 Type::Type(const Type &rhs)
142  : std::enable_shared_from_this<Type>(rhs), UserID(rhs), m_name(rhs.m_name),
149 
151  bool show_name) {
152  *s << "id = " << (const UserID &)*this;
153 
154  // Call the name accessor to make sure we resolve the type name
155  if (show_name) {
156  ConstString type_name = GetName();
157  if (type_name) {
158  *s << ", name = \"" << type_name << '"';
159  ConstString qualified_type_name(GetQualifiedName());
160  if (qualified_type_name != type_name) {
161  *s << ", qualified = \"" << qualified_type_name << '"';
162  }
163  }
164  }
165 
166  // Call the get byte size accesor so we resolve our byte size
167  if (GetByteSize())
168  s->Printf(", byte-size = %" PRIu64, m_byte_size);
169  bool show_fullpaths = (level == lldb::eDescriptionLevelVerbose);
170  m_decl.Dump(s, show_fullpaths);
171 
172  if (m_compiler_type.IsValid()) {
173  *s << ", compiler_type = \"";
175  *s << '"';
176  } else if (m_encoding_uid != LLDB_INVALID_UID) {
177  s->Printf(", type_uid = 0x%8.8" PRIx64, m_encoding_uid);
178  switch (m_encoding_uid_type) {
179  case eEncodingInvalid:
180  break;
181  case eEncodingIsUID:
182  s->PutCString(" (unresolved type)");
183  break;
184  case eEncodingIsConstUID:
185  s->PutCString(" (unresolved const type)");
186  break;
188  s->PutCString(" (unresolved restrict type)");
189  break;
191  s->PutCString(" (unresolved volatile type)");
192  break;
194  s->PutCString(" (unresolved typedef)");
195  break;
197  s->PutCString(" (unresolved pointer)");
198  break;
200  s->PutCString(" (unresolved L value reference)");
201  break;
203  s->PutCString(" (unresolved R value reference)");
204  break;
206  s->PutCString(" (synthetic type)");
207  break;
208  }
209  }
210 }
211 
212 void Type::Dump(Stream *s, bool show_context) {
213  s->Printf("%p: ", static_cast<void *>(this));
214  s->Indent();
215  *s << "Type" << static_cast<const UserID &>(*this) << ' ';
216  if (m_name)
217  *s << ", name = \"" << m_name << "\"";
218 
220  s->Printf(", size = %" PRIu64, m_byte_size);
221 
222  if (show_context && m_context != nullptr) {
223  s->PutCString(", context = ( ");
225  s->PutCString(" )");
226  }
227 
228  bool show_fullpaths = false;
229  m_decl.Dump(s, show_fullpaths);
230 
231  if (m_compiler_type.IsValid()) {
232  *s << ", compiler_type = " << m_compiler_type.GetOpaqueQualType() << ' ';
234  } else if (m_encoding_uid != LLDB_INVALID_UID) {
235  *s << ", type_data = " << (uint64_t)m_encoding_uid;
236  switch (m_encoding_uid_type) {
237  case eEncodingInvalid:
238  break;
239  case eEncodingIsUID:
240  s->PutCString(" (unresolved type)");
241  break;
242  case eEncodingIsConstUID:
243  s->PutCString(" (unresolved const type)");
244  break;
246  s->PutCString(" (unresolved restrict type)");
247  break;
249  s->PutCString(" (unresolved volatile type)");
250  break;
252  s->PutCString(" (unresolved typedef)");
253  break;
255  s->PutCString(" (unresolved pointer)");
256  break;
258  s->PutCString(" (unresolved L value reference)");
259  break;
261  s->PutCString(" (unresolved R value reference)");
262  break;
264  s->PutCString(" (synthetic type)");
265  break;
266  }
267  }
268 
269  //
270  // if (m_access)
271  // s->Printf(", access = %u", m_access);
272  s->EOL();
273 }
274 
276  if (!m_name)
278  return m_name;
279 }
280 
281 void Type::DumpTypeName(Stream *s) { GetName().Dump(s, "<invalid-type-name>"); }
282 
284  const DataExtractor &data, uint32_t data_byte_offset,
285  bool show_types, bool show_summary, bool verbose,
286  lldb::Format format) {
288  if (show_types) {
289  s->PutChar('(');
290  if (verbose)
291  s->Printf("Type{0x%8.8" PRIx64 "} ", GetID());
292  DumpTypeName(s);
293  s->PutCString(") ");
294  }
295 
297  exe_ctx, s, format == lldb::eFormatDefault ? GetFormat() : format, data,
298  data_byte_offset, GetByteSize().getValueOr(0),
299  0, // Bitfield bit size
300  0, // Bitfield bit offset
301  show_types, show_summary, verbose, 0);
302  }
303 }
304 
306  if (m_encoding_type == nullptr && m_encoding_uid != LLDB_INVALID_UID)
308  return m_encoding_type;
309 }
310 
311 llvm::Optional<uint64_t> Type::GetByteSize() {
313  return m_byte_size;
314 
315  switch (m_encoding_uid_type) {
316  case eEncodingInvalid:
318  break;
319  case eEncodingIsUID:
320  case eEncodingIsConstUID:
323  case eEncodingIsTypedefUID: {
324  Type *encoding_type = GetEncodingType();
325  if (encoding_type)
326  if (llvm::Optional<uint64_t> size = encoding_type->GetByteSize()) {
327  m_byte_size = *size;
328  m_byte_size_has_value = true;
329  return m_byte_size;
330  }
331 
332  if (llvm::Optional<uint64_t> size =
333  GetLayoutCompilerType().GetByteSize(nullptr)) {
334  m_byte_size = *size;
335  m_byte_size_has_value = true;
336  return m_byte_size;
337  }
338  } break;
339 
340  // If we are a pointer or reference, then this is just a pointer size;
345  m_byte_size = arch.GetAddressByteSize();
346  m_byte_size_has_value = true;
347  }
348  } break;
349  }
350  return {};
351 }
352 
353 uint32_t Type::GetNumChildren(bool omit_empty_base_classes) {
354  return GetForwardCompilerType().GetNumChildren(omit_empty_base_classes, nullptr);
355 }
356 
359 }
360 
361 lldb::TypeSP Type::GetTypedefType() {
362  lldb::TypeSP type_sp;
363  if (IsTypedef()) {
365  if (typedef_type)
366  type_sp = typedef_type->shared_from_this();
367  }
368  return type_sp;
369 }
370 
372 
374  // Make sure we resolve our type if it already hasn't been.
375  return GetForwardCompilerType().GetEncoding(count);
376 }
377 
379  lldb::addr_t address, AddressType address_type,
380  bool show_types, bool show_summary, bool verbose) {
381  if (address != LLDB_INVALID_ADDRESS) {
382  DataExtractor data;
383  Target *target = nullptr;
384  if (exe_ctx)
385  target = exe_ctx->GetTargetPtr();
386  if (target)
387  data.SetByteOrder(target->GetArchitecture().GetByteOrder());
388  if (ReadFromMemory(exe_ctx, address, address_type, data)) {
389  DumpValue(exe_ctx, s, data, 0, show_types, show_summary, verbose);
390  return true;
391  }
392  }
393  return false;
394 }
395 
397  AddressType address_type, DataExtractor &data) {
398  if (address_type == eAddressTypeFile) {
399  // Can't convert a file address to anything valid without more context
400  // (which Module it came from)
401  return false;
402  }
403 
404  const uint64_t byte_size = GetByteSize().getValueOr(0);
405  if (data.GetByteSize() < byte_size) {
406  lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0'));
407  data.SetData(data_sp);
408  }
409 
410  uint8_t *dst = const_cast<uint8_t *>(data.PeekData(0, byte_size));
411  if (dst != nullptr) {
412  if (address_type == eAddressTypeHost) {
413  // The address is an address in this process, so just copy it
414  if (addr == 0)
415  return false;
416  memcpy(dst, reinterpret_cast<uint8_t *>(addr), byte_size);
417  return true;
418  } else {
419  if (exe_ctx) {
420  Process *process = exe_ctx->GetProcessPtr();
421  if (process) {
422  Status error;
423  return exe_ctx->GetProcessPtr()->ReadMemory(addr, dst, byte_size,
424  error) == byte_size;
425  }
426  }
427  }
428  }
429  return false;
430 }
431 
433  AddressType address_type, DataExtractor &data) {
434  return false;
435 }
436 
438 
439 const Declaration &Type::GetDeclaration() const { return m_decl; }
440 
441 bool Type::ResolveClangType(ResolveState compiler_type_resolve_state) {
442  // TODO: This needs to consider the correct type system to use.
443  Type *encoding_type = nullptr;
444  if (!m_compiler_type.IsValid()) {
445  encoding_type = GetEncodingType();
446  if (encoding_type) {
447  switch (m_encoding_uid_type) {
448  case eEncodingIsUID: {
449  CompilerType encoding_compiler_type =
450  encoding_type->GetForwardCompilerType();
451  if (encoding_compiler_type.IsValid()) {
452  m_compiler_type = encoding_compiler_type;
454  encoding_type->m_flags.compiler_type_resolve_state;
455  }
456  } break;
457 
458  case eEncodingIsConstUID:
460  encoding_type->GetForwardCompilerType().AddConstModifier();
461  break;
462 
465  encoding_type->GetForwardCompilerType().AddRestrictModifier();
466  break;
467 
470  encoding_type->GetForwardCompilerType().AddVolatileModifier();
471  break;
472 
475  m_name.AsCString("__lldb_invalid_typedef_name"),
477  m_name.Clear();
478  break;
479 
482  encoding_type->GetForwardCompilerType().GetPointerType();
483  break;
484 
488  break;
489 
493  break;
494 
495  default:
496  llvm_unreachable("Unhandled encoding_data_type.");
497  }
498  } else {
499  // We have no encoding type, return void?
500  TypeSystem *type_system =
502  CompilerType void_compiler_type =
503  type_system->GetBasicTypeFromAST(eBasicTypeVoid);
504  switch (m_encoding_uid_type) {
505  case eEncodingIsUID:
506  m_compiler_type = void_compiler_type;
507  break;
508 
509  case eEncodingIsConstUID:
510  m_compiler_type = void_compiler_type.AddConstModifier();
511  break;
512 
514  m_compiler_type = void_compiler_type.AddRestrictModifier();
515  break;
516 
518  m_compiler_type = void_compiler_type.AddVolatileModifier();
519  break;
520 
522  m_compiler_type = void_compiler_type.CreateTypedef(
523  m_name.AsCString("__lldb_invalid_typedef_name"),
525  break;
526 
528  m_compiler_type = void_compiler_type.GetPointerType();
529  break;
530 
532  m_compiler_type = void_compiler_type.GetLValueReferenceType();
533  break;
534 
536  m_compiler_type = void_compiler_type.GetRValueReferenceType();
537  break;
538 
539  default:
540  llvm_unreachable("Unhandled encoding_data_type.");
541  }
542  }
543 
544  // When we have a EncodingUID, our "m_flags.compiler_type_resolve_state" is
545  // set to eResolveStateUnresolved so we need to update it to say that we
546  // now have a forward declaration since that is what we created above.
547  if (m_compiler_type.IsValid())
549  }
550 
551  // Check if we have a forward reference to a class/struct/union/enum?
552  if (compiler_type_resolve_state == eResolveStateLayout ||
553  compiler_type_resolve_state == eResolveStateFull) {
554  // Check if we have a forward reference to a class/struct/union/enum?
555  if (m_compiler_type.IsValid() &&
556  m_flags.compiler_type_resolve_state < compiler_type_resolve_state) {
558  if (!m_compiler_type.IsDefined()) {
559  // We have a forward declaration, we need to resolve it to a complete
560  // definition.
562  }
563  }
564  }
565 
566  // If we have an encoding type, then we need to make sure it is resolved
567  // appropriately.
569  if (encoding_type == nullptr)
570  encoding_type = GetEncodingType();
571  if (encoding_type) {
572  ResolveState encoding_compiler_type_resolve_state =
573  compiler_type_resolve_state;
574 
575  if (compiler_type_resolve_state == eResolveStateLayout) {
576  switch (m_encoding_uid_type) {
580  encoding_compiler_type_resolve_state = eResolveStateForward;
581  break;
582  default:
583  break;
584  }
585  }
586  encoding_type->ResolveClangType(encoding_compiler_type_resolve_state);
587  }
588  }
589  return m_compiler_type.IsValid();
590 }
592  uint32_t encoding_mask = 1u << m_encoding_uid_type;
593  Type *encoding_type = GetEncodingType();
594  assert(encoding_type != this);
595  if (encoding_type)
596  encoding_mask |= encoding_type->GetEncodingMask();
597  return encoding_mask;
598 }
599 
602  return m_compiler_type;
603 }
604 
607  return m_compiler_type;
608 }
609 
612  return m_compiler_type;
613 }
614 
615 int Type::Compare(const Type &a, const Type &b) {
616  // Just compare the UID values for now...
617  lldb::user_id_t a_uid = a.GetID();
618  lldb::user_id_t b_uid = b.GetID();
619  if (a_uid < b_uid)
620  return -1;
621  if (a_uid > b_uid)
622  return 1;
623  return 0;
624 }
625 
628 }
629 
630 bool Type::GetTypeScopeAndBasename(const llvm::StringRef& name,
631  llvm::StringRef &scope,
632  llvm::StringRef &basename,
633  TypeClass &type_class) {
634  type_class = eTypeClassAny;
635 
636  if (name.empty())
637  return false;
638 
639  basename = name;
640  if (basename.consume_front("struct "))
641  type_class = eTypeClassStruct;
642  else if (basename.consume_front("class "))
643  type_class = eTypeClassClass;
644  else if (basename.consume_front("union "))
645  type_class = eTypeClassUnion;
646  else if (basename.consume_front("enum "))
647  type_class = eTypeClassEnumeration;
648  else if (basename.consume_front("typedef "))
649  type_class = eTypeClassTypedef;
650 
651  size_t namespace_separator = basename.find("::");
652  if (namespace_separator == llvm::StringRef::npos)
653  return false;
654 
655  size_t template_begin = basename.find('<');
656  while (namespace_separator != llvm::StringRef::npos) {
657  if (template_begin != llvm::StringRef::npos &&
658  namespace_separator > template_begin) {
659  size_t template_depth = 1;
660  llvm::StringRef template_arg =
661  basename.drop_front(template_begin + 1);
662  while (template_depth > 0 && !template_arg.empty()) {
663  if (template_arg.front() == '<')
664  template_depth++;
665  else if (template_arg.front() == '>')
666  template_depth--;
667  template_arg = template_arg.drop_front(1);
668  }
669  if (template_depth != 0)
670  return false; // We have an invalid type name. Bail out.
671  if (template_arg.empty())
672  break; // The template ends at the end of the full name.
673  basename = template_arg;
674  } else {
675  basename = basename.drop_front(namespace_separator + 2);
676  }
677  template_begin = basename.find('<');
678  namespace_separator = basename.find("::");
679  }
680  if (basename.size() < name.size()) {
681  scope = name.take_front(name.size() - basename.size());
682  return true;
683  }
684  return false;
685 }
686 
687 ModuleSP Type::GetModule() {
688  if (m_symbol_file)
690  return ModuleSP();
691 }
692 
693 TypeAndOrName::TypeAndOrName(TypeSP &in_type_sp) {
694  if (in_type_sp) {
695  m_compiler_type = in_type_sp->GetForwardCompilerType();
696  m_type_name = in_type_sp->GetName();
697  }
698 }
699 
700 TypeAndOrName::TypeAndOrName(const char *in_type_str)
701  : m_type_name(in_type_str) {}
702 
704  : m_type_name(in_type_const_string) {}
705 
706 bool TypeAndOrName::operator==(const TypeAndOrName &other) const {
707  if (m_compiler_type != other.m_compiler_type)
708  return false;
709  if (m_type_name != other.m_type_name)
710  return false;
711  return true;
712 }
713 
714 bool TypeAndOrName::operator!=(const TypeAndOrName &other) const {
715  return !(*this == other);
716 }
717 
719  if (m_type_name)
720  return m_type_name;
721  if (m_compiler_type)
722  return m_compiler_type.GetTypeName();
723  return ConstString("<invalid>");
724 }
725 
727  m_type_name = type_name;
728 }
729 
730 void TypeAndOrName::SetName(const char *type_name_cstr) {
731  m_type_name.SetCString(type_name_cstr);
732 }
733 
734 void TypeAndOrName::SetTypeSP(lldb::TypeSP type_sp) {
735  if (type_sp) {
736  m_compiler_type = type_sp->GetForwardCompilerType();
737  m_type_name = type_sp->GetName();
738  } else
739  Clear();
740 }
741 
743  m_compiler_type = compiler_type;
744  if (m_compiler_type)
745  m_type_name = m_compiler_type.GetTypeName();
746 }
747 
749  return !((bool)m_type_name || (bool)m_compiler_type);
750 }
751 
753  m_type_name.Clear();
754  m_compiler_type.Clear();
755 }
756 
757 bool TypeAndOrName::HasName() const { return (bool)m_type_name; }
758 
760  return m_compiler_type.IsValid();
761 }
762 
763 TypeImpl::TypeImpl() : m_module_wp(), m_static_type(), m_dynamic_type() {}
764 
766  : m_module_wp(rhs.m_module_wp), m_static_type(rhs.m_static_type),
767  m_dynamic_type(rhs.m_dynamic_type) {}
768 
769 TypeImpl::TypeImpl(const lldb::TypeSP &type_sp)
770  : m_module_wp(), m_static_type(), m_dynamic_type() {
771  SetType(type_sp);
772 }
773 
774 TypeImpl::TypeImpl(const CompilerType &compiler_type)
775  : m_module_wp(), m_static_type(), m_dynamic_type() {
776  SetType(compiler_type);
777 }
778 
779 TypeImpl::TypeImpl(const lldb::TypeSP &type_sp, const CompilerType &dynamic)
780  : m_module_wp(), m_static_type(), m_dynamic_type(dynamic) {
781  SetType(type_sp, dynamic);
782 }
783 
784 TypeImpl::TypeImpl(const CompilerType &static_type,
785  const CompilerType &dynamic_type)
786  : m_module_wp(), m_static_type(), m_dynamic_type() {
787  SetType(static_type, dynamic_type);
788 }
789 
790 void TypeImpl::SetType(const lldb::TypeSP &type_sp) {
791  if (type_sp) {
792  m_static_type = type_sp->GetForwardCompilerType();
793  m_module_wp = type_sp->GetModule();
794  } else {
795  m_static_type.Clear();
796  m_module_wp = lldb::ModuleWP();
797  }
798 }
799 
800 void TypeImpl::SetType(const CompilerType &compiler_type) {
801  m_module_wp = lldb::ModuleWP();
802  m_static_type = compiler_type;
803 }
804 
805 void TypeImpl::SetType(const lldb::TypeSP &type_sp,
806  const CompilerType &dynamic) {
807  SetType(type_sp);
808  m_dynamic_type = dynamic;
809 }
810 
811 void TypeImpl::SetType(const CompilerType &compiler_type,
812  const CompilerType &dynamic) {
813  m_module_wp = lldb::ModuleWP();
814  m_static_type = compiler_type;
815  m_dynamic_type = dynamic;
816 }
817 
819  if (rhs != *this) {
820  m_module_wp = rhs.m_module_wp;
821  m_static_type = rhs.m_static_type;
822  m_dynamic_type = rhs.m_dynamic_type;
823  }
824  return *this;
825 }
826 
827 bool TypeImpl::CheckModule(lldb::ModuleSP &module_sp) const {
828  // Check if we have a module for this type. If we do and the shared pointer
829  // is can be successfully initialized with m_module_wp, return true. Else
830  // return false if we didn't have a module, or if we had a module and it has
831  // been deleted. Any functions doing anything with a TypeSP in this TypeImpl
832  // class should call this function and only do anything with the ivars if
833  // this function returns true. If we have a module, the "module_sp" will be
834  // filled in with a strong reference to the module so that the module will at
835  // least stay around long enough for the type query to succeed.
836  module_sp = m_module_wp.lock();
837  if (!module_sp) {
838  lldb::ModuleWP empty_module_wp;
839  // If either call to "std::weak_ptr::owner_before(...) value returns true,
840  // this indicates that m_module_wp once contained (possibly still does) a
841  // reference to a valid shared pointer. This helps us know if we had a
842  // valid reference to a section which is now invalid because the module it
843  // was in was deleted
844  if (empty_module_wp.owner_before(m_module_wp) ||
845  m_module_wp.owner_before(empty_module_wp)) {
846  // m_module_wp had a valid reference to a module, but all strong
847  // references have been released and the module has been deleted
848  return false;
849  }
850  }
851  // We either successfully locked the module, or didn't have one to begin with
852  return true;
853 }
854 
855 bool TypeImpl::operator==(const TypeImpl &rhs) const {
856  return m_static_type == rhs.m_static_type &&
857  m_dynamic_type == rhs.m_dynamic_type;
858 }
859 
860 bool TypeImpl::operator!=(const TypeImpl &rhs) const {
861  return !(*this == rhs);
862 }
863 
864 bool TypeImpl::IsValid() const {
865  // just a name is not valid
866  ModuleSP module_sp;
867  if (CheckModule(module_sp))
868  return m_static_type.IsValid() || m_dynamic_type.IsValid();
869  return false;
870 }
871 
872 TypeImpl::operator bool() const { return IsValid(); }
873 
875  m_module_wp = lldb::ModuleWP();
876  m_static_type.Clear();
877  m_dynamic_type.Clear();
878 }
879 
881  ModuleSP module_sp;
882  if (CheckModule(module_sp)) {
883  if (m_dynamic_type)
884  return m_dynamic_type.GetTypeName();
885  return m_static_type.GetTypeName();
886  }
887  return ConstString();
888 }
889 
891  ModuleSP module_sp;
892  if (CheckModule(module_sp)) {
893  if (m_dynamic_type)
894  return m_dynamic_type.GetDisplayTypeName();
895  return m_static_type.GetDisplayTypeName();
896  }
897  return ConstString();
898 }
899 
901  ModuleSP module_sp;
902  if (CheckModule(module_sp)) {
903  if (m_dynamic_type.IsValid()) {
904  return TypeImpl(m_static_type.GetPointerType(),
905  m_dynamic_type.GetPointerType());
906  }
907  return TypeImpl(m_static_type.GetPointerType());
908  }
909  return TypeImpl();
910 }
911 
913  ModuleSP module_sp;
914  if (CheckModule(module_sp)) {
915  if (m_dynamic_type.IsValid()) {
916  return TypeImpl(m_static_type.GetPointeeType(),
917  m_dynamic_type.GetPointeeType());
918  }
919  return TypeImpl(m_static_type.GetPointeeType());
920  }
921  return TypeImpl();
922 }
923 
925  ModuleSP module_sp;
926  if (CheckModule(module_sp)) {
927  if (m_dynamic_type.IsValid()) {
928  return TypeImpl(m_static_type.GetLValueReferenceType(),
929  m_dynamic_type.GetLValueReferenceType());
930  }
931  return TypeImpl(m_static_type.GetLValueReferenceType());
932  }
933  return TypeImpl();
934 }
935 
937  ModuleSP module_sp;
938  if (CheckModule(module_sp)) {
939  if (m_dynamic_type.IsValid()) {
940  return TypeImpl(m_static_type.GetTypedefedType(),
941  m_dynamic_type.GetTypedefedType());
942  }
943  return TypeImpl(m_static_type.GetTypedefedType());
944  }
945  return TypeImpl();
946 }
947 
949  ModuleSP module_sp;
950  if (CheckModule(module_sp)) {
951  if (m_dynamic_type.IsValid()) {
952  return TypeImpl(m_static_type.GetNonReferenceType(),
953  m_dynamic_type.GetNonReferenceType());
954  }
955  return TypeImpl(m_static_type.GetNonReferenceType());
956  }
957  return TypeImpl();
958 }
959 
961  ModuleSP module_sp;
962  if (CheckModule(module_sp)) {
963  if (m_dynamic_type.IsValid()) {
964  return TypeImpl(m_static_type.GetFullyUnqualifiedType(),
965  m_dynamic_type.GetFullyUnqualifiedType());
966  }
967  return TypeImpl(m_static_type.GetFullyUnqualifiedType());
968  }
969  return TypeImpl();
970 }
971 
973  ModuleSP module_sp;
974  if (CheckModule(module_sp)) {
975  if (m_dynamic_type.IsValid()) {
976  return TypeImpl(m_static_type.GetCanonicalType(),
977  m_dynamic_type.GetCanonicalType());
978  }
979  return TypeImpl(m_static_type.GetCanonicalType());
980  }
981  return TypeImpl();
982 }
983 
985  ModuleSP module_sp;
986  if (CheckModule(module_sp)) {
987  if (prefer_dynamic) {
988  if (m_dynamic_type.IsValid())
989  return m_dynamic_type;
990  }
991  return m_static_type;
992  }
993  return CompilerType();
994 }
995 
996 TypeSystem *TypeImpl::GetTypeSystem(bool prefer_dynamic) {
997  ModuleSP module_sp;
998  if (CheckModule(module_sp)) {
999  if (prefer_dynamic) {
1000  if (m_dynamic_type.IsValid())
1001  return m_dynamic_type.GetTypeSystem();
1002  }
1003  return m_static_type.GetTypeSystem();
1004  }
1005  return NULL;
1006 }
1007 
1009  lldb::DescriptionLevel description_level) {
1010  ModuleSP module_sp;
1011  if (CheckModule(module_sp)) {
1012  if (m_dynamic_type.IsValid()) {
1013  strm.Printf("Dynamic:\n");
1014  m_dynamic_type.DumpTypeDescription(&strm);
1015  strm.Printf("\nStatic:\n");
1016  }
1017  m_static_type.DumpTypeDescription(&strm);
1018  } else {
1019  strm.PutCString("Invalid TypeImpl module for type has been deleted\n");
1020  }
1021  return true;
1022 }
1023 
1025  return m_type.IsValid() && m_kind != lldb::eMemberFunctionKindUnknown;
1026 }
1027 
1029 
1031  return m_decl.GetMangledName();
1032 }
1033 
1035 
1037  return m_kind;
1038 }
1039 
1041  switch (m_kind) {
1043  return false;
1045  stream.Printf("constructor for %s",
1046  m_type.GetTypeName().AsCString("<unknown>"));
1047  break;
1049  stream.Printf("destructor for %s",
1050  m_type.GetTypeName().AsCString("<unknown>"));
1051  break;
1053  stream.Printf("instance method %s of type %s", m_name.AsCString(),
1054  m_decl.GetDeclContext().GetName().AsCString());
1055  break;
1057  stream.Printf("static method %s of type %s", m_name.AsCString(),
1058  m_decl.GetDeclContext().GetName().AsCString());
1059  break;
1060  }
1061  return true;
1062 }
1063 
1065  if (m_type)
1066  return m_type.GetFunctionReturnType();
1067  return m_decl.GetFunctionReturnType();
1068 }
1069 
1071  if (m_type)
1072  return m_type.GetNumberOfFunctionArguments();
1073  else
1074  return m_decl.GetNumFunctionArguments();
1075 }
1076 
1078  if (m_type)
1079  return m_type.GetFunctionArgumentAtIndex(idx);
1080  else
1081  return m_decl.GetFunctionArgumentType(idx);
1082 }
1083 
1084 TypeEnumMemberImpl::TypeEnumMemberImpl(const lldb::TypeImplSP &integer_type_sp,
1085  ConstString name,
1086  const llvm::APSInt &value)
1087  : m_integer_type_sp(integer_type_sp), m_name(name), m_value(value),
1088  m_valid((bool)name && (bool)integer_type_sp)
1089 
1090 {}
virtual ArchSpec GetArchitecture()=0
Get the ArchSpec for this object file.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
lldb::user_id_t m_encoding_uid
Definition: Type.h:216
const lldb_private::Declaration & GetDeclaration() const
Definition: Type.cpp:439
Declaration m_decl
Definition: Type.h:220
An data extractor class.
Definition: DataExtractor.h:47
lldb::MemberFunctionKind GetKind() const
Definition: Type.cpp:1036
CompilerType GetNonReferenceType() const
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
TypeSystem * GetTypeSystem(bool prefer_dynamic)
Definition: Type.cpp:996
const ArchSpec & GetArchitecture() const
Definition: Target.h:941
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:224
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
Address is an address as found in an object or symbol file.
Sometimes you can find the name of the type corresponding to an object, but we don&#39;t have debug infor...
Definition: Type.h:396
CompilerType GetReturnType() const
Definition: Type.cpp:1064
Type * m_encoding_type
Definition: Type.h:215
uint32_t GetNumChildren(bool omit_empty_base_classes)
Definition: Type.cpp:353
lldb::ModuleSP GetModule()
Definition: Type.cpp:687
CompilerType GetCompilerType(bool prefer_dynamic)
Definition: Type.cpp:984
bool GetDescription(Stream &stream)
Definition: Type.cpp:1040
void DumpValue(ExecutionContext *exe_ctx, Stream *s, lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, bool show_types, bool show_summary, bool verbose, uint32_t depth)
ConstString GetDisplayTypeName() const
Definition: Type.cpp:890
static bool GetTypeScopeAndBasename(const llvm::StringRef &name, llvm::StringRef &scope, llvm::StringRef &basename, lldb::TypeClass &type_class)
Definition: Type.cpp:630
void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name)
Definition: Type.cpp:150
void DumpValue(ExecutionContext *exe_ctx, Stream *s, const DataExtractor &data, uint32_t data_offset, bool show_type, bool show_summary, bool verbose, lldb::Format format=lldb::eFormatDefault)
Definition: Type.cpp:283
lldb::Format GetFormat() const
This type is the type whose UID is m_encoding_uid with the restrict qualifier added.
Definition: Type.h:67
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:49
A mix in class that contains a generic user ID.
Definition: UserID.h:33
An architecture specification class.
Definition: ArchSpec.h:32
SymbolFile * m_symbol_file
Definition: Type.h:212
struct lldb_private::Type::Flags m_flags
bool GetDescription(lldb_private::Stream &strm, lldb::DescriptionLevel description_level)
Definition: Type.cpp:1008
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void Dump(Stream *s, bool show_context)
Definition: Type.cpp:212
void SetName(ConstString type_name)
Definition: Type.cpp:726
virtual Type * ResolveTypeUID(lldb::user_id_t type_uid)=0
ConstString GetName() const
Definition: Type.cpp:1028
This type is the type whose UID is m_encoding_uid with the const qualifier added. ...
Definition: Type.h:65
#define LLDB_INVALID_UID
Definition: lldb-defines.h:91
bool ResolveClangType(ResolveState compiler_type_resolve_state)
Definition: Type.cpp:441
SymbolFile & m_symbol_file
Definition: Type.h:56
void SetCompilerType(CompilerType compiler_type)
Definition: Type.cpp:742
CompilerType GetLayoutCompilerType()
Definition: Type.cpp:605
llvm::Optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
uint32_t GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
CompilerType GetPointeeType() const
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:27
static int Compare(const Type &a, const Type &b)
Definition: Type.cpp:615
A subclass of DataBuffer that stores a data buffer on the heap.
EncodingDataType m_encoding_uid_type
Definition: Type.h:217
TypeImpl GetPointeeType() const
Definition: Type.cpp:912
CompilerType AddConstModifier() const
llvm::Optional< uint64_t > GetByteSize()
Definition: Type.cpp:311
uint64_t m_byte_size
Definition: Type.h:218
This type is the type whose UID is m_encoding_uid with the volatile qualifier added.
Definition: Type.h:69
ConstString m_name
Definition: Type.h:211
CompilerType m_compiler_type
Definition: Type.h:221
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:165
virtual lldb_private::TypeSystem * GetTypeSystemForLanguage(lldb::LanguageType language)
Definition: SymbolFile.cpp:89
ConstString GetName()
Definition: Type.cpp:275
CompilerType GetFullCompilerType()
Definition: Type.cpp:600
This type is pointer to a type whose UID is m_encoding_uid.
Definition: Type.h:73
Target * GetTargetPtr() const
Returns a pointer to the target object.
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
uint64_t user_id_t
Definition: lldb-types.h:84
TypeImpl & operator=(const TypeImpl &rhs)
Definition: Type.cpp:818
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
TypeImpl GetPointerType() const
Definition: Type.cpp:900
Address is an address in the process that is running this code.
This type is R value reference to a type whose UID is m_encoding_uid.
Definition: Type.h:77
bool operator()(const lldb::TypeSP &type)
Definition: Type.cpp:81
bool HasCompilerType() const
Definition: Type.cpp:759
bool operator==(const TypeImpl &rhs) const
Definition: Type.cpp:855
TypeSystem * GetTypeSystem() const
Definition: CompilerType.h:150
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:127
enum lldb_private::Type::ResolveStateTag ResolveState
bool IsTypedef()
Definition: Type.h:136
TypeAppendVisitor(TypeListImpl &type_list)
Definition: Type.cpp:79
virtual CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type)=0
virtual void DumpSymbolContext(Stream *s)=0
Dump the object&#39;s symbol context to the stream s.
bool operator!=(const TypeImpl &rhs) const
Definition: Type.cpp:860
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
Process * GetProcessPtr() const
Returns a pointer to the process object.
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:788
virtual bool CompleteType(CompilerType &compiler_type)=0
SymbolFile * GetSymbolFile()
Definition: Type.h:121
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
ConstString GetDisplayTypeName() const
bool operator!=(const TypeAndOrName &other) const
Definition: Type.cpp:714
This type is the type whose UID is m_encoding_uid.
Definition: Type.h:64
void Dump(Stream *s, const char *value_if_empty=nullptr) const
Dump the object description to a stream.
bool WriteToMemory(ExecutionContext *exe_ctx, lldb::addr_t address, AddressType address_type, DataExtractor &data)
Definition: Type.cpp:432
lldb::Format GetFormat()
Definition: Type.cpp:371
ConstString GetQualifiedName()
Definition: Type.cpp:626
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition: Declaration.cpp:14
This type is pointer to a type whose UID is m_encoding_uid.
Definition: Type.h:71
CompilerType GetPointerType() const
CompilerType GetLValueReferenceType() const
void SetTypeSP(lldb::TypeSP type_sp)
Definition: Type.cpp:734
TypeImpl GetUnqualifiedType() const
Definition: Type.cpp:960
bool ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t address, AddressType address_type, DataExtractor &data)
Definition: Type.cpp:396
TypeImpl GetCanonicalType() const
Definition: Type.cpp:972
CompilerType AddVolatileModifier() const
CompilerType GetForwardCompilerType()
Definition: Type.cpp:610
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
virtual TypeList * GetTypeList()
Definition: SymbolFile.cpp:83
CompilerType GetCanonicalType() const
void ForEach(std::function< bool(const lldb::TypeSP &type_sp)> const &callback) const
Definition: TypeList.cpp:78
bool IsEmpty() const
Definition: Type.cpp:748
ConstString GetName() const
Definition: Type.cpp:880
bool HasName() const
Definition: Type.cpp:757
size_t PutChar(char ch)
Definition: Stream.cpp:103
lldb::Encoding GetEncoding(uint64_t &count) const
TypeImpl GetTypedefedType() const
Definition: Type.cpp:936
lldb::TypeSP m_type_sp
Definition: Type.h:57
uint64_t addr_t
Definition: lldb-types.h:83
TypeImpl GetDereferencedType() const
Definition: Type.cpp:948
A uniqued constant string class.
Definition: ConstString.h:38
lldb::Encoding GetEncoding(uint64_t &count)
Definition: Type.cpp:373
bool IsValid() const
Definition: Type.cpp:864
bool DumpValueInMemory(ExecutionContext *exe_ctx, Stream *s, lldb::addr_t address, AddressType address_type, bool show_types, bool show_summary, bool verbose)
Definition: Type.cpp:378
void SetType(const lldb::TypeSP &type_sp)
Definition: Type.cpp:790
This type is L value reference to a type whose UID is m_encoding_uid.
Definition: Type.h:75
CompilerType CreateTypedef(const char *name, const CompilerDeclContext &decl_ctx) const
Non-standardized C, such as K&R.
bool IsAggregateType()
Definition: Type.cpp:357
CompilerType GetFullyUnqualifiedType() const
char * basename(char *path)
Definition: SBAddress.h:15
Type * GetEncodingType()
Definition: Type.cpp:305
CompilerType GetType() const
Definition: Type.cpp:1034
ConstString GetName() const
Definition: Type.cpp:718
CompilerType GetFunctionReturnType() const
uint64_t m_byte_size_has_value
Definition: Type.h:219
size_t Indent(const char *s=nullptr)
Indent the current line in the stream.
Definition: Stream.cpp:131
ObjectFile * GetObjectFile()
Definition: SymbolFile.h:213
bool operator==(const TypeAndOrName &other) const
Definition: Type.cpp:706
CompilerType GetFunctionArgumentAtIndex(const size_t index) const
CompilerType GetTypedefedType() const
CompilerType GetRValueReferenceType() const
TypeImpl GetReferenceType() const
Definition: Type.cpp:924
ConstString GetConstTypeName() const
ConstString GetTypeName() const
void DumpTypeName(Stream *s)
Definition: Type.cpp:281
enum lldb_private::Type::EncodingDataTypeTag EncodingDataType
ConstString GetMangledName() const
Definition: Type.cpp:1030
ResolveState compiler_type_resolve_state
Definition: Type.h:228
virtual CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid)
Definition: SymbolFile.h:156
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
CompilerType AddRestrictModifier() const
lldb::TypeSP GetTypedefType()
Definition: Type.cpp:361
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
CompilerType GetArgumentAtIndex(size_t idx) const
Definition: Type.cpp:1077
SymbolContextScope * m_context
Definition: Type.h:214
uint32_t GetEncodingMask()
Definition: Type.cpp:591
void Clear()
Clear this object&#39;s state.
Definition: ConstString.h:263
An error handling class.
Definition: Status.h:44
TypeList * GetTypeList()
Definition: Type.cpp:437
const uint8_t * PeekData(lldb::offset_t offset, lldb::offset_t length) const
Peek at a bytes at offset.
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
void SetCString(const char *cstr)
Set the C string value.
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition: Process.cpp:1966