summaryrefslogtreecommitdiffstats
path: root/lldb/source/Expression/ClangUserExpression.cpp
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2012-02-10 01:22:05 +0000
committerSean Callanan <scallanan@apple.com>2012-02-10 01:22:05 +0000
commit933693b6218327d9c2c75b86061f6808fdb4cdc0 (patch)
tree993701b34df0ef4b796e78d667f6f07c9a75f7cf /lldb/source/Expression/ClangUserExpression.cpp
parente963fd51a84731bf1dfa4a2d757b3459dd7cfeb5 (diff)
downloadbcm5719-llvm-933693b6218327d9c2c75b86061f6808fdb4cdc0.tar.gz
bcm5719-llvm-933693b6218327d9c2c75b86061f6808fdb4cdc0.zip
Fixed a bunch of ownership problems with the expression
parser. Specifically: - ClangUserExpression now keeps weak pointers to the structures it needs and then locks them when needed. This ensures that they continue to be valid without leaking memory if the ClangUserExpression is long lived. - ClangExpressionDeclMap, instead of keeping a pointer to an ExecutionContext, now contains an ExecutionContext. This prevents bugs if the pointer or its contents somehow become stale. It also no longer requires that ExecutionContexts be passed into any function except its initialization function, since it can count on the ExecutionContext still being around. There's a lot of room for improvement (specifically, ClangExpressionDeclMap should also use weak pointers insetad of shared pointers) but this is an important first step that codifies assumptions that already existed in the code. llvm-svn: 150217
Diffstat (limited to 'lldb/source/Expression/ClangUserExpression.cpp')
-rw-r--r--lldb/source/Expression/ClangUserExpression.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/lldb/source/Expression/ClangUserExpression.cpp b/lldb/source/Expression/ClangUserExpression.cpp
index dcecbc7a7da..a574e47de63 100644
--- a/lldb/source/Expression/ClangUserExpression.cpp
+++ b/lldb/source/Expression/ClangUserExpression.cpp
@@ -255,6 +255,8 @@ ClangUserExpression::Parse (Stream &error_stream,
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Error err;
+
+ InstallContext(exe_ctx);
ScanContext(exe_ctx, err);
@@ -385,6 +387,19 @@ ClangUserExpression::PrepareToExecuteJITExpression (Stream &error_stream,
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+ lldb::TargetSP target;
+ lldb::ProcessSP process;
+ lldb::StackFrameSP frame;
+
+ if (!LockAndCheckContext(exe_ctx,
+ target,
+ process,
+ frame))
+ {
+ error_stream.Printf("The context has changed before we could JIT the expression!");
+ return false;
+ }
+
if (m_jit_start_addr != LLDB_INVALID_ADDRESS)
{
Error materialize_error;
@@ -407,7 +422,7 @@ ClangUserExpression::PrepareToExecuteJITExpression (Stream &error_stream,
return false;
}
- if (!(m_expr_decl_map->GetObjectPointer(object_ptr, object_name, exe_ctx, materialize_error)))
+ if (!(m_expr_decl_map->GetObjectPointer(object_ptr, object_name, materialize_error)))
{
error_stream.Printf("warning: couldn't get required object pointer (substituting NULL): %s\n", materialize_error.AsCString());
object_ptr = 0;
@@ -417,7 +432,7 @@ ClangUserExpression::PrepareToExecuteJITExpression (Stream &error_stream,
{
ConstString cmd_name("_cmd");
- if (!(m_expr_decl_map->GetObjectPointer(cmd_ptr, cmd_name, exe_ctx, materialize_error, true)))
+ if (!(m_expr_decl_map->GetObjectPointer(cmd_ptr, cmd_name, materialize_error, true)))
{
error_stream.Printf("warning: couldn't get object pointer (substituting NULL): %s\n", materialize_error.AsCString());
cmd_ptr = 0;
@@ -425,7 +440,7 @@ ClangUserExpression::PrepareToExecuteJITExpression (Stream &error_stream,
}
}
- if (!m_expr_decl_map->Materialize(exe_ctx, struct_address, materialize_error))
+ if (!m_expr_decl_map->Materialize(struct_address, materialize_error))
{
error_stream.Printf("Couldn't materialize struct: %s\n", materialize_error.AsCString());
return false;
@@ -454,7 +469,7 @@ ClangUserExpression::PrepareToExecuteJITExpression (Stream &error_stream,
if (struct_address)
{
- if (!m_expr_decl_map->DumpMaterializedStruct(exe_ctx, args, dump_error))
+ if (!m_expr_decl_map->DumpMaterializedStruct(args, dump_error))
{
log->Printf(" Couldn't extract variable values : %s", dump_error.AsCString("unknown error"));
}
@@ -511,7 +526,7 @@ ClangUserExpression::FinalizeJITExecution (Stream &error_stream,
Error dump_error;
- if (!m_expr_decl_map->DumpMaterializedStruct(exe_ctx, args, dump_error))
+ if (!m_expr_decl_map->DumpMaterializedStruct(args, dump_error))
{
log->Printf(" Couldn't extract variable values : %s", dump_error.AsCString("unknown error"));
}
@@ -524,7 +539,7 @@ ClangUserExpression::FinalizeJITExecution (Stream &error_stream,
lldb::addr_t function_stack_bottom = function_stack_pointer - Host::GetPageSize();
- if (!m_expr_decl_map->Dematerialize(exe_ctx, result, function_stack_pointer, function_stack_bottom, expr_error))
+ if (!m_expr_decl_map->Dematerialize(result, function_stack_pointer, function_stack_bottom, expr_error))
{
error_stream.Printf ("Couldn't dematerialize struct : %s\n", expr_error.AsCString("unknown error"));
return false;
OpenPOWER on IntegriCloud