[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Materializer.cpp --------------------------------------------------===//
|
2013-04-11 08:09:05 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-04-11 08:09:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Expression/Materializer.h"
|
2017-03-04 04:57:05 +08:00
|
|
|
#include "lldb/Core/DumpDataExtractor.h"
|
2013-04-13 02:10:34 +08:00
|
|
|
#include "lldb/Core/ValueObjectConstResult.h"
|
2013-04-13 05:40:34 +08:00
|
|
|
#include "lldb/Core/ValueObjectVariable.h"
|
2015-10-01 03:57:57 +08:00
|
|
|
#include "lldb/Expression/ExpressionVariable.h"
|
2013-04-11 08:09:05 +08:00
|
|
|
#include "lldb/Symbol/Symbol.h"
|
|
|
|
#include "lldb/Symbol/Type.h"
|
|
|
|
#include "lldb/Symbol/Variable.h"
|
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2013-04-16 04:51:24 +08:00
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2013-11-04 17:33:30 +08:00
|
|
|
#include "lldb/Target/StackFrame.h"
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2013-06-21 02:42:16 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2022-02-03 20:26:10 +08:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/RegisterValue.h"
|
2013-04-11 08:09:05 +08:00
|
|
|
|
2019-02-12 07:13:08 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
uint32_t Materializer::AddStructMember(Entity &entity) {
|
|
|
|
uint32_t size = entity.GetSize();
|
|
|
|
uint32_t alignment = entity.GetAlignment();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
uint32_t ret;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-12 05:16:36 +08:00
|
|
|
if (m_current_offset == 0)
|
2013-04-11 08:09:05 +08:00
|
|
|
m_struct_alignment = alignment;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
if (m_current_offset % alignment)
|
|
|
|
m_current_offset += (alignment - (m_current_offset % alignment));
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
ret = m_current_offset;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
m_current_offset += size;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
class EntityPersistentVariable : public Materializer::Entity {
|
|
|
|
public:
|
2015-10-03 17:09:01 +08:00
|
|
|
EntityPersistentVariable(lldb::ExpressionVariableSP &persistent_variable_sp,
|
|
|
|
Materializer::PersistentVariableDelegate *delegate)
|
|
|
|
: Entity(), m_persistent_variable_sp(persistent_variable_sp),
|
|
|
|
m_delegate(delegate) {
|
2013-04-17 07:25:35 +08:00
|
|
|
// Hard-coding to maximum size of a pointer since persistent variables are
|
|
|
|
// materialized by reference
|
|
|
|
m_size = 8;
|
|
|
|
m_alignment = 8;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
void MakeAllocation(IRMemoryMap &map, Status &err) {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Expressions);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Allocate a spare memory area to store the persistent variable's
|
|
|
|
// contents.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status allocate_error;
|
2015-11-05 04:32:27 +08:00
|
|
|
const bool zero_memory = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
lldb::addr_t mem = map.Malloc(
|
2022-06-20 00:12:01 +08:00
|
|
|
m_persistent_variable_sp->GetByteSize().value_or(0), 8,
|
2013-04-13 02:10:34 +08:00
|
|
|
lldb::ePermissionsReadable | lldb::ePermissionsWritable,
|
|
|
|
IRMemoryMap::eAllocationPolicyMirror, zero_memory, allocate_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
if (!allocate_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't allocate a memory area to store %s: %s",
|
|
|
|
m_persistent_variable_sp->GetName().GetCString(),
|
|
|
|
allocate_error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Allocated %s (0x%" PRIx64 ") successfully",
|
|
|
|
m_persistent_variable_sp->GetName().GetCString(), mem);
|
2013-04-13 02:10:34 +08:00
|
|
|
|
|
|
|
// Put the location of the spare memory into the live data of the
|
|
|
|
// ValueObject.
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-11-05 04:32:27 +08:00
|
|
|
m_persistent_variable_sp->m_live_sp = ValueObjectConstResult::Create(
|
2013-04-13 02:10:34 +08:00
|
|
|
map.GetBestExecutionContextScope(),
|
2015-09-18 02:19:12 +08:00
|
|
|
m_persistent_variable_sp->GetCompilerType(),
|
2015-11-05 04:32:27 +08:00
|
|
|
m_persistent_variable_sp->GetName(), mem, eAddressTypeLoad,
|
|
|
|
map.GetAddressByteSize());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-05-17 08:55:28 +08:00
|
|
|
// Clear the flag if the variable will never be deallocated.
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2014-08-12 02:06:28 +08:00
|
|
|
if (m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVKeepInTarget) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status leak_error;
|
2014-08-12 02:06:28 +08:00
|
|
|
map.Leak(mem, leak_error);
|
|
|
|
m_persistent_variable_sp->m_flags &=
|
|
|
|
~ExpressionVariable::EVNeedsAllocation;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
// Write the contents of the variable to the area.
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status write_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
map.WriteMemory(mem, m_persistent_variable_sp->GetValueBytes(),
|
2022-06-20 00:12:01 +08:00
|
|
|
m_persistent_variable_sp->GetByteSize().value_or(0),
|
2020-07-25 23:27:21 +08:00
|
|
|
write_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-09-30 06:52:50 +08:00
|
|
|
if (!write_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't write %s to the target: %s",
|
|
|
|
m_persistent_variable_sp->GetName().AsCString(),
|
2013-05-23 06:49:06 +08:00
|
|
|
write_error.AsCString());
|
2015-09-30 06:52:50 +08:00
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-05-23 06:49:06 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
void DestroyAllocation(IRMemoryMap &map, Status &err) {
|
|
|
|
Status deallocate_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
map.Free((lldb::addr_t)m_persistent_variable_sp->m_live_sp->GetValue()
|
|
|
|
.GetScalar()
|
|
|
|
.ULongLong(),
|
|
|
|
deallocate_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
m_persistent_variable_sp->m_live_sp.reset();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
if (!deallocate_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't deallocate memory for %s: %s",
|
|
|
|
m_persistent_variable_sp->GetName().GetCString(),
|
2013-04-13 02:10:34 +08:00
|
|
|
deallocate_error.AsCString());
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t process_address, Status &err) override {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Expressions);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-20 10:40:45 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"EntityPersistentVariable::Materialize [address = 0x%" PRIx64
|
|
|
|
", m_name = %s, m_flags = 0x%hx]",
|
|
|
|
(uint64_t)load_addr,
|
|
|
|
m_persistent_variable_sp->GetName().AsCString(),
|
|
|
|
m_persistent_variable_sp->m_flags);
|
2013-04-13 02:10:34 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
if (m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVNeedsAllocation) {
|
|
|
|
MakeAllocation(map, err);
|
|
|
|
m_persistent_variable_sp->m_flags |=
|
2013-04-13 02:10:34 +08:00
|
|
|
ExpressionVariable::EVIsLLDBAllocated;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
if (!err.Success())
|
2013-07-12 06:46:58 +08:00
|
|
|
return;
|
2013-04-13 02:10:34 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-09-30 06:52:50 +08:00
|
|
|
if ((m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVIsProgramReference &&
|
|
|
|
m_persistent_variable_sp->m_live_sp) ||
|
2013-04-13 02:10:34 +08:00
|
|
|
m_persistent_variable_sp->m_flags &
|
2015-09-30 06:52:50 +08:00
|
|
|
ExpressionVariable::EVIsLLDBAllocated) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status write_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
map.WriteScalarToMemory(
|
|
|
|
load_addr,
|
2013-04-13 02:10:34 +08:00
|
|
|
m_persistent_variable_sp->m_live_sp->GetValue().GetScalar(),
|
2016-02-28 06:48:50 +08:00
|
|
|
map.GetAddressByteSize(), write_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
if (!write_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't write the location of %s to memory: %s",
|
|
|
|
m_persistent_variable_sp->GetName().AsCString(),
|
|
|
|
write_error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"no materialization happened for persistent variable %s",
|
|
|
|
m_persistent_variable_sp->GetName().AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
|
|
|
lldb::addr_t process_address, lldb::addr_t frame_top,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t frame_bottom, Status &err) override {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Expressions);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-30 06:52:50 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"EntityPersistentVariable::Dematerialize [address = 0x%" PRIx64
|
|
|
|
", m_name = %s, m_flags = 0x%hx]",
|
|
|
|
(uint64_t)process_address + m_offset,
|
|
|
|
m_persistent_variable_sp->GetName().AsCString(),
|
|
|
|
m_persistent_variable_sp->m_flags);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
if (m_delegate) {
|
|
|
|
m_delegate->DidDematerialize(m_persistent_variable_sp);
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-09-30 06:52:50 +08:00
|
|
|
if ((m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVIsLLDBAllocated) ||
|
|
|
|
(m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVIsProgramReference)) {
|
|
|
|
if (m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVIsProgramReference &&
|
|
|
|
!m_persistent_variable_sp->m_live_sp) {
|
2013-04-13 02:10:34 +08:00
|
|
|
// If the reference comes from the program, then the
|
2018-05-01 00:49:04 +08:00
|
|
|
// ClangExpressionVariable's live variable data hasn't been set up yet.
|
|
|
|
// Do this now.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-30 06:52:50 +08:00
|
|
|
lldb::addr_t location;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status read_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
map.ReadPointerFromMemory(&location, load_addr, read_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
if (!read_error.Success()) {
|
2013-07-12 06:46:58 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
2013-05-17 08:55:28 +08:00
|
|
|
"couldn't read the address of program-allocated variable %s: %s",
|
|
|
|
m_persistent_variable_sp->GetName().GetCString(),
|
2013-07-12 06:46:58 +08:00
|
|
|
read_error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
m_persistent_variable_sp->m_live_sp = ValueObjectConstResult::Create(
|
2013-04-13 02:10:34 +08:00
|
|
|
map.GetBestExecutionContextScope(),
|
2015-09-30 06:52:50 +08:00
|
|
|
m_persistent_variable_sp.get()->GetCompilerType(),
|
2013-05-17 08:55:28 +08:00
|
|
|
m_persistent_variable_sp->GetName(), location, eAddressTypeLoad,
|
2022-06-20 00:12:01 +08:00
|
|
|
m_persistent_variable_sp->GetByteSize().value_or(0));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
if (frame_top != LLDB_INVALID_ADDRESS &&
|
2013-04-27 10:19:33 +08:00
|
|
|
frame_bottom != LLDB_INVALID_ADDRESS && location >= frame_bottom &&
|
2013-04-13 02:10:34 +08:00
|
|
|
location <= frame_top) {
|
|
|
|
// If the variable is resident in the stack frame created by the
|
2018-05-01 00:49:04 +08:00
|
|
|
// expression, then it cannot be relied upon to stay around. We
|
|
|
|
// treat it as needing reallocation.
|
2013-04-13 02:10:34 +08:00
|
|
|
m_persistent_variable_sp->m_flags |=
|
|
|
|
ExpressionVariable::EVIsLLDBAllocated;
|
2015-09-30 06:52:50 +08:00
|
|
|
m_persistent_variable_sp->m_flags |=
|
|
|
|
ExpressionVariable::EVNeedsAllocation;
|
|
|
|
m_persistent_variable_sp->m_flags |=
|
|
|
|
ExpressionVariable::EVNeedsFreezeDry;
|
|
|
|
m_persistent_variable_sp->m_flags &=
|
|
|
|
~ExpressionVariable::EVIsProgramReference;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
lldb::addr_t mem = m_persistent_variable_sp->m_live_sp->GetValue()
|
2013-04-20 10:40:45 +08:00
|
|
|
.GetScalar()
|
2013-04-13 02:10:34 +08:00
|
|
|
.ULongLong();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
if (!m_persistent_variable_sp->m_live_sp) {
|
|
|
|
err.SetErrorStringWithFormat(
|
2013-05-17 08:55:28 +08:00
|
|
|
"couldn't find the memory area used to store %s",
|
|
|
|
m_persistent_variable_sp->GetName().GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-05-17 08:55:28 +08:00
|
|
|
if (m_persistent_variable_sp->m_live_sp->GetValue()
|
|
|
|
.GetValueAddressType() != eAddressTypeLoad) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"the address of the memory area for %s is in an incorrect format",
|
|
|
|
m_persistent_variable_sp->GetName().GetCString());
|
2013-04-13 02:10:34 +08:00
|
|
|
return;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
if (m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVNeedsFreezeDry ||
|
|
|
|
m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVKeepInTarget) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Dematerializing %s from 0x%" PRIx64 " (size = %llu)",
|
|
|
|
m_persistent_variable_sp->GetName().GetCString(),
|
|
|
|
(uint64_t)mem,
|
2020-07-25 23:27:21 +08:00
|
|
|
(unsigned long long)m_persistent_variable_sp->GetByteSize()
|
2022-06-20 00:12:01 +08:00
|
|
|
.value_or(0));
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
// Read the contents of the spare memory area
|
|
|
|
|
2013-04-13 02:10:34 +08:00
|
|
|
m_persistent_variable_sp->ValueUpdated();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status read_error;
|
2015-10-03 17:09:01 +08:00
|
|
|
|
2015-09-30 06:52:50 +08:00
|
|
|
map.ReadMemory(m_persistent_variable_sp->GetValueBytes(), mem,
|
2022-06-20 00:12:01 +08:00
|
|
|
m_persistent_variable_sp->GetByteSize().value_or(0),
|
|
|
|
read_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-17 08:55:28 +08:00
|
|
|
if (!read_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't read the contents of %s from memory: %s",
|
2013-04-13 02:10:34 +08:00
|
|
|
m_persistent_variable_sp->GetName().GetCString(),
|
|
|
|
read_error.AsCString());
|
2013-05-17 08:55:28 +08:00
|
|
|
return;
|
2013-04-13 02:10:34 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-30 06:52:50 +08:00
|
|
|
m_persistent_variable_sp->m_flags &=
|
|
|
|
~ExpressionVariable::EVNeedsFreezeDry;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
} else {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"no dematerialization happened for persistent variable %s",
|
|
|
|
m_persistent_variable_sp->GetName().AsCString());
|
2013-04-13 02:10:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-20 10:40:45 +08:00
|
|
|
lldb::ProcessSP process_sp =
|
|
|
|
map.GetBestExecutionContextScope()->CalculateProcess();
|
|
|
|
if (!process_sp || !process_sp->CanJIT()) {
|
|
|
|
// Allocations are not persistent so persistent variables cannot stay
|
|
|
|
// materialized.
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-09-30 06:52:50 +08:00
|
|
|
m_persistent_variable_sp->m_flags |=
|
|
|
|
ExpressionVariable::EVNeedsAllocation;
|
2013-04-20 10:40:45 +08:00
|
|
|
|
|
|
|
DestroyAllocation(map, err);
|
|
|
|
if (!err.Success())
|
|
|
|
return;
|
2015-09-30 06:52:50 +08:00
|
|
|
} else if (m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVNeedsAllocation &&
|
|
|
|
!(m_persistent_variable_sp->m_flags &
|
|
|
|
ExpressionVariable::EVKeepInTarget)) {
|
2013-04-13 02:10:34 +08:00
|
|
|
DestroyAllocation(map, err);
|
|
|
|
if (!err.Success())
|
|
|
|
return;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
|
|
|
|
Log *log) override {
|
2013-04-16 06:48:23 +08:00
|
|
|
StreamString dump_stream;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status err;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
|
|
|
|
|
|
|
dump_stream.Printf("0x%" PRIx64 ": EntityPersistentVariable (%s)\n",
|
|
|
|
load_addr,
|
|
|
|
m_persistent_variable_sp->GetName().AsCString());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
{
|
|
|
|
dump_stream.Printf("Pointer:\n");
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
DataBufferHeap data(m_size, 0);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
if (!err.Success()) {
|
|
|
|
dump_stream.Printf(" <could not be read>\n");
|
|
|
|
} else {
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
|
|
|
|
load_addr);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
dump_stream.PutChar('\n');
|
2013-04-16 06:48:23 +08:00
|
|
|
}
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
{
|
|
|
|
dump_stream.Printf("Target:\n");
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
lldb::addr_t target_address;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
map.ReadPointerFromMemory(&target_address, load_addr, err);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
if (!err.Success()) {
|
|
|
|
dump_stream.Printf(" <could not be read>\n");
|
|
|
|
} else {
|
2022-06-20 00:12:01 +08:00
|
|
|
DataBufferHeap data(m_persistent_variable_sp->GetByteSize().value_or(0),
|
|
|
|
0);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
map.ReadMemory(data.GetBytes(), target_address,
|
2022-06-20 00:12:01 +08:00
|
|
|
m_persistent_variable_sp->GetByteSize().value_or(0),
|
|
|
|
err);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
if (!err.Success()) {
|
|
|
|
dump_stream.Printf(" <could not be read>\n");
|
|
|
|
} else {
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
|
|
|
|
target_address);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
dump_stream.PutChar('\n');
|
2013-04-16 06:48:23 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-16 06:48:23 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2016-11-17 05:15:24 +08:00
|
|
|
log->PutString(dump_stream.GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {}
|
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
private:
|
2015-09-05 04:49:51 +08:00
|
|
|
lldb::ExpressionVariableSP m_persistent_variable_sp;
|
2015-10-03 17:09:01 +08:00
|
|
|
Materializer::PersistentVariableDelegate *m_delegate;
|
2013-04-11 08:09:05 +08:00
|
|
|
};
|
|
|
|
|
2015-10-03 17:09:01 +08:00
|
|
|
uint32_t Materializer::AddPersistentVariable(
|
|
|
|
lldb::ExpressionVariableSP &persistent_variable_sp,
|
2017-05-12 12:51:55 +08:00
|
|
|
PersistentVariableDelegate *delegate, Status &err) {
|
2013-04-11 08:09:05 +08:00
|
|
|
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
|
2020-06-25 08:44:33 +08:00
|
|
|
*iter = std::make_unique<EntityPersistentVariable>(persistent_variable_sp,
|
|
|
|
delegate);
|
2013-04-11 08:09:05 +08:00
|
|
|
uint32_t ret = AddStructMember(**iter);
|
|
|
|
(*iter)->SetOffset(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
class EntityVariable : public Materializer::Entity {
|
|
|
|
public:
|
|
|
|
EntityVariable(lldb::VariableSP &variable_sp)
|
2022-03-15 04:32:03 +08:00
|
|
|
: Entity(), m_variable_sp(variable_sp) {
|
2013-04-13 05:40:34 +08:00
|
|
|
// Hard-coding to maximum size of a pointer since all variables are
|
|
|
|
// materialized by reference
|
2013-04-12 05:16:36 +08:00
|
|
|
m_size = 8;
|
|
|
|
m_alignment = 8;
|
2015-08-25 07:46:31 +08:00
|
|
|
m_is_reference =
|
|
|
|
m_variable_sp->GetType()->GetForwardCompilerType().IsReferenceType();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t process_address, Status &err) override {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Expressions);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2015-08-25 07:46:31 +08:00
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"EntityVariable::Materialize [address = 0x%" PRIx64
|
|
|
|
", m_variable_sp = %s]",
|
|
|
|
(uint64_t)load_addr, m_variable_sp->GetName().AsCString());
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
ExecutionContextScope *scope = frame_sp.get();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
if (!scope)
|
|
|
|
scope = map.GetBestExecutionContextScope();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 01:12:47 +08:00
|
|
|
lldb::ValueObjectSP valobj_sp =
|
|
|
|
ValueObjectVariable::Create(scope, m_variable_sp);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 01:12:47 +08:00
|
|
|
if (!valobj_sp) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't get a value object for variable %s",
|
|
|
|
m_variable_sp->GetName().AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status valobj_error = valobj_sp->GetError();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
if (valobj_error.Fail()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat("couldn't get the value of variable %s: %s",
|
|
|
|
m_variable_sp->GetName().AsCString(),
|
|
|
|
valobj_error.AsCString());
|
2013-04-13 05:40:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
if (m_is_reference) {
|
|
|
|
DataExtractor valobj_extractor;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status extract_error;
|
2014-03-01 06:27:53 +08:00
|
|
|
valobj_sp->GetData(valobj_extractor, extract_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2014-03-01 06:27:53 +08:00
|
|
|
if (!extract_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't read contents of reference variable %s: %s",
|
|
|
|
m_variable_sp->GetName().AsCString(), extract_error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
lldb::offset_t offset = 0;
|
2014-03-01 06:27:53 +08:00
|
|
|
lldb::addr_t reference_addr = valobj_extractor.GetAddress(&offset);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status write_error;
|
2014-03-01 06:27:53 +08:00
|
|
|
map.WritePointerToMemory(load_addr, reference_addr, write_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-03-01 06:27:53 +08:00
|
|
|
if (!write_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat("couldn't write the contents of reference "
|
2013-05-17 08:55:28 +08:00
|
|
|
"variable %s to memory: %s",
|
|
|
|
m_variable_sp->GetName().AsCString(),
|
|
|
|
write_error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2014-01-08 07:15:26 +08:00
|
|
|
AddressType address_type = eAddressTypeInvalid;
|
|
|
|
const bool scalar_is_load_address = false;
|
2014-03-01 06:27:53 +08:00
|
|
|
lldb::addr_t addr_of_valobj =
|
|
|
|
valobj_sp->GetAddressOf(scalar_is_load_address, &address_type);
|
2013-10-23 04:01:17 +08:00
|
|
|
if (addr_of_valobj != LLDB_INVALID_ADDRESS) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status write_error;
|
2013-10-23 04:01:17 +08:00
|
|
|
map.WritePointerToMemory(load_addr, addr_of_valobj, write_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
if (!write_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
2014-03-01 06:27:53 +08:00
|
|
|
"couldn't write the address of variable %s to memory: %s",
|
|
|
|
m_variable_sp->GetName().AsCString(), write_error.AsCString());
|
|
|
|
return;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-04-13 05:40:34 +08:00
|
|
|
DataExtractor data;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status extract_error;
|
2014-03-01 06:27:53 +08:00
|
|
|
valobj_sp->GetData(data, extract_error);
|
|
|
|
if (!extract_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat("couldn't get the value of %s: %s",
|
|
|
|
m_variable_sp->GetName().AsCString(),
|
|
|
|
extract_error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"trying to create a temporary region for %s but one exists",
|
|
|
|
m_variable_sp->GetName().AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-22 04:53:43 +08:00
|
|
|
if (data.GetByteSize() < m_variable_sp->GetType()->GetByteSize(scope)) {
|
2013-05-17 08:55:28 +08:00
|
|
|
if (data.GetByteSize() == 0 &&
|
2018-12-15 08:15:33 +08:00
|
|
|
!m_variable_sp->LocationExpression().IsValid()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat("the variable '%s' has no location, "
|
|
|
|
"it may have been optimized out",
|
|
|
|
m_variable_sp->GetName().AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2016-03-09 02:35:09 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"size of variable %s (%" PRIu64
|
|
|
|
") is larger than the ValueObject's size (%" PRIu64 ")",
|
2013-11-14 02:01:16 +08:00
|
|
|
m_variable_sp->GetName().AsCString(),
|
2022-06-20 00:12:01 +08:00
|
|
|
m_variable_sp->GetType()->GetByteSize(scope).value_or(0),
|
2019-01-30 01:52:34 +08:00
|
|
|
data.GetByteSize());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-13 04:03:19 +08:00
|
|
|
llvm::Optional<size_t> opt_bit_align =
|
2019-08-13 05:49:54 +08:00
|
|
|
m_variable_sp->GetType()->GetLayoutCompilerType().GetTypeBitAlign(scope);
|
2019-08-13 04:03:19 +08:00
|
|
|
if (!opt_bit_align) {
|
|
|
|
err.SetErrorStringWithFormat("can't get the type alignment for %s",
|
|
|
|
m_variable_sp->GetName().AsCString());
|
|
|
|
return;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-08-13 04:03:19 +08:00
|
|
|
size_t byte_align = (*opt_bit_align + 7) / 8;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status alloc_error;
|
2015-11-05 04:32:27 +08:00
|
|
|
const bool zero_memory = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-05 04:32:27 +08:00
|
|
|
m_temporary_allocation = map.Malloc(
|
2013-05-17 08:55:28 +08:00
|
|
|
data.GetByteSize(), byte_align,
|
2015-11-05 04:32:27 +08:00
|
|
|
lldb::ePermissionsReadable | lldb::ePermissionsWritable,
|
|
|
|
IRMemoryMap::eAllocationPolicyMirror, zero_memory, alloc_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
m_temporary_allocation_size = data.GetByteSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-02-12 07:13:08 +08:00
|
|
|
m_original_data = std::make_shared<DataBufferHeap>(data.GetDataStart(),
|
|
|
|
data.GetByteSize());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2014-03-01 06:27:53 +08:00
|
|
|
if (!alloc_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat(
|
2013-05-17 08:55:28 +08:00
|
|
|
"couldn't allocate a temporary region for %s: %s",
|
|
|
|
m_variable_sp->GetName().AsCString(), alloc_error.AsCString());
|
2013-04-13 05:40:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status write_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-17 08:55:28 +08:00
|
|
|
map.WriteMemory(m_temporary_allocation, data.GetDataStart(),
|
2016-03-09 02:35:09 +08:00
|
|
|
data.GetByteSize(), write_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-14 09:14:40 +08:00
|
|
|
if (!write_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't write to the temporary region for %s: %s",
|
|
|
|
m_variable_sp->GetName().AsCString(), write_error.AsCString());
|
2013-04-13 05:40:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status pointer_write_error;
|
2013-04-13 05:40:34 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
map.WritePointerToMemory(load_addr, m_temporary_allocation,
|
|
|
|
pointer_write_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
if (!pointer_write_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't write the address of the temporary region for %s: %s",
|
2013-04-13 05:40:34 +08:00
|
|
|
m_variable_sp->GetName().AsCString(),
|
|
|
|
pointer_write_error.AsCString());
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
|
|
|
lldb::addr_t process_address, lldb::addr_t frame_top,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t frame_bottom, Status &err) override {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Expressions);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"EntityVariable::Dematerialize [address = 0x%" PRIx64
|
|
|
|
", m_variable_sp = %s]",
|
|
|
|
(uint64_t)load_addr, m_variable_sp->GetName().AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {
|
2013-04-16 01:12:47 +08:00
|
|
|
ExecutionContextScope *scope = frame_sp.get();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 01:12:47 +08:00
|
|
|
if (!scope)
|
|
|
|
scope = map.GetBestExecutionContextScope();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 01:12:47 +08:00
|
|
|
lldb::ValueObjectSP valobj_sp =
|
|
|
|
ValueObjectVariable::Create(scope, m_variable_sp);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
if (!valobj_sp) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't get a value object for variable %s",
|
|
|
|
m_variable_sp->GetName().AsCString());
|
2013-04-13 05:40:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 10:06:42 +08:00
|
|
|
lldb_private::DataExtractor data;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status extract_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2020-07-25 23:27:21 +08:00
|
|
|
map.GetMemoryData(data, m_temporary_allocation,
|
2022-06-20 00:12:01 +08:00
|
|
|
valobj_sp->GetByteSize().value_or(0), extract_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 10:06:42 +08:00
|
|
|
if (!extract_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat("couldn't get the data for variable %s",
|
|
|
|
m_variable_sp->GetName().AsCString());
|
2013-04-13 10:06:42 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2014-03-26 06:30:19 +08:00
|
|
|
bool actually_write = true;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2014-03-26 06:30:19 +08:00
|
|
|
if (m_original_data) {
|
|
|
|
if ((data.GetByteSize() == m_original_data->GetByteSize()) &&
|
2014-04-25 05:43:04 +08:00
|
|
|
!memcmp(m_original_data->GetBytes(), data.GetDataStart(),
|
|
|
|
data.GetByteSize())) {
|
2014-03-26 06:30:19 +08:00
|
|
|
actually_write = false;
|
|
|
|
}
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status set_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2014-03-26 06:30:19 +08:00
|
|
|
if (actually_write) {
|
|
|
|
valobj_sp->SetData(data, set_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2014-03-26 06:30:19 +08:00
|
|
|
if (!set_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't write the new contents of %s back into the variable",
|
|
|
|
m_variable_sp->GetName().AsCString());
|
|
|
|
return;
|
|
|
|
}
|
2013-04-13 10:06:42 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status free_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
map.Free(m_temporary_allocation, free_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 05:40:34 +08:00
|
|
|
if (!free_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't free the temporary region for %s: %s",
|
|
|
|
m_variable_sp->GetName().AsCString(), free_error.AsCString());
|
2013-04-13 05:40:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2014-03-26 06:30:19 +08:00
|
|
|
m_original_data.reset();
|
2013-04-13 05:40:34 +08:00
|
|
|
m_temporary_allocation = LLDB_INVALID_ADDRESS;
|
2013-04-16 06:48:23 +08:00
|
|
|
m_temporary_allocation_size = 0;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
|
|
|
|
Log *log) override {
|
2013-04-16 06:48:23 +08:00
|
|
|
StreamString dump_stream;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
|
|
|
dump_stream.Printf("0x%" PRIx64 ": EntityVariable\n", load_addr);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status err;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
{
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.Printf("Pointer:\n");
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
DataBufferHeap data(m_size, 0);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
if (!err.Success()) {
|
|
|
|
dump_stream.Printf(" <could not be read>\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-07-12 06:46:58 +08:00
|
|
|
DataExtractor extractor(data.GetBytes(), data.GetByteSize(),
|
|
|
|
map.GetByteOrder(), map.GetAddressByteSize());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
|
|
|
|
load_addr);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2022-01-26 23:46:19 +08:00
|
|
|
lldb::offset_t offset = 0;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2020-02-18 17:37:04 +08:00
|
|
|
ptr = extractor.GetAddress(&offset);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.PutChar('\n');
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (m_temporary_allocation == LLDB_INVALID_ADDRESS) {
|
|
|
|
dump_stream.Printf("Points to process memory:\n");
|
|
|
|
} else {
|
2013-04-17 07:25:35 +08:00
|
|
|
dump_stream.Printf("Temporary allocation:\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
if (ptr == LLDB_INVALID_ADDRESS) {
|
|
|
|
dump_stream.Printf(" <could not be be found>\n");
|
|
|
|
} else {
|
|
|
|
DataBufferHeap data(m_temporary_allocation_size, 0);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
map.ReadMemory(data.GetBytes(), m_temporary_allocation,
|
|
|
|
m_temporary_allocation_size, err);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
if (!err.Success()) {
|
|
|
|
dump_stream.Printf(" <could not be read>\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
|
|
|
|
load_addr);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.PutChar('\n');
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-16 06:48:23 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2016-11-17 05:15:24 +08:00
|
|
|
log->PutString(dump_stream.GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {
|
|
|
|
if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status free_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
map.Free(m_temporary_allocation, free_error);
|
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
m_temporary_allocation = LLDB_INVALID_ADDRESS;
|
2013-04-17 07:25:35 +08:00
|
|
|
m_temporary_allocation_size = 0;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-10-27 01:00:13 +08:00
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
private:
|
2013-04-13 05:40:34 +08:00
|
|
|
lldb::VariableSP m_variable_sp;
|
2022-03-15 04:32:03 +08:00
|
|
|
bool m_is_reference = false;
|
|
|
|
lldb::addr_t m_temporary_allocation = LLDB_INVALID_ADDRESS;
|
|
|
|
size_t m_temporary_allocation_size = 0;
|
2014-03-26 06:30:19 +08:00
|
|
|
lldb::DataBufferSP m_original_data;
|
2013-04-11 08:09:05 +08:00
|
|
|
};
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
uint32_t Materializer::AddVariable(lldb::VariableSP &variable_sp, Status &err) {
|
2013-04-11 08:09:05 +08:00
|
|
|
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
|
2020-06-25 08:44:33 +08:00
|
|
|
*iter = std::make_unique<EntityVariable>(variable_sp);
|
2013-04-11 08:09:05 +08:00
|
|
|
uint32_t ret = AddStructMember(**iter);
|
|
|
|
(*iter)->SetOffset(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
class EntityResultVariable : public Materializer::Entity {
|
|
|
|
public:
|
2015-10-03 17:09:01 +08:00
|
|
|
EntityResultVariable(const CompilerType &type, bool is_program_reference,
|
|
|
|
bool keep_in_memory,
|
|
|
|
Materializer::PersistentVariableDelegate *delegate)
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
: Entity(), m_type(type), m_is_program_reference(is_program_reference),
|
2022-03-15 04:32:03 +08:00
|
|
|
m_keep_in_memory(keep_in_memory), m_delegate(delegate) {
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
// Hard-coding to maximum size of a pointer since all results are
|
|
|
|
// materialized by reference
|
|
|
|
m_size = 8;
|
|
|
|
m_alignment = 8;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t process_address, Status &err) override {
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (!m_is_program_reference) {
|
|
|
|
if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {
|
|
|
|
err.SetErrorString("Trying to create a temporary region for the result "
|
|
|
|
"but one exists");
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-11-05 04:32:27 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2020-07-09 05:35:02 +08:00
|
|
|
ExecutionContextScope *exe_scope = frame_sp.get();
|
|
|
|
if (!exe_scope)
|
|
|
|
exe_scope = map.GetBestExecutionContextScope();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2019-01-16 04:33:58 +08:00
|
|
|
llvm::Optional<uint64_t> byte_size = m_type.GetByteSize(exe_scope);
|
2019-01-16 02:07:52 +08:00
|
|
|
if (!byte_size) {
|
2021-06-12 08:58:05 +08:00
|
|
|
err.SetErrorStringWithFormat("can't get size of type \"%s\"",
|
|
|
|
m_type.GetTypeName().AsCString());
|
2019-01-16 02:07:52 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2019-08-13 05:49:54 +08:00
|
|
|
llvm::Optional<size_t> opt_bit_align = m_type.GetTypeBitAlign(exe_scope);
|
2019-08-13 04:03:19 +08:00
|
|
|
if (!opt_bit_align) {
|
2021-06-12 08:58:05 +08:00
|
|
|
err.SetErrorStringWithFormat("can't get the alignment of type \"%s\"",
|
|
|
|
m_type.GetTypeName().AsCString());
|
2019-08-13 04:03:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t byte_align = (*opt_bit_align + 7) / 8;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status alloc_error;
|
2013-07-12 06:46:58 +08:00
|
|
|
const bool zero_memory = true;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
m_temporary_allocation = map.Malloc(
|
2019-01-16 02:07:52 +08:00
|
|
|
*byte_size, byte_align,
|
2013-07-12 06:46:58 +08:00
|
|
|
lldb::ePermissionsReadable | lldb::ePermissionsWritable,
|
|
|
|
IRMemoryMap::eAllocationPolicyMirror, zero_memory, alloc_error);
|
2019-01-16 02:07:52 +08:00
|
|
|
m_temporary_allocation_size = *byte_size;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (!alloc_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't allocate a temporary region for the result: %s",
|
|
|
|
alloc_error.AsCString());
|
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status pointer_write_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
map.WritePointerToMemory(load_addr, m_temporary_allocation,
|
|
|
|
pointer_write_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-03 02:40:30 +08:00
|
|
|
if (!pointer_write_error.Success()) {
|
|
|
|
err.SetErrorStringWithFormat("couldn't write the address of the "
|
|
|
|
"temporary region for the result: %s",
|
|
|
|
pointer_write_error.AsCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-03 02:40:30 +08:00
|
|
|
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
|
|
|
lldb::addr_t process_address, lldb::addr_t frame_top,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t frame_bottom, Status &err) override {
|
2015-10-03 02:40:30 +08:00
|
|
|
err.Clear();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2020-07-09 05:35:02 +08:00
|
|
|
ExecutionContextScope *exe_scope = frame_sp.get();
|
|
|
|
if (!exe_scope)
|
|
|
|
exe_scope = map.GetBestExecutionContextScope();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-01 03:57:57 +08:00
|
|
|
if (!exe_scope) {
|
|
|
|
err.SetErrorString("Couldn't dematerialize a result variable: invalid "
|
|
|
|
"execution context scope");
|
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
lldb::addr_t address;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status read_error;
|
2015-10-03 17:09:01 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-02 07:07:06 +08:00
|
|
|
map.ReadPointerFromMemory(&address, load_addr, read_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (!read_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorString("Couldn't dematerialize a result variable: couldn't "
|
|
|
|
"read its address");
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-20 10:40:45 +08:00
|
|
|
lldb::TargetSP target_sp = exe_scope->CalculateTarget();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-03 17:09:01 +08:00
|
|
|
if (!target_sp) {
|
|
|
|
err.SetErrorString("Couldn't dematerialize a result variable: no target");
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
2015-10-03 17:09:01 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2019-07-31 06:12:34 +08:00
|
|
|
auto type_system_or_err =
|
|
|
|
target_sp->GetScratchTypeSystemForLanguage(m_type.GetMinimumLanguage());
|
2013-04-20 10:40:45 +08:00
|
|
|
|
2019-07-31 06:12:34 +08:00
|
|
|
if (auto error = type_system_or_err.takeError()) {
|
2013-04-20 10:40:45 +08:00
|
|
|
err.SetErrorStringWithFormat("Couldn't dematerialize a result variable: "
|
|
|
|
"couldn't get the corresponding type "
|
|
|
|
"system: %s",
|
2019-07-31 06:12:34 +08:00
|
|
|
llvm::toString(std::move(error)).c_str());
|
2013-10-09 10:04:57 +08:00
|
|
|
return;
|
2013-04-20 10:40:45 +08:00
|
|
|
}
|
2015-10-01 03:57:57 +08:00
|
|
|
PersistentExpressionState *persistent_state =
|
2019-07-31 06:12:34 +08:00
|
|
|
type_system_or_err->GetPersistentExpressionState();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (!persistent_state) {
|
|
|
|
err.SetErrorString("Couldn't dematerialize a result variable: "
|
|
|
|
"corresponding type system doesn't handle persistent "
|
|
|
|
"variables");
|
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2020-03-21 05:59:54 +08:00
|
|
|
ConstString name = m_delegate
|
|
|
|
? m_delegate->GetName()
|
|
|
|
: persistent_state->GetNextPersistentVariableName();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
lldb::ExpressionVariableSP ret = persistent_state->CreatePersistentVariable(
|
|
|
|
exe_scope, name, m_type, map.GetByteOrder(), map.GetAddressByteSize());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-20 10:40:45 +08:00
|
|
|
if (!ret) {
|
2015-09-30 06:52:50 +08:00
|
|
|
err.SetErrorStringWithFormat("couldn't dematerialize a result variable: "
|
|
|
|
"failed to make persistent variable %s",
|
2013-05-17 08:55:28 +08:00
|
|
|
name.AsCString());
|
2015-09-30 06:52:50 +08:00
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-20 10:40:45 +08:00
|
|
|
lldb::ProcessSP process_sp =
|
|
|
|
map.GetBestExecutionContextScope()->CalculateProcess();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-03 17:09:01 +08:00
|
|
|
if (m_delegate) {
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
m_delegate->DidDematerialize(ret);
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
bool can_persist =
|
|
|
|
(m_is_program_reference && process_sp && process_sp->CanJIT() &&
|
|
|
|
!(address >= frame_bottom && address < frame_top));
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
if (can_persist && m_keep_in_memory) {
|
|
|
|
ret->m_live_sp = ValueObjectConstResult::Create(exe_scope, m_type, name,
|
|
|
|
address, eAddressTypeLoad,
|
|
|
|
map.GetAddressByteSize());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-07-12 06:46:58 +08:00
|
|
|
|
|
|
|
ret->ValueUpdated();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2022-06-20 00:12:01 +08:00
|
|
|
const size_t pvar_byte_size = ret->GetByteSize().value_or(0);
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
uint8_t *pvar_data = ret->GetValueBytes();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
map.ReadMemory(pvar_data, address, pvar_byte_size, read_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (!read_error.Success()) {
|
|
|
|
err.SetErrorString(
|
|
|
|
"Couldn't dematerialize a result variable: couldn't read its memory");
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (!can_persist || !m_keep_in_memory) {
|
|
|
|
ret->m_flags |= ExpressionVariable::EVNeedsAllocation;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
if (m_temporary_allocation != LLDB_INVALID_ADDRESS) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status free_error;
|
2013-07-12 06:46:58 +08:00
|
|
|
map.Free(m_temporary_allocation, free_error);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2013-07-12 06:46:58 +08:00
|
|
|
ret->m_flags |= ExpressionVariable::EVIsLLDBAllocated;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
m_temporary_allocation = LLDB_INVALID_ADDRESS;
|
|
|
|
m_temporary_allocation_size = 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
|
2015-10-27 01:00:13 +08:00
|
|
|
Log *log) override {
|
2013-07-12 06:46:58 +08:00
|
|
|
StreamString dump_stream;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
dump_stream.Printf("0x%" PRIx64 ": EntityResultVariable\n", load_addr);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status err;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
{
|
|
|
|
dump_stream.Printf("Pointer:\n");
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
DataBufferHeap data(m_size, 0);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
if (!err.Success()) {
|
|
|
|
dump_stream.Printf(" <could not be read>\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-07-12 06:46:58 +08:00
|
|
|
DataExtractor extractor(data.GetBytes(), data.GetByteSize(),
|
|
|
|
map.GetByteOrder(), map.GetAddressByteSize());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
|
|
|
|
load_addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-01-26 23:46:19 +08:00
|
|
|
lldb::offset_t offset = 0;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2020-02-18 17:37:04 +08:00
|
|
|
ptr = extractor.GetAddress(&offset);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.PutChar('\n');
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-16 06:48:23 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (m_temporary_allocation == LLDB_INVALID_ADDRESS) {
|
|
|
|
dump_stream.Printf("Points to process memory:\n");
|
|
|
|
} else {
|
|
|
|
dump_stream.Printf("Temporary allocation:\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (ptr == LLDB_INVALID_ADDRESS) {
|
|
|
|
dump_stream.Printf(" <could not be be found>\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
DataBufferHeap data(m_temporary_allocation_size, 0);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
map.ReadMemory(data.GetBytes(), m_temporary_allocation,
|
|
|
|
m_temporary_allocation_size, err);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (!err.Success()) {
|
|
|
|
dump_stream.Printf(" <could not be read>\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
|
|
|
|
load_addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
dump_stream.PutChar('\n');
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-17 05:15:24 +08:00
|
|
|
log->PutString(dump_stream.GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
if (!m_keep_in_memory && m_temporary_allocation != LLDB_INVALID_ADDRESS) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status free_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
map.Free(m_temporary_allocation, free_error);
|
2013-04-17 07:25:35 +08:00
|
|
|
}
|
2015-10-27 01:00:13 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
m_temporary_allocation = LLDB_INVALID_ADDRESS;
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
m_temporary_allocation_size = 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
private:
|
2015-09-30 06:52:50 +08:00
|
|
|
CompilerType m_type;
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
bool m_is_program_reference;
|
2013-04-13 02:10:34 +08:00
|
|
|
bool m_keep_in_memory;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2022-03-15 04:32:03 +08:00
|
|
|
lldb::addr_t m_temporary_allocation = LLDB_INVALID_ADDRESS;
|
|
|
|
size_t m_temporary_allocation_size = 0;
|
2015-10-03 17:09:01 +08:00
|
|
|
Materializer::PersistentVariableDelegate *m_delegate;
|
2013-04-11 08:09:05 +08:00
|
|
|
};
|
|
|
|
|
2015-10-03 17:09:01 +08:00
|
|
|
uint32_t Materializer::AddResultVariable(const CompilerType &type,
|
|
|
|
bool is_program_reference,
|
|
|
|
bool keep_in_memory,
|
|
|
|
PersistentVariableDelegate *delegate,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &err) {
|
2013-04-11 08:09:05 +08:00
|
|
|
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
|
2020-06-25 08:44:33 +08:00
|
|
|
*iter = std::make_unique<EntityResultVariable>(type, is_program_reference,
|
|
|
|
keep_in_memory, delegate);
|
2013-04-11 08:09:05 +08:00
|
|
|
uint32_t ret = AddStructMember(**iter);
|
|
|
|
(*iter)->SetOffset(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
class EntitySymbol : public Materializer::Entity {
|
|
|
|
public:
|
|
|
|
EntitySymbol(const Symbol &symbol) : Entity(), m_symbol(symbol) {
|
|
|
|
// Hard-coding to maximum size of a symbol
|
|
|
|
m_size = 8;
|
|
|
|
m_alignment = 8;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t process_address, Status &err) override {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Expressions);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"EntitySymbol::Materialize [address = 0x%" PRIx64
|
|
|
|
", m_symbol = %s]",
|
|
|
|
(uint64_t)load_addr, m_symbol.GetName().AsCString());
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const Address sym_address = m_symbol.GetAddress();
|
|
|
|
|
2020-07-09 05:35:02 +08:00
|
|
|
ExecutionContextScope *exe_scope = frame_sp.get();
|
|
|
|
if (!exe_scope)
|
|
|
|
exe_scope = map.GetBestExecutionContextScope();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-06-26 05:46:34 +08:00
|
|
|
lldb::TargetSP target_sp;
|
2013-04-13 10:25:02 +08:00
|
|
|
|
|
|
|
if (exe_scope)
|
|
|
|
target_sp = map.GetBestExecutionContextScope()->CalculateTarget();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 10:25:02 +08:00
|
|
|
if (!target_sp) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't resolve symbol %s because there is no target",
|
|
|
|
m_symbol.GetName().AsCString());
|
2013-04-13 10:25:02 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 10:25:02 +08:00
|
|
|
lldb::addr_t resolved_address = sym_address.GetLoadAddress(target_sp.get());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 10:25:02 +08:00
|
|
|
if (resolved_address == LLDB_INVALID_ADDRESS)
|
|
|
|
resolved_address = sym_address.GetFileAddress();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status pointer_write_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
map.WritePointerToMemory(load_addr, resolved_address, pointer_write_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-13 10:25:02 +08:00
|
|
|
if (!pointer_write_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't write the address of symbol %s: %s",
|
|
|
|
m_symbol.GetName().AsCString(), pointer_write_error.AsCString());
|
2013-04-16 04:51:24 +08:00
|
|
|
return;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
|
|
|
lldb::addr_t process_address, lldb::addr_t frame_top,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t frame_bottom, Status &err) override {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Expressions);
|
2013-04-16 04:51:24 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"EntitySymbol::Dematerialize [address = 0x%" PRIx64
|
|
|
|
", m_symbol = %s]",
|
|
|
|
(uint64_t)load_addr, m_symbol.GetName().AsCString());
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
// no work needs to be done
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
|
|
|
|
Log *log) override {
|
|
|
|
StreamString dump_stream;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status err;
|
2013-07-12 06:46:58 +08:00
|
|
|
|
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.Printf("0x%" PRIx64 ": EntitySymbol (%s)\n", load_addr,
|
|
|
|
m_symbol.GetName().AsCString());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
{
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.Printf("Pointer:\n");
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
DataBufferHeap data(m_size, 0);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
if (!err.Success()) {
|
|
|
|
dump_stream.Printf(" <could not be read>\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
|
|
|
|
load_addr);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.PutChar('\n');
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-16 06:48:23 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2016-11-17 05:15:24 +08:00
|
|
|
log->PutString(dump_stream.GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {}
|
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
private:
|
|
|
|
Symbol m_symbol;
|
|
|
|
};
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
uint32_t Materializer::AddSymbol(const Symbol &symbol_sp, Status &err) {
|
2013-04-11 08:09:05 +08:00
|
|
|
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
|
2020-06-25 08:44:33 +08:00
|
|
|
*iter = std::make_unique<EntitySymbol>(symbol_sp);
|
2013-04-11 08:09:05 +08:00
|
|
|
uint32_t ret = AddStructMember(**iter);
|
|
|
|
(*iter)->SetOffset(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
class EntityRegister : public Materializer::Entity {
|
|
|
|
public:
|
|
|
|
EntityRegister(const RegisterInfo ®ister_info)
|
|
|
|
: Entity(), m_register_info(register_info) {
|
|
|
|
// Hard-coding alignment conservatively
|
|
|
|
m_size = m_register_info.byte_size;
|
|
|
|
m_alignment = m_register_info.byte_size;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t process_address, Status &err) override {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Expressions);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"EntityRegister::Materialize [address = 0x%" PRIx64
|
|
|
|
", m_register_info = %s]",
|
|
|
|
(uint64_t)load_addr, m_register_info.name);
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
RegisterValue reg_value;
|
2013-07-12 06:46:58 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
if (!frame_sp.get()) {
|
2013-07-12 06:46:58 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't materialize register %s without a stack frame",
|
2013-04-16 04:51:24 +08:00
|
|
|
m_register_info.name);
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
2013-04-16 04:51:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::RegisterContextSP reg_context_sp = frame_sp->GetRegisterContext();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-05-17 08:55:28 +08:00
|
|
|
if (!reg_context_sp->ReadRegister(&m_register_info, reg_value)) {
|
|
|
|
err.SetErrorStringWithFormat("couldn't read the value of register %s",
|
|
|
|
m_register_info.name);
|
2013-04-16 04:51:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
DataExtractor register_data;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
if (!reg_value.GetData(register_data)) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat("couldn't get the data for register %s",
|
|
|
|
m_register_info.name);
|
2013-04-16 04:51:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
if (register_data.GetByteSize() != m_register_info.byte_size) {
|
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"data for register %s had size %llu but we expected %llu",
|
2013-05-17 08:55:28 +08:00
|
|
|
m_register_info.name, (unsigned long long)register_data.GetByteSize(),
|
2013-04-16 04:51:24 +08:00
|
|
|
(unsigned long long)m_register_info.byte_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2019-02-12 07:13:08 +08:00
|
|
|
m_register_contents = std::make_shared<DataBufferHeap>(
|
|
|
|
register_data.GetDataStart(), register_data.GetByteSize());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status write_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-13 07:35:21 +08:00
|
|
|
map.WriteMemory(load_addr, register_data.GetDataStart(),
|
|
|
|
register_data.GetByteSize(), write_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
if (!write_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't write the contents of register %s: %s",
|
|
|
|
m_register_info.name, write_error.AsCString());
|
2013-04-16 04:51:24 +08:00
|
|
|
return;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
|
|
|
lldb::addr_t process_address, lldb::addr_t frame_top,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t frame_bottom, Status &err) override {
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Expressions);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"EntityRegister::Dematerialize [address = 0x%" PRIx64
|
|
|
|
", m_register_info = %s]",
|
|
|
|
(uint64_t)load_addr, m_register_info.name);
|
2013-04-16 04:51:24 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status extract_error;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
DataExtractor register_data;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
if (!frame_sp.get()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat(
|
|
|
|
"couldn't dematerialize register %s without a stack frame",
|
|
|
|
m_register_info.name);
|
2013-04-16 04:51:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
lldb::RegisterContextSP reg_context_sp = frame_sp->GetRegisterContext();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
map.GetMemoryData(register_data, load_addr, m_register_info.byte_size,
|
|
|
|
extract_error);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
if (!extract_error.Success()) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat("couldn't get the data for register %s: %s",
|
|
|
|
m_register_info.name,
|
|
|
|
extract_error.AsCString());
|
2013-04-16 04:51:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-13 07:35:21 +08:00
|
|
|
if (!memcmp(register_data.GetDataStart(), m_register_contents->GetBytes(),
|
|
|
|
register_data.GetByteSize())) {
|
|
|
|
// No write required, and in particular we avoid errors if the register
|
|
|
|
// wasn't writable
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-13 07:35:21 +08:00
|
|
|
m_register_contents.reset();
|
|
|
|
return;
|
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-13 07:35:21 +08:00
|
|
|
m_register_contents.reset();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2020-09-07 15:33:58 +08:00
|
|
|
RegisterValue register_value(register_data.GetData(),
|
|
|
|
register_data.GetByteOrder());
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 04:51:24 +08:00
|
|
|
if (!reg_context_sp->WriteRegister(&m_register_info, register_value)) {
|
2013-05-17 08:55:28 +08:00
|
|
|
err.SetErrorStringWithFormat("couldn't write the value of register %s",
|
|
|
|
m_register_info.name);
|
2013-04-16 04:51:24 +08:00
|
|
|
return;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
void DumpToLog(IRMemoryMap &map, lldb::addr_t process_address,
|
|
|
|
Log *log) override {
|
2013-04-16 06:48:23 +08:00
|
|
|
StreamString dump_stream;
|
2013-07-12 06:46:58 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status err;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const lldb::addr_t load_addr = process_address + m_offset;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.Printf("0x%" PRIx64 ": EntityRegister (%s)\n", load_addr,
|
|
|
|
m_register_info.name);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
{
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.Printf("Value:\n");
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
DataBufferHeap data(m_size, 0);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
map.ReadMemory(data.GetBytes(), load_addr, m_size, err);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
if (!err.Success()) {
|
|
|
|
dump_stream.Printf(" <could not be read>\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2017-03-04 04:57:05 +08:00
|
|
|
DumpHexBytes(&dump_stream, data.GetBytes(), data.GetByteSize(), 16,
|
|
|
|
load_addr);
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-16 06:48:23 +08:00
|
|
|
dump_stream.PutChar('\n');
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-16 06:48:23 +08:00
|
|
|
}
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2016-11-17 05:15:24 +08:00
|
|
|
log->PutString(dump_stream.GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
void Wipe(IRMemoryMap &map, lldb::addr_t process_address) override {}
|
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
private:
|
|
|
|
RegisterInfo m_register_info;
|
2013-07-13 07:35:21 +08:00
|
|
|
lldb::DataBufferSP m_register_contents;
|
2013-04-11 08:09:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t Materializer::AddRegister(const RegisterInfo ®ister_info,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &err) {
|
2013-04-11 08:09:05 +08:00
|
|
|
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
|
2020-06-25 08:44:33 +08:00
|
|
|
*iter = std::make_unique<EntityRegister>(register_info);
|
2013-04-11 08:09:05 +08:00
|
|
|
uint32_t ret = AddStructMember(**iter);
|
|
|
|
(*iter)->SetOffset(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
Materializer::~Materializer() {
|
|
|
|
DematerializerSP dematerializer_sp = m_dematerializer_wp.lock();
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
if (dematerializer_sp)
|
|
|
|
dematerializer_sp->Wipe();
|
|
|
|
}
|
2013-04-11 08:09:05 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
Materializer::DematerializerSP
|
2013-11-04 17:33:30 +08:00
|
|
|
Materializer::Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::addr_t process_address, Status &error) {
|
2013-04-16 01:12:47 +08:00
|
|
|
ExecutionContextScope *exe_scope = frame_sp.get();
|
|
|
|
if (!exe_scope)
|
|
|
|
exe_scope = map.GetBestExecutionContextScope();
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
DematerializerSP dematerializer_sp = m_dematerializer_wp.lock();
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
if (dematerializer_sp) {
|
|
|
|
error.SetErrorToGenericError();
|
|
|
|
error.SetErrorString("Couldn't materialize: already materialized");
|
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
DematerializerSP ret(
|
|
|
|
new Dematerializer(*this, frame_sp, map, process_address));
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-16 01:12:47 +08:00
|
|
|
if (!exe_scope) {
|
|
|
|
error.SetErrorToGenericError();
|
2013-04-17 07:25:35 +08:00
|
|
|
error.SetErrorString("Couldn't materialize: target doesn't exist");
|
2013-04-16 01:12:47 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
for (EntityUP &entity_up : m_entities) {
|
|
|
|
entity_up->Materialize(frame_sp, map, process_address, error);
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
if (!error.Success())
|
2013-04-17 07:25:35 +08:00
|
|
|
return DematerializerSP();
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
if (Log *log = GetLog(LLDBLog::Expressions)) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(
|
|
|
|
log,
|
2014-04-04 12:06:10 +08:00
|
|
|
"Materializer::Materialize (frame_sp = %p, process_address = 0x%" PRIx64
|
|
|
|
") materialized:",
|
|
|
|
static_cast<void *>(frame_sp.get()), process_address);
|
2013-04-16 06:48:23 +08:00
|
|
|
for (EntityUP &entity_up : m_entities)
|
|
|
|
entity_up->DumpToLog(map, process_address, log);
|
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
m_dematerializer_wp = ret;
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
return ret;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
void Materializer::Dematerializer::Dematerialize(Status &error,
|
2015-10-03 17:09:01 +08:00
|
|
|
lldb::addr_t frame_bottom,
|
|
|
|
lldb::addr_t frame_top) {
|
2013-11-04 17:33:30 +08:00
|
|
|
lldb::StackFrameSP frame_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-06-21 02:42:16 +08:00
|
|
|
lldb::ThreadSP thread_sp = m_thread_wp.lock();
|
|
|
|
if (thread_sp)
|
|
|
|
frame_sp = thread_sp->GetFrameWithStackID(m_stack_id);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-07-09 05:35:02 +08:00
|
|
|
ExecutionContextScope *exe_scope = frame_sp.get();
|
|
|
|
if (!exe_scope)
|
|
|
|
exe_scope = m_map->GetBestExecutionContextScope();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
if (!IsValid()) {
|
|
|
|
error.SetErrorToGenericError();
|
|
|
|
error.SetErrorString("Couldn't dematerialize: invalid dematerializer");
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-16 01:12:47 +08:00
|
|
|
if (!exe_scope) {
|
2013-04-11 08:09:05 +08:00
|
|
|
error.SetErrorToGenericError();
|
2013-04-16 01:12:47 +08:00
|
|
|
error.SetErrorString("Couldn't dematerialize: target is gone");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2022-01-31 22:57:48 +08:00
|
|
|
if (Log *log = GetLog(LLDBLog::Expressions)) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Materializer::Dematerialize (frame_sp = %p, process_address "
|
|
|
|
"= 0x%" PRIx64 ") about to dematerialize:",
|
|
|
|
static_cast<void *>(frame_sp.get()), m_process_address);
|
2013-04-17 07:25:35 +08:00
|
|
|
for (EntityUP &entity_up : m_materializer->m_entities)
|
|
|
|
entity_up->DumpToLog(*m_map, m_process_address, log);
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
for (EntityUP &entity_up : m_materializer->m_entities) {
|
2015-10-03 17:09:01 +08:00
|
|
|
entity_up->Dematerialize(frame_sp, *m_map, m_process_address, frame_top,
|
|
|
|
frame_bottom, error);
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-11 08:09:05 +08:00
|
|
|
if (!error.Success())
|
|
|
|
break;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
Wipe();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Materializer::Dematerializer::Wipe() {
|
|
|
|
if (!IsValid())
|
|
|
|
return;
|
2016-02-27 06:12:35 +08:00
|
|
|
|
2013-04-17 07:25:35 +08:00
|
|
|
for (EntityUP &entity_up : m_materializer->m_entities) {
|
|
|
|
entity_up->Wipe(*m_map, m_process_address);
|
|
|
|
}
|
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
m_materializer = nullptr;
|
|
|
|
m_map = nullptr;
|
2013-04-17 07:25:35 +08:00
|
|
|
m_process_address = LLDB_INVALID_ADDRESS;
|
2013-04-11 08:09:05 +08:00
|
|
|
}
|
2015-10-03 17:09:01 +08:00
|
|
|
|
2015-10-27 01:00:13 +08:00
|
|
|
Materializer::PersistentVariableDelegate::~PersistentVariableDelegate() =
|
|
|
|
default;
|