Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:47

0001 //===-- ValueObjectPrinter.h ------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_DATAFORMATTERS_VALUEOBJECTPRINTER_H
0010 #define LLDB_DATAFORMATTERS_VALUEOBJECTPRINTER_H
0011 
0012 #include "lldb/lldb-private.h"
0013 #include "lldb/lldb-public.h"
0014 
0015 #include "lldb/Utility/Flags.h"
0016 
0017 #include "lldb/DataFormatters/DumpValueObjectOptions.h"
0018 #include "lldb/Symbol/CompilerType.h"
0019 
0020 namespace lldb_private {
0021 
0022 class ValueObjectPrinter {
0023   /// The ValueObjectPrinter is a one-shot printer for ValueObjects.  It
0024   /// does not retain the ValueObject it is printing, that is the job of
0025   /// its caller.  It also doesn't attempt to track changes in the
0026   /// ValueObject, e.g. changing synthetic child providers or changing
0027   /// dynamic versus static versus synthetic settings.
0028 public:
0029   ValueObjectPrinter(ValueObject &valobj, Stream *s);
0030 
0031   ValueObjectPrinter(ValueObject &valobj, Stream *s,
0032                      const DumpValueObjectOptions &options);
0033 
0034   ~ValueObjectPrinter() = default;
0035 
0036   llvm::Error PrintValueObject();
0037 
0038 protected:
0039   typedef std::set<uint64_t> InstancePointersSet;
0040   typedef std::shared_ptr<InstancePointersSet> InstancePointersSetSP;
0041 
0042   InstancePointersSetSP m_printed_instance_pointers;
0043 
0044   /// Only this class (and subclasses, if any) should ever be
0045   /// concerned with the depth mechanism.
0046   ValueObjectPrinter(ValueObject &valobj, Stream *s,
0047                      const DumpValueObjectOptions &options,
0048                      const DumpValueObjectOptions::PointerDepth &ptr_depth,
0049                      uint32_t curr_depth,
0050                      InstancePointersSetSP printed_instance_pointers);
0051 
0052   /// Ee should actually be using delegating constructors here but
0053   /// some versions of GCC still have trouble with those.
0054   void Init(ValueObject &valobj, Stream *s,
0055             const DumpValueObjectOptions &options,
0056             const DumpValueObjectOptions::PointerDepth &ptr_depth,
0057             uint32_t curr_depth,
0058             InstancePointersSetSP printed_instance_pointers);
0059 
0060   /// Cache the ValueObject we are actually going to print.  If this
0061   /// ValueObject has a Dynamic type, we return that, if either the original
0062   /// ValueObject or its Dynamic type has a Synthetic provider, return that.
0063   /// This will never return an empty ValueObject, since we use the ValueObject
0064   /// to carry errors.
0065   /// Note, this gets called when making the printer object, and uses the
0066   /// use dynamic and use synthetic settings of the ValueObject being printed,
0067   /// so changes made to these settings won't affect already made
0068   /// ValueObjectPrinters. SetupMostSpecializedValue();
0069   ///
0070   /// Access the cached "most specialized value" - that is the one to use for
0071   /// printing the value object's value.  However, be sure to use
0072   /// GetValueForChildGeneration when you are generating the children of this
0073   /// value.
0074   ValueObject &GetMostSpecializedValue();
0075 
0076   void SetupMostSpecializedValue();
0077 
0078   llvm::Expected<std::string> GetDescriptionForDisplay();
0079 
0080   const char *GetRootNameForDisplay();
0081 
0082   bool ShouldPrintValueObject();
0083 
0084   bool IsNil();
0085 
0086   bool IsUninitialized();
0087 
0088   bool IsPtr();
0089 
0090   bool IsRef();
0091 
0092   bool IsInstancePointer();
0093 
0094   bool IsAggregate();
0095 
0096   bool PrintLocationIfNeeded();
0097 
0098   void PrintDecl();
0099 
0100   bool CheckScopeIfNeeded();
0101 
0102   bool ShouldPrintEmptyBrackets(bool value_printed, bool summary_printed);
0103 
0104   TypeSummaryImpl *GetSummaryFormatter(bool null_if_omitted = true);
0105 
0106   void GetValueSummaryError(std::string &value, std::string &summary,
0107                             std::string &error);
0108 
0109   bool PrintValueAndSummaryIfNeeded(bool &value_printed, bool &summary_printed);
0110 
0111   llvm::Error PrintObjectDescriptionIfNeeded(bool value_printed,
0112                                              bool summary_printed);
0113 
0114   bool
0115   ShouldPrintChildren(DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
0116 
0117   bool ShouldExpandEmptyAggregates();
0118 
0119   ValueObject &GetValueObjectForChildrenGeneration();
0120 
0121   void PrintChildrenPreamble(bool value_printed, bool summary_printed);
0122 
0123   void PrintChildrenPostamble(bool print_dotdotdot);
0124 
0125   lldb::ValueObjectSP GenerateChild(ValueObject &synth_valobj, size_t idx);
0126 
0127   void PrintChild(lldb::ValueObjectSP child_sp,
0128                   const DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
0129 
0130   llvm::Expected<uint32_t> GetMaxNumChildrenToPrint(bool &print_dotdotdot);
0131 
0132   void
0133   PrintChildren(bool value_printed, bool summary_printed,
0134                 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
0135 
0136   llvm::Error PrintChildrenIfNeeded(bool value_printed, bool summary_printed);
0137 
0138   bool PrintChildrenOneLiner(bool hide_names);
0139 
0140   bool HasReachedMaximumDepth();
0141 
0142 private:
0143   bool ShouldShowName() const;
0144 
0145   ValueObject &m_orig_valobj;
0146   /// Cache the current "most specialized" value.  Don't use this
0147   /// directly, use GetMostSpecializedValue.
0148   ValueObject *m_cached_valobj;
0149   Stream *m_stream;
0150   DumpValueObjectOptions m_options;
0151   Flags m_type_flags;
0152   CompilerType m_compiler_type;
0153   DumpValueObjectOptions::PointerDepth m_ptr_depth;
0154   uint32_t m_curr_depth;
0155   LazyBool m_should_print;
0156   LazyBool m_is_nil;
0157   LazyBool m_is_uninit;
0158   LazyBool m_is_ptr;
0159   LazyBool m_is_ref;
0160   LazyBool m_is_aggregate;
0161   LazyBool m_is_instance_ptr;
0162   std::pair<TypeSummaryImpl *, bool> m_summary_formatter;
0163   std::string m_value;
0164   std::string m_summary;
0165   std::string m_error;
0166   bool m_val_summary_ok;
0167 
0168   friend struct StringSummaryFormat;
0169 
0170   ValueObjectPrinter(const ValueObjectPrinter &) = delete;
0171   const ValueObjectPrinter &operator=(const ValueObjectPrinter &) = delete;
0172 };
0173 
0174 } // namespace lldb_private
0175 
0176 #endif // LLDB_DATAFORMATTERS_VALUEOBJECTPRINTER_H