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 liblldb_Materializer_h
10 #define liblldb_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();
26  ~Materializer();
27 
29  public:
31  : m_materializer(nullptr), m_map(nullptr),
32  m_process_address(LLDB_INVALID_ADDRESS) {}
33 
35 
36  void Dematerialize(Status &err, lldb::addr_t frame_top,
37  lldb::addr_t frame_bottom);
38 
39  void Wipe();
40 
41  bool IsValid() {
42  return m_materializer && m_map &&
43  (m_process_address != LLDB_INVALID_ADDRESS);
44  }
45 
46  private:
47  friend class Materializer;
48 
49  Dematerializer(Materializer &materializer, lldb::StackFrameSP &frame_sp,
50  IRMemoryMap &map, lldb::addr_t process_address)
51  : m_materializer(&materializer), m_map(&map),
52  m_process_address(process_address) {
53  if (frame_sp) {
54  m_thread_wp = frame_sp->GetThread();
55  m_stack_id = frame_sp->GetStackID();
56  }
57  }
58 
59  Materializer *m_materializer;
60  lldb::ThreadWP m_thread_wp;
61  StackID m_stack_id;
62  IRMemoryMap *m_map;
63  lldb::addr_t m_process_address;
64  };
65 
66  typedef std::shared_ptr<Dematerializer> DematerializerSP;
67  typedef std::weak_ptr<Dematerializer> DematerializerWP;
68 
69  DematerializerSP Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
70  lldb::addr_t process_address, Status &err);
71 
73  public:
74  virtual ~PersistentVariableDelegate();
75  virtual ConstString GetName() = 0;
76  virtual void DidDematerialize(lldb::ExpressionVariableSP &variable) = 0;
77  };
78 
79  uint32_t
80  AddPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp,
81  PersistentVariableDelegate *delegate, Status &err);
82  uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err);
83  uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue,
84  bool keep_in_memory,
85  PersistentVariableDelegate *delegate, Status &err);
86  uint32_t AddSymbol(const Symbol &symbol_sp, Status &err);
87  uint32_t AddRegister(const RegisterInfo &register_info, Status &err);
88 
89  uint32_t GetStructAlignment() { return m_struct_alignment; }
90 
91  uint32_t GetStructByteSize() { return m_current_offset; }
92 
93  class Entity {
94  public:
95  Entity() : m_alignment(1), m_size(0), m_offset(0) {}
96 
97  virtual ~Entity() = default;
98 
99  virtual void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
100  lldb::addr_t process_address, Status &err) = 0;
101  virtual void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
102  lldb::addr_t process_address,
103  lldb::addr_t frame_top,
104  lldb::addr_t frame_bottom, Status &err) = 0;
105  virtual void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
106  Log *log) = 0;
107  virtual void Wipe(IRMemoryMap &map, lldb::addr_t process_address) = 0;
108 
109  uint32_t GetAlignment() { return m_alignment; }
110 
111  uint32_t GetSize() { return m_size; }
112 
113  uint32_t GetOffset() { return m_offset; }
114 
115  void SetOffset(uint32_t offset) { m_offset = offset; }
116 
117  protected:
118  void SetSizeAndAlignmentFromType(CompilerType &type);
119 
123  };
124 
125 private:
126  uint32_t AddStructMember(Entity &entity);
127 
128  typedef std::unique_ptr<Entity> EntityUP;
129  typedef std::vector<EntityUP> EntityVector;
130 
131  DematerializerWP m_dematerializer_wp;
132  EntityVector m_entities;
133  uint32_t m_current_offset;
134  uint32_t m_struct_alignment;
135 };
136 
137 } // namespace lldb_private
138 
139 #endif // liblldb_Materializer_h
uint32_t AddRegister(const RegisterInfo &register_info, Status &err)
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
void Dematerialize(Status &err, lldb::addr_t frame_top, lldb::addr_t frame_bottom)
uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue, bool keep_in_memory, PersistentVariableDelegate *delegate, Status &err)
uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err)
void SetOffset(uint32_t offset)
Definition: Materializer.h:115
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
Encapsulates memory that may exist in the process but must also be available in the host process...
Definition: IRMemoryMap.h:34
std::weak_ptr< Dematerializer > DematerializerWP
Definition: Materializer.h:67
uint32_t AddSymbol(const Symbol &symbol_sp, Status &err)
uint32_t AddPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp, PersistentVariableDelegate *delegate, Status &err)
uint64_t addr_t
Definition: lldb-types.h:83
A uniqued constant string class.
Definition: ConstString.h:38
DematerializerSP Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err)
std::shared_ptr< Dematerializer > DematerializerSP
Definition: Materializer.h:66
An error handling class.
Definition: Status.h:44