1 //===-- Materializer.h ------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_Materializer_h
10 #define liblldb_Materializer_h
15 #include "lldb/Expression/IRMemoryMap.h"
16 #include "lldb/Symbol/TaggedASTType.h"
17 #include "lldb/Target/StackFrame.h"
18 #include "lldb/Utility/Status.h"
19 #include "lldb/lldb-private-types.h"
21 namespace lldb_private {
28 class Dematerializer {
31 : m_materializer(nullptr), m_map(nullptr),
32 m_process_address(LLDB_INVALID_ADDRESS) {}
34 ~Dematerializer() { Wipe(); }
36 void Dematerialize(Status &err, lldb::addr_t frame_top,
37 lldb::addr_t frame_bottom);
42 return m_materializer && m_map &&
43 (m_process_address != LLDB_INVALID_ADDRESS);
47 friend class Materializer;
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) {
54 m_thread_wp = frame_sp->GetThread();
55 m_stack_id = frame_sp->GetStackID();
59 Materializer *m_materializer;
60 lldb::ThreadWP m_thread_wp;
63 lldb::addr_t m_process_address;
66 typedef std::shared_ptr<Dematerializer> DematerializerSP;
67 typedef std::weak_ptr<Dematerializer> DematerializerWP;
69 DematerializerSP Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
70 lldb::addr_t process_address, Status &err);
72 class PersistentVariableDelegate {
74 virtual ~PersistentVariableDelegate();
75 virtual ConstString GetName() = 0;
76 virtual void DidDematerialize(lldb::ExpressionVariableSP &variable) = 0;
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,
85 PersistentVariableDelegate *delegate, Status &err);
86 uint32_t AddSymbol(const Symbol &symbol_sp, Status &err);
87 uint32_t AddRegister(const RegisterInfo ®ister_info, Status &err);
89 uint32_t GetStructAlignment() { return m_struct_alignment; }
91 uint32_t GetStructByteSize() { return m_current_offset; }
95 Entity() : m_alignment(1), m_size(0), m_offset(0) {}
97 virtual ~Entity() = default;
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,
107 virtual void Wipe(IRMemoryMap &map, lldb::addr_t process_address) = 0;
109 uint32_t GetAlignment() { return m_alignment; }
111 uint32_t GetSize() { return m_size; }
113 uint32_t GetOffset() { return m_offset; }
115 void SetOffset(uint32_t offset) { m_offset = offset; }
118 uint32_t m_alignment;
124 uint32_t AddStructMember(Entity &entity);
126 typedef std::unique_ptr<Entity> EntityUP;
127 typedef std::vector<EntityUP> EntityVector;
129 DematerializerWP m_dematerializer_wp;
130 EntityVector m_entities;
131 uint32_t m_current_offset;
132 uint32_t m_struct_alignment;
135 } // namespace lldb_private
137 #endif // liblldb_Materializer_h