Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- Materializer.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_EXPRESSION_MATERIALIZER_H
0010 #define LLDB_EXPRESSION_MATERIALIZER_H
0011 
0012 #include <memory>
0013 #include <vector>
0014 
0015 #include "lldb/Expression/IRMemoryMap.h"
0016 #include "lldb/Symbol/TaggedASTType.h"
0017 #include "lldb/Target/StackFrame.h"
0018 #include "lldb/Utility/Status.h"
0019 #include "lldb/lldb-private-types.h"
0020 
0021 namespace lldb_private {
0022 
0023 class Materializer {
0024 public:
0025   Materializer() = default;
0026   ~Materializer();
0027 
0028   class Dematerializer {
0029   public:
0030     Dematerializer() = default;
0031 
0032     ~Dematerializer() { Wipe(); }
0033 
0034     void Dematerialize(Status &err, lldb::addr_t frame_top,
0035                        lldb::addr_t frame_bottom);
0036 
0037     void Wipe();
0038 
0039     bool IsValid() {
0040       return m_materializer && m_map &&
0041              (m_process_address != LLDB_INVALID_ADDRESS);
0042     }
0043 
0044   private:
0045     friend class Materializer;
0046 
0047     Dematerializer(Materializer &materializer, lldb::StackFrameSP &frame_sp,
0048                    IRMemoryMap &map, lldb::addr_t process_address)
0049         : m_materializer(&materializer), m_map(&map),
0050           m_process_address(process_address) {
0051       if (frame_sp) {
0052         m_thread_wp = frame_sp->GetThread();
0053         m_stack_id = frame_sp->GetStackID();
0054       }
0055     }
0056 
0057     Materializer *m_materializer = nullptr;
0058     lldb::ThreadWP m_thread_wp;
0059     StackID m_stack_id;
0060     IRMemoryMap *m_map = nullptr;
0061     lldb::addr_t m_process_address = LLDB_INVALID_ADDRESS;
0062   };
0063 
0064   typedef std::shared_ptr<Dematerializer> DematerializerSP;
0065   typedef std::weak_ptr<Dematerializer> DematerializerWP;
0066 
0067   DematerializerSP Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
0068                                lldb::addr_t process_address, Status &err);
0069 
0070   class PersistentVariableDelegate {
0071   public:
0072     PersistentVariableDelegate();
0073     virtual ~PersistentVariableDelegate();
0074     virtual ConstString GetName() = 0;
0075     virtual void DidDematerialize(lldb::ExpressionVariableSP &variable) = 0;
0076   };
0077 
0078   uint32_t
0079   AddPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp,
0080                         PersistentVariableDelegate *delegate, Status &err);
0081   uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err);
0082 
0083   /// Create entity from supplied ValueObject and count it as a member
0084   /// of the materialized struct.
0085   ///
0086   /// Behaviour is undefined if 'valobj_provider' is empty.
0087   ///
0088   /// \param[in] name Name of variable to materialize
0089   ///
0090   /// \param[in] valobj_provider When materializing values multiple
0091   ///            times, this callback gets used to fetch a fresh
0092   ///            ValueObject corresponding to the supplied frame.
0093   ///            This is mainly used for conditional breakpoints
0094   ///            that re-apply an expression whatever the frame
0095   ///            happens to be when the breakpoint got hit.
0096   ///
0097   /// \param[out] err Error status that gets set on error.
0098   ///
0099   /// \returns Offset in bytes of the member we just added to the
0100   ///          materialized struct.
0101   uint32_t AddValueObject(ConstString name,
0102                           ValueObjectProviderTy valobj_provider, Status &err);
0103 
0104   uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue,
0105                              bool keep_in_memory,
0106                              PersistentVariableDelegate *delegate, Status &err);
0107   uint32_t AddSymbol(const Symbol &symbol_sp, Status &err);
0108   uint32_t AddRegister(const RegisterInfo &register_info, Status &err);
0109 
0110   uint32_t GetStructAlignment() { return m_struct_alignment; }
0111 
0112   uint32_t GetStructByteSize() { return m_current_offset; }
0113 
0114   class Entity {
0115   public:
0116     Entity() = default;
0117 
0118     virtual ~Entity() = default;
0119 
0120     virtual void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
0121                              lldb::addr_t process_address, Status &err) = 0;
0122     virtual void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
0123                                lldb::addr_t process_address,
0124                                lldb::addr_t frame_top,
0125                                lldb::addr_t frame_bottom, Status &err) = 0;
0126     virtual void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
0127                            Log *log) = 0;
0128     virtual void Wipe(IRMemoryMap &map, lldb::addr_t process_address) = 0;
0129 
0130     uint32_t GetAlignment() { return m_alignment; }
0131 
0132     uint32_t GetSize() { return m_size; }
0133 
0134     uint32_t GetOffset() { return m_offset; }
0135 
0136     void SetOffset(uint32_t offset) { m_offset = offset; }
0137 
0138   protected:
0139     uint32_t m_alignment = 1;
0140     uint32_t m_size = 0;
0141     uint32_t m_offset = 0;
0142   };
0143 
0144 private:
0145   uint32_t AddStructMember(Entity &entity);
0146 
0147   typedef std::unique_ptr<Entity> EntityUP;
0148   typedef std::vector<EntityUP> EntityVector;
0149 
0150   DematerializerWP m_dematerializer_wp;
0151   EntityVector m_entities;
0152   uint32_t m_current_offset = 0;
0153   uint32_t m_struct_alignment = 8;
0154 };
0155 
0156 } // namespace lldb_private
0157 
0158 #endif // LLDB_EXPRESSION_MATERIALIZER_H