Path: blob/main/contrib/llvm-project/lldb/source/Expression/Materializer.cpp
39587 views
//===-- Materializer.cpp --------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Expression/Materializer.h"9#include "lldb/Core/DumpDataExtractor.h"10#include "lldb/Core/ValueObjectConstResult.h"11#include "lldb/Core/ValueObjectVariable.h"12#include "lldb/Expression/ExpressionVariable.h"13#include "lldb/Symbol/Symbol.h"14#include "lldb/Symbol/Type.h"15#include "lldb/Symbol/Variable.h"16#include "lldb/Target/ExecutionContext.h"17#include "lldb/Target/RegisterContext.h"18#include "lldb/Target/StackFrame.h"19#include "lldb/Target/Target.h"20#include "lldb/Target/Thread.h"21#include "lldb/Utility/LLDBLog.h"22#include "lldb/Utility/Log.h"23#include "lldb/Utility/RegisterValue.h"24#include "lldb/lldb-forward.h"2526#include <memory>27#include <optional>2829using namespace lldb_private;3031// FIXME: these should be retrieved from the target32// instead of being hard-coded. Currently we33// assume that persistent vars are materialized34// as references, and thus pick the size of a35// 64-bit pointer.36static constexpr uint32_t g_default_var_alignment = 8;37static constexpr uint32_t g_default_var_byte_size = 8;3839uint32_t Materializer::AddStructMember(Entity &entity) {40uint32_t size = entity.GetSize();41uint32_t alignment = entity.GetAlignment();4243uint32_t ret;4445if (m_current_offset == 0)46m_struct_alignment = alignment;4748if (m_current_offset % alignment)49m_current_offset += (alignment - (m_current_offset % alignment));5051ret = m_current_offset;5253m_current_offset += size;5455return ret;56}5758class EntityPersistentVariable : public Materializer::Entity {59public:60EntityPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp,61Materializer::PersistentVariableDelegate *delegate)62: Entity(), m_persistent_variable_sp(persistent_variable_sp),63m_delegate(delegate) {64// Hard-coding to maximum size of a pointer since persistent variables are65// materialized by reference66m_size = g_default_var_byte_size;67m_alignment = g_default_var_alignment;68}6970void MakeAllocation(IRMemoryMap &map, Status &err) {71Log *log = GetLog(LLDBLog::Expressions);7273// Allocate a spare memory area to store the persistent variable's74// contents.7576Status allocate_error;77const bool zero_memory = false;7879lldb::addr_t mem = map.Malloc(80m_persistent_variable_sp->GetByteSize().value_or(0), 8,81lldb::ePermissionsReadable | lldb::ePermissionsWritable,82IRMemoryMap::eAllocationPolicyMirror, zero_memory, allocate_error);8384if (!allocate_error.Success()) {85err.SetErrorStringWithFormat(86"couldn't allocate a memory area to store %s: %s",87m_persistent_variable_sp->GetName().GetCString(),88allocate_error.AsCString());89return;90}9192LLDB_LOGF(log, "Allocated %s (0x%" PRIx64 ") successfully",93m_persistent_variable_sp->GetName().GetCString(), mem);9495// Put the location of the spare memory into the live data of the96// ValueObject.9798m_persistent_variable_sp->m_live_sp = ValueObjectConstResult::Create(99map.GetBestExecutionContextScope(),100m_persistent_variable_sp->GetCompilerType(),101m_persistent_variable_sp->GetName(), mem, eAddressTypeLoad,102map.GetAddressByteSize());103104// Clear the flag if the variable will never be deallocated.105106if (m_persistent_variable_sp->m_flags &107ExpressionVariable::EVKeepInTarget) {108Status leak_error;109map.Leak(mem, leak_error);110m_persistent_variable_sp->m_flags &=111~ExpressionVariable::EVNeedsAllocation;112}113114// Write the contents of the variable to the area.115116Status write_error;117118map.WriteMemory(mem, m_persistent_variable_sp->GetValueBytes(),119m_persistent_variable_sp->GetByteSize().value_or(0),120write_error);121122if (!write_error.Success()) {123err.SetErrorStringWithFormat(124"couldn't write %s to the target: %s",125m_persistent_variable_sp->GetName().AsCString(),126write_error.AsCString());127return;128}129}130131void DestroyAllocation(IRMemoryMap &map, Status &err) {132Status deallocate_error;133134map.Free((lldb::addr_t)m_persistent_variable_sp->m_live_sp->GetValue()135.GetScalar()136.ULongLong(),137deallocate_error);138139m_persistent_variable_sp->m_live_sp.reset();140141if (!deallocate_error.Success()) {142err.SetErrorStringWithFormat(143"couldn't deallocate memory for %s: %s",144m_persistent_variable_sp->GetName().GetCString(),145deallocate_error.AsCString());146}147}148149void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,150lldb::addr_t process_address, Status &err) override {151Log *log = GetLog(LLDBLog::Expressions);152153const lldb::addr_t load_addr = process_address + m_offset;154155if (log) {156LLDB_LOGF(log,157"EntityPersistentVariable::Materialize [address = 0x%" PRIx64158", m_name = %s, m_flags = 0x%hx]",159(uint64_t)load_addr,160m_persistent_variable_sp->GetName().AsCString(),161m_persistent_variable_sp->m_flags);162}163164if (m_persistent_variable_sp->m_flags &165ExpressionVariable::EVNeedsAllocation) {166MakeAllocation(map, err);167m_persistent_variable_sp->m_flags |=168ExpressionVariable::EVIsLLDBAllocated;169170if (!err.Success())171return;172}173174if ((m_persistent_variable_sp->m_flags &175ExpressionVariable::EVIsProgramReference &&176m_persistent_variable_sp->m_live_sp) ||177m_persistent_variable_sp->m_flags &178ExpressionVariable::EVIsLLDBAllocated) {179Status write_error;180181map.WriteScalarToMemory(182load_addr,183m_persistent_variable_sp->m_live_sp->GetValue().GetScalar(),184map.GetAddressByteSize(), write_error);185186if (!write_error.Success()) {187err.SetErrorStringWithFormat(188"couldn't write the location of %s to memory: %s",189m_persistent_variable_sp->GetName().AsCString(),190write_error.AsCString());191}192} else {193err.SetErrorStringWithFormat(194"no materialization happened for persistent variable %s",195m_persistent_variable_sp->GetName().AsCString());196return;197}198}199200void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,201lldb::addr_t process_address, lldb::addr_t frame_top,202lldb::addr_t frame_bottom, Status &err) override {203Log *log = GetLog(LLDBLog::Expressions);204205const lldb::addr_t load_addr = process_address + m_offset;206207if (log) {208LLDB_LOGF(log,209"EntityPersistentVariable::Dematerialize [address = 0x%" PRIx64210", m_name = %s, m_flags = 0x%hx]",211(uint64_t)process_address + m_offset,212m_persistent_variable_sp->GetName().AsCString(),213m_persistent_variable_sp->m_flags);214}215216if (m_delegate) {217m_delegate->DidDematerialize(m_persistent_variable_sp);218}219220if ((m_persistent_variable_sp->m_flags &221ExpressionVariable::EVIsLLDBAllocated) ||222(m_persistent_variable_sp->m_flags &223ExpressionVariable::EVIsProgramReference)) {224if (m_persistent_variable_sp->m_flags &225ExpressionVariable::EVIsProgramReference &&226!m_persistent_variable_sp->m_live_sp) {227// If the reference comes from the program, then the228// ClangExpressionVariable's live variable data hasn't been set up yet.229// Do this now.230231lldb::addr_t location;232Status read_error;233234map.ReadPointerFromMemory(&location, load_addr, read_error);235236if (!read_error.Success()) {237err.SetErrorStringWithFormat(238"couldn't read the address of program-allocated variable %s: %s",239m_persistent_variable_sp->GetName().GetCString(),240read_error.AsCString());241return;242}243244m_persistent_variable_sp->m_live_sp = ValueObjectConstResult::Create(245map.GetBestExecutionContextScope(),246m_persistent_variable_sp.get()->GetCompilerType(),247m_persistent_variable_sp->GetName(), location, eAddressTypeLoad,248m_persistent_variable_sp->GetByteSize().value_or(0));249250if (frame_top != LLDB_INVALID_ADDRESS &&251frame_bottom != LLDB_INVALID_ADDRESS && location >= frame_bottom &&252location <= frame_top) {253// If the variable is resident in the stack frame created by the254// expression, then it cannot be relied upon to stay around. We255// treat it as needing reallocation.256m_persistent_variable_sp->m_flags |=257ExpressionVariable::EVIsLLDBAllocated;258m_persistent_variable_sp->m_flags |=259ExpressionVariable::EVNeedsAllocation;260m_persistent_variable_sp->m_flags |=261ExpressionVariable::EVNeedsFreezeDry;262m_persistent_variable_sp->m_flags &=263~ExpressionVariable::EVIsProgramReference;264}265}266267lldb::addr_t mem = m_persistent_variable_sp->m_live_sp->GetValue()268.GetScalar()269.ULongLong();270271if (!m_persistent_variable_sp->m_live_sp) {272err.SetErrorStringWithFormat(273"couldn't find the memory area used to store %s",274m_persistent_variable_sp->GetName().GetCString());275return;276}277278if (m_persistent_variable_sp->m_live_sp->GetValue()279.GetValueAddressType() != eAddressTypeLoad) {280err.SetErrorStringWithFormat(281"the address of the memory area for %s is in an incorrect format",282m_persistent_variable_sp->GetName().GetCString());283return;284}285286if (m_persistent_variable_sp->m_flags &287ExpressionVariable::EVNeedsFreezeDry ||288m_persistent_variable_sp->m_flags &289ExpressionVariable::EVKeepInTarget) {290LLDB_LOGF(log, "Dematerializing %s from 0x%" PRIx64 " (size = %llu)",291m_persistent_variable_sp->GetName().GetCString(),292(uint64_t)mem,293(unsigned long long)m_persistent_variable_sp->GetByteSize()294.value_or(0));295296// Read the contents of the spare memory area297298m_persistent_variable_sp->ValueUpdated();299300Status read_error;301302map.ReadMemory(m_persistent_variable_sp->GetValueBytes(), mem,303m_persistent_variable_sp->GetByteSize().value_or(0),304read_error);305306if (!read_error.Success()) {307err.SetErrorStringWithFormat(308"couldn't read the contents of %s from memory: %s",309m_persistent_variable_sp->GetName().GetCString(),310read_error.AsCString());311return;312}313314m_persistent_variable_sp->m_flags &=315~ExpressionVariable::EVNeedsFreezeDry;316}317} else {318err.SetErrorStringWithFormat(319"no dematerialization happened for persistent variable %s",320m_persistent_variable_sp->GetName().AsCString());321return;322}323324lldb::ProcessSP process_sp =325map.GetBestExecutionContextScope()->CalculateProcess();326if (!process_sp || !process_sp->CanJIT()) {327// Allocations are not persistent so persistent variables cannot stay328// materialized.329330m_persistent_variable_sp->m_flags |=331ExpressionVariable::EVNeedsAllocation;332333DestroyAllocation(map, err);334if (!err.Success())335return;336} else if (m_persistent_variable_sp->m_flags &337ExpressionVariable::EVNeedsAllocation &&338!(m_persistent_variable_sp->m_flags &339ExpressionVariable::EVKeepInTarget)) {340DestroyAllocation(map, err);341if (!err.Success())342return;343}344}345346void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,347Log *log) override {348StreamString dump_stream;349350Status err;351352const lldb::addr_t load_addr = process_address + m_offset;353354dump_stream.Printf("0x%" PRIx64 ": EntityPersistentVariable (%s)\n",355load_addr,356m_persistent_variable_sp->GetName().AsCString());357358{359dump_stream.Printf("Pointer:\n");360361DataBufferHeap data(m_size, 0);362363map.ReadMemory(data.GetBytes(), load_addr, m_size, err);364365if (!err.Success()) {366dump_stream.Printf(" <could not be read>\n");367} else {368DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,369load_addr);370371dump_stream.PutChar('\n');372}373}374375{376dump_stream.Printf("Target:\n");377378lldb::addr_t target_address;379380map.ReadPointerFromMemory(&target_address, load_addr, err);381382if (!err.Success()) {383dump_stream.Printf(" <could not be read>\n");384} else {385DataBufferHeap data(m_persistent_variable_sp->GetByteSize().value_or(0),3860);387388map.ReadMemory(data.GetBytes(), target_address,389m_persistent_variable_sp->GetByteSize().value_or(0),390err);391392if (!err.Success()) {393dump_stream.Printf(" <could not be read>\n");394} else {395DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,396target_address);397398dump_stream.PutChar('\n');399}400}401}402403log->PutString(dump_stream.GetString());404}405406void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {}407408private:409lldb::ExpressionVariableSP m_persistent_variable_sp;410Materializer::PersistentVariableDelegate *m_delegate;411};412413uint32_t Materializer::AddPersistentVariable(414lldb::ExpressionVariableSP &persistent_variable_sp,415PersistentVariableDelegate *delegate, Status &err) {416EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());417*iter = std::make_unique<EntityPersistentVariable>(persistent_variable_sp,418delegate);419uint32_t ret = AddStructMember(**iter);420(*iter)->SetOffset(ret);421return ret;422}423424/// Base class for materialization of Variables and ValueObjects.425///426/// Subclasses specify how to obtain the Value which is to be427/// materialized.428class EntityVariableBase : public Materializer::Entity {429public:430virtual ~EntityVariableBase() = default;431432EntityVariableBase() {433// Hard-coding to maximum size of a pointer since all variables are434// materialized by reference435m_size = g_default_var_byte_size;436m_alignment = g_default_var_alignment;437}438439void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,440lldb::addr_t process_address, Status &err) override {441Log *log = GetLog(LLDBLog::Expressions);442443const lldb::addr_t load_addr = process_address + m_offset;444if (log) {445LLDB_LOGF(log,446"EntityVariable::Materialize [address = 0x%" PRIx64447", m_variable_sp = %s]",448(uint64_t)load_addr, GetName().GetCString());449}450451ExecutionContextScope *scope = frame_sp.get();452453if (!scope)454scope = map.GetBestExecutionContextScope();455456lldb::ValueObjectSP valobj_sp = SetupValueObject(scope);457458if (!valobj_sp) {459err.SetErrorStringWithFormat(460"couldn't get a value object for variable %s", GetName().AsCString());461return;462}463464Status valobj_error = valobj_sp->GetError();465466if (valobj_error.Fail()) {467err.SetErrorStringWithFormat("couldn't get the value of variable %s: %s",468GetName().AsCString(),469valobj_error.AsCString());470return;471}472473if (m_is_reference) {474DataExtractor valobj_extractor;475Status extract_error;476valobj_sp->GetData(valobj_extractor, extract_error);477478if (!extract_error.Success()) {479err.SetErrorStringWithFormat(480"couldn't read contents of reference variable %s: %s",481GetName().AsCString(), extract_error.AsCString());482return;483}484485lldb::offset_t offset = 0;486lldb::addr_t reference_addr = valobj_extractor.GetAddress(&offset);487488Status write_error;489map.WritePointerToMemory(load_addr, reference_addr, write_error);490491if (!write_error.Success()) {492err.SetErrorStringWithFormat("couldn't write the contents of reference "493"variable %s to memory: %s",494GetName().AsCString(),495write_error.AsCString());496return;497}498} else {499AddressType address_type = eAddressTypeInvalid;500const bool scalar_is_load_address = false;501lldb::addr_t addr_of_valobj =502valobj_sp->GetAddressOf(scalar_is_load_address, &address_type);503if (addr_of_valobj != LLDB_INVALID_ADDRESS) {504Status write_error;505map.WritePointerToMemory(load_addr, addr_of_valobj, write_error);506507if (!write_error.Success()) {508err.SetErrorStringWithFormat(509"couldn't write the address of variable %s to memory: %s",510GetName().AsCString(), write_error.AsCString());511return;512}513} else {514DataExtractor data;515Status extract_error;516valobj_sp->GetData(data, extract_error);517if (!extract_error.Success()) {518err.SetErrorStringWithFormat("couldn't get the value of %s: %s",519GetName().AsCString(),520extract_error.AsCString());521return;522}523524if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {525err.SetErrorStringWithFormat(526"trying to create a temporary region for %s but one exists",527GetName().AsCString());528return;529}530531if (data.GetByteSize() < GetByteSize(scope)) {532if (data.GetByteSize() == 0 && !LocationExpressionIsValid()) {533err.SetErrorStringWithFormat("the variable '%s' has no location, "534"it may have been optimized out",535GetName().AsCString());536} else {537err.SetErrorStringWithFormat(538"size of variable %s (%" PRIu64539") is larger than the ValueObject's size (%" PRIu64 ")",540GetName().AsCString(), GetByteSize(scope).value_or(0),541data.GetByteSize());542}543return;544}545546std::optional<size_t> opt_bit_align = GetTypeBitAlign(scope);547if (!opt_bit_align) {548err.SetErrorStringWithFormat("can't get the type alignment for %s",549GetName().AsCString());550return;551}552553size_t byte_align = (*opt_bit_align + 7) / 8;554555Status alloc_error;556const bool zero_memory = false;557558m_temporary_allocation = map.Malloc(559data.GetByteSize(), byte_align,560lldb::ePermissionsReadable | lldb::ePermissionsWritable,561IRMemoryMap::eAllocationPolicyMirror, zero_memory, alloc_error);562563m_temporary_allocation_size = data.GetByteSize();564565m_original_data = std::make_shared<DataBufferHeap>(data.GetDataStart(),566data.GetByteSize());567568if (!alloc_error.Success()) {569err.SetErrorStringWithFormat(570"couldn't allocate a temporary region for %s: %s",571GetName().AsCString(), alloc_error.AsCString());572return;573}574575Status write_error;576577map.WriteMemory(m_temporary_allocation, data.GetDataStart(),578data.GetByteSize(), write_error);579580if (!write_error.Success()) {581err.SetErrorStringWithFormat(582"couldn't write to the temporary region for %s: %s",583GetName().AsCString(), write_error.AsCString());584return;585}586587Status pointer_write_error;588589map.WritePointerToMemory(load_addr, m_temporary_allocation,590pointer_write_error);591592if (!pointer_write_error.Success()) {593err.SetErrorStringWithFormat(594"couldn't write the address of the temporary region for %s: %s",595GetName().AsCString(), pointer_write_error.AsCString());596}597}598}599}600601void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,602lldb::addr_t process_address, lldb::addr_t frame_top,603lldb::addr_t frame_bottom, Status &err) override {604Log *log = GetLog(LLDBLog::Expressions);605606const lldb::addr_t load_addr = process_address + m_offset;607if (log) {608LLDB_LOGF(log,609"EntityVariable::Dematerialize [address = 0x%" PRIx64610", m_variable_sp = %s]",611(uint64_t)load_addr, GetName().AsCString());612}613614if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {615ExecutionContextScope *scope = frame_sp.get();616617if (!scope)618scope = map.GetBestExecutionContextScope();619620lldb::ValueObjectSP valobj_sp = SetupValueObject(scope);621622if (!valobj_sp) {623err.SetErrorStringWithFormat(624"couldn't get a value object for variable %s",625GetName().AsCString());626return;627}628629lldb_private::DataExtractor data;630631Status extract_error;632633map.GetMemoryData(data, m_temporary_allocation,634valobj_sp->GetByteSize().value_or(0), extract_error);635636if (!extract_error.Success()) {637err.SetErrorStringWithFormat("couldn't get the data for variable %s",638GetName().AsCString());639return;640}641642bool actually_write = true;643644if (m_original_data) {645if ((data.GetByteSize() == m_original_data->GetByteSize()) &&646!memcmp(m_original_data->GetBytes(), data.GetDataStart(),647data.GetByteSize())) {648actually_write = false;649}650}651652Status set_error;653654if (actually_write) {655valobj_sp->SetData(data, set_error);656657if (!set_error.Success()) {658err.SetErrorStringWithFormat(659"couldn't write the new contents of %s back into the variable",660GetName().AsCString());661return;662}663}664665Status free_error;666667map.Free(m_temporary_allocation, free_error);668669if (!free_error.Success()) {670err.SetErrorStringWithFormat(671"couldn't free the temporary region for %s: %s",672GetName().AsCString(), free_error.AsCString());673return;674}675676m_original_data.reset();677m_temporary_allocation = LLDB_INVALID_ADDRESS;678m_temporary_allocation_size = 0;679}680}681682void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,683Log *log) override {684StreamString dump_stream;685686const lldb::addr_t load_addr = process_address + m_offset;687dump_stream.Printf("0x%" PRIx64 ": EntityVariable\n", load_addr);688689Status err;690691lldb::addr_t ptr = LLDB_INVALID_ADDRESS;692693{694dump_stream.Printf("Pointer:\n");695696DataBufferHeap data(m_size, 0);697698map.ReadMemory(data.GetBytes(), load_addr, m_size, err);699700if (!err.Success()) {701dump_stream.Printf(" <could not be read>\n");702} else {703DataExtractor extractor(data.GetBytes(), data.GetByteSize(),704map.GetByteOrder(), map.GetAddressByteSize());705706DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,707load_addr);708709lldb::offset_t offset = 0;710711ptr = extractor.GetAddress(&offset);712713dump_stream.PutChar('\n');714}715}716717if (m_temporary_allocation == LLDB_INVALID_ADDRESS) {718dump_stream.Printf("Points to process memory:\n");719} else {720dump_stream.Printf("Temporary allocation:\n");721}722723if (ptr == LLDB_INVALID_ADDRESS) {724dump_stream.Printf(" <could not be be found>\n");725} else {726DataBufferHeap data(m_temporary_allocation_size, 0);727728map.ReadMemory(data.GetBytes(), m_temporary_allocation,729m_temporary_allocation_size, err);730731if (!err.Success()) {732dump_stream.Printf(" <could not be read>\n");733} else {734DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,735load_addr);736737dump_stream.PutChar('\n');738}739}740741log->PutString(dump_stream.GetString());742}743744void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {745if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {746Status free_error;747748map.Free(m_temporary_allocation, free_error);749750m_temporary_allocation = LLDB_INVALID_ADDRESS;751m_temporary_allocation_size = 0;752}753}754755private:756virtual ConstString GetName() const = 0;757758/// Creates and returns ValueObject tied to this variable759/// and prepares Entity for materialization.760///761/// Called each time the Materializer (de)materializes a762/// variable. We re-create the ValueObject based on the763/// current ExecutionContextScope since clients such as764/// conditional breakpoints may materialize the same765/// EntityVariable multiple times with different frames.766///767/// Each subsequent use of the EntityVariableBase interface768/// will query the newly created ValueObject until this769/// function is called again.770virtual lldb::ValueObjectSP771SetupValueObject(ExecutionContextScope *scope) = 0;772773/// Returns size in bytes of the type associated with this variable774///775/// \returns On success, returns byte size of the type associated776/// with this variable. Returns std::nullopt otherwise.777virtual std::optional<uint64_t>778GetByteSize(ExecutionContextScope *scope) const = 0;779780/// Returns 'true' if the location expression associated with this variable781/// is valid.782virtual bool LocationExpressionIsValid() const = 0;783784/// Returns alignment of the type associated with this variable in bits.785///786/// \returns On success, returns alignment in bits for the type associated787/// with this variable. Returns std::nullopt otherwise.788virtual std::optional<size_t>789GetTypeBitAlign(ExecutionContextScope *scope) const = 0;790791protected:792bool m_is_reference = false;793lldb::addr_t m_temporary_allocation = LLDB_INVALID_ADDRESS;794size_t m_temporary_allocation_size = 0;795lldb::DataBufferSP m_original_data;796};797798/// Represents an Entity constructed from a VariableSP.799///800/// This class is used for materialization of variables for which801/// the user has a VariableSP on hand. The ValueObject is then802/// derived from the associated DWARF location expression when needed803/// by the Materializer.804class EntityVariable : public EntityVariableBase {805public:806EntityVariable(lldb::VariableSP &variable_sp) : m_variable_sp(variable_sp) {807m_is_reference =808m_variable_sp->GetType()->GetForwardCompilerType().IsReferenceType();809}810811ConstString GetName() const override { return m_variable_sp->GetName(); }812813lldb::ValueObjectSP SetupValueObject(ExecutionContextScope *scope) override {814assert(m_variable_sp != nullptr);815return ValueObjectVariable::Create(scope, m_variable_sp);816}817818std::optional<uint64_t>819GetByteSize(ExecutionContextScope *scope) const override {820return m_variable_sp->GetType()->GetByteSize(scope);821}822823bool LocationExpressionIsValid() const override {824return m_variable_sp->LocationExpressionList().IsValid();825}826827std::optional<size_t>828GetTypeBitAlign(ExecutionContextScope *scope) const override {829return m_variable_sp->GetType()->GetLayoutCompilerType().GetTypeBitAlign(830scope);831}832833private:834lldb::VariableSP m_variable_sp; ///< Variable that this entity is based on.835};836837/// Represents an Entity constructed from a VariableSP.838///839/// This class is used for materialization of variables for840/// which the user does not have a VariableSP available (e.g.,841/// when materializing ivars).842class EntityValueObject : public EntityVariableBase {843public:844EntityValueObject(ConstString name, ValueObjectProviderTy provider)845: m_name(name), m_valobj_provider(std::move(provider)) {846assert(m_valobj_provider);847}848849ConstString GetName() const override { return m_name; }850851lldb::ValueObjectSP SetupValueObject(ExecutionContextScope *scope) override {852m_valobj_sp =853m_valobj_provider(GetName(), scope->CalculateStackFrame().get());854855if (m_valobj_sp)856m_is_reference = m_valobj_sp->GetCompilerType().IsReferenceType();857858return m_valobj_sp;859}860861std::optional<uint64_t>862GetByteSize(ExecutionContextScope *scope) const override {863if (m_valobj_sp)864return m_valobj_sp->GetCompilerType().GetByteSize(scope);865866return {};867}868869bool LocationExpressionIsValid() const override {870if (m_valobj_sp)871return m_valobj_sp->GetError().Success();872873return false;874}875876std::optional<size_t>877GetTypeBitAlign(ExecutionContextScope *scope) const override {878if (m_valobj_sp)879return m_valobj_sp->GetCompilerType().GetTypeBitAlign(scope);880881return {};882}883884private:885ConstString m_name;886lldb::ValueObjectSP m_valobj_sp;887ValueObjectProviderTy m_valobj_provider;888};889890uint32_t Materializer::AddVariable(lldb::VariableSP &variable_sp, Status &err) {891EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());892*iter = std::make_unique<EntityVariable>(variable_sp);893uint32_t ret = AddStructMember(**iter);894(*iter)->SetOffset(ret);895return ret;896}897898uint32_t Materializer::AddValueObject(ConstString name,899ValueObjectProviderTy valobj_provider,900Status &err) {901assert(valobj_provider);902EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());903*iter = std::make_unique<EntityValueObject>(name, std::move(valobj_provider));904uint32_t ret = AddStructMember(**iter);905(*iter)->SetOffset(ret);906return ret;907}908909class EntityResultVariable : public Materializer::Entity {910public:911EntityResultVariable(const CompilerType &type, bool is_program_reference,912bool keep_in_memory,913Materializer::PersistentVariableDelegate *delegate)914: Entity(), m_type(type), m_is_program_reference(is_program_reference),915m_keep_in_memory(keep_in_memory), m_delegate(delegate) {916// Hard-coding to maximum size of a pointer since all results are917// materialized by reference918m_size = g_default_var_byte_size;919m_alignment = g_default_var_alignment;920}921922void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,923lldb::addr_t process_address, Status &err) override {924if (!m_is_program_reference) {925if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {926err.SetErrorString("Trying to create a temporary region for the result "927"but one exists");928return;929}930931const lldb::addr_t load_addr = process_address + m_offset;932933ExecutionContextScope *exe_scope = frame_sp.get();934if (!exe_scope)935exe_scope = map.GetBestExecutionContextScope();936937std::optional<uint64_t> byte_size = m_type.GetByteSize(exe_scope);938if (!byte_size) {939err.SetErrorStringWithFormat("can't get size of type \"%s\"",940m_type.GetTypeName().AsCString());941return;942}943944std::optional<size_t> opt_bit_align = m_type.GetTypeBitAlign(exe_scope);945if (!opt_bit_align) {946err.SetErrorStringWithFormat("can't get the alignment of type \"%s\"",947m_type.GetTypeName().AsCString());948return;949}950951size_t byte_align = (*opt_bit_align + 7) / 8;952953Status alloc_error;954const bool zero_memory = true;955956m_temporary_allocation = map.Malloc(957*byte_size, byte_align,958lldb::ePermissionsReadable | lldb::ePermissionsWritable,959IRMemoryMap::eAllocationPolicyMirror, zero_memory, alloc_error);960m_temporary_allocation_size = *byte_size;961962if (!alloc_error.Success()) {963err.SetErrorStringWithFormat(964"couldn't allocate a temporary region for the result: %s",965alloc_error.AsCString());966return;967}968969Status pointer_write_error;970971map.WritePointerToMemory(load_addr, m_temporary_allocation,972pointer_write_error);973974if (!pointer_write_error.Success()) {975err.SetErrorStringWithFormat("couldn't write the address of the "976"temporary region for the result: %s",977pointer_write_error.AsCString());978}979}980}981982void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,983lldb::addr_t process_address, lldb::addr_t frame_top,984lldb::addr_t frame_bottom, Status &err) override {985err.Clear();986987ExecutionContextScope *exe_scope = frame_sp.get();988if (!exe_scope)989exe_scope = map.GetBestExecutionContextScope();990991if (!exe_scope) {992err.SetErrorString("Couldn't dematerialize a result variable: invalid "993"execution context scope");994return;995}996997lldb::addr_t address;998Status read_error;999const lldb::addr_t load_addr = process_address + m_offset;10001001map.ReadPointerFromMemory(&address, load_addr, read_error);10021003if (!read_error.Success()) {1004err.SetErrorString("Couldn't dematerialize a result variable: couldn't "1005"read its address");1006return;1007}10081009lldb::TargetSP target_sp = exe_scope->CalculateTarget();10101011if (!target_sp) {1012err.SetErrorString("Couldn't dematerialize a result variable: no target");1013return;1014}10151016auto type_system_or_err =1017target_sp->GetScratchTypeSystemForLanguage(m_type.GetMinimumLanguage());10181019if (auto error = type_system_or_err.takeError()) {1020err.SetErrorStringWithFormat("Couldn't dematerialize a result variable: "1021"couldn't get the corresponding type "1022"system: %s",1023llvm::toString(std::move(error)).c_str());1024return;1025}1026auto ts = *type_system_or_err;1027if (!ts) {1028err.SetErrorStringWithFormat("Couldn't dematerialize a result variable: "1029"couldn't corresponding type system is "1030"no longer live.");1031return;1032}1033PersistentExpressionState *persistent_state =1034ts->GetPersistentExpressionState();10351036if (!persistent_state) {1037err.SetErrorString("Couldn't dematerialize a result variable: "1038"corresponding type system doesn't handle persistent "1039"variables");1040return;1041}10421043ConstString name = m_delegate1044? m_delegate->GetName()1045: persistent_state->GetNextPersistentVariableName();10461047lldb::ExpressionVariableSP ret = persistent_state->CreatePersistentVariable(1048exe_scope, name, m_type, map.GetByteOrder(), map.GetAddressByteSize());10491050if (!ret) {1051err.SetErrorStringWithFormat("couldn't dematerialize a result variable: "1052"failed to make persistent variable %s",1053name.AsCString());1054return;1055}10561057lldb::ProcessSP process_sp =1058map.GetBestExecutionContextScope()->CalculateProcess();10591060if (m_delegate) {1061m_delegate->DidDematerialize(ret);1062}10631064bool can_persist =1065(m_is_program_reference && process_sp && process_sp->CanJIT() &&1066!(address >= frame_bottom && address < frame_top));10671068if (can_persist && m_keep_in_memory) {1069ret->m_live_sp = ValueObjectConstResult::Create(exe_scope, m_type, name,1070address, eAddressTypeLoad,1071map.GetAddressByteSize());1072}10731074ret->ValueUpdated();10751076const size_t pvar_byte_size = ret->GetByteSize().value_or(0);1077uint8_t *pvar_data = ret->GetValueBytes();10781079map.ReadMemory(pvar_data, address, pvar_byte_size, read_error);10801081if (!read_error.Success()) {1082err.SetErrorString(1083"Couldn't dematerialize a result variable: couldn't read its memory");1084return;1085}10861087if (!can_persist || !m_keep_in_memory) {1088ret->m_flags |= ExpressionVariable::EVNeedsAllocation;10891090if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {1091Status free_error;1092map.Free(m_temporary_allocation, free_error);1093}1094} else {1095ret->m_flags |= ExpressionVariable::EVIsLLDBAllocated;1096}10971098m_temporary_allocation = LLDB_INVALID_ADDRESS;1099m_temporary_allocation_size = 0;1100}11011102void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,1103Log *log) override {1104StreamString dump_stream;11051106const lldb::addr_t load_addr = process_address + m_offset;11071108dump_stream.Printf("0x%" PRIx64 ": EntityResultVariable\n", load_addr);11091110Status err;11111112lldb::addr_t ptr = LLDB_INVALID_ADDRESS;11131114{1115dump_stream.Printf("Pointer:\n");11161117DataBufferHeap data(m_size, 0);11181119map.ReadMemory(data.GetBytes(), load_addr, m_size, err);11201121if (!err.Success()) {1122dump_stream.Printf(" <could not be read>\n");1123} else {1124DataExtractor extractor(data.GetBytes(), data.GetByteSize(),1125map.GetByteOrder(), map.GetAddressByteSize());11261127DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,1128load_addr);11291130lldb::offset_t offset = 0;11311132ptr = extractor.GetAddress(&offset);11331134dump_stream.PutChar('\n');1135}1136}11371138if (m_temporary_allocation == LLDB_INVALID_ADDRESS) {1139dump_stream.Printf("Points to process memory:\n");1140} else {1141dump_stream.Printf("Temporary allocation:\n");1142}11431144if (ptr == LLDB_INVALID_ADDRESS) {1145dump_stream.Printf(" <could not be be found>\n");1146} else {1147DataBufferHeap data(m_temporary_allocation_size, 0);11481149map.ReadMemory(data.GetBytes(), m_temporary_allocation,1150m_temporary_allocation_size, err);11511152if (!err.Success()) {1153dump_stream.Printf(" <could not be read>\n");1154} else {1155DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,1156load_addr);11571158dump_stream.PutChar('\n');1159}1160}11611162log->PutString(dump_stream.GetString());1163}11641165void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {1166if (!m_keep_in_memory && m_temporary_allocation != LLDB_INVALID_ADDRESS) {1167Status free_error;11681169map.Free(m_temporary_allocation, free_error);1170}11711172m_temporary_allocation = LLDB_INVALID_ADDRESS;1173m_temporary_allocation_size = 0;1174}11751176private:1177CompilerType m_type;1178bool m_is_program_reference;1179bool m_keep_in_memory;11801181lldb::addr_t m_temporary_allocation = LLDB_INVALID_ADDRESS;1182size_t m_temporary_allocation_size = 0;1183Materializer::PersistentVariableDelegate *m_delegate;1184};11851186uint32_t Materializer::AddResultVariable(const CompilerType &type,1187bool is_program_reference,1188bool keep_in_memory,1189PersistentVariableDelegate *delegate,1190Status &err) {1191EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());1192*iter = std::make_unique<EntityResultVariable>(type, is_program_reference,1193keep_in_memory, delegate);1194uint32_t ret = AddStructMember(**iter);1195(*iter)->SetOffset(ret);1196return ret;1197}11981199class EntitySymbol : public Materializer::Entity {1200public:1201EntitySymbol(const Symbol &symbol) : Entity(), m_symbol(symbol) {1202// Hard-coding to maximum size of a symbol1203m_size = g_default_var_byte_size;1204m_alignment = g_default_var_alignment;1205}12061207void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,1208lldb::addr_t process_address, Status &err) override {1209Log *log = GetLog(LLDBLog::Expressions);12101211const lldb::addr_t load_addr = process_address + m_offset;12121213if (log) {1214LLDB_LOGF(log,1215"EntitySymbol::Materialize [address = 0x%" PRIx641216", m_symbol = %s]",1217(uint64_t)load_addr, m_symbol.GetName().AsCString());1218}12191220const Address sym_address = m_symbol.GetAddress();12211222ExecutionContextScope *exe_scope = frame_sp.get();1223if (!exe_scope)1224exe_scope = map.GetBestExecutionContextScope();12251226lldb::TargetSP target_sp;12271228if (exe_scope)1229target_sp = map.GetBestExecutionContextScope()->CalculateTarget();12301231if (!target_sp) {1232err.SetErrorStringWithFormat(1233"couldn't resolve symbol %s because there is no target",1234m_symbol.GetName().AsCString());1235return;1236}12371238lldb::addr_t resolved_address = sym_address.GetLoadAddress(target_sp.get());12391240if (resolved_address == LLDB_INVALID_ADDRESS)1241resolved_address = sym_address.GetFileAddress();12421243Status pointer_write_error;12441245map.WritePointerToMemory(load_addr, resolved_address, pointer_write_error);12461247if (!pointer_write_error.Success()) {1248err.SetErrorStringWithFormat(1249"couldn't write the address of symbol %s: %s",1250m_symbol.GetName().AsCString(), pointer_write_error.AsCString());1251return;1252}1253}12541255void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,1256lldb::addr_t process_address, lldb::addr_t frame_top,1257lldb::addr_t frame_bottom, Status &err) override {1258Log *log = GetLog(LLDBLog::Expressions);12591260const lldb::addr_t load_addr = process_address + m_offset;12611262if (log) {1263LLDB_LOGF(log,1264"EntitySymbol::Dematerialize [address = 0x%" PRIx641265", m_symbol = %s]",1266(uint64_t)load_addr, m_symbol.GetName().AsCString());1267}12681269// no work needs to be done1270}12711272void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,1273Log *log) override {1274StreamString dump_stream;12751276Status err;12771278const lldb::addr_t load_addr = process_address + m_offset;12791280dump_stream.Printf("0x%" PRIx64 ": EntitySymbol (%s)\n", load_addr,1281m_symbol.GetName().AsCString());12821283{1284dump_stream.Printf("Pointer:\n");12851286DataBufferHeap data(m_size, 0);12871288map.ReadMemory(data.GetBytes(), load_addr, m_size, err);12891290if (!err.Success()) {1291dump_stream.Printf(" <could not be read>\n");1292} else {1293DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,1294load_addr);12951296dump_stream.PutChar('\n');1297}1298}12991300log->PutString(dump_stream.GetString());1301}13021303void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {}13041305private:1306Symbol m_symbol;1307};13081309uint32_t Materializer::AddSymbol(const Symbol &symbol_sp, Status &err) {1310EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());1311*iter = std::make_unique<EntitySymbol>(symbol_sp);1312uint32_t ret = AddStructMember(**iter);1313(*iter)->SetOffset(ret);1314return ret;1315}13161317class EntityRegister : public Materializer::Entity {1318public:1319EntityRegister(const RegisterInfo ®ister_info)1320: Entity(), m_register_info(register_info) {1321// Hard-coding alignment conservatively1322m_size = m_register_info.byte_size;1323m_alignment = m_register_info.byte_size;1324}13251326void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,1327lldb::addr_t process_address, Status &err) override {1328Log *log = GetLog(LLDBLog::Expressions);13291330const lldb::addr_t load_addr = process_address + m_offset;13311332if (log) {1333LLDB_LOGF(log,1334"EntityRegister::Materialize [address = 0x%" PRIx641335", m_register_info = %s]",1336(uint64_t)load_addr, m_register_info.name);1337}13381339RegisterValue reg_value;13401341if (!frame_sp.get()) {1342err.SetErrorStringWithFormat(1343"couldn't materialize register %s without a stack frame",1344m_register_info.name);1345return;1346}13471348lldb::RegisterContextSP reg_context_sp = frame_sp->GetRegisterContext();13491350if (!reg_context_sp->ReadRegister(&m_register_info, reg_value)) {1351err.SetErrorStringWithFormat("couldn't read the value of register %s",1352m_register_info.name);1353return;1354}13551356DataExtractor register_data;13571358if (!reg_value.GetData(register_data)) {1359err.SetErrorStringWithFormat("couldn't get the data for register %s",1360m_register_info.name);1361return;1362}13631364if (register_data.GetByteSize() != m_register_info.byte_size) {1365err.SetErrorStringWithFormat(1366"data for register %s had size %llu but we expected %llu",1367m_register_info.name, (unsigned long long)register_data.GetByteSize(),1368(unsigned long long)m_register_info.byte_size);1369return;1370}13711372m_register_contents = std::make_shared<DataBufferHeap>(1373register_data.GetDataStart(), register_data.GetByteSize());13741375Status write_error;13761377map.WriteMemory(load_addr, register_data.GetDataStart(),1378register_data.GetByteSize(), write_error);13791380if (!write_error.Success()) {1381err.SetErrorStringWithFormat(1382"couldn't write the contents of register %s: %s",1383m_register_info.name, write_error.AsCString());1384return;1385}1386}13871388void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,1389lldb::addr_t process_address, lldb::addr_t frame_top,1390lldb::addr_t frame_bottom, Status &err) override {1391Log *log = GetLog(LLDBLog::Expressions);13921393const lldb::addr_t load_addr = process_address + m_offset;13941395if (log) {1396LLDB_LOGF(log,1397"EntityRegister::Dematerialize [address = 0x%" PRIx641398", m_register_info = %s]",1399(uint64_t)load_addr, m_register_info.name);1400}14011402Status extract_error;14031404DataExtractor register_data;14051406if (!frame_sp.get()) {1407err.SetErrorStringWithFormat(1408"couldn't dematerialize register %s without a stack frame",1409m_register_info.name);1410return;1411}14121413lldb::RegisterContextSP reg_context_sp = frame_sp->GetRegisterContext();14141415map.GetMemoryData(register_data, load_addr, m_register_info.byte_size,1416extract_error);14171418if (!extract_error.Success()) {1419err.SetErrorStringWithFormat("couldn't get the data for register %s: %s",1420m_register_info.name,1421extract_error.AsCString());1422return;1423}14241425if (!memcmp(register_data.GetDataStart(), m_register_contents->GetBytes(),1426register_data.GetByteSize())) {1427// No write required, and in particular we avoid errors if the register1428// wasn't writable14291430m_register_contents.reset();1431return;1432}14331434m_register_contents.reset();14351436RegisterValue register_value(register_data.GetData(),1437register_data.GetByteOrder());14381439if (!reg_context_sp->WriteRegister(&m_register_info, register_value)) {1440err.SetErrorStringWithFormat("couldn't write the value of register %s",1441m_register_info.name);1442return;1443}1444}14451446void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,1447Log *log) override {1448StreamString dump_stream;14491450Status err;14511452const lldb::addr_t load_addr = process_address + m_offset;14531454dump_stream.Printf("0x%" PRIx64 ": EntityRegister (%s)\n", load_addr,1455m_register_info.name);14561457{1458dump_stream.Printf("Value:\n");14591460DataBufferHeap data(m_size, 0);14611462map.ReadMemory(data.GetBytes(), load_addr, m_size, err);14631464if (!err.Success()) {1465dump_stream.Printf(" <could not be read>\n");1466} else {1467DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,1468load_addr);14691470dump_stream.PutChar('\n');1471}1472}14731474log->PutString(dump_stream.GetString());1475}14761477void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {}14781479private:1480RegisterInfo m_register_info;1481lldb::DataBufferSP m_register_contents;1482};14831484uint32_t Materializer::AddRegister(const RegisterInfo ®ister_info,1485Status &err) {1486EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());1487*iter = std::make_unique<EntityRegister>(register_info);1488uint32_t ret = AddStructMember(**iter);1489(*iter)->SetOffset(ret);1490return ret;1491}14921493Materializer::~Materializer() {1494DematerializerSP dematerializer_sp = m_dematerializer_wp.lock();14951496if (dematerializer_sp)1497dematerializer_sp->Wipe();1498}14991500Materializer::DematerializerSP1501Materializer::Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,1502lldb::addr_t process_address, Status &error) {1503ExecutionContextScope *exe_scope = frame_sp.get();1504if (!exe_scope)1505exe_scope = map.GetBestExecutionContextScope();15061507DematerializerSP dematerializer_sp = m_dematerializer_wp.lock();15081509if (dematerializer_sp) {1510error.SetErrorToGenericError();1511error.SetErrorString("Couldn't materialize: already materialized");1512}15131514DematerializerSP ret(1515new Dematerializer(*this, frame_sp, map, process_address));15161517if (!exe_scope) {1518error.SetErrorToGenericError();1519error.SetErrorString("Couldn't materialize: target doesn't exist");1520}15211522for (EntityUP &entity_up : m_entities) {1523entity_up->Materialize(frame_sp, map, process_address, error);15241525if (!error.Success())1526return DematerializerSP();1527}15281529if (Log *log = GetLog(LLDBLog::Expressions)) {1530LLDB_LOGF(1531log,1532"Materializer::Materialize (frame_sp = %p, process_address = 0x%" PRIx641533") materialized:",1534static_cast<void *>(frame_sp.get()), process_address);1535for (EntityUP &entity_up : m_entities)1536entity_up->DumpToLog(map, process_address, log);1537}15381539m_dematerializer_wp = ret;15401541return ret;1542}15431544void Materializer::Dematerializer::Dematerialize(Status &error,1545lldb::addr_t frame_bottom,1546lldb::addr_t frame_top) {1547lldb::StackFrameSP frame_sp;15481549lldb::ThreadSP thread_sp = m_thread_wp.lock();1550if (thread_sp)1551frame_sp = thread_sp->GetFrameWithStackID(m_stack_id);15521553ExecutionContextScope *exe_scope = frame_sp.get();1554if (!exe_scope)1555exe_scope = m_map->GetBestExecutionContextScope();15561557if (!IsValid()) {1558error.SetErrorToGenericError();1559error.SetErrorString("Couldn't dematerialize: invalid dematerializer");1560}15611562if (!exe_scope) {1563error.SetErrorToGenericError();1564error.SetErrorString("Couldn't dematerialize: target is gone");1565} else {1566if (Log *log = GetLog(LLDBLog::Expressions)) {1567LLDB_LOGF(log,1568"Materializer::Dematerialize (frame_sp = %p, process_address "1569"= 0x%" PRIx64 ") about to dematerialize:",1570static_cast<void *>(frame_sp.get()), m_process_address);1571for (EntityUP &entity_up : m_materializer->m_entities)1572entity_up->DumpToLog(*m_map, m_process_address, log);1573}15741575for (EntityUP &entity_up : m_materializer->m_entities) {1576entity_up->Dematerialize(frame_sp, *m_map, m_process_address, frame_top,1577frame_bottom, error);15781579if (!error.Success())1580break;1581}1582}15831584Wipe();1585}15861587void Materializer::Dematerializer::Wipe() {1588if (!IsValid())1589return;15901591for (EntityUP &entity_up : m_materializer->m_entities) {1592entity_up->Wipe(*m_map, m_process_address);1593}15941595m_materializer = nullptr;1596m_map = nullptr;1597m_process_address = LLDB_INVALID_ADDRESS;1598}15991600Materializer::PersistentVariableDelegate::PersistentVariableDelegate() =1601default;1602Materializer::PersistentVariableDelegate::~PersistentVariableDelegate() =1603default;160416051606