summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2015-09-15 21:13:50 +0000
committerJim Ingham <jingham@apple.com>2015-09-15 21:13:50 +0000
commit151c032c86aa7de4244a9ed52d420ecb09550d0b (patch)
tree44f8d890499ac2e99bb2a4fd50975f7c986d72a8 /lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
parent01fa3f96b37499e43d0d26b46151268b1b891342 (diff)
downloadbcm5719-llvm-151c032c86aa7de4244a9ed52d420ecb09550d0b.tar.gz
bcm5719-llvm-151c032c86aa7de4244a9ed52d420ecb09550d0b.zip
This patch makes Clang-independent base classes for all the expression types that lldb currently vends.
Before we had: ClangFunction ClangUtilityFunction ClangUserExpression and code all over in lldb that explicitly made Clang-based expressions. This patch adds an Expression base class, and three pure virtual implementations for the Expression kinds: FunctionCaller UtilityFunction UserExpression You can request one of these expression types from the Target using the Get<ExpressionType>ForLanguage. The Target will then consult all the registered TypeSystem plugins, and if the type system that matches the language can make an expression of that kind, it will do so and return it. Because all of the real expression types need to communicate with their ExpressionParser in a uniform way, I also added a ExpressionTypeSystemHelper class that expressions generically can vend, and a ClangExpressionHelper that encapsulates the operations that the ClangExpressionParser needs to perform on the ClangExpression types. Then each of the Clang* expression kinds constructs the appropriate helper to do what it needs. The patch also fixes a wart in the UtilityFunction that to use it you had to create a parallel FunctionCaller to actually call the function made by the UtilityFunction. Now the UtilityFunction can be asked to vend a FunctionCaller that will run its function. This cleaned up a lot of boiler plate code using UtilityFunctions. Note, in this patch all the expression types explicitly depend on the LLVM JIT and IR, and all the common JIT running code is in the FunctionCaller etc base classes. At some point we could also abstract that dependency but I don't see us adding another back end in the near term, so I'll leave that exercise till it is actually necessary. llvm-svn: 247720
Diffstat (limited to 'lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp')
-rw-r--r--lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp98
1 files changed, 33 insertions, 65 deletions
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
index db5b7f0a406..d38a076ad5d 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
@@ -22,9 +22,9 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/Value.h"
-#include "lldb/Expression/ClangExpression.h"
-#include "lldb/Expression/ClangFunction.h"
-#include "lldb/Expression/ClangUtilityFunction.h"
+#include "lldb/Expression/UserExpression.h"
+#include "lldb/Expression/FunctionCaller.h"
+#include "lldb/Expression/UtilityFunction.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Symbol.h"
@@ -741,10 +741,10 @@ lldb::addr_t
AppleObjCTrampolineHandler::SetupDispatchFunction (Thread &thread, ValueList &dispatch_values)
{
ExecutionContext exe_ctx (thread.shared_from_this());
- Address impl_code_address;
StreamString errors;
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
lldb::addr_t args_addr = LLDB_INVALID_ADDRESS;
+ FunctionCaller *impl_function_caller = nullptr;
// Scope for mutex locker:
{
@@ -752,38 +752,23 @@ AppleObjCTrampolineHandler::SetupDispatchFunction (Thread &thread, ValueList &di
// First stage is to make the ClangUtility to hold our injected function:
- #define USE_BUILTIN_FUNCTION 0 // Define this to 1 and we will use the get_implementation function found in the target.
- // This is useful for debugging additions to the get_impl function 'cause you don't have
- // to bother with string-ifying the code into g_lookup_implementation_function_code.
-
- if (USE_BUILTIN_FUNCTION)
- {
- ConstString our_utility_function_name("__lldb_objc_find_implementation_for_selector");
- SymbolContextList sc_list;
-
- exe_ctx.GetTargetRef().GetImages().FindSymbolsWithNameAndType (our_utility_function_name, eSymbolTypeCode, sc_list);
- if (sc_list.GetSize() == 1)
- {
- SymbolContext sc;
- sc_list.GetContextAtIndex(0, sc);
- if (sc.symbol != NULL)
- impl_code_address = sc.symbol->GetAddress();
-
- //lldb::addr_t addr = impl_code_address.GetOpcodeLoadAddress (exe_ctx.GetTargetPtr());
- //printf ("Getting address for our_utility_function: 0x%" PRIx64 ".\n", addr);
- }
- else
- {
- //printf ("Could not find implementation function address.\n");
- return args_addr;
- }
- }
- else if (!m_impl_code.get())
+ if (!m_impl_code.get())
{
if (g_lookup_implementation_function_code != NULL)
{
- m_impl_code.reset (new ClangUtilityFunction (g_lookup_implementation_function_code,
- g_lookup_implementation_function_name));
+ Error error;
+ m_impl_code.reset (exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage (g_lookup_implementation_function_code,
+ eLanguageTypeObjC,
+ g_lookup_implementation_function_name,
+ error));
+ if (error.Fail())
+ {
+ if (log)
+ log->Printf ("Failed to get Utility Function for implementation lookup: %s.", error.AsCString());
+ m_impl_code.reset();
+ return args_addr;
+ }
+
if (!m_impl_code->Install(errors, exe_ctx))
{
if (log)
@@ -800,43 +785,26 @@ AppleObjCTrampolineHandler::SetupDispatchFunction (Thread &thread, ValueList &di
return LLDB_INVALID_ADDRESS;
}
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_impl_code->StartAddress());
- }
- else
- {
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_impl_code->StartAddress());
- }
- // Next make the runner function for our implementation utility function.
- if (!m_impl_function.get())
- {
+ // Next make the runner function for our implementation utility function.
ClangASTContext *clang_ast_context = thread.GetProcess()->GetTarget().GetScratchClangASTContext();
CompilerType clang_void_ptr_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
- m_impl_function.reset(new ClangFunction (thread,
- clang_void_ptr_type,
- impl_code_address,
- dispatch_values,
- "objc-dispatch-lookup"));
+ Error error;
- errors.Clear();
- unsigned num_errors = m_impl_function->CompileFunction(errors);
- if (num_errors)
+ impl_function_caller = m_impl_code->MakeFunctionCaller(clang_void_ptr_type,
+ dispatch_values,
+ error);
+ if (error.Fail())
{
if (log)
- log->Printf ("Error compiling function: \"%s\".", errors.GetData());
- return args_addr;
- }
-
- errors.Clear();
- if (!m_impl_function->WriteFunctionWrapper(exe_ctx, errors))
- {
- if (log)
- log->Printf ("Error Inserting function: \"%s\".", errors.GetData());
+ log->Printf ("Error getting function caller for dispatch lookup: \"%s\".", error.AsCString());
return args_addr;
}
}
+ else
+ {
+ impl_function_caller = m_impl_code->GetFunctionCaller();
+ }
}
errors.Clear();
@@ -845,7 +813,7 @@ AppleObjCTrampolineHandler::SetupDispatchFunction (Thread &thread, ValueList &di
// if other threads were calling into here, but actually it isn't because we allocate a new args structure for
// this call by passing args_addr = LLDB_INVALID_ADDRESS...
- if (!m_impl_function->WriteFunctionArguments (exe_ctx, args_addr, impl_code_address, dispatch_values, errors))
+ if (impl_function_caller->WriteFunctionArguments (exe_ctx, args_addr, dispatch_values, errors))
{
if (log)
log->Printf ("Error writing function arguments: \"%s\".", errors.GetData());
@@ -1169,8 +1137,8 @@ AppleObjCTrampolineHandler::GetStepThroughDispatchPlan (Thread &thread, bool sto
return ret_plan_sp;
}
-ClangFunction *
-AppleObjCTrampolineHandler::GetLookupImplementationWrapperFunction ()
+FunctionCaller *
+AppleObjCTrampolineHandler::GetLookupImplementationFunctionCaller ()
{
- return m_impl_function.get();
+ return m_impl_code->GetFunctionCaller();
}
OpenPOWER on IntegriCloud