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
19#include "lldb/Utility/Status.h"
21
22namespace lldb_private {
23
25public:
26 Materializer() = default;
28
30 public:
31 Dematerializer() = default;
32
34
35 void Dematerialize(Status &err, lldb::addr_t frame_top,
36 lldb::addr_t frame_bottom);
37
38 void Wipe();
39
40 bool IsValid() {
41 return m_materializer && m_map &&
43 }
44
45 private:
46 friend class Materializer;
47
49 IRMemoryMap &map, lldb::addr_t process_address)
50 : m_materializer(&materializer), m_map(&map),
51 m_process_address(process_address) {
52 if (frame_sp) {
53 m_thread_wp = frame_sp->GetThread();
54 m_stack_id = frame_sp->GetStackID();
55 }
56 }
57
61 IRMemoryMap *m_map = nullptr;
63 };
64
65 typedef std::shared_ptr<Dematerializer> DematerializerSP;
66 typedef std::weak_ptr<Dematerializer> DematerializerWP;
67
69 lldb::addr_t process_address, Status &err);
70
78
79 uint32_t
81 PersistentVariableDelegate *delegate, Status &err);
82 uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err);
83
84 /// Create entity from supplied ValueObject and count it as a member
85 /// of the materialized struct.
86 ///
87 /// Behaviour is undefined if 'valobj_provider' is empty.
88 ///
89 /// \param[in] name Name of variable to materialize
90 ///
91 /// \param[in] valobj_provider When materializing values multiple
92 /// times, this callback gets used to fetch a fresh
93 /// ValueObject corresponding to the supplied frame.
94 /// This is mainly used for conditional breakpoints
95 /// that re-apply an expression whatever the frame
96 /// happens to be when the breakpoint got hit.
97 ///
98 /// \param[out] err Error status that gets set on error.
99 ///
100 /// \returns Offset in bytes of the member we just added to the
101 /// materialized struct.
102 uint32_t AddValueObject(ConstString name,
103 ValueObjectProviderTy valobj_provider, Status &err);
104
105 uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue,
106 bool keep_in_memory,
107 PersistentVariableDelegate *delegate, Status &err);
108 uint32_t AddSymbol(const Symbol &symbol_sp, Status &err);
109 uint32_t AddRegister(const RegisterInfo &register_info, Status &err);
110
112
113 uint32_t GetStructByteSize() { return m_current_offset; }
114
115 class Entity {
116 public:
117 Entity() = default;
118
119 virtual ~Entity() = default;
120
121 virtual void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
122 lldb::addr_t process_address, Status &err) = 0;
123 virtual void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
124 lldb::addr_t process_address,
125 lldb::addr_t frame_top,
126 lldb::addr_t frame_bottom, Status &err) = 0;
127 virtual void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
128 Log *log) = 0;
129 virtual void Wipe(IRMemoryMap &map, lldb::addr_t process_address) = 0;
130
131 uint32_t GetAlignment() { return m_alignment; }
132
133 uint32_t GetSize() { return m_size; }
134
135 uint32_t GetOffset() { return m_offset; }
136
137 void SetOffset(uint32_t offset) { m_offset = offset; }
138
139 protected:
140 uint32_t m_alignment = 1;
141 uint32_t m_size = 0;
142 uint32_t m_offset = 0;
143 };
144
145private:
146 uint32_t AddStructMember(Entity &entity);
147
148 typedef std::unique_ptr<Entity> EntityUP;
149 typedef std::vector<EntityUP> EntityVector;
150
153 uint32_t m_current_offset = 0;
154 uint32_t m_struct_alignment = 8;
155};
156
157} // namespace lldb_private
158
159#endif // LLDB_EXPRESSION_MATERIALIZER_H
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
Encapsulates memory that may exist in the process but must also be available in the host process.
Definition IRMemoryMap.h:35
Dematerializer(Materializer &materializer, lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address)
void Dematerialize(Status &err, lldb::addr_t frame_top, lldb::addr_t frame_bottom)
virtual void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err)=0
void SetOffset(uint32_t offset)
virtual void Wipe(IRMemoryMap &map, lldb::addr_t process_address)=0
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
virtual void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address, Log *log)=0
virtual void DidDematerialize(lldb::ExpressionVariableSP &variable)=0
uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue, bool keep_in_memory, PersistentVariableDelegate *delegate, Status &err)
uint32_t AddStructMember(Entity &entity)
std::weak_ptr< Dematerializer > DematerializerWP
std::unique_ptr< Entity > EntityUP
std::vector< EntityUP > EntityVector
std::shared_ptr< Dematerializer > DematerializerSP
DematerializerSP Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err)
uint32_t AddSymbol(const Symbol &symbol_sp, Status &err)
uint32_t AddRegister(const RegisterInfo &register_info, Status &err)
DematerializerWP m_dematerializer_wp
uint32_t AddValueObject(ConstString name, ValueObjectProviderTy valobj_provider, Status &err)
Create entity from supplied ValueObject and count it as a member of the materialized struct.
uint32_t AddPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp, PersistentVariableDelegate *delegate, Status &err)
uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err)
An error handling class.
Definition Status.h:118
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
std::function< lldb::ValueObjectSP(ConstString, StackFrame *)> ValueObjectProviderTy
Functor that returns a ValueObjectSP for a variable given its name and the StackFrame of interest.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
std::shared_ptr< lldb_private::Variable > VariableSP
uint64_t addr_t
Definition lldb-types.h:80
std::weak_ptr< lldb_private::Thread > ThreadWP
Every register is described in detail including its name, alternate name (optional),...