summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2015-10-03 09:09:01 +0000
committerSean Callanan <scallanan@apple.com>2015-10-03 09:09:01 +0000
commit9fda9d2177abd04e272d0f512555d3eca9e36426 (patch)
tree6f6547a919e7e5fd8ad46fc728667ca865300474
parent5860fe1bfba1561a7115e7bc0be2892eb0817013 (diff)
downloadbcm5719-llvm-9fda9d2177abd04e272d0f512555d3eca9e36426.tar.gz
bcm5719-llvm-9fda9d2177abd04e272d0f512555d3eca9e36426.zip
Add PersistentVariableDelegate to handle language-specific dematerialization.
The concept here is that languages may have different ways of communicating results. In particular, languages may have different names for their result variables and in fact may have multiple types of result variables (e.g., error results). Materializer was tied to one specific model of result handling. Instead, now UserExpressions can register their own handlers for the result variables they inject. This allows language-specific code in Materializer to be moved into the expression parser plug-in, and it simplifies Materializer. These delegates are subclasses of PersistentVariableDelegate. PersistentVariableDelegate can provide the name of the result variable, and is notified when the result variable is populated. It can also be used to touch persistent variables if need be, updating language-specific state. The UserExpression owns the delegate and can decide on its result based on consulting all of its (potentially multiple) delegates. The user expression itself now makes the determination of what the final result of the expression is, rather than relying on the Materializer, and I've added a virtual function to UserExpression to allow this. llvm-svn: 249233
-rw-r--r--lldb/include/lldb/Expression/Materializer.h37
-rw-r--r--lldb/include/lldb/Expression/UserExpression.h6
-rw-r--r--lldb/source/Expression/Materializer.cpp75
-rw-r--r--lldb/source/Expression/UserExpression.cpp4
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp15
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h6
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp58
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h25
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp2
9 files changed, 168 insertions, 60 deletions
diff --git a/lldb/include/lldb/Expression/Materializer.h b/lldb/include/lldb/Expression/Materializer.h
index 2bea8c12114..54323784a8b 100644
--- a/lldb/include/lldb/Expression/Materializer.h
+++ b/lldb/include/lldb/Expression/Materializer.h
@@ -44,7 +44,6 @@ public:
}
void Dematerialize (Error &err,
- lldb::ExpressionVariableSP &result_sp,
lldb::addr_t frame_top,
lldb::addr_t frame_bottom);
@@ -84,11 +83,28 @@ public:
DematerializerSP Materialize (lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Error &err);
- uint32_t AddPersistentVariable (lldb::ExpressionVariableSP &persistent_variable_sp, Error &err);
- uint32_t AddVariable (lldb::VariableSP &variable_sp, Error &err);
- uint32_t AddResultVariable (const CompilerType &type, bool is_lvalue, bool keep_in_memory, Error &err);
- uint32_t AddSymbol (const Symbol &symbol_sp, Error &err);
- uint32_t AddRegister (const RegisterInfo &register_info, Error &err);
+ class PersistentVariableDelegate
+ {
+ public:
+ virtual ~PersistentVariableDelegate();
+ virtual ConstString GetName() = 0;
+ virtual void DidDematerialize(lldb::ExpressionVariableSP &variable) = 0;
+ };
+
+ uint32_t AddPersistentVariable (lldb::ExpressionVariableSP &persistent_variable_sp,
+ PersistentVariableDelegate *delegate,
+ Error &err);
+ uint32_t AddVariable (lldb::VariableSP &variable_sp,
+ Error &err);
+ uint32_t AddResultVariable (const CompilerType &type,
+ bool is_lvalue,
+ bool keep_in_memory,
+ PersistentVariableDelegate *delegate,
+ Error &err);
+ uint32_t AddSymbol (const Symbol &symbol_sp,
+ Error &err);
+ uint32_t AddRegister (const RegisterInfo &register_info,
+ Error &err);
uint32_t GetStructAlignment ()
{
@@ -100,14 +116,6 @@ public:
return m_current_offset;
}
- uint32_t GetResultOffset ()
- {
- if (m_result_entity)
- return m_result_entity->GetOffset();
- else
- return UINT32_MAX;
- }
-
class Entity
{
public:
@@ -163,7 +171,6 @@ private:
DematerializerWP m_dematerializer_wp;
EntityVector m_entities;
- Entity *m_result_entity;
uint32_t m_current_offset;
uint32_t m_struct_alignment;
};
diff --git a/lldb/include/lldb/Expression/UserExpression.h b/lldb/include/lldb/Expression/UserExpression.h
index 34ae83d354d..7a6df8c593c 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -249,6 +249,12 @@ public:
{
return true;
}
+
+ virtual lldb::ExpressionVariableSP
+ GetResultAfterDematerialization(ExecutionContextScope *exe_scope)
+ {
+ return lldb::ExpressionVariableSP();
+ }
//------------------------------------------------------------------
/// Evaluate one expression in the scratch context of the
diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp
index 9b1a11e23f7..7e748d1386a 100644
--- a/lldb/source/Expression/Materializer.cpp
+++ b/lldb/source/Expression/Materializer.cpp
@@ -65,9 +65,11 @@ Materializer::Entity::SetSizeAndAlignmentFromType (CompilerType &type)
class EntityPersistentVariable : public Materializer::Entity
{
public:
- EntityPersistentVariable (lldb::ExpressionVariableSP &persistent_variable_sp) :
+ EntityPersistentVariable (lldb::ExpressionVariableSP &persistent_variable_sp,
+ Materializer::PersistentVariableDelegate *delegate) :
Entity(),
- m_persistent_variable_sp(persistent_variable_sp)
+ m_persistent_variable_sp(persistent_variable_sp),
+ m_delegate(delegate)
{
// Hard-coding to maximum size of a pointer since persistent variables are materialized by reference
m_size = 8;
@@ -210,6 +212,11 @@ public:
m_persistent_variable_sp->m_flags);
}
+ if (m_delegate)
+ {
+ m_delegate->DidDematerialize(m_persistent_variable_sp);
+ }
+
if ((m_persistent_variable_sp->m_flags & ExpressionVariable::EVIsLLDBAllocated) ||
(m_persistent_variable_sp->m_flags & ExpressionVariable::EVIsProgramReference))
{
@@ -390,13 +397,16 @@ public:
}
private:
lldb::ExpressionVariableSP m_persistent_variable_sp;
+ Materializer::PersistentVariableDelegate *m_delegate;
};
uint32_t
-Materializer::AddPersistentVariable (lldb::ExpressionVariableSP &persistent_variable_sp, Error &err)
+Materializer::AddPersistentVariable (lldb::ExpressionVariableSP &persistent_variable_sp,
+ PersistentVariableDelegate *delegate,
+ Error &err)
{
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
- iter->reset (new EntityPersistentVariable (persistent_variable_sp));
+ iter->reset (new EntityPersistentVariable (persistent_variable_sp, delegate));
uint32_t ret = AddStructMember(**iter);
(*iter)->SetOffset(ret);
return ret;
@@ -755,13 +765,17 @@ Materializer::AddVariable (lldb::VariableSP &variable_sp, Error &err)
class EntityResultVariable : public Materializer::Entity
{
public:
- EntityResultVariable (const CompilerType &type, bool is_program_reference, bool keep_in_memory) :
+ EntityResultVariable (const CompilerType &type,
+ bool is_program_reference,
+ bool keep_in_memory,
+ Materializer::PersistentVariableDelegate *delegate) :
Entity(),
m_type(type),
m_is_program_reference(is_program_reference),
m_keep_in_memory(keep_in_memory),
m_temporary_allocation(LLDB_INVALID_ADDRESS),
- m_temporary_allocation_size(0)
+ m_temporary_allocation_size(0),
+ m_delegate(delegate)
{
// Hard-coding to maximum size of a pointer since all results are materialized by reference
m_size = 8;
@@ -816,17 +830,6 @@ public:
lldb::addr_t frame_bottom,
Error &err)
{
- err.SetErrorString("Tried to detmaterialize a result variable with the normal Dematerialize method");
- }
-
- void Dematerialize (lldb::ExpressionVariableSP &result_variable_sp,
- lldb::StackFrameSP &frame_sp,
- IRMemoryMap &map,
- lldb::addr_t process_address,
- lldb::addr_t frame_top,
- lldb::addr_t frame_bottom,
- Error &err)
- {
err.Clear();
ExecutionContextScope *exe_scope = map.GetBestExecutionContextScope();
@@ -874,7 +877,7 @@ public:
return;
}
- ConstString name = persistent_state->GetNextPersistentVariableName();
+ ConstString name = m_delegate ? m_delegate->GetName() : persistent_state->GetNextPersistentVariableName();
lldb::ExpressionVariableSP ret = persistent_state->CreatePersistentVariable(exe_scope,
name,
@@ -890,6 +893,11 @@ public:
lldb::ProcessSP process_sp = map.GetBestExecutionContextScope()->CalculateProcess();
+ if (m_delegate)
+ {
+ m_delegate->DidDematerialize(ret);
+ }
+
bool can_persist = (m_is_program_reference && process_sp && process_sp->CanJIT() && !(address >= frame_bottom && address < frame_top));
if (can_persist && m_keep_in_memory)
@@ -914,8 +922,6 @@ public:
err.SetErrorString("Couldn't dematerialize a result variable: couldn't read its memory");
return;
}
-
- result_variable_sp = persistent_state->GetVariable(name);
if (!can_persist || !m_keep_in_memory)
{
@@ -1028,16 +1034,20 @@ private:
lldb::addr_t m_temporary_allocation;
size_t m_temporary_allocation_size;
+ Materializer::PersistentVariableDelegate *m_delegate;
};
uint32_t
-Materializer::AddResultVariable (const CompilerType &type, bool is_program_reference, bool keep_in_memory, Error &err)
+Materializer::AddResultVariable (const CompilerType &type,
+ bool is_program_reference,
+ bool keep_in_memory,
+ PersistentVariableDelegate *delegate,
+ Error &err)
{
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
- iter->reset (new EntityResultVariable (type, is_program_reference, keep_in_memory));
+ iter->reset (new EntityResultVariable (type, is_program_reference, keep_in_memory, delegate));
uint32_t ret = AddStructMember(**iter);
(*iter)->SetOffset(ret);
- m_result_entity = iter->get();
return ret;
}
@@ -1349,7 +1359,6 @@ Materializer::AddRegister (const RegisterInfo &register_info, Error &err)
Materializer::Materializer () :
m_dematerializer_wp(),
- m_result_entity(NULL),
m_current_offset(0),
m_struct_alignment(8)
{
@@ -1409,7 +1418,9 @@ Materializer::Materialize (lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb:
}
void
-Materializer::Dematerializer::Dematerialize (Error &error, lldb::ExpressionVariableSP &result_sp, lldb::addr_t frame_bottom, lldb::addr_t frame_top)
+Materializer::Dematerializer::Dematerialize (Error &error,
+ lldb::addr_t frame_bottom,
+ lldb::addr_t frame_top)
{
lldb::StackFrameSP frame_sp;
@@ -1442,14 +1453,7 @@ Materializer::Dematerializer::Dematerialize (Error &error, lldb::ExpressionVaria
for (EntityUP &entity_up : m_materializer->m_entities)
{
- if (entity_up.get() == m_materializer->m_result_entity)
- {
- static_cast<EntityResultVariable*>(m_materializer->m_result_entity)->Dematerialize (result_sp, frame_sp, *m_map, m_process_address, frame_top, frame_bottom, error);
- }
- else
- {
- entity_up->Dematerialize (frame_sp, *m_map, m_process_address, frame_top, frame_bottom, error);
- }
+ entity_up->Dematerialize (frame_sp, *m_map, m_process_address, frame_top, frame_bottom, error);
if (!error.Success())
break;
@@ -1474,3 +1478,8 @@ Materializer::Dematerializer::Wipe ()
m_map = NULL;
m_process_address = LLDB_INVALID_ADDRESS;
}
+
+Materializer::PersistentVariableDelegate::~PersistentVariableDelegate()
+{
+}
+
diff --git a/lldb/source/Expression/UserExpression.cpp b/lldb/source/Expression/UserExpression.cpp
index 7e0446f507c..77e05b79616 100644
--- a/lldb/source/Expression/UserExpression.cpp
+++ b/lldb/source/Expression/UserExpression.cpp
@@ -265,7 +265,7 @@ UserExpression::FinalizeJITExecution (Stream &error_stream,
Error dematerialize_error;
- m_dematerializer_sp->Dematerialize(dematerialize_error, result, function_stack_bottom, function_stack_top);
+ m_dematerializer_sp->Dematerialize(dematerialize_error, function_stack_bottom, function_stack_top);
if (!dematerialize_error.Success())
{
@@ -273,6 +273,8 @@ UserExpression::FinalizeJITExecution (Stream &error_stream,
return false;
}
+ result = GetResultAfterDematerialization(exe_ctx.GetBestExecutionContextScope());
+
if (result)
result->TransferAddress();
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 3f0517f3c47..3da495e8c4b 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -56,11 +56,14 @@ using namespace lldb;
using namespace lldb_private;
using namespace clang;
-ClangExpressionDeclMap::ClangExpressionDeclMap (bool keep_result_in_memory, ExecutionContext &exe_ctx) :
+ClangExpressionDeclMap::ClangExpressionDeclMap (bool keep_result_in_memory,
+ Materializer::PersistentVariableDelegate *result_delegate,
+ ExecutionContext &exe_ctx) :
ClangASTSource (exe_ctx.GetTargetSP()),
m_found_entities (),
m_struct_members (),
m_keep_result_in_memory (keep_result_in_memory),
+ m_result_delegate (result_delegate),
m_parser_vars (),
m_struct_vars ()
{
@@ -216,8 +219,12 @@ ClangExpressionDeclMap::AddPersistentVariable
ast->getASTContext(),
parser_type.GetOpaqueQualType()),
context);
-
- uint32_t offset = m_parser_vars->m_materializer->AddResultVariable(user_type, is_lvalue, m_keep_result_in_memory, err);
+
+ uint32_t offset = m_parser_vars->m_materializer->AddResultVariable(user_type,
+ is_lvalue,
+ m_keep_result_in_memory,
+ m_result_delegate,
+ err);
ClangExpressionVariable *var = new ClangExpressionVariable(exe_ctx.GetBestExecutionContextScope(),
name,
@@ -381,7 +388,7 @@ ClangExpressionDeclMap::AddValueToStruct
if (is_persistent_variable)
{
ExpressionVariableSP var_sp(var->shared_from_this());
- offset = m_parser_vars->m_materializer->AddPersistentVariable(var_sp, err);
+ offset = m_parser_vars->m_materializer->AddPersistentVariable(var_sp, nullptr, err);
}
else
{
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
index 1ed2c4e3f20..a8b874d8c34 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
@@ -71,10 +71,15 @@ public:
/// the result persistent variable, and instead marks the variable
/// as persisting.
///
+ /// @param[in] delegate
+ /// If non-NULL, use this delegate to report result values. This
+ /// allows the client ClangUserExpression to report a result.
+ ///
/// @param[in] exe_ctx
/// The execution context to use when parsing.
//------------------------------------------------------------------
ClangExpressionDeclMap (bool keep_result_in_memory,
+ Materializer::PersistentVariableDelegate *result_delegate,
ExecutionContext &exe_ctx);
//------------------------------------------------------------------
@@ -391,6 +396,7 @@ private:
ExpressionVariableList m_found_entities; ///< All entities that were looked up for the parser.
ExpressionVariableList m_struct_members; ///< All entities that need to be placed in the struct.
bool m_keep_result_in_memory; ///< True if result persistent variables generated by this expression should stay in memory.
+ Materializer::PersistentVariableDelegate *m_result_delegate; ///< If non-NULL, used to report expression results to ClangUserExpression.
//----------------------------------------------------------------------
/// The following values should not live beyond parsing
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
index c32ad579fd3..22b09131855 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -336,6 +336,24 @@ ClangUserExpression::Parse (Stream &error_stream,
Error err;
InstallContext(exe_ctx);
+
+ if (Target *target = exe_ctx.GetTargetPtr())
+ {
+ if (PersistentExpressionState *persistent_state = target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC))
+ {
+ m_result_delegate.RegisterPersistentState(persistent_state);
+ }
+ else
+ {
+ error_stream.PutCString ("error: couldn't start parsing (no persistent data)");
+ return false;
+ }
+ }
+ else
+ {
+ error_stream.PutCString ("error: couldn't start parsing (no target)");
+ return false;
+ }
ScanContext(exe_ctx, err);
@@ -424,7 +442,7 @@ ClangUserExpression::Parse (Stream &error_stream,
m_materializer_ap.reset(new Materializer());
- ResetDeclMap(exe_ctx, keep_result_in_memory);
+ ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
class OnExit
{
@@ -598,10 +616,16 @@ ClangUserExpression::AddInitialArguments (ExecutionContext &exe_ctx,
return true;
}
+lldb::ExpressionVariableSP
+ClangUserExpression::GetResultAfterDematerialization(ExecutionContextScope *exe_scope)
+{
+ return m_result_delegate.GetVariable();
+}
+
void
-ClangUserExpression::ClangUserExpressionHelper::ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory)
+ClangUserExpression::ClangUserExpressionHelper::ResetDeclMap(ExecutionContext &exe_ctx, Materializer::PersistentVariableDelegate &delegate, bool keep_result_in_memory)
{
- m_expr_decl_map_up.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx));
+ m_expr_decl_map_up.reset(new ClangExpressionDeclMap(keep_result_in_memory, &delegate, exe_ctx));
}
clang::ASTConsumer *
@@ -613,3 +637,31 @@ ClangUserExpression::ClangUserExpressionHelper::ASTTransformer (clang::ASTConsum
return m_result_synthesizer_up.get();
}
+ClangUserExpression::ResultDelegate::ResultDelegate()
+{
+}
+
+ConstString
+ClangUserExpression::ResultDelegate::GetName()
+{
+ return m_persistent_state->GetNextPersistentVariableName();
+}
+
+void
+ClangUserExpression::ResultDelegate::DidDematerialize(lldb::ExpressionVariableSP &variable)
+{
+ m_variable = variable;
+}
+
+void
+ClangUserExpression::ResultDelegate::RegisterPersistentState(PersistentExpressionState *persistent_state)
+{
+ m_persistent_state = persistent_state;
+}
+
+lldb::ExpressionVariableSP &
+ClangUserExpression::ResultDelegate::GetVariable()
+{
+ return m_variable;
+}
+
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
index a2b8beda0ac..ba5f2ea895b 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
@@ -81,7 +81,7 @@ public:
}
void
- ResetDeclMap (ExecutionContext & exe_ctx, bool keep_result_in_memory);
+ ResetDeclMap (ExecutionContext & exe_ctx, Materializer::PersistentVariableDelegate &result_delegate, bool keep_result_in_memory);
//------------------------------------------------------------------
/// Return the object that the parser should allow to access ASTs.
@@ -177,10 +177,13 @@ public:
}
void
- ResetDeclMap (ExecutionContext & exe_ctx, bool keep_result_in_memory)
+ ResetDeclMap (ExecutionContext & exe_ctx, Materializer::PersistentVariableDelegate &result_delegate, bool keep_result_in_memory)
{
- m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory);
+ m_type_system_helper.ResetDeclMap(exe_ctx, result_delegate, keep_result_in_memory);
}
+
+ lldb::ExpressionVariableSP
+ GetResultAfterDematerialization(ExecutionContextScope *exe_scope) override;
private:
//------------------------------------------------------------------
@@ -197,6 +200,22 @@ private:
Stream &error_stream) override;
ClangUserExpressionHelper m_type_system_helper;
+
+ class ResultDelegate : public Materializer::PersistentVariableDelegate
+ {
+ public:
+ ResultDelegate();
+ ConstString GetName() override;
+ void DidDematerialize(lldb::ExpressionVariableSP &variable) override;
+
+ void RegisterPersistentState(PersistentExpressionState *persistent_state);
+ lldb::ExpressionVariableSP &GetVariable();
+ private:
+ PersistentExpressionState *m_persistent_state;
+ lldb::ExpressionVariableSP m_variable;
+ };
+
+ ResultDelegate m_result_delegate;
};
} // namespace lldb_private
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
index 457056c64a0..fe044c17ac7 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
@@ -185,5 +185,5 @@ ClangUtilityFunction::Install (Stream &error_stream,
void
ClangUtilityFunction::ClangUtilityFunctionHelper::ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory)
{
- m_expr_decl_map_up.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx));
+ m_expr_decl_map_up.reset(new ClangExpressionDeclMap(keep_result_in_memory, nullptr, exe_ctx));
}
OpenPOWER on IntegriCloud