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
18#include "lldb/Utility/Status.h"
20
21namespace lldb_private {
22
24public:
25 Materializer() = default;
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
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
60 IRMemoryMap *m_map = nullptr;
62 };
63
64 typedef std::shared_ptr<Dematerializer> DematerializerSP;
65 typedef std::weak_ptr<Dematerializer> DematerializerWP;
66
68 lldb::addr_t process_address, Status &err);
69
71 public:
74 virtual ConstString GetName() = 0;
75 virtual void DidDematerialize(lldb::ExpressionVariableSP &variable) = 0;
76 };
77
78 uint32_t
80 PersistentVariableDelegate *delegate, Status &err);
81 uint32_t AddVariable(lldb::VariableSP &variable_sp, Status &err);
82
83 /// Create entity from supplied ValueObject and count it as a member
84 /// of the materialized struct.
85 ///
86 /// Behaviour is undefined if 'valobj_provider' is empty.
87 ///
88 /// \param[in] name Name of variable to materialize
89 ///
90 /// \param[in] valobj_provider When materializing values multiple
91 /// times, this callback gets used to fetch a fresh
92 /// ValueObject corresponding to the supplied frame.
93 /// This is mainly used for conditional breakpoints
94 /// that re-apply an expression whatever the frame
95 /// happens to be when the breakpoint got hit.
96 ///
97 /// \param[out] err Error status that gets set on error.
98 ///
99 /// \returns Offset in bytes of the member we just added to the
100 /// materialized struct.
101 uint32_t AddValueObject(ConstString name,
102 ValueObjectProviderTy valobj_provider, Status &err);
103
104 uint32_t AddResultVariable(const CompilerType &type, bool is_lvalue,
105 bool keep_in_memory,
106 PersistentVariableDelegate *delegate, Status &err);
107 uint32_t AddSymbol(const Symbol &symbol_sp, Status &err);
108 uint32_t AddRegister(const RegisterInfo &register_info, Status &err);
109
111
112 uint32_t GetStructByteSize() { return m_current_offset; }
113
114 class Entity {
115 public:
116 Entity() = default;
117
118 virtual ~Entity() = default;
119
120 virtual void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
121 lldb::addr_t process_address, Status &err) = 0;
122 virtual void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
123 lldb::addr_t process_address,
124 lldb::addr_t frame_top,
125 lldb::addr_t frame_bottom, Status &err) = 0;
126 virtual void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
127 Log *log) = 0;
128 virtual void Wipe(IRMemoryMap &map, lldb::addr_t process_address) = 0;
129
130 uint32_t GetAlignment() { return m_alignment; }
131
132 uint32_t GetSize() { return m_size; }
133
134 uint32_t GetOffset() { return m_offset; }
135
136 void SetOffset(uint32_t offset) { m_offset = offset; }
137
138 protected:
139 uint32_t m_alignment = 1;
140 uint32_t m_size = 0;
141 uint32_t m_offset = 0;
142 };
143
144private:
145 uint32_t AddStructMember(Entity &entity);
146
147 typedef std::unique_ptr<Entity> EntityUP;
148 typedef std::vector<EntityUP> EntityVector;
149
152 uint32_t m_current_offset = 0;
153 uint32_t m_struct_alignment = 8;
154};
155
156} // namespace lldb_private
157
158#endif // LLDB_EXPRESSION_MATERIALIZER_H
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
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:34
Dematerializer(Materializer &materializer, lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address)
Definition: Materializer.h:47
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)
Definition: Materializer.h:136
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
Definition: Materializer.h:65
std::unique_ptr< Entity > EntityUP
Definition: Materializer.h:147
std::vector< EntityUP > EntityVector
Definition: Materializer.h:148
std::shared_ptr< Dematerializer > DematerializerSP
Definition: Materializer.h:64
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
Definition: Materializer.h:150
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:44
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
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
Definition: lldb-forward.h:420
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
Definition: lldb-forward.h:349
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:482
uint64_t addr_t
Definition: lldb-types.h:80
std::weak_ptr< lldb_private::Thread > ThreadWP
Definition: lldb-forward.h:447
Every register is described in detail including its name, alternate name (optional),...