diff options
author | dim <dim@FreeBSD.org> | 2017-04-02 17:24:58 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2017-04-02 17:24:58 +0000 |
commit | 60b571e49a90d38697b3aca23020d9da42fc7d7f (patch) | |
tree | 99351324c24d6cb146b6285b6caffa4d26fce188 /contrib/llvm/tools/lldb/source/Expression/FunctionCaller.cpp | |
parent | bea1b22c7a9bce1dfdd73e6e5b65bc4752215180 (diff) | |
download | FreeBSD-src-60b571e49a90d38697b3aca23020d9da42fc7d7f.zip FreeBSD-src-60b571e49a90d38697b3aca23020d9da42fc7d7f.tar.gz |
Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release:
MFC r309142 (by emaste):
Add WITH_LLD_AS_LD build knob
If set it installs LLD as /usr/bin/ld. LLD (as of version 3.9) is not
capable of linking the world and kernel, but can self-host and link many
substantial applications. GNU ld continues to be used for the world and
kernel build, regardless of how this knob is set.
It is on by default for arm64, and off for all other CPU architectures.
Sponsored by: The FreeBSD Foundation
MFC r310840:
Reapply 310775, now it also builds correctly if lldb is disabled:
Move llvm-objdump from CLANG_EXTRAS to installed by default
We currently install three tools from binutils 2.17.50: as, ld, and
objdump. Work is underway to migrate to a permissively-licensed
tool-chain, with one goal being the retirement of binutils 2.17.50.
LLVM's llvm-objdump is intended to be compatible with GNU objdump
although it is currently missing some options and may have formatting
differences. Enable it by default for testing and further investigation.
It may later be changed to install as /usr/bin/objdump, it becomes a
fully viable replacement.
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D8879
MFC r312855 (by emaste):
Rename LLD_AS_LD to LLD_IS_LD, for consistency with CLANG_IS_CC
Reported by: Dan McGregor <dan.mcgregor usask.ca>
MFC r313559 | glebius | 2017-02-10 18:34:48 +0100 (Fri, 10 Feb 2017) | 5 lines
Don't check struct rtentry on FreeBSD, it is an internal kernel structure.
On other systems it may be API structure for SIOCADDRT/SIOCDELRT.
Reviewed by: emaste, dim
MFC r314152 (by jkim):
Remove an assembler flag, which is redundant since r309124. The upstream
took care of it by introducing a macro NO_EXEC_STACK_DIRECTIVE.
http://llvm.org/viewvc/llvm-project?rev=273500&view=rev
Reviewed by: dim
MFC r314564:
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
4.0.0 (branches/release_40 296509). The release will follow soon.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Also note that as of 4.0.0, lld should be able to link the base system
on amd64 and aarch64. See the WITH_LLD_IS_LLD setting in src.conf(5).
Though please be aware that this is work in progress.
Release notes for llvm, clang and lld will be available here:
<http://releases.llvm.org/4.0.0/docs/ReleaseNotes.html>
<http://releases.llvm.org/4.0.0/tools/clang/docs/ReleaseNotes.html>
<http://releases.llvm.org/4.0.0/tools/lld/docs/ReleaseNotes.html>
Thanks to Ed Maste, Jan Beich, Antoine Brodin and Eric Fiselier for
their help.
Relnotes: yes
Exp-run: antoine
PR: 215969, 216008
MFC r314708:
For now, revert r287232 from upstream llvm trunk (by Daniil Fukalov):
[SCEV] limit recursion depth of CompareSCEVComplexity
Summary:
CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled
loop) and runs almost infinite time.
Added cache of "equal" SCEV pairs to earlier cutoff of further
estimation. Recursion depth limit was also introduced as a parameter.
Reviewers: sanjoy
Subscribers: mzolotukhin, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D26389
This commit is the cause of excessive compile times on skein_block.c
(and possibly other files) during kernel builds on amd64.
We never saw the problematic behavior described in this upstream commit,
so for now it is better to revert it. An upstream bug has been filed
here: https://bugs.llvm.org/show_bug.cgi?id=32142
Reported by: mjg
MFC r314795:
Reapply r287232 from upstream llvm trunk (by Daniil Fukalov):
[SCEV] limit recursion depth of CompareSCEVComplexity
Summary:
CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled
loop) and runs almost infinite time.
Added cache of "equal" SCEV pairs to earlier cutoff of further
estimation. Recursion depth limit was also introduced as a parameter.
Reviewers: sanjoy
Subscribers: mzolotukhin, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D26389
Pull in r296992 from upstream llvm trunk (by Sanjoy Das):
[SCEV] Decrease the recursion threshold for CompareValueComplexity
Fixes PR32142.
r287232 accidentally increased the recursion threshold for
CompareValueComplexity from 2 to 32. This change reverses that
change by introducing a separate flag for CompareValueComplexity's
threshold.
The latter revision fixes the excessive compile times for skein_block.c.
MFC r314907 | mmel | 2017-03-08 12:40:27 +0100 (Wed, 08 Mar 2017) | 7 lines
Unbreak ARMv6 world.
The new compiler_rt library imported with clang 4.0.0 have several fatal
issues (non-functional __udivsi3 for example) with ARM specific instrict
functions. As temporary workaround, until upstream solve these problems,
disable all thumb[1][2] related feature.
MFC r315016:
Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release.
We were already very close to the last release candidate, so this is a
pretty minor update.
Relnotes: yes
MFC r316005:
Revert r314907, and pull in r298713 from upstream compiler-rt trunk (by
Weiming Zhao):
builtins: Select correct code fragments when compiling for Thumb1/Thum2/ARM ISA.
Summary:
Value of __ARM_ARCH_ISA_THUMB isn't based on the actual compilation
mode (-mthumb, -marm), it reflect's capability of given CPU.
Due to this:
- use __tbumb__ and __thumb2__ insteand of __ARM_ARCH_ISA_THUMB
- use '.thumb' directive consistently in all affected files
- decorate all thumb functions using
DEFINE_COMPILERRT_THUMB_FUNCTION()
---------
Note: This patch doesn't fix broken Thumb1 variant of __udivsi3 !
Reviewers: weimingz, rengolin, compnerd
Subscribers: aemerson, dim
Differential Revision: https://reviews.llvm.org/D30938
Discussed with: mmel
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Expression/FunctionCaller.cpp')
-rw-r--r-- | contrib/llvm/tools/lldb/source/Expression/FunctionCaller.cpp | 633 |
1 files changed, 313 insertions, 320 deletions
diff --git a/contrib/llvm/tools/lldb/source/Expression/FunctionCaller.cpp b/contrib/llvm/tools/lldb/source/Expression/FunctionCaller.cpp index 3a4f1fe..f218ccb 100644 --- a/contrib/llvm/tools/lldb/source/Expression/FunctionCaller.cpp +++ b/contrib/llvm/tools/lldb/source/Expression/FunctionCaller.cpp @@ -1,4 +1,4 @@ -//===-- FunctionCaller.cpp ---------------------------------------*- C++ -*-===// +//===-- FunctionCaller.cpp ---------------------------------------*- C++-*-===// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// - // C Includes // C++ Includes // Other libraries and framework includes @@ -38,364 +37,358 @@ using namespace lldb_private; //---------------------------------------------------------------------- // FunctionCaller constructor //---------------------------------------------------------------------- -FunctionCaller::FunctionCaller -( - ExecutionContextScope &exe_scope, - const CompilerType &return_type, - const Address& functionAddress, - const ValueList &arg_value_list, - const char *name -) : - Expression (exe_scope), - m_execution_unit_sp(), - m_parser(), - m_jit_module_wp(), - m_name (name ? name : "<unknown>"), - m_function_ptr (NULL), - m_function_addr (functionAddress), - m_function_return_type(return_type), - m_wrapper_function_name ("__lldb_caller_function"), - m_wrapper_struct_name ("__lldb_caller_struct"), - m_wrapper_args_addrs (), - m_arg_values (arg_value_list), - m_compiled (false), - m_JITted (false) -{ - m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess()); - // Can't make a FunctionCaller without a process. - assert (m_jit_process_wp.lock()); +FunctionCaller::FunctionCaller(ExecutionContextScope &exe_scope, + const CompilerType &return_type, + const Address &functionAddress, + const ValueList &arg_value_list, + const char *name) + : Expression(exe_scope), m_execution_unit_sp(), m_parser(), + m_jit_module_wp(), m_name(name ? name : "<unknown>"), + m_function_ptr(NULL), m_function_addr(functionAddress), + m_function_return_type(return_type), + m_wrapper_function_name("__lldb_caller_function"), + m_wrapper_struct_name("__lldb_caller_struct"), m_wrapper_args_addrs(), + m_arg_values(arg_value_list), m_compiled(false), m_JITted(false) { + m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess()); + // Can't make a FunctionCaller without a process. + assert(m_jit_process_wp.lock()); } //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- -FunctionCaller::~FunctionCaller() -{ - 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); - } +FunctionCaller::~FunctionCaller() { + 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); + } } -bool -FunctionCaller::WriteFunctionWrapper(ExecutionContext &exe_ctx, DiagnosticManager &diagnostic_manager) -{ - Process *process = exe_ctx.GetProcessPtr(); - - if (!process) - return false; - - lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock()); - - if (process != jit_process_sp.get()) - return false; - - if (!m_compiled) - return false; - - if (m_JITted) - return true; - - bool can_interpret = false; // should stay that way - - Error jit_error (m_parser->PrepareForExecution (m_jit_start_addr, - m_jit_end_addr, - m_execution_unit_sp, - exe_ctx, - can_interpret, - eExecutionPolicyAlways)); - - 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 = process->shared_from_this(); - - m_JITted = true; +bool FunctionCaller::WriteFunctionWrapper( + ExecutionContext &exe_ctx, DiagnosticManager &diagnostic_manager) { + Process *process = exe_ctx.GetProcessPtr(); + + if (!process) + return false; + + lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock()); + + if (process != jit_process_sp.get()) + return false; + if (!m_compiled) + return false; + + if (m_JITted) return true; + + bool can_interpret = false; // should stay that way + + Error jit_error(m_parser->PrepareForExecution( + m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx, + can_interpret, eExecutionPolicyAlways)); + + 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 = process->shared_from_this(); + + m_JITted = true; + + return true; } -bool -FunctionCaller::WriteFunctionArguments(ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, - DiagnosticManager &diagnostic_manager) -{ - return WriteFunctionArguments(exe_ctx, args_addr_ref, m_arg_values, diagnostic_manager); +bool FunctionCaller::WriteFunctionArguments( + ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, + DiagnosticManager &diagnostic_manager) { + return WriteFunctionArguments(exe_ctx, args_addr_ref, m_arg_values, + diagnostic_manager); } -// FIXME: Assure that the ValueList we were passed in is consistent with the one that defined this function. - -bool -FunctionCaller::WriteFunctionArguments(ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, ValueList &arg_values, - DiagnosticManager &diagnostic_manager) -{ - // All the information to reconstruct the struct is provided by the - // StructExtractor. - if (!m_struct_valid) - { - diagnostic_manager.PutCString( - eDiagnosticSeverityError, - "Argument information was not correctly parsed, so the function cannot be called."); - return false; - } +// FIXME: Assure that the ValueList we were passed in is consistent with the one +// that defined this function. + +bool FunctionCaller::WriteFunctionArguments( + ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, + ValueList &arg_values, DiagnosticManager &diagnostic_manager) { + // All the information to reconstruct the struct is provided by the + // StructExtractor. + if (!m_struct_valid) { + diagnostic_manager.PutString(eDiagnosticSeverityError, + "Argument information was not correctly " + "parsed, so the function cannot be called."); + return false; + } - Error error; - lldb::ExpressionResults return_value = lldb::eExpressionSetupError; + Error error; + lldb::ExpressionResults return_value = lldb::eExpressionSetupError; - Process *process = exe_ctx.GetProcessPtr(); + Process *process = exe_ctx.GetProcessPtr(); - if (process == NULL) - return return_value; + if (process == NULL) + return return_value; - lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock()); - - if (process != jit_process_sp.get()) - return false; - + lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock()); + + if (process != jit_process_sp.get()) + return false; + + if (args_addr_ref == LLDB_INVALID_ADDRESS) { + args_addr_ref = process->AllocateMemory( + m_struct_size, lldb::ePermissionsReadable | lldb::ePermissionsWritable, + error); if (args_addr_ref == LLDB_INVALID_ADDRESS) - { - args_addr_ref = process->AllocateMemory(m_struct_size, lldb::ePermissionsReadable|lldb::ePermissionsWritable, error); - if (args_addr_ref == LLDB_INVALID_ADDRESS) - return false; - m_wrapper_args_addrs.push_back (args_addr_ref); - } - else - { - // Make sure this is an address that we've already handed out. - if (find (m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(), args_addr_ref) == m_wrapper_args_addrs.end()) - { - return false; - } + return false; + m_wrapper_args_addrs.push_back(args_addr_ref); + } else { + // Make sure this is an address that we've already handed out. + if (find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(), + args_addr_ref) == m_wrapper_args_addrs.end()) { + return false; } + } - // TODO: verify fun_addr needs to be a callable address - Scalar fun_addr (m_function_addr.GetCallableLoadAddress(exe_ctx.GetTargetPtr())); - uint64_t first_offset = m_member_offsets[0]; - process->WriteScalarToMemory(args_addr_ref + first_offset, fun_addr, process->GetAddressByteSize(), error); + // TODO: verify fun_addr needs to be a callable address + Scalar fun_addr( + m_function_addr.GetCallableLoadAddress(exe_ctx.GetTargetPtr())); + uint64_t first_offset = m_member_offsets[0]; + process->WriteScalarToMemory(args_addr_ref + first_offset, fun_addr, + process->GetAddressByteSize(), error); - // FIXME: We will need to extend this for Variadic functions. + // FIXME: We will need to extend this for Variadic functions. - Error value_error; + Error value_error; - size_t num_args = arg_values.GetSize(); - if (num_args != m_arg_values.GetSize()) - { - diagnostic_manager.Printf(eDiagnosticSeverityError, - "Wrong number of arguments - was: %" PRIu64 " should be: %" PRIu64 "", - (uint64_t)num_args, (uint64_t)m_arg_values.GetSize()); - return false; - } + size_t num_args = arg_values.GetSize(); + if (num_args != m_arg_values.GetSize()) { + diagnostic_manager.Printf( + eDiagnosticSeverityError, + "Wrong number of arguments - was: %" PRIu64 " should be: %" PRIu64 "", + (uint64_t)num_args, (uint64_t)m_arg_values.GetSize()); + return false; + } - for (size_t i = 0; i < num_args; i++) - { - // FIXME: We should sanity check sizes. - - uint64_t offset = m_member_offsets[i+1]; // Clang sizes are in bytes. - Value *arg_value = arg_values.GetValueAtIndex(i); - - // FIXME: For now just do scalars: - - // Special case: if it's a pointer, don't do anything (the ABI supports passing cstrings) - - if (arg_value->GetValueType() == Value::eValueTypeHostAddress && - arg_value->GetContextType() == Value::eContextTypeInvalid && - arg_value->GetCompilerType().IsPointerType()) - continue; - - const Scalar &arg_scalar = arg_value->ResolveValue(&exe_ctx); - - if (!process->WriteScalarToMemory(args_addr_ref + offset, arg_scalar, arg_scalar.GetByteSize(), error)) - return false; - } + for (size_t i = 0; i < num_args; i++) { + // FIXME: We should sanity check sizes. - return true; -} + uint64_t offset = m_member_offsets[i + 1]; // Clang sizes are in bytes. + Value *arg_value = arg_values.GetValueAtIndex(i); -bool -FunctionCaller::InsertFunction(ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, - DiagnosticManager &diagnostic_manager) -{ - if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0) - return false; - if (!WriteFunctionWrapper(exe_ctx, diagnostic_manager)) - return false; - if (!WriteFunctionArguments(exe_ctx, args_addr_ref, diagnostic_manager)) - return false; - - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); - if (log) - log->Printf ("Call Address: 0x%" PRIx64 " Struct Address: 0x%" PRIx64 ".\n", m_jit_start_addr, args_addr_ref); - - return true; + // FIXME: For now just do scalars: + + // Special case: if it's a pointer, don't do anything (the ABI supports + // passing cstrings) + + if (arg_value->GetValueType() == Value::eValueTypeHostAddress && + arg_value->GetContextType() == Value::eContextTypeInvalid && + arg_value->GetCompilerType().IsPointerType()) + continue; + + const Scalar &arg_scalar = arg_value->ResolveValue(&exe_ctx); + + if (!process->WriteScalarToMemory(args_addr_ref + offset, arg_scalar, + arg_scalar.GetByteSize(), error)) + return false; + } + + return true; } -lldb::ThreadPlanSP -FunctionCaller::GetThreadPlanToCallFunction(ExecutionContext &exe_ctx, lldb::addr_t args_addr, - const EvaluateExpressionOptions &options, - DiagnosticManager &diagnostic_manager) -{ - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); - - if (log) - log->Printf("-- [FunctionCaller::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(); - if (thread == NULL) - { - diagnostic_manager.PutCString(eDiagnosticSeverityError, "Can't call a function without a valid thread."); - return NULL; - } +bool FunctionCaller::InsertFunction(ExecutionContext &exe_ctx, + lldb::addr_t &args_addr_ref, + DiagnosticManager &diagnostic_manager) { + if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0) + return false; + if (!WriteFunctionWrapper(exe_ctx, diagnostic_manager)) + return false; + if (!WriteFunctionArguments(exe_ctx, args_addr_ref, diagnostic_manager)) + return false; + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); + if (log) + log->Printf("Call Address: 0x%" PRIx64 " Struct Address: 0x%" PRIx64 ".\n", + m_jit_start_addr, args_addr_ref); + + return true; +} - // Okay, now run the function: - - Address wrapper_address (m_jit_start_addr); - - lldb::addr_t args = { args_addr }; - - lldb::ThreadPlanSP new_plan_sp (new ThreadPlanCallFunction (*thread, - wrapper_address, - CompilerType(), - args, - options)); - new_plan_sp->SetIsMasterPlan(true); - new_plan_sp->SetOkayToDiscard (false); - return new_plan_sp; +lldb::ThreadPlanSP FunctionCaller::GetThreadPlanToCallFunction( + ExecutionContext &exe_ctx, lldb::addr_t args_addr, + const EvaluateExpressionOptions &options, + DiagnosticManager &diagnostic_manager) { + Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | + LIBLLDB_LOG_STEP)); + + if (log) + log->Printf("-- [FunctionCaller::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(); + if (thread == NULL) { + diagnostic_manager.PutString( + eDiagnosticSeverityError, + "Can't call a function without a valid thread."); + return NULL; + } + + // Okay, now run the function: + + Address wrapper_address(m_jit_start_addr); + + lldb::addr_t args = {args_addr}; + + lldb::ThreadPlanSP new_plan_sp(new ThreadPlanCallFunction( + *thread, wrapper_address, CompilerType(), args, options)); + new_plan_sp->SetIsMasterPlan(true); + new_plan_sp->SetOkayToDiscard(false); + return new_plan_sp; } -bool -FunctionCaller::FetchFunctionResults (ExecutionContext &exe_ctx, lldb::addr_t args_addr, Value &ret_value) -{ - // Read the return value - it is the last field in the struct: - // FIXME: How does clang tell us there's no return value? We need to handle that case. - // FIXME: Create our ThreadPlanCallFunction with the return CompilerType, and then use GetReturnValueObject - // to fetch the value. That way we can fetch any values we need. - - Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); - - if (log) - log->Printf("-- [FunctionCaller::FetchFunctionResults] Fetching function results for \"%s\"--", m_name.c_str()); - - Process *process = exe_ctx.GetProcessPtr(); - - if (process == NULL) - return false; - - lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock()); - - if (process != jit_process_sp.get()) - return false; - - Error error; - ret_value.GetScalar() = process->ReadUnsignedIntegerFromMemory (args_addr + m_return_offset, m_return_size, 0, error); - - if (error.Fail()) - return false; - - ret_value.SetCompilerType(m_function_return_type); - ret_value.SetValueType(Value::eValueTypeScalar); - return true; +bool FunctionCaller::FetchFunctionResults(ExecutionContext &exe_ctx, + lldb::addr_t args_addr, + Value &ret_value) { + // Read the return value - it is the last field in the struct: + // FIXME: How does clang tell us there's no return value? We need to handle + // that case. + // FIXME: Create our ThreadPlanCallFunction with the return CompilerType, and + // then use GetReturnValueObject + // to fetch the value. That way we can fetch any values we need. + + Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | + LIBLLDB_LOG_STEP)); + + if (log) + log->Printf("-- [FunctionCaller::FetchFunctionResults] Fetching function " + "results for \"%s\"--", + m_name.c_str()); + + Process *process = exe_ctx.GetProcessPtr(); + + if (process == NULL) + return false; + + lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock()); + + if (process != jit_process_sp.get()) + return false; + + Error error; + ret_value.GetScalar() = process->ReadUnsignedIntegerFromMemory( + args_addr + m_return_offset, m_return_size, 0, error); + + if (error.Fail()) + return false; + + ret_value.SetCompilerType(m_function_return_type); + ret_value.SetValueType(Value::eValueTypeScalar); + return true; } -void -FunctionCaller::DeallocateFunctionResults (ExecutionContext &exe_ctx, lldb::addr_t args_addr) -{ - std::list<lldb::addr_t>::iterator pos; - pos = std::find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(), args_addr); - if (pos != m_wrapper_args_addrs.end()) - m_wrapper_args_addrs.erase(pos); - - exe_ctx.GetProcessRef().DeallocateMemory(args_addr); +void FunctionCaller::DeallocateFunctionResults(ExecutionContext &exe_ctx, + lldb::addr_t args_addr) { + std::list<lldb::addr_t>::iterator pos; + pos = std::find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(), + args_addr); + if (pos != m_wrapper_args_addrs.end()) + m_wrapper_args_addrs.erase(pos); + + exe_ctx.GetProcessRef().DeallocateMemory(args_addr); } -lldb::ExpressionResults -FunctionCaller::ExecuteFunction(ExecutionContext &exe_ctx, lldb::addr_t *args_addr_ptr, - const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager, - Value &results) -{ - lldb::ExpressionResults return_value = lldb::eExpressionSetupError; - - // FunctionCaller::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. - EvaluateExpressionOptions real_options = options; - real_options.SetDebug(false); - real_options.SetUnwindOnError(true); - real_options.SetIgnoreBreakpoints(true); - - lldb::addr_t args_addr; - - if (args_addr_ptr != NULL) - args_addr = *args_addr_ptr; - else - args_addr = LLDB_INVALID_ADDRESS; - - if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0) - return lldb::eExpressionSetupError; - - if (args_addr == LLDB_INVALID_ADDRESS) - { - if (!InsertFunction(exe_ctx, args_addr, diagnostic_manager)) - return lldb::eExpressionSetupError; +lldb::ExpressionResults FunctionCaller::ExecuteFunction( + ExecutionContext &exe_ctx, lldb::addr_t *args_addr_ptr, + const EvaluateExpressionOptions &options, + DiagnosticManager &diagnostic_manager, Value &results) { + lldb::ExpressionResults return_value = lldb::eExpressionSetupError; + + // FunctionCaller::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. + EvaluateExpressionOptions real_options = options; + real_options.SetDebug(false); + real_options.SetUnwindOnError(true); + real_options.SetIgnoreBreakpoints(true); + + lldb::addr_t args_addr; + + if (args_addr_ptr != NULL) + args_addr = *args_addr_ptr; + else + args_addr = LLDB_INVALID_ADDRESS; + + if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0) + return lldb::eExpressionSetupError; + + if (args_addr == LLDB_INVALID_ADDRESS) { + if (!InsertFunction(exe_ctx, args_addr, diagnostic_manager)) + return lldb::eExpressionSetupError; + } + + Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | + LIBLLDB_LOG_STEP)); + + if (log) + log->Printf( + "== [FunctionCaller::ExecuteFunction] Executing function \"%s\" ==", + m_name.c_str()); + + lldb::ThreadPlanSP call_plan_sp = GetThreadPlanToCallFunction( + exe_ctx, args_addr, real_options, diagnostic_manager); + if (!call_plan_sp) + return lldb::eExpressionSetupError; + + // 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); + + return_value = exe_ctx.GetProcessRef().RunThreadPlan( + exe_ctx, call_plan_sp, real_options, diagnostic_manager); + + if (log) { + if (return_value != lldb::eExpressionCompleted) { + log->Printf("== [FunctionCaller::ExecuteFunction] Execution of \"%s\" " + "completed abnormally ==", + m_name.c_str()); + } else { + log->Printf("== [FunctionCaller::ExecuteFunction] Execution of \"%s\" " + "completed normally ==", + m_name.c_str()); } + } - Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); + if (exe_ctx.GetProcessPtr()) + exe_ctx.GetProcessPtr()->SetRunningUserExpression(false); - if (log) - log->Printf("== [FunctionCaller::ExecuteFunction] Executing function \"%s\" ==", m_name.c_str()); + if (args_addr_ptr != NULL) + *args_addr_ptr = args_addr; - lldb::ThreadPlanSP call_plan_sp = GetThreadPlanToCallFunction(exe_ctx, args_addr, real_options, diagnostic_manager); - if (!call_plan_sp) - return lldb::eExpressionSetupError; + if (return_value != lldb::eExpressionCompleted) + return return_value; - // 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); + FetchFunctionResults(exe_ctx, args_addr, results); - return_value = exe_ctx.GetProcessRef().RunThreadPlan(exe_ctx, call_plan_sp, real_options, diagnostic_manager); + if (args_addr_ptr == NULL) + DeallocateFunctionResults(exe_ctx, args_addr); - if (log) - { - if (return_value != lldb::eExpressionCompleted) - { - log->Printf("== [FunctionCaller::ExecuteFunction] Execution of \"%s\" completed abnormally ==", m_name.c_str()); - } - else - { - log->Printf("== [FunctionCaller::ExecuteFunction] Execution of \"%s\" completed normally ==", m_name.c_str()); - } - } - - if (exe_ctx.GetProcessPtr()) - exe_ctx.GetProcessPtr()->SetRunningUserExpression(false); - - if (args_addr_ptr != NULL) - *args_addr_ptr = args_addr; - - if (return_value != lldb::eExpressionCompleted) - return return_value; - - FetchFunctionResults(exe_ctx, args_addr, results); - - if (args_addr_ptr == NULL) - DeallocateFunctionResults(exe_ctx, args_addr); - - return lldb::eExpressionCompleted; + return lldb::eExpressionCompleted; } |