aboutsummaryrefslogtreecommitdiff
path: root/source/Expression/ClangFunction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Expression/ClangFunction.cpp')
-rw-r--r--source/Expression/ClangFunction.cpp88
1 files changed, 59 insertions, 29 deletions
diff --git a/source/Expression/ClangFunction.cpp b/source/Expression/ClangFunction.cpp
index e707c60ffced..27afba2898ab 100644
--- a/source/Expression/ClangFunction.cpp
+++ b/source/Expression/ClangFunction.cpp
@@ -22,18 +22,20 @@
#include "llvm/IR/Module.h"
// Project includes
-#include "lldb/Expression/ASTStructExtractor.h"
-#include "lldb/Expression/ClangExpressionParser.h"
-#include "lldb/Expression/ClangFunction.h"
-#include "lldb/Expression/IRExecutionUnit.h"
-#include "lldb/Symbol/Type.h"
#include "lldb/Core/DataExtractor.h"
+#include "lldb/Core/Log.h"
+#include "lldb/Core/Module.h"
#include "lldb/Core/State.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Core/ValueObjectList.h"
+#include "lldb/Expression/ASTStructExtractor.h"
+#include "lldb/Expression/ClangExpressionParser.h"
+#include "lldb/Expression/ClangFunction.h"
+#include "lldb/Expression/IRExecutionUnit.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/Type.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
@@ -41,7 +43,6 @@
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadPlan.h"
#include "lldb/Target/ThreadPlanCallFunction.h"
-#include "lldb/Core/Log.h"
using namespace lldb_private;
@@ -53,8 +54,13 @@ ClangFunction::ClangFunction
ExecutionContextScope &exe_scope,
const ClangASTType &return_type,
const Address& functionAddress,
- const ValueList &arg_value_list
+ const ValueList &arg_value_list,
+ const char *name
) :
+ m_parser(),
+ m_execution_unit_sp(),
+ m_jit_module_wp(),
+ m_name (name ? name : "<unknown>"),
m_function_ptr (NULL),
m_function_addr (functionAddress),
m_function_return_type(return_type),
@@ -75,8 +81,10 @@ ClangFunction::ClangFunction
ExecutionContextScope &exe_scope,
Function &function,
ClangASTContext *ast_context,
- const ValueList &arg_value_list
+ const ValueList &arg_value_list,
+ const char *name
) :
+ m_name (name ? name : "<unknown>"),
m_function_ptr (&function),
m_function_addr (),
m_function_return_type (),
@@ -87,7 +95,7 @@ ClangFunction::ClangFunction
m_compiled (false),
m_JITted (false)
{
- m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
+ m_jit_process_wp = exe_scope.CalculateProcess();
// Can't make a ClangFunction without a process.
assert (m_jit_process_wp.lock());
@@ -100,6 +108,13 @@ ClangFunction::ClangFunction
//----------------------------------------------------------------------
ClangFunction::~ClangFunction()
{
+ lldb::ProcessSP process_sp (m_jit_process_wp.lock());
+ if (process_sp)
+ {
+ lldb::ModuleSP jit_module_sp (m_jit_module_wp.lock());
+ if (jit_module_sp)
+ process_sp->GetTarget().GetImages().Remove(jit_module_sp);
+ }
}
unsigned
@@ -173,7 +188,7 @@ ClangFunction::CompileFunction (Stream &errors)
}
else
{
- errors.Printf("Could not determine type of input value %zu.", i);
+ errors.Printf("Could not determine type of input value %" PRIu64 ".", (uint64_t)i);
return 1;
}
}
@@ -222,7 +237,8 @@ ClangFunction::CompileFunction (Stream &errors)
lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
if (jit_process_sp)
{
- m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this));
+ const bool generate_debug_info = true;
+ m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this, generate_debug_info));
num_errors = m_parser->Parse (errors);
}
@@ -263,7 +279,7 @@ ClangFunction::WriteFunctionWrapper (ExecutionContext &exe_ctx, Stream &errors)
Error jit_error (m_parser->PrepareForExecution (m_jit_start_addr,
m_jit_end_addr,
- m_execution_unit_ap,
+ m_execution_unit_sp,
exe_ctx,
can_interpret,
eExecutionPolicyAlways));
@@ -271,8 +287,22 @@ ClangFunction::WriteFunctionWrapper (ExecutionContext &exe_ctx, Stream &errors)
if (!jit_error.Success())
return false;
+ if (m_parser->GetGenerateDebugInfo())
+ {
+ lldb::ModuleSP jit_module_sp ( m_execution_unit_sp->GetJITModule());
+
+ if (jit_module_sp)
+ {
+ ConstString const_func_name(FunctionName());
+ FileSpec jit_file;
+ jit_file.GetFilename() = const_func_name;
+ jit_module_sp->SetFileSpecAndObjectName (jit_file, ConstString());
+ m_jit_module_wp = jit_module_sp;
+ process->GetTarget().GetImages().Append(jit_module_sp);
+ }
+ }
if (process && m_jit_start_addr)
- m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
+ m_jit_process_wp = process->shared_from_this();
m_JITted = true;
@@ -304,7 +334,7 @@ ClangFunction::WriteFunctionArguments (ExecutionContext &exe_ctx,
Error error;
using namespace clang;
- ExecutionResults return_value = eExecutionSetupError;
+ lldb::ExpressionResults return_value = lldb::eExpressionSetupError;
Process *process = exe_ctx.GetProcessPtr();
@@ -344,7 +374,7 @@ ClangFunction::WriteFunctionArguments (ExecutionContext &exe_ctx,
size_t num_args = arg_values.GetSize();
if (num_args != m_arg_values.GetSize())
{
- errors.Printf ("Wrong number of arguments - was: %zu should be: %zu", num_args, m_arg_values.GetSize());
+ errors.Printf ("Wrong number of arguments - was: %" PRIu64 " should be: %" PRIu64 "", (uint64_t)num_args, (uint64_t)m_arg_values.GetSize());
return false;
}
@@ -401,7 +431,7 @@ ClangFunction::GetThreadPlanToCallFunction (ExecutionContext &exe_ctx,
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP));
if (log)
- log->Printf("-- [ClangFunction::GetThreadPlanToCallFunction] Creating thread plan to call function --");
+ log->Printf("-- [ClangFunction::GetThreadPlanToCallFunction] Creating thread plan to call function \"%s\" --", m_name.c_str());
// FIXME: Use the errors Stream for better error reporting.
Thread *thread = exe_ctx.GetThreadPtr();
@@ -438,7 +468,7 @@ ClangFunction::FetchFunctionResults (ExecutionContext &exe_ctx, lldb::addr_t arg
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP));
if (log)
- log->Printf("-- [ClangFunction::FetchFunctionResults] Fetching function results --");
+ log->Printf("-- [ClangFunction::FetchFunctionResults] Fetching function results for \"%s\"--", m_name.c_str());
Process *process = exe_ctx.GetProcessPtr();
@@ -472,7 +502,7 @@ ClangFunction::DeallocateFunctionResults (ExecutionContext &exe_ctx, lldb::addr_
exe_ctx.GetProcessRef().DeallocateMemory(args_addr);
}
-ExecutionResults
+lldb::ExpressionResults
ClangFunction::ExecuteFunction(
ExecutionContext &exe_ctx,
lldb::addr_t *args_addr_ptr,
@@ -481,7 +511,7 @@ ClangFunction::ExecuteFunction(
Value &results)
{
using namespace clang;
- ExecutionResults return_value = eExecutionSetupError;
+ lldb::ExpressionResults return_value = lldb::eExpressionSetupError;
// ClangFunction::ExecuteFunction execution is always just to get the result. Do make sure we ignore
// breakpoints, unwind on error, and don't try to debug it.
@@ -498,27 +528,27 @@ ClangFunction::ExecuteFunction(
args_addr = LLDB_INVALID_ADDRESS;
if (CompileFunction(errors) != 0)
- return eExecutionSetupError;
+ return lldb::eExpressionSetupError;
if (args_addr == LLDB_INVALID_ADDRESS)
{
if (!InsertFunction(exe_ctx, args_addr, errors))
- return eExecutionSetupError;
+ return lldb::eExpressionSetupError;
}
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP));
if (log)
- log->Printf("== [ClangFunction::ExecuteFunction] Executing function ==");
+ log->Printf("== [ClangFunction::ExecuteFunction] Executing function \"%s\" ==", m_name.c_str());
lldb::ThreadPlanSP call_plan_sp (GetThreadPlanToCallFunction (exe_ctx,
args_addr,
real_options,
errors));
if (!call_plan_sp)
- return eExecutionSetupError;
+ return lldb::eExpressionSetupError;
- // <rdar://problem/12027563> we need to make sure we record the fact that we are running an expression here
+ // We need to make sure we record the fact that we are running an expression here
// otherwise this fact will fail to be recorded when fetching an Objective-C object description
if (exe_ctx.GetProcessPtr())
exe_ctx.GetProcessPtr()->SetRunningUserExpression(true);
@@ -530,13 +560,13 @@ ClangFunction::ExecuteFunction(
if (log)
{
- if (return_value != eExecutionCompleted)
+ if (return_value != lldb::eExpressionCompleted)
{
- log->Printf("== [ClangFunction::ExecuteFunction] Execution completed abnormally ==");
+ log->Printf("== [ClangFunction::ExecuteFunction] Execution of \"%s\" completed abnormally ==", m_name.c_str());
}
else
{
- log->Printf("== [ClangFunction::ExecuteFunction] Execution completed normally ==");
+ log->Printf("== [ClangFunction::ExecuteFunction] Execution of \"%s\" completed normally ==", m_name.c_str());
}
}
@@ -546,7 +576,7 @@ ClangFunction::ExecuteFunction(
if (args_addr_ptr != NULL)
*args_addr_ptr = args_addr;
- if (return_value != eExecutionCompleted)
+ if (return_value != lldb::eExpressionCompleted)
return return_value;
FetchFunctionResults(exe_ctx, args_addr, results);
@@ -554,7 +584,7 @@ ClangFunction::ExecuteFunction(
if (args_addr_ptr == NULL)
DeallocateFunctionResults(exe_ctx, args_addr);
- return eExecutionCompleted;
+ return lldb::eExpressionCompleted;
}
clang::ASTConsumer *