LLDB mainline
Type.h
Go to the documentation of this file.
1//===-- Type.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_TYPE_H
10#define LLDB_SYMBOL_TYPE_H
11
16#include "lldb/Symbol/TypeMap.h"
19#include "lldb/Utility/UserID.h"
20#include "lldb/lldb-private.h"
21
22#include "llvm/ADT/APSInt.h"
23#include "llvm/ADT/DenseSet.h"
24#include "llvm/ADT/STLForwardCompat.h"
25#include "llvm/Support/raw_ostream.h"
26
27#include <optional>
28#include <set>
29
30namespace lldb_private {
31class SymbolFileCommon;
32
33/// A SmallBitVector that represents a set of source languages (\p
34/// lldb::LanguageType). Each lldb::LanguageType is represented by
35/// the bit with the position of its enumerator. The largest
36/// LanguageType is < 64, so this is space-efficient and on 64-bit
37/// architectures a LanguageSet can be completely stack-allocated.
39 llvm::SmallBitVector bitvector;
41
42 /// If the set contains a single language only, return it.
43 std::optional<lldb::LanguageType> GetSingularLanguage();
44 void Insert(lldb::LanguageType language);
45 bool Empty() const;
46 size_t Size() const;
47 bool operator[](unsigned i) const;
48};
49
50/// CompilerContext allows an array of these items to be passed to perform
51/// detailed lookups in SymbolVendor and SymbolFile functions.
54
55 bool operator==(const CompilerContext &rhs) const {
56 return kind == rhs.kind && name == rhs.name;
57 }
58 bool operator!=(const CompilerContext &rhs) const { return !(*this == rhs); }
59
60 void Dump(Stream &s) const;
61
64};
65llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
66 const CompilerContext &rhs);
67
68FLAGS_ENUM(TypeQueryOptions){
69 e_none = 0u,
70 /// If set, TypeQuery::m_context contains an exact context that must match
71 /// the full context. If not set, TypeQuery::m_context can contain a partial
72 /// type match where the full context isn't fully specified.
73 e_exact_match = (1u << 0),
74 /// If set, TypeQuery::m_context is a clang module compiler context. If not
75 /// set TypeQuery::m_context is normal type lookup context.
76 e_module_search = (1u << 1),
77 /// If set, the query will ignore all Module entries in the type context,
78 /// even for exact matches.
79 e_ignore_modules = (1u << 2),
80 /// When true, the find types call should stop the query as soon as a single
81 /// matching type is found. When false, the type query should find all
82 /// matching types.
83 e_find_one = (1u << 3),
84};
85LLDB_MARK_AS_BITMASK_ENUM(TypeQueryOptions)
86
87/// A class that contains all state required for type lookups.
88///
89/// Using a TypeQuery class for matching types simplifies the internal APIs we
90/// need to implement type lookups in LLDB. Type lookups can fully specify the
91/// exact typename by filling out a complete or partial CompilerContext array.
92/// This technique allows for powerful searches and also allows the SymbolFile
93/// classes to use the m_context array to lookup types by basename, then
94/// eliminate potential matches without having to resolve types into each
95/// TypeSystem. This makes type lookups vastly more efficient and allows the
96/// SymbolFile objects to stop looking up types when the type matching is
97/// complete, like if we are looking for only a single type in our search.
98class TypeQuery {
99public:
100 TypeQuery() = delete;
101
102 /// Construct a type match object using a fully- or partially-qualified name.
103 ///
104 /// The specified \a type_name will be chopped up and the m_context will be
105 /// populated by separating the string by looking for "::". We do this because
106 /// symbol files have indexes that contain only the type's basename. This also
107 /// allows symbol files to efficiently not realize types that don't match the
108 /// specified context. Example of \a type_name values that can be specified
109 /// include:
110 /// "foo": Look for any type whose basename matches "foo".
111 /// If \a exact_match is true, then the type can't be contained in any
112 /// declaration context like a namespace, class, or other containing
113 /// scope.
114 /// If \a exact match is false, then we will find all matches including
115 /// ones that are contained in other declaration contexts, including top
116 /// level types.
117 /// "foo::bar": Look for any type whose basename matches "bar" but make sure
118 /// its parent declaration context is any named declaration context
119 /// (namespace, class, struct, etc) whose name matches "foo".
120 /// If \a exact_match is true, then the "foo" declaration context must
121 /// appear at the source file level or inside of a function.
122 /// If \a exact match is false, then the "foo" declaration context can
123 /// be contained in any other declaration contexts.
124 /// "class foo": Only match types that are classes whose basename matches
125 /// "foo".
126 /// "struct foo": Only match types that are structures whose basename
127 /// matches "foo".
128 /// "class foo::bar": Only match types that are classes whose basename
129 /// matches "bar" and that are contained in any named declaration context
130 /// named "foo".
131 ///
132 /// \param[in] type_name
133 /// A fully- or partially-qualified type name. This name will be parsed and
134 /// broken up and the m_context will be populated with the various parts of
135 /// the name. This typename can be prefixed with "struct ", "class ",
136 /// "union", "enum " or "typedef " before the actual type name to limit the
137 /// results of the types that match. The declaration context can be
138 /// specified with the "::" string. For example, "a::b::my_type".
139 ///
140 /// \param[in] options A set of boolean enumeration flags from the
141 /// TypeQueryOptions enumerations. \see TypeQueryOptions.
142 TypeQuery(llvm::StringRef name, TypeQueryOptions options = e_none);
143
144 /// Construct a type-match object that matches a type basename that exists
145 /// in the specified declaration context.
146 ///
147 /// This allows the m_context to be first populated using a declaration
148 /// context to exactly identify the containing declaration context of a type.
149 /// This can be used when you have a forward declaration to a type and you
150 /// need to search for its complete type.
151 ///
152 /// \param[in] decl_ctx
153 /// A declaration context object that comes from a TypeSystem plug-in. This
154 /// object will be asked to populate the array of CompilerContext objects
155 /// by adding the top most declaration context first into the array and then
156 /// adding any containing declaration contexts.
157 ///
158 /// \param[in] type_basename
159 /// The basename of the type to lookup in the specified declaration context.
160 ///
161 /// \param[in] options A set of boolean enumeration flags from the
162 /// TypeQueryOptions enumerations. \see TypeQueryOptions.
163 TypeQuery(const CompilerDeclContext &decl_ctx, ConstString type_basename,
164 TypeQueryOptions options = e_none);
165 /// Construct a type-match object using a compiler declaration that specifies
166 /// a typename and a declaration context to use when doing exact type lookups.
167 ///
168 /// This allows the m_context to be first populated using a type declaration.
169 /// The type declaration might have a declaration context and each TypeSystem
170 /// plug-in can populate the declaration context needed to perform an exact
171 /// lookup for a type.
172 /// This can be used when you have a forward declaration to a type and you
173 /// need to search for its complete type.
174 ///
175 /// \param[in] decl
176 /// A type declaration context object that comes from a TypeSystem plug-in.
177 /// This object will be asked to full the array of CompilerContext objects
178 /// by adding the top most declaration context first into the array and then
179 /// adding any containing declaration contexts, and ending with the exact
180 /// typename and the kind of type it is (class, struct, union, enum, etc).
181 ///
182 /// \param[in] options A set of boolean enumeration flags from the
183 /// TypeQueryOptions enumerations. \see TypeQueryOptions.
184 TypeQuery(const CompilerDecl &decl, TypeQueryOptions options = e_none);
185
186 /// Construct a type-match object using a CompilerContext array.
187 ///
188 /// Clients can manually create compiler contexts and use these to find
189 /// matches when searching for types. There are two types of contexts that
190 /// are supported when doing type searchs: type contexts and clang module
191 /// contexts. Type contexts have contexts that specify the type and its
192 /// containing declaration context like namespaces and classes. Clang module
193 /// contexts specify contexts more completely to find exact matches within
194 /// clang module debug information. They will include the modules that the
195 /// type is included in and any functions that the type might be defined in.
196 /// This allows very fine-grained type resolution.
197 ///
198 /// \param[in] context The compiler context to use when doing the search.
199 ///
200 /// \param[in] options A set of boolean enumeration flags from the
201 /// TypeQueryOptions enumerations. \see TypeQueryOptions.
202 TypeQuery(const llvm::ArrayRef<lldb_private::CompilerContext> &context,
203 TypeQueryOptions options = e_none);
204
205 /// Construct a type-match object that duplicates all matching criterea,
206 /// but not any searched symbol files or the type map for matches. This allows
207 /// the m_context to be modified prior to performing another search.
208 TypeQuery(const TypeQuery &rhs) = default;
209 /// Assign a type-match object that duplicates all matching criterea,
210 /// but not any searched symbol files or the type map for matches. This allows
211 /// the m_context to be modified prior to performing another search.
212 TypeQuery &operator=(const TypeQuery &rhs) = default;
213
214 /// Check of a CompilerContext array from matching type from a symbol file
215 /// matches the \a m_context.
216 ///
217 /// \param[in] context
218 /// A fully qualified CompilerContext array for a potential match that is
219 /// created by the symbol file prior to trying to actually resolve a type.
220 ///
221 /// \returns
222 /// True if the context matches, false if it doesn't. If e_exact_match
223 /// is set in m_options, then \a context must exactly match \a m_context. If
224 /// e_exact_match is not set, then the bottom m_context.size() objects in
225 /// \a context must match. This allows SymbolFile objects the fill in a
226 /// potential type basename match from the index into \a context, and see if
227 /// it matches prior to having to resolve a lldb_private::Type object for
228 /// the type from the index. This allows type parsing to be as efficient as
229 /// possible and only realize the types that match the query.
230 bool
231 ContextMatches(llvm::ArrayRef<lldb_private::CompilerContext> context) const;
232
233 /// Get the type basename to use when searching the type indexes in each
234 /// SymbolFile object.
235 ///
236 /// Debug information indexes often contain indexes that track the basename
237 /// of types only, not a fully qualified path. This allows the indexes to be
238 /// smaller and allows for efficient lookups.
239 ///
240 /// \returns
241 /// The type basename to use when doing lookups as a constant string.
242 ConstString GetTypeBasename() const;
243
244 /// Returns true if any matching languages have been specified in this type
245 /// matching object.
246 bool HasLanguage() const { return m_languages.has_value(); }
247
248 /// Add a language family to the list of languages that should produce a
249 /// match.
250 void AddLanguage(lldb::LanguageType language);
251
252 /// Set the list of languages that should produce a match to only the ones
253 /// specified in \ref languages.
254 void SetLanguages(LanguageSet languages);
255
256 /// Check if the language matches any languages that have been added to this
257 /// match object.
258 ///
259 /// \returns
260 /// True if no language have been specified, or if some language have been
261 /// added using AddLanguage(...) and they match. False otherwise.
262 bool LanguageMatches(lldb::LanguageType language) const;
263
264 bool GetExactMatch() const { return (m_options & e_exact_match) != 0; }
265
266 bool GetIgnoreModules() const { return (m_options & e_ignore_modules) != 0; }
267 void SetIgnoreModules() { m_options &= ~e_ignore_modules; }
268
269 /// The \a m_context can be used in two ways: normal types searching with
270 /// the context containing a stanadard declaration context for a type, or
271 /// with the context being more complete for exact matches in clang modules.
272 /// Set this to true if you wish to search for a type in clang module.
273 bool GetModuleSearch() const { return (m_options & e_module_search) != 0; }
274
275 /// Returns true if the type query is supposed to find only a single matching
276 /// type. Returns false if the type query should find all matches.
277 bool GetFindOne() const { return (m_options & e_find_one) != 0; }
278 void SetFindOne(bool b) {
279 if (b)
280 m_options |= e_find_one;
281 else
282 m_options &= (e_exact_match | e_find_one);
283 }
284
285 /// Access the internal compiler context array.
286 ///
287 /// Clients can use this to populate the context manually.
288 std::vector<lldb_private::CompilerContext> &GetContextRef() {
289 return m_context;
290 }
291
292protected:
293 /// A full or partial compiler context array where the parent declaration
294 /// contexts appear at the top of the array starting at index zero and the
295 /// last entry contains the type and name of the type we are looking for.
296 std::vector<lldb_private::CompilerContext> m_context;
297 /// An options bitmask that contains enabled options for the type query.
298 /// \see TypeQueryOptions.
299 TypeQueryOptions m_options;
300 /// If this variable has a value, then the language family must match at least
301 /// one of the specified languages. If this variable has no value, then the
302 /// language of the type doesn't need to match any types that are searched.
303 std::optional<LanguageSet> m_languages;
304};
305
306/// This class tracks the state and results of a \ref TypeQuery.
307///
308/// Any mutable state required for type lookups and the results are tracked in
309/// this object.
311public:
312 /// Construct a type results object
313 TypeResults() = default;
314
315 /// When types that match a TypeQuery are found, this API is used to insert
316 /// the matching types.
317 ///
318 /// \return
319 /// True if the type was added, false if the \a type_sp was already in the
320 /// results.
321 bool InsertUnique(const lldb::TypeSP &type_sp);
322
323 /// Check if the type matching has found all of the matches that it needs.
324 bool Done(const TypeQuery &query) const;
325
326 /// Check if a SymbolFile object has already been searched by this type match
327 /// object.
328 ///
329 /// This function will add \a sym_file to the set of SymbolFile objects if it
330 /// isn't already in the set and return \a false. Returns true if \a sym_file
331 /// was already in the set and doesn't need to be searched.
332 ///
333 /// Any clients that search for types should first check that the symbol file
334 /// has not already been searched. If this function returns true, the type
335 /// search function should early return to avoid duplicating type searchihng
336 /// efforts.
337 ///
338 /// \param[in] sym_file
339 /// A SymbolFile pointer that will be used to track which symbol files have
340 /// already been searched.
341 ///
342 /// \returns
343 /// True if the symbol file has been search already, false otherwise.
345
346 /// Access the set of searched symbol files.
347 llvm::DenseSet<lldb_private::SymbolFile *> &GetSearchedSymbolFiles() {
349 }
350
353 const TypeMap &GetTypeMap() const { return m_type_map; }
354
355private:
356 /// Matching types get added to this map as type search continues.
358 /// This set is used to track and make sure we only perform lookups in a
359 /// symbol file one time.
360 llvm::DenseSet<lldb_private::SymbolFile *> m_searched_symbol_files;
361};
362
363class SymbolFileType : public std::enable_shared_from_this<SymbolFileType>,
364 public UserID {
365public:
367 : UserID(uid), m_symbol_file(symbol_file) {}
368
369 SymbolFileType(SymbolFile &symbol_file, const lldb::TypeSP &type_sp);
370
371 ~SymbolFileType() = default;
372
373 Type *operator->() { return GetType(); }
374
375 Type *GetType();
377
378protected:
381};
382
383class Type : public std::enable_shared_from_this<Type>, public UserID {
384public:
386 /// Invalid encoding.
388 /// This type is the type whose UID is m_encoding_uid.
390 /// This type is the type whose UID is m_encoding_uid with the const
391 /// qualifier added.
393 /// This type is the type whose UID is m_encoding_uid with the restrict
394 /// qualifier added.
396 /// This type is the type whose UID is m_encoding_uid with the volatile
397 /// qualifier added.
399 /// This type is alias to a type whose UID is m_encoding_uid.
401 /// This type is pointer to a type whose UID is m_encoding_uid.
403 /// This type is L value reference to a type whose UID is m_encoding_uid.
405 /// This type is R value reference to a type whose UID is m_encoding_uid.
407 /// This type is the type whose UID is m_encoding_uid as an atomic type.
409 /// This type is the synthetic type whose UID is m_encoding_uid.
411 /// This type is a signed pointer.
413 };
414
415 enum class ResolveState : unsigned char {
416 Unresolved = 0,
417 Forward = 1,
418 Layout = 2,
419 Full = 3
420 };
421
422 void Dump(Stream *s, bool show_context,
424
425 void DumpTypeName(Stream *s);
426
427 /// Since Type instances only keep a "SymbolFile *" internally, other classes
428 /// like TypeImpl need make sure the module is still around before playing
429 /// with
430 /// Type instances. They can store a weak pointer to the Module;
432
433 /// GetModule may return module for compile unit's object file.
434 /// GetExeModule returns module for executable object file that contains
435 /// compile unit where type was actually defined.
436 /// GetModule and GetExeModule may return the same value.
438
439 void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name,
440 ExecutionContextScope *exe_scope);
441
443 const SymbolFile *GetSymbolFile() const { return m_symbol_file; }
444
446
448
449 std::optional<uint64_t> GetByteSize(ExecutionContextScope *exe_scope);
450
451 llvm::Expected<uint32_t> GetNumChildren(bool omit_empty_base_classes);
452
453 bool IsAggregateType();
454
455 // Returns if the type is a templated decl. Does not look through typedefs.
456 bool IsTemplateType();
457
459
461
463
464 ConstString GetName() const { return m_name; }
465
467
468 bool ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t address,
469 AddressType address_type, DataExtractor &data);
470
471 bool WriteToMemory(ExecutionContext *exe_ctx, lldb::addr_t address,
472 AddressType address_type, DataExtractor &data);
473
475
476 lldb::Encoding GetEncoding(uint64_t &count);
477
481 m_context = context;
482 }
483
485
486 // Get the clang type, and resolve definitions for any
487 // class/struct/union/enum types completely.
489
490 // Get the clang type, and resolve definitions enough so that the type could
491 // have layout performed. This allows ptrs and refs to
492 // class/struct/union/enum types remain forward declarations.
494
495 // Get the clang type and leave class/struct/union/enum types as forward
496 // declarations if they haven't already been fully defined.
498
499 static int Compare(const Type &a, const Type &b);
500
501 // Represents a parsed type name coming out of GetTypeScopeAndBasename. The
502 // structure holds StringRefs pointing to portions of the original name, and
503 // so must not be used after the name is destroyed.
504 struct ParsedName {
505 lldb::TypeClass type_class = lldb::eTypeClassAny;
506
507 // Scopes of the type, starting with the outermost. Absolute type references
508 // have a "::" as the first scope.
509 llvm::SmallVector<llvm::StringRef> scope;
510
511 llvm::StringRef basename;
512
513 friend bool operator==(const ParsedName &lhs, const ParsedName &rhs) {
514 return lhs.type_class == rhs.type_class && lhs.scope == rhs.scope &&
515 lhs.basename == rhs.basename;
516 }
517
518 friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
519 const ParsedName &name) {
520 return os << llvm::formatv(
521 "Type::ParsedName({0:x}, [{1}], {2})",
522 llvm::to_underlying(name.type_class),
523 llvm::make_range(name.scope.begin(), name.scope.end()),
524 name.basename);
525 }
526 };
527 // From a fully qualified typename, split the type into the type basename and
528 // the remaining type scope (namespaces/classes).
529 static std::optional<ParsedName>
530 GetTypeScopeAndBasename(llvm::StringRef name);
531
532 void SetEncodingType(Type *encoding_type) { m_encoding_type = encoding_type; }
533
534 uint32_t GetEncodingMask();
535
536 typedef uint32_t Payload;
537 /// Return the language-specific payload.
539 /// Return the language-specific payload.
540 void SetPayload(Payload opaque_payload) { m_payload = opaque_payload; }
541
542protected:
545 /// The symbol context in which this type is defined.
550 uint64_t m_byte_size : 63;
555 /// Language-specific flags.
557
559
560 bool ResolveCompilerType(ResolveState compiler_type_resolve_state);
561private:
562 /// Only allow Symbol File to create types, as they should own them by keeping
563 /// them in their TypeList. \see SymbolFileCommon::MakeType() reference in the
564 /// header documentation here so users will know what function to use if the
565 /// get a compile error.
567
568 Type(lldb::user_id_t uid, SymbolFile *symbol_file, ConstString name,
569 std::optional<uint64_t> byte_size, SymbolContextScope *context,
570 lldb::user_id_t encoding_uid, EncodingDataType encoding_uid_type,
571 const Declaration &decl, const CompilerType &compiler_qual_type,
572 ResolveState compiler_type_resolve_state, uint32_t opaque_payload = 0);
573
574 // This makes an invalid type. Used for functions that return a Type when
575 // they get an error.
576 Type();
577
578 Type(Type &t) = default;
579
580 Type(Type &&t) = default;
581
582 Type &operator=(const Type &t) = default;
583
584 Type &operator=(Type &&t) = default;
585};
586
587// the two classes here are used by the public API as a backend to the SBType
588// and SBTypeList classes
589
590class TypeImpl {
591public:
592 TypeImpl() = default;
593
594 ~TypeImpl() = default;
595
596 TypeImpl(const lldb::TypeSP &type_sp);
597
598 TypeImpl(const CompilerType &compiler_type);
599
600 TypeImpl(const lldb::TypeSP &type_sp, const CompilerType &dynamic);
601
602 TypeImpl(const CompilerType &compiler_type, const CompilerType &dynamic);
603
604 void SetType(const lldb::TypeSP &type_sp);
605
606 void SetType(const CompilerType &compiler_type);
607
608 void SetType(const lldb::TypeSP &type_sp, const CompilerType &dynamic);
609
610 void SetType(const CompilerType &compiler_type, const CompilerType &dynamic);
611
612 bool operator==(const TypeImpl &rhs) const;
613
614 bool operator!=(const TypeImpl &rhs) const;
615
616 bool IsValid() const;
617
618 explicit operator bool() const;
619
620 void Clear();
621
623
624 ConstString GetName() const;
625
627
628 TypeImpl GetPointerType() const;
629
630 TypeImpl GetPointeeType() const;
631
633
635
637
639
641
642 CompilerType GetCompilerType(bool prefer_dynamic);
643
645
647 lldb::DescriptionLevel description_level);
648
649 CompilerType FindDirectNestedType(llvm::StringRef name);
650
651private:
652 bool CheckModule(lldb::ModuleSP &module_sp) const;
653 bool CheckExeModule(lldb::ModuleSP &module_sp) const;
654 bool CheckModuleCommon(const lldb::ModuleWP &input_module_wp,
655 lldb::ModuleSP &module_sp) const;
656
661};
662
664public:
665 TypeListImpl() = default;
666
667 void Append(const lldb::TypeImplSP &type) { m_content.push_back(type); }
668
670 public:
671 AppendVisitor(TypeListImpl &type_list) : m_type_list(type_list) {}
672
673 void operator()(const lldb::TypeImplSP &type) { m_type_list.Append(type); }
674
675 private:
677 };
678
679 void Append(const lldb_private::TypeList &type_list);
680
682 lldb::TypeImplSP type_sp;
683 if (idx < GetSize())
684 type_sp = m_content[idx];
685 return type_sp;
686 }
687
688 size_t GetSize() { return m_content.size(); }
689
690private:
691 std::vector<lldb::TypeImplSP> m_content;
692};
693
695public:
696 TypeMemberImpl() = default;
697
698 TypeMemberImpl(const lldb::TypeImplSP &type_impl_sp, uint64_t bit_offset,
699 ConstString name, uint32_t bitfield_bit_size = 0,
700 bool is_bitfield = false)
701 : m_type_impl_sp(type_impl_sp), m_bit_offset(bit_offset), m_name(name),
702 m_bitfield_bit_size(bitfield_bit_size), m_is_bitfield(is_bitfield) {}
703
704 TypeMemberImpl(const lldb::TypeImplSP &type_impl_sp, uint64_t bit_offset)
705 : m_type_impl_sp(type_impl_sp), m_bit_offset(bit_offset),
707 if (m_type_impl_sp)
708 m_name = m_type_impl_sp->GetName();
709 }
710
712
713 ConstString GetName() const { return m_name; }
714
715 uint64_t GetBitOffset() const { return m_bit_offset; }
716
717 uint32_t GetBitfieldBitSize() const { return m_bitfield_bit_size; }
718
719 void SetBitfieldBitSize(uint32_t bitfield_bit_size) {
720 m_bitfield_bit_size = bitfield_bit_size;
721 }
722
723 bool GetIsBitfield() const { return m_is_bitfield; }
724
725 void SetIsBitfield(bool is_bitfield) { m_is_bitfield = is_bitfield; }
726
727protected:
729 uint64_t m_bit_offset = 0;
731 uint32_t m_bitfield_bit_size = 0; // Bit size for bitfield members only
732 bool m_is_bitfield = false;
733};
734
735///
736/// Sometimes you can find the name of the type corresponding to an object, but
737/// we don't have debug
738/// information for it. If that is the case, you can return one of these
739/// objects, and then if it
740/// has a full type, you can use that, but if not at least you can print the
741/// name for informational
742/// purposes.
743///
744
746public:
747 TypeAndOrName() = default;
748 TypeAndOrName(lldb::TypeSP &type_sp);
749 TypeAndOrName(const CompilerType &compiler_type);
750 TypeAndOrName(const char *type_str);
751 TypeAndOrName(ConstString &type_const_string);
752
753 bool operator==(const TypeAndOrName &other) const;
754
755 bool operator!=(const TypeAndOrName &other) const;
756
757 ConstString GetName() const;
758
760
761 void SetName(ConstString type_name);
762
763 void SetName(const char *type_name_cstr);
764
765 void SetName(llvm::StringRef name);
766
767 void SetTypeSP(lldb::TypeSP type_sp);
768
769 void SetCompilerType(CompilerType compiler_type);
770
771 bool IsEmpty() const;
772
773 bool HasName() const;
774
775 bool HasCompilerType() const;
776
777 bool HasType() const { return HasCompilerType(); }
778
779 void Clear();
780
781 explicit operator bool() { return !IsEmpty(); }
782
783private:
786};
787
789public:
791
793 const std::string &name,
794 const lldb::MemberFunctionKind &kind)
795 : m_type(type), m_decl(decl), m_name(name), m_kind(kind) {}
796
797 bool IsValid();
798
799 ConstString GetName() const;
800
802
803 CompilerType GetType() const;
804
806
807 size_t GetNumArguments() const;
808
809 CompilerType GetArgumentAtIndex(size_t idx) const;
810
812
813 bool GetDescription(Stream &stream);
814
815protected:
816 std::string GetPrintableTypeName();
817
818private:
823};
824
826public:
827 TypeEnumMemberImpl() : m_name("<invalid>") {}
828
829 TypeEnumMemberImpl(const lldb::TypeImplSP &integer_type_sp, ConstString name,
830 const llvm::APSInt &value);
831
833
835
836 bool IsValid() { return m_valid; }
837
838 ConstString GetName() const { return m_name; }
839
841
842 uint64_t GetValueAsUnsigned() const { return m_value.getZExtValue(); }
843
844 int64_t GetValueAsSigned() const { return m_value.getSExtValue(); }
845
846protected:
849 llvm::APSInt m_value;
850 bool m_valid = false;
851};
852
854public:
856
858 m_content.push_back(type);
859 }
860
862
864 lldb::TypeEnumMemberImplSP enum_member;
865 if (idx < GetSize())
866 enum_member = m_content[idx];
867 return enum_member;
868 }
869
870 size_t GetSize() { return m_content.size(); }
871
872private:
873 std::vector<lldb::TypeEnumMemberImplSP> m_content;
874};
875
876} // namespace lldb_private
877
878#endif // LLDB_SYMBOL_TYPE_H
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
This is a minimal wrapper of a TypeSystem shared pointer as returned by CompilerType which conventien...
Definition: CompilerType.h:49
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
An data extractor class.
Definition: DataExtractor.h:48
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
"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.
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Containing protected virtual methods for child classes to override.
Definition: SymbolFile.h:504
SymbolFile & m_symbol_file
Definition: Type.h:379
SymbolFileType(SymbolFile &symbol_file, lldb::user_id_t uid)
Definition: Type.h:366
SymbolFile & GetSymbolFile() const
Definition: Type.h:376
lldb::TypeSP m_type_sp
Definition: Type.h:380
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:50
Sometimes you can find the name of the type corresponding to an object, but we don't have debug infor...
Definition: Type.h:745
void SetName(ConstString type_name)
Definition: Type.cpp:866
TypeAndOrName(const CompilerType &compiler_type)
bool operator!=(const TypeAndOrName &other) const
Definition: Type.cpp:854
bool operator==(const TypeAndOrName &other) const
Definition: Type.cpp:846
CompilerType GetCompilerType() const
Definition: Type.h:759
bool HasName() const
Definition: Type.cpp:901
ConstString GetName() const
Definition: Type.cpp:858
bool HasCompilerType() const
Definition: Type.cpp:903
void SetCompilerType(CompilerType compiler_type)
Definition: Type.cpp:886
ConstString m_type_name
Definition: Type.h:785
void SetTypeSP(lldb::TypeSP type_sp)
Definition: Type.cpp:878
bool HasType() const
Definition: Type.h:777
CompilerType m_compiler_type
Definition: Type.h:784
bool IsEmpty() const
Definition: Type.cpp:892
int64_t GetValueAsSigned() const
Definition: Type.h:844
ConstString GetName() const
Definition: Type.h:838
const lldb::TypeImplSP & GetIntegerType() const
Definition: Type.h:840
TypeEnumMemberImpl(const TypeEnumMemberImpl &rhs)=default
TypeEnumMemberImpl & operator=(const TypeEnumMemberImpl &rhs)
lldb::TypeImplSP m_integer_type_sp
Definition: Type.h:847
uint64_t GetValueAsUnsigned() const
Definition: Type.h:842
lldb::TypeEnumMemberImplSP GetTypeEnumMemberAtIndex(size_t idx)
Definition: Type.h:863
std::vector< lldb::TypeEnumMemberImplSP > m_content
Definition: Type.h:873
void Append(const lldb_private::TypeEnumMemberListImpl &type_list)
void Append(const lldb::TypeEnumMemberImplSP &type)
Definition: Type.h:857
CompilerType GetCompilerType(bool prefer_dynamic)
Definition: Type.cpp:1130
bool operator!=(const TypeImpl &rhs) const
Definition: Type.cpp:999
bool CheckExeModule(lldb::ModuleSP &module_sp) const
Definition: Type.cpp:961
bool GetDescription(lldb_private::Stream &strm, lldb::DescriptionLevel description_level)
Definition: Type.cpp:1154
bool operator==(const TypeImpl &rhs) const
Definition: Type.cpp:994
bool CheckModuleCommon(const lldb::ModuleWP &input_module_wp, lldb::ModuleSP &module_sp) const
Definition: Type.cpp:965
TypeImpl GetCanonicalType() const
Definition: Type.cpp:1118
void SetType(const lldb::TypeSP &type_sp)
Definition: Type.cpp:928
TypeImpl GetUnqualifiedType() const
Definition: Type.cpp:1106
TypeImpl GetPointeeType() const
Definition: Type.cpp:1058
CompilerType m_dynamic_type
Definition: Type.h:660
CompilerType::TypeSystemSPWrapper GetTypeSystem(bool prefer_dynamic)
Definition: Type.cpp:1142
CompilerType m_static_type
Definition: Type.h:659
bool CheckModule(lldb::ModuleSP &module_sp) const
Definition: Type.cpp:957
lldb::ModuleSP GetModule() const
Definition: Type.cpp:1019
TypeImpl GetDereferencedType() const
Definition: Type.cpp:1094
bool IsValid() const
Definition: Type.cpp:1003
TypeImpl GetPointerType() const
Definition: Type.cpp:1046
lldb::ModuleWP m_exe_module_wp
Definition: Type.h:658
TypeImpl GetReferenceType() const
Definition: Type.cpp:1070
TypeImpl GetTypedefedType() const
Definition: Type.cpp:1082
lldb::ModuleWP m_module_wp
Definition: Type.h:657
ConstString GetName() const
Definition: Type.cpp:1026
CompilerType FindDirectNestedType(llvm::StringRef name)
Definition: Type.cpp:1170
ConstString GetDisplayTypeName() const
Definition: Type.cpp:1036
void operator()(const lldb::TypeImplSP &type)
Definition: Type.h:673
AppendVisitor(TypeListImpl &type_list)
Definition: Type.h:671
lldb::TypeImplSP GetTypeAtIndex(size_t idx)
Definition: Type.h:681
void Append(const lldb::TypeImplSP &type)
Definition: Type.h:667
std::vector< lldb::TypeImplSP > m_content
Definition: Type.h:691
lldb::TypeSP FirstType() const
Definition: TypeMap.cpp:94
CompilerType GetReturnType() const
Definition: Type.cpp:1217
ConstString GetMangledName() const
Definition: Type.cpp:1183
CompilerType GetType() const
Definition: Type.cpp:1187
ConstString GetName() const
Definition: Type.cpp:1181
TypeMemberFunctionImpl(const CompilerType &type, const CompilerDecl &decl, const std::string &name, const lldb::MemberFunctionKind &kind)
Definition: Type.h:792
CompilerType GetArgumentAtIndex(size_t idx) const
Definition: Type.cpp:1230
bool GetDescription(Stream &stream)
Definition: Type.cpp:1193
lldb::MemberFunctionKind GetKind() const
Definition: Type.cpp:1189
lldb::MemberFunctionKind m_kind
Definition: Type.h:822
bool GetIsBitfield() const
Definition: Type.h:723
uint32_t GetBitfieldBitSize() const
Definition: Type.h:717
void SetIsBitfield(bool is_bitfield)
Definition: Type.h:725
const lldb::TypeImplSP & GetTypeImpl()
Definition: Type.h:711
ConstString GetName() const
Definition: Type.h:713
TypeMemberImpl(const lldb::TypeImplSP &type_impl_sp, uint64_t bit_offset, ConstString name, uint32_t bitfield_bit_size=0, bool is_bitfield=false)
Definition: Type.h:698
uint32_t m_bitfield_bit_size
Definition: Type.h:731
uint64_t GetBitOffset() const
Definition: Type.h:715
TypeMemberImpl(const lldb::TypeImplSP &type_impl_sp, uint64_t bit_offset)
Definition: Type.h:704
lldb::TypeImplSP m_type_impl_sp
Definition: Type.h:728
void SetBitfieldBitSize(uint32_t bitfield_bit_size)
Definition: Type.h:719
A class that contains all state required for type lookups.
Definition: Type.h:98
TypeQuery(const TypeQuery &rhs)=default
Construct a type-match object that duplicates all matching criterea, but not any searched symbol file...
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...
Definition: Type.h:296
bool GetModuleSearch() const
The m_context can be used in two ways: normal types searching with the context containing a stanadard...
Definition: Type.h:273
std::vector< lldb_private::CompilerContext > & GetContextRef()
Access the internal compiler context array.
Definition: Type.h:288
TypeQuery & operator=(const TypeQuery &rhs)=default
Assign a type-match object that duplicates all matching criterea, but not any searched symbol files o...
bool HasLanguage() const
Returns true if any matching languages have been specified in this type matching object.
Definition: Type.h:246
void SetIgnoreModules()
Definition: Type.h:267
TypeQueryOptions m_options
An options bitmask that contains enabled options for the type query.
Definition: Type.h:299
bool GetExactMatch() const
Definition: Type.h:264
bool GetIgnoreModules() const
Definition: Type.h:266
std::optional< LanguageSet > m_languages
If this variable has a value, then the language family must match at least one of the specified langu...
Definition: Type.h:303
void SetFindOne(bool b)
Definition: Type.h:278
bool GetFindOne() const
Returns true if the type query is supposed to find only a single matching type.
Definition: Type.h:277
This class tracks the state and results of a TypeQuery.
Definition: Type.h:310
bool InsertUnique(const lldb::TypeSP &type_sp)
When types that match a TypeQuery are found, this API is used to insert the matching types.
Definition: Type.cpp:173
const TypeMap & GetTypeMap() const
Definition: Type.h:353
TypeMap & GetTypeMap()
Definition: Type.h:352
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.
Definition: Type.h:360
TypeResults()=default
Construct a type results object.
lldb::TypeSP GetFirstType() const
Definition: Type.h:351
bool AlreadySearched(lldb_private::SymbolFile *sym_file)
Check if a SymbolFile object has already been searched by this type match object.
Definition: Type.cpp:169
llvm::DenseSet< lldb_private::SymbolFile * > & GetSearchedSymbolFiles()
Access the set of searched symbol files.
Definition: Type.h:347
TypeMap m_type_map
Matching types get added to this map as type search continues.
Definition: Type.h:357
Type * m_encoding_type
Definition: Type.h:547
void SetEncodingType(Type *encoding_type)
Definition: Type.h:532
CompilerType m_compiler_type
Definition: Type.h:553
CompilerType GetForwardCompilerType()
Definition: Type.cpp:754
lldb::Format GetFormat()
Definition: Type.cpp:506
Declaration m_decl
Definition: Type.h:552
Type & operator=(const Type &t)=default
Type * GetEncodingType()
Definition: Type.cpp:432
ConstString GetName()
Definition: Type.cpp:420
const SymbolContextScope * GetSymbolContextScope() const
Definition: Type.h:479
void SetSymbolContextScope(SymbolContextScope *context)
Definition: Type.h:480
const lldb_private::Declaration & GetDeclaration() const
Definition: Type.cpp:556
uint64_t m_byte_size_has_value
Definition: Type.h:551
bool IsTemplateType()
Definition: Type.cpp:492
ResolveState m_compiler_type_resolve_state
Definition: Type.h:554
ConstString m_name
Definition: Type.h:543
static int Compare(const Type &a, const Type &b)
uint32_t GetEncodingMask()
Definition: Type.cpp:735
void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name, ExecutionContextScope *exe_scope)
Definition: Type.cpp:284
Type & operator=(Type &&t)=default
const SymbolFile * GetSymbolFile() const
Definition: Type.h:443
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes)
Definition: Type.cpp:484
SymbolContextScope * m_context
The symbol context in which this type is defined.
Definition: Type.h:546
bool IsValidType()
Definition: Type.h:458
lldb::user_id_t m_encoding_uid
Definition: Type.h:548
@ eEncodingIsRestrictUID
This type is the type whose UID is m_encoding_uid with the restrict qualifier added.
Definition: Type.h:395
@ eEncodingIsConstUID
This type is the type whose UID is m_encoding_uid with the const qualifier added.
Definition: Type.h:392
@ eEncodingIsVolatileUID
This type is the type whose UID is m_encoding_uid with the volatile qualifier added.
Definition: Type.h:398
@ eEncodingIsAtomicUID
This type is the type whose UID is m_encoding_uid as an atomic type.
Definition: Type.h:408
@ eEncodingIsLLVMPtrAuthUID
This type is a signed pointer.
Definition: Type.h:412
@ eEncodingIsSyntheticUID
This type is the synthetic type whose UID is m_encoding_uid.
Definition: Type.h:410
@ eEncodingInvalid
Invalid encoding.
Definition: Type.h:387
@ eEncodingIsTypedefUID
This type is alias to a type whose UID is m_encoding_uid.
Definition: Type.h:400
@ eEncodingIsPointerUID
This type is pointer to a type whose UID is m_encoding_uid.
Definition: Type.h:402
@ eEncodingIsLValueReferenceUID
This type is L value reference to a type whose UID is m_encoding_uid.
Definition: Type.h:404
@ eEncodingIsRValueReferenceUID
This type is R value reference to a type whose UID is m_encoding_uid.
Definition: Type.h:406
@ eEncodingIsUID
This type is the type whose UID is m_encoding_uid.
Definition: Type.h:389
Payload m_payload
Language-specific flags.
Definition: Type.h:556
SymbolFile * GetSymbolFile()
Definition: Type.h:442
void Dump(Stream *s, bool show_context, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
Definition: Type.cpp:352
Payload GetPayload()
Return the language-specific payload.
Definition: Type.h:538
CompilerType GetLayoutCompilerType()
Definition: Type.cpp:749
void SetPayload(Payload opaque_payload)
Return the language-specific payload.
Definition: Type.h:540
lldb::Encoding GetEncoding(uint64_t &count)
Definition: Type.cpp:508
Type(Type &&t)=default
lldb::ModuleSP GetExeModule()
GetModule may return module for compile unit's object file.
Definition: Type.cpp:821
void DumpTypeName(Stream *s)
Definition: Type.cpp:430
static std::optional< ParsedName > GetTypeScopeAndBasename(llvm::StringRef name)
Definition: Type.cpp:764
SymbolContextScope * GetSymbolContextScope()
Definition: Type.h:478
lldb::TypeSP GetTypedefType()
Definition: Type.cpp:496
bool ResolveCompilerType(ResolveState compiler_type_resolve_state)
Definition: Type.cpp:558
SymbolFile * m_symbol_file
Definition: Type.h:544
ConstString GetName() const
Definition: Type.h:464
Type(Type &t)=default
bool IsAggregateType()
Definition: Type.cpp:488
EncodingDataType m_encoding_uid_type
Definition: Type.h:549
uint64_t m_byte_size
Definition: Type.h:550
uint32_t Payload
Definition: Type.h:536
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope)
Definition: Type.cpp:438
bool ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t address, AddressType address_type, DataExtractor &data)
Definition: Type.cpp:513
ConstString GetBaseName()
Definition: Type.cpp:426
ConstString GetQualifiedName()
Definition: Type.cpp:759
CompilerType GetFullCompilerType()
Definition: Type.cpp:744
lldb::ModuleSP GetModule()
Since Type instances only keep a "SymbolFile *" internally, other classes like TypeImpl need make sur...
Definition: Type.cpp:815
bool WriteToMemory(ExecutionContext *exe_ctx, lldb::addr_t address, AddressType address_type, DataExtractor &data)
Definition: Type.cpp:551
bool IsTypedef()
Definition: Type.h:460
#define LLDB_INVALID_UID
Definition: lldb-defines.h:88
#define LLDB_MARK_AS_BITMASK_ENUM(Enum)
#define FLAGS_ENUM(Name)
A class that represents a running process on the host machine.
Stream & operator<<(Stream &s, const Mangled &obj)
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelFull
std::weak_ptr< lldb_private::Module > ModuleWP
Definition: lldb-forward.h:371
Format
Display format definitions.
std::shared_ptr< lldb_private::TypeEnumMemberImpl > TypeEnumMemberImplSP
Definition: lldb-forward.h:462
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Type > TypeSP
Definition: lldb-forward.h:456
Encoding
Register encoding definitions.
MemberFunctionKind
Kind of member function.
@ eMemberFunctionKindUnknown
Not sure what the type of this is.
uint64_t user_id_t
Definition: lldb-types.h:82
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::TypeImpl > TypeImplSP
Definition: lldb-forward.h:459
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:370
CompilerContext allows an array of these items to be passed to perform detailed lookups in SymbolVend...
Definition: Type.h:52
void Dump(Stream &s) const
Definition: Type.cpp:185
CompilerContextKind kind
Definition: Type.h:62
bool operator==(const CompilerContext &rhs) const
Definition: Type.h:55
bool operator!=(const CompilerContext &rhs) const
Definition: Type.h:58
CompilerContext(CompilerContextKind t, ConstString n)
Definition: Type.h:53
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: Type.h:38
llvm::SmallBitVector bitvector
Definition: Type.h:39
std::optional< lldb::LanguageType > GetSingularLanguage()
If the set contains a single language only, return it.
Definition: TypeSystem.cpp:28
bool operator[](unsigned i) const
Definition: TypeSystem.cpp:37
void Insert(lldb::LanguageType language)
Definition: TypeSystem.cpp:34
friend bool operator==(const ParsedName &lhs, const ParsedName &rhs)
Definition: Type.h:513
llvm::SmallVector< llvm::StringRef > scope
Definition: Type.h:509
lldb::TypeClass type_class
Definition: Type.h:505
llvm::StringRef basename
Definition: Type.h:511
friend llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const ParsedName &name)
Definition: Type.h:518
A mix in class that contains a generic user ID.
Definition: UserID.h:31