LLDB  mainline
Materializer.h
Go to the documentation of this file.
1 //===-- Materializer.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_EXPRESSION_MATERIALIZER_H
10 #define LLDB_EXPRESSION_MATERIALIZER_H
11 
12 #include <memory>
13 #include <vector>
14 
17 #include "lldb/Target/StackFrame.h"
18 #include "lldb/Utility/Status.h"
20 
21 namespace lldb_private {
22 
23 class Materializer {
24 public:
25  Materializer() = default;
26  ~Materializer();
27 
29  public:
30  Dematerializer() = default;
31 
33 
34  void Dematerialize(Status &err, lldb::addr_t frame_top,
35  lldb::addr_t frame_bottom);
36 
37  void Wipe();
38 
39  bool IsValid() {
40  return m_materializer && m_map &&
42  }
43 
44  private:
45  friend class Materializer;
46 
47  Dematerializer(Materializer &materializer, lldb::StackFrameSP &frame_sp,
48  IRMemoryMap &map, lldb::addr_t process_address)
49  : m_materializer(&materializer), m_map(&map),
50  m_process_address(process_address) {
51  if (frame_sp) {
52  m_thread_wp = frame_sp->GetThread();
53  m_stack_id = frame_sp->GetStackID();
54  }
55  }
56 
58  lldb::ThreadWP m_thread_wp;
60  IRMemoryMap *m_map = nullptr;
62  };
63 
64  typedef std::shared_ptr<Dematerializer> DematerializerSP;
65  typedef std::weak_ptr<Dematerializer> DematerializerWP;
66 
67  DematerializerSP Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
68  lldb::addr_t process_address, Status &err);
69 
71  public:
73  virtual ConstString GetName() = 0;
74  virtual void DidDematerialize(lldb::ExpressionVariableSP &variable) = 0;
75  };
76 
77  uint32_t
78  AddPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp,
79  PersistentVariableDelegate *delegate, Status &err);
80  uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err);
81  uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue,
82  bool keep_in_memory,
83  PersistentVariableDelegate *delegate, Status &err);
84  uint32_t AddSymbol(const Symbol &symbol_sp, Status &err);
85  uint32_t AddRegister(const RegisterInfo &register_info, Status &err);
86 
88 
90 
91  class Entity {
92  public:
93  Entity() = default;
94 
95  virtual ~Entity() = default;
96 
97  virtual void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
98  lldb::addr_t process_address, Status &err) = 0;
99  virtual void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
100  lldb::addr_t process_address,
101  lldb::addr_t frame_top,
102  lldb::addr_t frame_bottom, Status &err) = 0;
103  virtual void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
104  Log *log) = 0;
105  virtual void Wipe(IRMemoryMap &map, lldb::addr_t process_address) = 0;
106 
108 
109  uint32_t GetSize() { return m_size; }
110 
112 
113  void SetOffset(uint32_t offset) { m_offset = offset; }
114 
115  protected:
119  };
120 
121 private:
123 
124  typedef std::unique_ptr<Entity> EntityUP;
125  typedef std::vector<EntityUP> EntityVector;
126 
131 };
132 
133 } // namespace lldb_private
134 
135 #endif // LLDB_EXPRESSION_MATERIALIZER_H
lldb_private::Materializer::Entity::GetAlignment
uint32_t GetAlignment()
Definition: Materializer.h:107
lldb_private::Materializer::Materialize
DematerializerSP Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err)
Definition: Materializer.cpp:1352
lldb-private-types.h
lldb_private::Materializer::Materializer
Materializer()=default
lldb_private::Materializer::m_current_offset
uint32_t m_current_offset
Definition: Materializer.h:129
IRMemoryMap.h
lldb_private::Materializer::Entity::Entity
Entity()=default
lldb_private::Materializer::GetStructAlignment
uint32_t GetStructAlignment()
Definition: Materializer.h:87
lldb_private::Materializer::PersistentVariableDelegate::~PersistentVariableDelegate
virtual ~PersistentVariableDelegate()
lldb_private::Materializer::Entity::Materialize
virtual void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err)=0
lldb_private::Symbol
Definition: Symbol.h:20
lldb_private::Materializer::Entity::~Entity
virtual ~Entity()=default
lldb_private::Materializer::Entity::Dematerialize
virtual void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err)=0
lldb_private::Materializer::Dematerializer::m_stack_id
StackID m_stack_id
Definition: Materializer.h:59
lldb_private::Materializer::AddPersistentVariable
uint32_t AddPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp, PersistentVariableDelegate *delegate, Status &err)
Definition: Materializer.cpp:401
lldb_private::Materializer::Entity::m_offset
uint32_t m_offset
Definition: Materializer.h:118
lldb_private::Materializer::Dematerializer::m_materializer
Materializer * m_materializer
Definition: Materializer.h:57
lldb_private::Materializer::PersistentVariableDelegate::GetName
virtual ConstString GetName()=0
lldb_private::Materializer::m_dematerializer_wp
DematerializerWP m_dematerializer_wp
Definition: Materializer.h:127
lldb_private::Materializer::Dematerializer::Dematerialize
void Dematerialize(Status &err, lldb::addr_t frame_top, lldb::addr_t frame_bottom)
Definition: Materializer.cpp:1396
StackFrame.h
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::Materializer::GetStructByteSize
uint32_t GetStructByteSize()
Definition: Materializer.h:89
lldb_private::Materializer::Entity::SetOffset
void SetOffset(uint32_t offset)
Definition: Materializer.h:113
lldb_private::Materializer::EntityVector
std::vector< EntityUP > EntityVector
Definition: Materializer.h:125
lldb_private::Materializer::AddResultVariable
uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue, bool keep_in_memory, PersistentVariableDelegate *delegate, Status &err)
Definition: Materializer.cpp:1037
lldb_private::Materializer::Dematerializer::Dematerializer
Dematerializer()=default
lldb_private::Materializer::Entity
Definition: Materializer.h:91
lldb_private::Materializer::Entity::Wipe
virtual void Wipe(IRMemoryMap &map, lldb::addr_t process_address)=0
lldb_private::Materializer::~Materializer
~Materializer()
Definition: Materializer.cpp:1344
lldb_private::Materializer::Dematerializer::m_thread_wp
lldb::ThreadWP m_thread_wp
Definition: Materializer.h:58
lldb_private::Materializer::DematerializerSP
std::shared_ptr< Dematerializer > DematerializerSP
Definition: Materializer.h:64
lldb_private::Materializer::AddRegister
uint32_t AddRegister(const RegisterInfo &register_info, Status &err)
Definition: Materializer.cpp:1335
lldb_private::Materializer::EntityUP
std::unique_ptr< Entity > EntityUP
Definition: Materializer.h:124
lldb_private::Materializer::Dematerializer::Wipe
void Wipe()
Definition: Materializer.cpp:1440
lldb_private::Materializer::AddSymbol
uint32_t AddSymbol(const Symbol &symbol_sp, Status &err)
Definition: Materializer.cpp:1160
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::Materializer::Entity::GetSize
uint32_t GetSize()
Definition: Materializer.h:109
lldb_private::Materializer::Dematerializer::~Dematerializer
~Dematerializer()
Definition: Materializer.h:32
lldb_private::Materializer::PersistentVariableDelegate
Definition: Materializer.h:70
lldb_private::Materializer::Dematerializer::Dematerializer
Dematerializer(Materializer &materializer, lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address)
Definition: Materializer.h:47
lldb_private::Materializer
Definition: Materializer.h:23
lldb_private::Materializer::Entity::GetOffset
uint32_t GetOffset()
Definition: Materializer.h:111
lldb_private::Materializer::Dematerializer::m_process_address
lldb::addr_t m_process_address
Definition: Materializer.h:61
lldb_private::Materializer::Entity::DumpToLog
virtual void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address, Log *log)=0
lldb_private::Materializer::DematerializerWP
std::weak_ptr< Dematerializer > DematerializerWP
Definition: Materializer.h:65
lldb_private::Materializer::AddStructMember
uint32_t AddStructMember(Entity &entity)
Definition: Materializer.cpp:29
lldb_private::Status
Definition: Status.h:44
uint32_t
lldb_private::Materializer::PersistentVariableDelegate::DidDematerialize
virtual void DidDematerialize(lldb::ExpressionVariableSP &variable)=0
lldb_private::Materializer::Entity::m_size
uint32_t m_size
Definition: Materializer.h:117
lldb_private::Materializer::Entity::m_alignment
uint32_t m_alignment
Definition: Materializer.h:116
TaggedASTType.h
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Materializer::Dematerializer::m_map
IRMemoryMap * m_map
Definition: Materializer.h:60
lldb_private::StackID
Definition: StackID.h:17
lldb_private::Log
Definition: Log.h:49
lldb_private::Materializer::m_entities
EntityVector m_entities
Definition: Materializer.h:128
lldb_private::Materializer::Dematerializer::IsValid
bool IsValid()
Definition: Materializer.h:39
lldb_private::IRMemoryMap
Definition: IRMemoryMap.h:34
lldb_private::Materializer::Dematerializer
Definition: Materializer.h:28
lldb_private::Materializer::m_struct_alignment
uint32_t m_struct_alignment
Definition: Materializer.h:130
lldb_private::Materializer::AddVariable
uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err)
Definition: Materializer.cpp:757