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