37#include "llvm/ADT/StringRef.h"
45 rhs.
Dump(lldb_stream);
50 if (type_class == eTypeClassAny)
51 return CompilerContextKind::AnyType;
53 if (type_class & (lldb::eTypeClassClass | lldb::eTypeClassStruct))
54 result |= CompilerContextKind::ClassOrStruct;
55 if (type_class & lldb::eTypeClassUnion)
56 result |= CompilerContextKind::Union;
57 if (type_class & lldb::eTypeClassEnumeration)
58 result |= CompilerContextKind::Enum;
59 if (type_class & lldb::eTypeClassFunction)
60 result |= CompilerContextKind::Function;
61 if (type_class & lldb::eTypeClassTypedef)
62 result |= CompilerContextKind::Typedef;
67 : m_options(options) {
68 if (std::optional<Type::ParsedName> parsed_name =
70 llvm::ArrayRef scope = parsed_name->scope;
72 if (scope[0] ==
"::") {
74 scope = scope.drop_front();
76 for (llvm::StringRef s : scope) {
89 ConstString type_basename, TypeQueryOptions options)
90 : m_options(options) {
98 const llvm::ArrayRef<lldb_private::CompilerContext> &context,
99 TypeQueryOptions options)
100 : m_context(context), m_options(options) {
106 : m_options(options) {
129 llvm::ArrayRef<CompilerContext> context_chain)
const {
130 auto ctx = context_chain.rbegin(), ctx_end = context_chain.rend();
141 if (ctx->name != pat->name)
159 return ctx == ctx_end;
191 s <<
"TranslationUnit";
200 s <<
"ClassOrStruct";
221 s <<
"(" <<
name <<
")";
245 m_symbol_file(symbol_file), m_type_sp(type_sp) {}
251 m_type_sp = resolved_type->shared_from_this();
260 ResolveState compiler_type_resolve_state, uint32_t opaque_payload)
261 : std::enable_shared_from_this<
Type>(),
UserID(uid), m_name(name),
262 m_symbol_file(symbol_file), m_context(context),
263 m_encoding_uid(encoding_uid), m_encoding_uid_type(encoding_uid_type),
264 m_decl(decl), m_compiler_type(compiler_type),
265 m_compiler_type_resolve_state(compiler_type ? compiler_type_resolve_state
267 m_payload(opaque_payload) {
278 : std::enable_shared_from_this<
Type>(),
UserID(0), m_name(
"<INVALID TYPE>"),
286 *s <<
"id = " << (
const UserID &)*
this;
292 *s <<
", name = \"" << type_name <<
'"';
294 if (qualified_type_name != type_name) {
295 *s <<
", qualified = \"" << qualified_type_name <<
'"';
307 *s <<
", compiler_type = \"";
337 s->
PutCString(
" (unresolved L value reference)");
340 s->
PutCString(
" (unresolved R value reference)");
353 s->
Printf(
"%p: ",
static_cast<void *
>(
this));
355 *s <<
"Type" <<
static_cast<const UserID &
>(*this) <<
' ';
357 *s <<
", name = \"" <<
m_name <<
"\"";
362 if (show_context &&
m_context !=
nullptr) {
368 bool show_fullpaths =
false;
401 s->
PutCString(
" (unresolved L value reference)");
404 s->
PutCString(
" (unresolved R value reference)");
454 if (std::optional<uint64_t> size =
461 if (std::optional<uint64_t> size =
501 type_sp = typedef_type->shared_from_this();
521 const uint64_t byte_size =
529 uint8_t *dst =
const_cast<uint8_t *
>(data.
PeekData(0, byte_size));
530 if (dst !=
nullptr) {
535 memcpy(dst,
reinterpret_cast<uint8_t *
>(addr), byte_size);
560 Type *encoding_type =
nullptr;
568 if (encoding_compiler_type.
IsValid()) {
624 llvm_unreachable(
"Unhandled encoding_data_type.");
628 auto type_system_or_err =
630 if (
auto err = type_system_or_err.takeError()) {
633 "Unable to construct void type from TypeSystemClang: {0}");
636 auto ts = *type_system_or_err;
679 llvm_unreachable(
"Cannot handle eEncodingIsLLVMPtrAuthUID without "
680 "valid encoding_type");
683 llvm_unreachable(
"Unhandled encoding_data_type.");
713 if (encoding_type ==
nullptr)
717 compiler_type_resolve_state;
738 assert(encoding_type !=
this);
741 return encoding_mask;
763std::optional<Type::ParsedName>
770 if (name.consume_front(
"struct "))
772 else if (name.consume_front(
"class "))
774 else if (name.consume_front(
"union "))
776 else if (name.consume_front(
"enum "))
778 else if (name.consume_front(
"typedef "))
781 if (name.consume_front(
"::"))
782 result.
scope.push_back(
"::");
784 bool prev_is_colon =
false;
785 size_t template_depth = 0;
786 size_t name_begin = 0;
787 for (
const auto &pos : llvm::enumerate(name)) {
788 switch (pos.value()) {
790 if (prev_is_colon && template_depth == 0) {
791 result.
scope.push_back(name.slice(name_begin, pos.index() - 1));
792 name_begin = pos.index() + 1;
799 if (template_depth == 0)
804 prev_is_colon = pos.value() ==
':';
807 if (name_begin < name.size() && template_depth == 0)
808 result.
basename = name.substr(name_begin);
826 SymbolFile *symbol_file = ts->GetSymbolFile();
841 : m_type_name(in_type_str) {}
844 : m_type_name(in_type_const_string) {}
855 return !(*
this == other);
908 : m_module_wp(), m_static_type(), m_dynamic_type() {
913 : m_module_wp(), m_static_type(), m_dynamic_type() {
918 : m_module_wp(), m_static_type(), m_dynamic_type(dynamic) {
924 : m_module_wp(), m_static_type(), m_dynamic_type() {
925 SetType(static_type, dynamic_type);
975 module_sp = input_module_wp.lock();
983 if (empty_module_wp.owner_before(input_module_wp) ||
984 input_module_wp.owner_before(empty_module_wp)) {
1000 return !(*
this == rhs);
1011TypeImpl::operator bool()
const {
return IsValid(); }
1133 if (prefer_dynamic) {
1145 if (prefer_dynamic) {
1159 strm.
Printf(
"Dynamic:\n");
1161 strm.
Printf(
"\nStatic:\n");
1165 strm.
PutCString(
"Invalid TypeImpl module for type has been deleted\n");
1198 stream.
Printf(
"constructor for %s",
1202 stream.
Printf(
"destructor for %s",
1239 const llvm::APSInt &value)
1240 : m_integer_type_sp(integer_type_sp), m_name(name), m_value(value),
1241 m_valid((bool)name && (bool)integer_type_sp)
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
static CompilerContextKind ConvertTypeClass(lldb::TypeClass type_class)
bool operator()(const lldb::TypeSP &type)
TypeListImpl & m_type_list
TypeAppendVisitor(TypeListImpl &type_list)
An architecture specification class.
Represents a generic declaration context in a program.
ConstString GetName() const
std::vector< lldb_private::CompilerContext > GetCompilerContext() const
Populate a valid compiler context from the current decl context.
Represents a generic declaration such as a function declaration.
ConstString GetMangledName() const
CompilerType GetFunctionArgumentType(size_t arg_idx) const
CompilerType GetFunctionReturnType() const
CompilerDeclContext GetDeclContext() const
size_t GetNumFunctionArguments() const
std::vector< lldb_private::CompilerContext > GetCompilerContext() const
Populate a valid compiler context from the current declaration.
This is a minimal wrapper of a TypeSystem shared pointer as returned by CompilerType which conventien...
Generic representation of a type in a programming language.
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) const
Create related types using the current type's AST.
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
CompilerType AddConstModifier() const
Return a new CompilerType adds a const modifier to this type if this type is valid and the type syste...
lldb::Encoding GetEncoding(uint64_t &count) const
ConstString GetDisplayTypeName() const
CompilerType GetRValueReferenceType() const
Return a new CompilerType that is a R value reference to this type if this type is valid and the type...
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
CompilerType AddVolatileModifier() const
Return a new CompilerType adds a volatile modifier to this type if this type is valid and the type sy...
CompilerType AddRestrictModifier() const
Return a new CompilerType adds a restrict modifier to this type if this type is valid and the type sy...
CompilerType GetDirectNestedTypeWithName(llvm::StringRef name) const
CompilerType GetFunctionArgumentAtIndex(const size_t index) const
CompilerType GetLValueReferenceType() const
Return a new CompilerType that is a L value reference to this type if this type is valid and the type...
size_t GetNumberOfFunctionArguments() const
CompilerType GetNonReferenceType() const
If this type is a reference to a type (L value or R value reference), return a new type with the refe...
ConstString GetTypeName(bool BaseOnly=false) const
CompilerType GetTypedefedType() const
If the current object represents a typedef type, get the underlying type.
bool IsAggregateType() const
lldb::Format GetFormat() const
CompilerType GetFullyUnqualifiedType() const
CompilerType GetPointeeType() const
If this type is a pointer type, return the type that the pointer points to, else return an invalid ty...
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
CompilerType CreateTypedef(const char *name, const CompilerDeclContext &decl_ctx, uint32_t payload) const
Create a typedef to this type using "name" as the name of the typedef this type is valid and the type...
CompilerType GetFunctionReturnType() const
CompilerType GetAtomicType() const
Return a new CompilerType that is the atomic type of this type.
bool IsTemplateType() const
CompilerType GetCanonicalType() const
void DumpTypeDescription(lldb::DescriptionLevel level=lldb::eDescriptionLevelFull) const
Dump to stdout.
CompilerType AddPtrAuthModifier(uint32_t payload) const
Return a new CompilerType adds a ptrauth modifier from the given 32-bit opaque payload to this type i...
A uniqued constant string class.
void SetCString(const char *cstr)
Set the C string value.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
void Dump(Stream *s, const char *value_if_empty=nullptr) const
Dump the object description to a stream.
void SetString(llvm::StringRef s)
void Clear()
Clear this object's state.
A subclass of DataBuffer that stores a data buffer on the heap.
A class that describes the declaration location of a lldb object.
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Process * GetProcessPtr() const
Returns a pointer to the process object.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
virtual ArchSpec GetArchitecture()=0
Get the ArchSpec for this object file.
A plug-in interface definition class for debugging a process.
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
virtual void DumpSymbolContext(Stream *s)=0
Dump the object's symbol context to the stream s.
SymbolFile & m_symbol_file
SymbolFileType(SymbolFile &symbol_file, lldb::user_id_t uid)
Provides public interface for all SymbolFiles.
virtual bool CompleteType(CompilerType &compiler_type)=0
virtual Type * ResolveTypeUID(lldb::user_id_t type_uid)=0
virtual llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language)=0
virtual ObjectFile * GetObjectFile()=0
Sometimes you can find the name of the type corresponding to an object, but we don't have debug infor...
void SetName(ConstString type_name)
bool operator!=(const TypeAndOrName &other) const
bool operator==(const TypeAndOrName &other) const
ConstString GetName() const
bool HasCompilerType() const
void SetCompilerType(CompilerType compiler_type)
void SetTypeSP(lldb::TypeSP type_sp)
CompilerType m_compiler_type
CompilerType GetCompilerType(bool prefer_dynamic)
bool operator!=(const TypeImpl &rhs) const
bool CheckExeModule(lldb::ModuleSP &module_sp) const
bool GetDescription(lldb_private::Stream &strm, lldb::DescriptionLevel description_level)
bool operator==(const TypeImpl &rhs) const
bool CheckModuleCommon(const lldb::ModuleWP &input_module_wp, lldb::ModuleSP &module_sp) const
TypeImpl GetCanonicalType() const
void SetType(const lldb::TypeSP &type_sp)
TypeImpl GetUnqualifiedType() const
TypeImpl GetPointeeType() const
CompilerType m_dynamic_type
CompilerType::TypeSystemSPWrapper GetTypeSystem(bool prefer_dynamic)
CompilerType m_static_type
bool CheckModule(lldb::ModuleSP &module_sp) const
lldb::ModuleSP GetModule() const
TypeImpl GetDereferencedType() const
TypeImpl GetPointerType() const
lldb::ModuleWP m_exe_module_wp
TypeImpl GetReferenceType() const
TypeImpl GetTypedefedType() const
lldb::ModuleWP m_module_wp
ConstString GetName() const
CompilerType FindDirectNestedType(llvm::StringRef name)
ConstString GetDisplayTypeName() const
void Append(const lldb::TypeImplSP &type)
void ForEach(std::function< bool(const lldb::TypeSP &type_sp)> const &callback) const
bool InsertUnique(const lldb::TypeSP &type)
size_t GetNumArguments() const
CompilerType GetReturnType() const
ConstString GetMangledName() const
CompilerType GetType() const
ConstString GetName() const
CompilerType GetArgumentAtIndex(size_t idx) const
bool GetDescription(Stream &stream)
lldb::MemberFunctionKind GetKind() const
lldb::MemberFunctionKind m_kind
A class that contains all state required for type lookups.
std::vector< lldb_private::CompilerContext > m_context
A full or partial compiler context array where the parent declaration contexts appear at the top of t...
void AddLanguage(lldb::LanguageType language)
Add a language family to the list of languages that should produce a match.
TypeQueryOptions m_options
An options bitmask that contains enabled options for the type query.
bool LanguageMatches(lldb::LanguageType language) const
Check if the language matches any languages that have been added to this match object.
bool GetExactMatch() const
bool GetIgnoreModules() const
void SetLanguages(LanguageSet languages)
Set the list of languages that should produce a match to only the ones specified in languages.
std::optional< LanguageSet > m_languages
If this variable has a value, then the language family must match at least one of the specified langu...
ConstString GetTypeBasename() const
Get the type basename to use when searching the type indexes in each SymbolFile object.
bool ContextMatches(llvm::ArrayRef< lldb_private::CompilerContext > context) const
Check of a CompilerContext array from matching type from a symbol file matches the m_context.
bool GetFindOne() const
Returns true if the type query is supposed to find only a single matching type.
bool InsertUnique(const lldb::TypeSP &type_sp)
When types that match a TypeQuery are found, this API is used to insert the matching types.
llvm::DenseSet< lldb_private::SymbolFile * > m_searched_symbol_files
This set is used to track and make sure we only perform lookups in a symbol file one time.
bool Done(const TypeQuery &query) const
Check if the type matching has found all of the matches that it needs.
bool AlreadySearched(lldb_private::SymbolFile *sym_file)
Check if a SymbolFile object has already been searched by this type match object.
TypeMap m_type_map
Matching types get added to this map as type search continues.
CompilerType m_compiler_type
CompilerType GetForwardCompilerType()
const lldb_private::Declaration & GetDeclaration() const
uint64_t m_byte_size_has_value
ResolveState m_compiler_type_resolve_state
uint32_t GetEncodingMask()
void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name, ExecutionContextScope *exe_scope)
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes)
SymbolContextScope * m_context
The symbol context in which this type is defined.
lldb::user_id_t m_encoding_uid
@ eEncodingIsRestrictUID
This type is the type whose UID is m_encoding_uid with the restrict qualifier added.
@ eEncodingIsConstUID
This type is the type whose UID is m_encoding_uid with the const qualifier added.
@ eEncodingIsVolatileUID
This type is the type whose UID is m_encoding_uid with the volatile qualifier added.
@ eEncodingIsAtomicUID
This type is the type whose UID is m_encoding_uid as an atomic type.
@ eEncodingIsLLVMPtrAuthUID
This type is a signed pointer.
@ eEncodingIsSyntheticUID
This type is the synthetic type whose UID is m_encoding_uid.
@ eEncodingInvalid
Invalid encoding.
@ eEncodingIsTypedefUID
This type is alias to a type whose UID is m_encoding_uid.
@ eEncodingIsPointerUID
This type is pointer to a type whose UID is m_encoding_uid.
@ eEncodingIsLValueReferenceUID
This type is L value reference to a type whose UID is m_encoding_uid.
@ eEncodingIsRValueReferenceUID
This type is R value reference to a type whose UID is m_encoding_uid.
@ eEncodingIsUID
This type is the type whose UID is m_encoding_uid.
Payload m_payload
Language-specific flags.
SymbolFile * GetSymbolFile()
void Dump(Stream *s, bool show_context, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
CompilerType GetLayoutCompilerType()
lldb::Encoding GetEncoding(uint64_t &count)
lldb::ModuleSP GetExeModule()
GetModule may return module for compile unit's object file.
void DumpTypeName(Stream *s)
static std::optional< ParsedName > GetTypeScopeAndBasename(llvm::StringRef name)
lldb::TypeSP GetTypedefType()
bool ResolveCompilerType(ResolveState compiler_type_resolve_state)
SymbolFile * m_symbol_file
EncodingDataType m_encoding_uid_type
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope)
bool ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t address, AddressType address_type, DataExtractor &data)
ConstString GetBaseName()
ConstString GetQualifiedName()
CompilerType GetFullCompilerType()
lldb::ModuleSP GetModule()
Since Type instances only keep a "SymbolFile *" internally, other classes like TypeImpl need make sur...
bool WriteToMemory(ExecutionContext *exe_ctx, lldb::addr_t address, AddressType address_type, DataExtractor &data)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
@ AnyDeclContext
Math any declaration context.
Stream & operator<<(Stream &s, const Mangled &obj)
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
@ eAddressTypeHost
Address is an address in the process that is running this code.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
std::weak_ptr< lldb_private::Module > ModuleWP
Format
Display format definitions.
LanguageType
Programming language type.
@ eLanguageTypeC
Non-standardized C, such as K&R.
std::shared_ptr< lldb_private::Type > TypeSP
Encoding
Register encoding definitions.
MemberFunctionKind
Kind of member function.
@ eMemberFunctionKindInstanceMethod
A function that applies to a specific instance.
@ eMemberFunctionKindConstructor
A function used to create instances.
@ eMemberFunctionKindUnknown
Not sure what the type of this is.
@ eMemberFunctionKindDestructor
A function used to tear down existing instances.
@ eMemberFunctionKindStaticMethod
A function that applies to a type rather than any instance.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::TypeImpl > TypeImplSP
std::shared_ptr< lldb_private::Module > ModuleSP
CompilerContext allows an array of these items to be passed to perform detailed lookups in SymbolVend...
void Dump(Stream &s) const
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
llvm::SmallVector< llvm::StringRef > scope
lldb::TypeClass type_class
A mix in class that contains a generic user ID.
lldb::user_id_t GetID() const
Get accessor for the user ID.