summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/SystemRuntime/MacOSX
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/SystemRuntime/MacOSX
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/SystemRuntime/MacOSX')
-rw-r--r--lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp112
-rw-r--r--lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h9
-rw-r--r--lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp99
-rw-r--r--lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.h8
-rw-r--r--lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp117
-rw-r--r--lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h8
-rw-r--r--lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp109
-rw-r--r--lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.h8
-rw-r--r--lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp2
9 files changed, 179 insertions, 293 deletions
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
index a882b7e3e87..66b8b8bcf59 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp
@@ -22,9 +22,8 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Value.h"
-#include "lldb/Expression/ClangExpression.h"
-#include "lldb/Expression/ClangFunction.h"
-#include "lldb/Expression/ClangUtilityFunction.h"
+#include "lldb/Expression/FunctionCaller.h"
+#include "lldb/Expression/UtilityFunction.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/ExecutionContext.h"
@@ -101,7 +100,6 @@ extern \"C\"
AppleGetItemInfoHandler::AppleGetItemInfoHandler (Process *process) :
m_process (process),
- m_get_item_info_function (),
m_get_item_info_impl_code (),
m_get_item_info_function_mutex(),
m_get_item_info_return_buffer_addr (LLDB_INVALID_ADDRESS),
@@ -140,49 +138,33 @@ lldb::addr_t
AppleGetItemInfoHandler::SetupGetItemInfoFunction (Thread &thread, ValueList &get_item_info_arglist)
{
ExecutionContext exe_ctx (thread.shared_from_this());
- Address impl_code_address;
StreamString errors;
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME));
lldb::addr_t args_addr = LLDB_INVALID_ADDRESS;
+ FunctionCaller *get_item_info_caller = nullptr;
// Scope for mutex locker:
{
Mutex::Locker locker(m_get_item_info_function_mutex);
- // First stage is to make the ClangUtility to hold our injected function:
+ // First stage is to make the UtilityFunction 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_get_item_info_function_code.
-
- if (USE_BUILTIN_FUNCTION)
- {
- ConstString our_utility_function_name("__lldb_backtrace_recording_get_item_info");
- 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 queues introspection function address.\n");
- return args_addr;
- }
- }
- else if (!m_get_item_info_impl_code.get())
+ if (!m_get_item_info_impl_code.get())
{
if (g_get_item_info_function_code != NULL)
{
- m_get_item_info_impl_code.reset (new ClangUtilityFunction (g_get_item_info_function_code,
- g_get_item_info_function_name));
+ Error error;
+ m_get_item_info_impl_code.reset(exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage (g_get_item_info_function_code,
+ eLanguageTypeObjC,
+ g_get_item_info_function_name,
+ error));
+ if (error.Fail())
+ {
+ if (log)
+ log->Printf ("Failed to get utility function: %s.", error.AsCString());
+ return args_addr;
+ }
+
if (!m_get_item_info_impl_code->Install(errors, exe_ctx))
{
if (log)
@@ -198,41 +180,32 @@ AppleGetItemInfoHandler::SetupGetItemInfoFunction (Thread &thread, ValueList &ge
errors.Printf ("No get-item-info introspection code found.");
return LLDB_INVALID_ADDRESS;
}
-
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_get_item_info_impl_code->StartAddress());
- }
- else
- {
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_get_item_info_impl_code->StartAddress());
- }
- // Next make the runner function for our implementation utility function.
- if (!m_get_item_info_function.get())
- {
- ClangASTContext *clang_ast_context = thread.GetProcess()->GetTarget().GetScratchClangASTContext();
- CompilerType get_item_info_return_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
- m_get_item_info_function.reset(new ClangFunction (thread,
- get_item_info_return_type,
- impl_code_address,
- get_item_info_arglist,
- "queue-bt-item-info"));
+ // Next make the runner function for our implementation utility function.
+ Error error;
+
+ TypeSystem *type_system = thread.GetProcess()->GetTarget().GetScratchTypeSystemForLanguage(eLanguageTypeC);
+ CompilerType get_item_info_return_type = type_system->GetBasicTypeFromAST(eBasicTypeVoid).GetPointerType();
- errors.Clear();
- unsigned num_errors = m_get_item_info_function->CompileFunction(errors);
- if (num_errors)
+ get_item_info_caller = m_get_item_info_impl_code->MakeFunctionCaller(get_item_info_return_type,
+ get_item_info_arglist,
+ error);
+ if (error.Fail())
{
if (log)
- log->Printf ("Error compiling get-item-info function: \"%s\".", errors.GetData());
+ log->Printf ("Error Inserting get-item-info function: \"%s\".", error.AsCString());
return args_addr;
}
-
- errors.Clear();
- if (!m_get_item_info_function->WriteFunctionWrapper(exe_ctx, errors))
+ }
+ else
+ {
+ // If it's already made, then we can just retrieve the caller:
+ get_item_info_caller = m_get_item_info_impl_code->GetFunctionCaller();
+ if (!get_item_info_caller)
{
if (log)
- log->Printf ("Error Inserting get-item-info function: \"%s\".", errors.GetData());
+ log->Printf ("Failed to get get-item-info introspection caller.");
+ m_get_item_info_impl_code.reset();
return args_addr;
}
}
@@ -244,7 +217,7 @@ AppleGetItemInfoHandler::SetupGetItemInfoFunction (Thread &thread, ValueList &ge
// 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_get_item_info_function->WriteFunctionArguments (exe_ctx, args_addr, impl_code_address, get_item_info_arglist, errors))
+ if (!get_item_info_caller->WriteFunctionArguments (exe_ctx, args_addr, get_item_info_arglist, errors))
{
if (log)
log->Printf ("Error writing get-item-info function arguments: \"%s\".", errors.GetData());
@@ -364,7 +337,7 @@ AppleGetItemInfoHandler::GetItemInfo (Thread &thread, uint64_t item, addr_t page
options.SetTryAllThreads (false);
thread.CalculateExecutionContext (exe_ctx);
- if (m_get_item_info_function == NULL)
+ if (!m_get_item_info_impl_code)
{
error.SetErrorString ("Unable to compile function to call __introspection_dispatch_queue_item_get_info");
return return_value;
@@ -373,7 +346,16 @@ AppleGetItemInfoHandler::GetItemInfo (Thread &thread, uint64_t item, addr_t page
ExpressionResults func_call_ret;
Value results;
- func_call_ret = m_get_item_info_function->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
+ FunctionCaller *func_caller = m_get_item_info_impl_code->GetFunctionCaller();
+ if (!func_caller)
+ {
+ if (log)
+ log->Printf ("Could not retrieve function caller for __introspection_dispatch_queue_item_get_info.");
+ error.SetErrorString("Could not retrieve function caller for __introspection_dispatch_queue_item_get_info.");
+ return return_value;
+ }
+
+ func_call_ret = func_caller->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
if (func_call_ret != eExpressionCompleted || !error.Success())
{
if (log)
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h
index 5c086c61978..51182a62493 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h
@@ -18,11 +18,11 @@
// Project includes
#include "lldb/lldb-public.h"
#include "lldb/Core/Error.h"
-#include "lldb/Expression/ClangFunction.h"
+#include "lldb/Expression/UtilityFunction.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Symbol/CompilerType.h"
-// This class will insert a ClangUtilityFunction into the inferior process for
+// This class will insert a UtilityFunction into the inferior process for
// calling libBacktraceRecording's __introspection_dispatch_queue_item_get_info()
// function. The function in the inferior will return a struct by value
// with these members:
@@ -37,7 +37,7 @@
// space (item_buffer_size in size) which must be mach_vm_deallocate'd by
// lldb.
//
-// The AppleGetItemInfoHandler object should persist so that the ClangUtilityFunction
+// The AppleGetItemInfoHandler object should persist so that the UtilityFunction
// can be reused multiple times.
namespace lldb_private
@@ -104,8 +104,7 @@ private:
static const char *g_get_item_info_function_code;
lldb_private::Process *m_process;
- std::unique_ptr<ClangFunction> m_get_item_info_function;
- std::unique_ptr<ClangUtilityFunction> m_get_item_info_impl_code;
+ std::unique_ptr<UtilityFunction> m_get_item_info_impl_code;
Mutex m_get_item_info_function_mutex;
lldb::addr_t m_get_item_info_return_buffer_addr;
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
index c3e68eaa0a6..3e3a2620013 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp
@@ -22,9 +22,8 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Value.h"
-#include "lldb/Expression/ClangExpression.h"
-#include "lldb/Expression/ClangFunction.h"
-#include "lldb/Expression/ClangUtilityFunction.h"
+#include "lldb/Expression/FunctionCaller.h"
+#include "lldb/Expression/UtilityFunction.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/ExecutionContext.h"
@@ -105,7 +104,6 @@ extern \"C\"
AppleGetPendingItemsHandler::AppleGetPendingItemsHandler (Process *process) :
m_process (process),
- m_get_pending_items_function (),
m_get_pending_items_impl_code (),
m_get_pending_items_function_mutex(),
m_get_pending_items_return_buffer_addr (LLDB_INVALID_ADDRESS),
@@ -144,49 +142,33 @@ lldb::addr_t
AppleGetPendingItemsHandler::SetupGetPendingItemsFunction (Thread &thread, ValueList &get_pending_items_arglist)
{
ExecutionContext exe_ctx (thread.shared_from_this());
- Address impl_code_address;
StreamString errors;
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME));
lldb::addr_t args_addr = LLDB_INVALID_ADDRESS;
-
+ FunctionCaller *get_pending_items_caller = nullptr;
+
// Scope for mutex locker:
{
Mutex::Locker locker(m_get_pending_items_function_mutex);
// 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_get_pending_items_function_code.
-
- if (USE_BUILTIN_FUNCTION)
- {
- ConstString our_utility_function_name("__lldb_backtrace_recording_get_pending_items");
- 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 queues introspection function address.\n");
- return args_addr;
- }
- }
- else if (!m_get_pending_items_impl_code.get())
+ if (!m_get_pending_items_impl_code.get())
{
if (g_get_pending_items_function_code != NULL)
{
- m_get_pending_items_impl_code.reset (new ClangUtilityFunction (g_get_pending_items_function_code,
- g_get_pending_items_function_name));
+ Error error;
+ m_get_pending_items_impl_code.reset (exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage(g_get_pending_items_function_code,
+ eLanguageTypeObjC,
+ g_get_pending_items_function_name,
+ error));
+ if (error.Fail())
+ {
+ if (log)
+ log->Printf ("Failed to get UtilityFunction for pending-items introspection: %s.", error.AsCString());
+ return args_addr;
+ }
+
if (!m_get_pending_items_impl_code->Install(errors, exe_ctx))
{
if (log)
@@ -203,43 +185,22 @@ AppleGetPendingItemsHandler::SetupGetPendingItemsFunction (Thread &thread, Value
return LLDB_INVALID_ADDRESS;
}
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_get_pending_items_impl_code->StartAddress());
- }
- else
- {
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_get_pending_items_impl_code->StartAddress());
- }
-
- // Next make the runner function for our implementation utility function.
- if (!m_get_pending_items_function.get())
- {
+ // Next make the runner function for our implementation utility function.
+ Error error;
ClangASTContext *clang_ast_context = thread.GetProcess()->GetTarget().GetScratchClangASTContext();
CompilerType get_pending_items_return_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
- m_get_pending_items_function.reset(new ClangFunction (thread,
- get_pending_items_return_type,
- impl_code_address,
- get_pending_items_arglist,
- "queue-pending-items"));
-
- errors.Clear();
- unsigned num_errors = m_get_pending_items_function->CompileFunction(errors);
- if (num_errors)
+ get_pending_items_caller = m_get_pending_items_impl_code->MakeFunctionCaller (get_pending_items_return_type,
+ get_pending_items_arglist,
+ error);
+ if (error.Fail())
{
if (log)
- log->Printf ("Error compiling pending-items function: \"%s\".", errors.GetData());
- return args_addr;
- }
-
- errors.Clear();
- if (!m_get_pending_items_function->WriteFunctionWrapper(exe_ctx, errors))
- {
- if (log)
- log->Printf ("Error Inserting pending-items function: \"%s\".", errors.GetData());
+ log->Printf ("Failed to install pending-items introspection function caller: %s.", error.AsCString());
+ m_get_pending_items_impl_code.reset();
return args_addr;
}
}
+
}
errors.Clear();
@@ -248,7 +209,7 @@ AppleGetPendingItemsHandler::SetupGetPendingItemsFunction (Thread &thread, Value
// 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_get_pending_items_function->WriteFunctionArguments (exe_ctx, args_addr, impl_code_address, get_pending_items_arglist, errors))
+ if (!get_pending_items_caller->WriteFunctionArguments (exe_ctx, args_addr, get_pending_items_arglist, errors))
{
if (log)
log->Printf ("Error writing pending-items function arguments: \"%s\".", errors.GetData());
@@ -362,6 +323,8 @@ AppleGetPendingItemsHandler::GetPendingItems (Thread &thread, addr_t queue, addr
StreamString errors;
ExecutionContext exe_ctx;
+ FunctionCaller *get_pending_items_caller = m_get_pending_items_impl_code->GetFunctionCaller();
+
EvaluateExpressionOptions options;
options.SetUnwindOnError (true);
options.SetIgnoreBreakpoints (true);
@@ -370,7 +333,7 @@ AppleGetPendingItemsHandler::GetPendingItems (Thread &thread, addr_t queue, addr
options.SetTryAllThreads (false);
thread.CalculateExecutionContext (exe_ctx);
- if (m_get_pending_items_function == NULL)
+ if (get_pending_items_caller == NULL)
{
error.SetErrorString ("Unable to compile function to call __introspection_dispatch_queue_get_pending_items");
return return_value;
@@ -379,7 +342,7 @@ AppleGetPendingItemsHandler::GetPendingItems (Thread &thread, addr_t queue, addr
ExpressionResults func_call_ret;
Value results;
- func_call_ret = m_get_pending_items_function->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
+ func_call_ret = get_pending_items_caller->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
if (func_call_ret != eExpressionCompleted || !error.Success())
{
if (log)
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.h b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.h
index 22ab1f6132c..445c4a0fb82 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.h
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.h
@@ -18,11 +18,10 @@
// Project includes
#include "lldb/lldb-public.h"
#include "lldb/Core/Error.h"
-#include "lldb/Expression/ClangFunction.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Symbol/CompilerType.h"
-// This class will insert a ClangUtilityFunction into the inferior process for
+// This class will insert a UtilityFunction into the inferior process for
// calling libBacktraceRecording's __introspection_dispatch_queue_get_pending_items()
// function. The function in the inferior will return a struct by value
// with these members:
@@ -38,7 +37,7 @@
// space (items_buffer_size in size) which must be mach_vm_deallocate'd by
// lldb. count is the number of items that were stored in the buffer.
//
-// The AppleGetPendingItemsHandler object should persist so that the ClangUtilityFunction
+// The AppleGetPendingItemsHandler object should persist so that the UtilityFunction
// can be reused multiple times.
namespace lldb_private
@@ -107,8 +106,7 @@ private:
static const char *g_get_pending_items_function_code;
lldb_private::Process *m_process;
- std::unique_ptr<ClangFunction> m_get_pending_items_function;
- std::unique_ptr<ClangUtilityFunction> m_get_pending_items_impl_code;
+ std::unique_ptr<UtilityFunction> m_get_pending_items_impl_code;
Mutex m_get_pending_items_function_mutex;
lldb::addr_t m_get_pending_items_return_buffer_addr;
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
index d5b1380e273..6d7eaf72191 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
@@ -21,9 +21,8 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Value.h"
-#include "lldb/Expression/ClangExpression.h"
-#include "lldb/Expression/ClangFunction.h"
-#include "lldb/Expression/ClangUtilityFunction.h"
+#include "lldb/Expression/FunctionCaller.h"
+#include "lldb/Expression/UtilityFunction.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/ExecutionContext.h"
@@ -101,8 +100,7 @@ extern \"C\"
AppleGetQueuesHandler::AppleGetQueuesHandler (Process *process) :
m_process (process),
- m_get_queues_function (),
- m_get_queues_impl_code (),
+ m_get_queues_impl_code_up (),
m_get_queues_function_mutex(),
m_get_queues_return_buffer_addr (LLDB_INVALID_ADDRESS),
m_get_queues_retbuffer_mutex()
@@ -156,6 +154,8 @@ AppleGetQueuesHandler::SetupGetQueuesFunction (Thread &thread, ValueList &get_qu
StreamString errors;
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME));
lldb::addr_t args_addr = LLDB_INVALID_ADDRESS;
+
+ FunctionCaller *get_queues_caller = nullptr;
// Scope for mutex locker:
{
@@ -163,43 +163,27 @@ AppleGetQueuesHandler::SetupGetQueuesFunction (Thread &thread, ValueList &get_qu
// 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_get_current_queues_function_code.
-
- if (USE_BUILTIN_FUNCTION)
- {
- ConstString our_utility_function_name("__lldb_backtrace_recording_get_current_queues");
- 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 queues introspection function address.\n");
- return args_addr;
- }
- }
- else if (!m_get_queues_impl_code.get())
+ if (!m_get_queues_impl_code_up.get())
{
if (g_get_current_queues_function_code != NULL)
{
- m_get_queues_impl_code.reset (new ClangUtilityFunction (g_get_current_queues_function_code,
- g_get_current_queues_function_name));
- if (!m_get_queues_impl_code->Install(errors, exe_ctx))
+ Error error;
+ m_get_queues_impl_code_up.reset (exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage(g_get_current_queues_function_code,
+ eLanguageTypeC,
+ g_get_current_queues_function_name,
+ error));
+ if (error.Fail())
+ {
+ if (log)
+ log->Printf ("Failed to get UtilityFunction for queues introspection: %s.", error.AsCString());
+ return args_addr;
+ }
+
+ if (!m_get_queues_impl_code_up->Install(errors, exe_ctx))
{
if (log)
log->Printf ("Failed to install queues introspection: %s.", errors.GetData());
- m_get_queues_impl_code.reset();
+ m_get_queues_impl_code_up.reset();
return args_addr;
}
}
@@ -210,43 +194,20 @@ AppleGetQueuesHandler::SetupGetQueuesFunction (Thread &thread, ValueList &get_qu
errors.Printf ("No queues introspection code found.");
return LLDB_INVALID_ADDRESS;
}
-
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_get_queues_impl_code->StartAddress());
- }
- else
- {
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_get_queues_impl_code->StartAddress());
}
-
+
// Next make the runner function for our implementation utility function.
- if (!m_get_queues_function.get())
+ ClangASTContext *clang_ast_context = thread.GetProcess()->GetTarget().GetScratchClangASTContext();
+ CompilerType get_queues_return_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
+ Error error;
+ get_queues_caller = m_get_queues_impl_code_up->MakeFunctionCaller (get_queues_return_type,
+ get_queues_arglist,
+ error);
+ if (error.Fail())
{
- ClangASTContext *clang_ast_context = thread.GetProcess()->GetTarget().GetScratchClangASTContext();
- CompilerType get_queues_return_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
- m_get_queues_function.reset(new ClangFunction (thread,
- get_queues_return_type,
- impl_code_address,
- get_queues_arglist,
- "queue-fetch-queues"));
-
- errors.Clear();
- unsigned num_errors = m_get_queues_function->CompileFunction(errors);
- if (num_errors)
- {
- if (log)
- log->Printf ("Error compiling get-queues function: \"%s\".", errors.GetData());
- return args_addr;
- }
-
- errors.Clear();
- if (!m_get_queues_function->WriteFunctionWrapper(exe_ctx, errors))
- {
- if (log)
- log->Printf ("Error Inserting get-queues function: \"%s\".", errors.GetData());
- return args_addr;
- }
+ if (log)
+ log->Printf ("Could not get function caller for get-queues function: %s.", error.AsCString());
+ return args_addr;
}
}
@@ -256,7 +217,7 @@ AppleGetQueuesHandler::SetupGetQueuesFunction (Thread &thread, ValueList &get_qu
// 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_get_queues_function->WriteFunctionArguments (exe_ctx, args_addr, impl_code_address, get_queues_arglist, errors))
+ if (!get_queues_caller->WriteFunctionArguments (exe_ctx, args_addr, get_queues_arglist, errors))
{
if (log)
log->Printf ("Error writing get-queues function arguments: \"%s\".", errors.GetData());
@@ -360,9 +321,17 @@ AppleGetQueuesHandler::GetCurrentQueues (Thread &thread, addr_t page_to_free, ui
addr_t args_addr = SetupGetQueuesFunction (thread, argument_values);
- if (m_get_queues_function == NULL)
+ if (!m_get_queues_impl_code_up)
+ {
+ error.SetErrorString ("Unable to compile __introspection_dispatch_get_queues.");
+ return return_value;
+ }
+
+ FunctionCaller *get_queues_caller = m_get_queues_impl_code_up->GetFunctionCaller();
+
+ if (get_queues_caller == NULL)
{
- error.SetErrorString ("Unable to compile function to call __introspection_dispatch_get_queues");
+ error.SetErrorString ("Unable to get caller for call __introspection_dispatch_get_queues");
return return_value;
}
@@ -378,7 +347,7 @@ AppleGetQueuesHandler::GetCurrentQueues (Thread &thread, addr_t page_to_free, ui
ExpressionResults func_call_ret;
Value results;
- func_call_ret = m_get_queues_function->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
+ func_call_ret = get_queues_caller->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
if (func_call_ret != eExpressionCompleted || !error.Success())
{
if (log)
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h
index 83730b58374..6f3df5f6280 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h
@@ -18,11 +18,10 @@
// Project includes
#include "lldb/lldb-public.h"
#include "lldb/Core/Error.h"
-#include "lldb/Expression/ClangFunction.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Symbol/CompilerType.h"
-// This class will insert a ClangUtilityFunction into the inferior process for
+// This class will insert a UtilityFunction into the inferior process for
// calling libBacktraceRecording's introspection_get_dispatch_queues()
// function. The function in the inferior will return a struct by value
// with these members:
@@ -38,7 +37,7 @@
// space (queues_buffer_size in size) which must be mach_vm_deallocate'd by
// lldb. count is the number of queues that were stored in the buffer.
//
-// The AppleGetQueuesHandler object should persist so that the ClangUtilityFunction
+// The AppleGetQueuesHandler object should persist so that the UtilityFunction
// can be reused multiple times.
namespace lldb_private
@@ -104,8 +103,7 @@ private:
static const char *g_get_current_queues_function_code;
lldb_private::Process *m_process;
- std::unique_ptr<ClangFunction> m_get_queues_function;
- std::unique_ptr<ClangUtilityFunction> m_get_queues_impl_code;
+ std::unique_ptr<UtilityFunction> m_get_queues_impl_code_up;
Mutex m_get_queues_function_mutex;
lldb::addr_t m_get_queues_return_buffer_addr;
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
index 2509b3ba0ef..ea7014147b6 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp
@@ -17,18 +17,20 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclCXX.h"
+#include "lldb/lldb-private.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Value.h"
-#include "lldb/Expression/ClangExpression.h"
-#include "lldb/Expression/ClangFunction.h"
-#include "lldb/Expression/ClangUtilityFunction.h"
+#include "lldb/Expression/Expression.h"
+#include "lldb/Expression/FunctionCaller.h"
+#include "lldb/Expression/UtilityFunction.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
@@ -105,7 +107,6 @@ extern \"C\"
AppleGetThreadItemInfoHandler::AppleGetThreadItemInfoHandler (Process *process) :
m_process (process),
- m_get_thread_item_info_function (),
m_get_thread_item_info_impl_code (),
m_get_thread_item_info_function_mutex(),
m_get_thread_item_info_return_buffer_addr (LLDB_INVALID_ADDRESS),
@@ -148,6 +149,7 @@ AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction (Thread &thread, V
StreamString errors;
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME));
lldb::addr_t args_addr = LLDB_INVALID_ADDRESS;
+ FunctionCaller *get_thread_item_info_caller = nullptr;
// Scope for mutex locker:
{
@@ -155,38 +157,24 @@ AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction (Thread &thread, V
// 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_get_thread_item_info_function_code.
-
- if (USE_BUILTIN_FUNCTION)
- {
- ConstString our_utility_function_name("__lldb_backtrace_recording_get_thread_item_info");
- 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 queues introspection function address.\n");
- return args_addr;
- }
- }
- else if (!m_get_thread_item_info_impl_code.get())
+ if (!m_get_thread_item_info_impl_code.get())
{
+ Error error;
if (g_get_thread_item_info_function_code != NULL)
{
- m_get_thread_item_info_impl_code.reset (new ClangUtilityFunction (g_get_thread_item_info_function_code,
- g_get_thread_item_info_function_name));
+ m_get_thread_item_info_impl_code.reset (exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage (g_get_thread_item_info_function_code,
+ eLanguageTypeC,
+ g_get_thread_item_info_function_name,
+ error));
+ if (error.Fail())
+ {
+ if (log)
+ log->Printf ("Failed to get UtilityFunction for get-thread-item-info introspection: %s.",
+ error.AsCString());
+ m_get_thread_item_info_impl_code.reset();
+ return args_addr;
+ }
+
if (!m_get_thread_item_info_impl_code->Install(errors, exe_ctx))
{
if (log)
@@ -203,42 +191,26 @@ AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction (Thread &thread, V
return LLDB_INVALID_ADDRESS;
}
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_get_thread_item_info_impl_code->StartAddress());
- }
- else
- {
- impl_code_address.Clear();
- impl_code_address.SetOffset(m_get_thread_item_info_impl_code->StartAddress());
- }
-
- // Next make the runner function for our implementation utility function.
- if (!m_get_thread_item_info_function.get())
- {
+ // Also make the FunctionCaller for this UtilityFunction:
+
ClangASTContext *clang_ast_context = thread.GetProcess()->GetTarget().GetScratchClangASTContext();
CompilerType get_thread_item_info_return_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
- m_get_thread_item_info_function.reset(new ClangFunction (thread,
- get_thread_item_info_return_type,
- impl_code_address,
- get_thread_item_info_arglist,
- "queue-thread-item-info"));
- errors.Clear();
- unsigned num_errors = m_get_thread_item_info_function->CompileFunction(errors);
- if (num_errors)
+ get_thread_item_info_caller = m_get_thread_item_info_impl_code->MakeFunctionCaller (get_thread_item_info_return_type,
+ get_thread_item_info_arglist,
+ error);
+ if (error.Fail())
{
if (log)
- log->Printf ("Error compiling get-thread-item-info function: \"%s\".", errors.GetData());
+ log->Printf ("Failed to install get-thread-item-info introspection caller: %s.", error.AsCString());
+ m_get_thread_item_info_impl_code.reset();
return args_addr;
}
- errors.Clear();
- if (!m_get_thread_item_info_function->WriteFunctionWrapper(exe_ctx, errors))
- {
- if (log)
- log->Printf ("Error Inserting get-thread-item-info function: \"%s\".", errors.GetData());
- return args_addr;
- }
+ }
+ else
+ {
+ get_thread_item_info_caller = m_get_thread_item_info_impl_code->GetFunctionCaller();
}
}
@@ -248,7 +220,7 @@ AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction (Thread &thread, V
// 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_get_thread_item_info_function->WriteFunctionArguments (exe_ctx, args_addr, impl_code_address, get_thread_item_info_arglist, errors))
+ if (!get_thread_item_info_caller->WriteFunctionArguments (exe_ctx, args_addr, get_thread_item_info_arglist, errors))
{
if (log)
log->Printf ("Error writing get-thread-item-info function arguments: \"%s\".", errors.GetData());
@@ -360,6 +332,8 @@ AppleGetThreadItemInfoHandler::GetThreadItemInfo (Thread &thread, tid_t thread_i
StreamString errors;
ExecutionContext exe_ctx;
EvaluateExpressionOptions options;
+ FunctionCaller *get_thread_item_info_caller = nullptr;
+
options.SetUnwindOnError (true);
options.SetIgnoreBreakpoints (true);
options.SetStopOthers (true);
@@ -367,16 +341,23 @@ AppleGetThreadItemInfoHandler::GetThreadItemInfo (Thread &thread, tid_t thread_i
options.SetTryAllThreads (false);
thread.CalculateExecutionContext (exe_ctx);
- if (m_get_thread_item_info_function == NULL)
+ if (!m_get_thread_item_info_impl_code)
{
error.SetErrorString ("Unable to compile function to call __introspection_dispatch_thread_get_item_info");
return return_value;
}
+ get_thread_item_info_caller = m_get_thread_item_info_impl_code->GetFunctionCaller();
+
+ if (!get_thread_item_info_caller)
+ {
+ error.SetErrorString ("Unable to compile function caller for __introspection_dispatch_thread_get_item_info");
+ return return_value;
+ }
ExpressionResults func_call_ret;
Value results;
- func_call_ret = m_get_thread_item_info_function->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
+ func_call_ret = get_thread_item_info_caller->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
if (func_call_ret != eExpressionCompleted || !error.Success())
{
if (log)
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.h b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.h
index 6ced39ae851..c1798fb515b 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.h
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.h
@@ -18,11 +18,10 @@
// Project includes
#include "lldb/lldb-public.h"
#include "lldb/Core/Error.h"
-#include "lldb/Expression/ClangFunction.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Symbol/CompilerType.h"
-// This class will insert a ClangUtilityFunction into the inferior process for
+// This class will insert a UtilityFunction into the inferior process for
// calling libBacktraceRecording's __introspection_dispatch_thread_get_item_info()
// function. The function in the inferior will return a struct by value
// with these members:
@@ -37,7 +36,7 @@
// space (item_buffer_size in size) which must be mach_vm_deallocate'd by
// lldb.
//
-// The AppleGetThreadItemInfoHandler object should persist so that the ClangUtilityFunction
+// The AppleGetThreadItemInfoHandler object should persist so that the UtilityFunction
// can be reused multiple times.
namespace lldb_private
@@ -101,8 +100,7 @@ private:
static const char *g_get_thread_item_info_function_code;
lldb_private::Process *m_process;
- std::unique_ptr<ClangFunction> m_get_thread_item_info_function;
- std::unique_ptr<ClangUtilityFunction> m_get_thread_item_info_impl_code;
+ std::unique_ptr<UtilityFunction> m_get_thread_item_info_impl_code;
Mutex m_get_thread_item_info_function_mutex;
lldb::addr_t m_get_thread_item_info_return_buffer_addr;
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
index 90271f29c71..11b47df87d0 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
@@ -17,8 +17,6 @@
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/StreamString.h"
-#include "lldb/Expression/ClangFunction.h"
-#include "lldb/Expression/ClangUtilityFunction.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ObjectFile.h"
OpenPOWER on IntegriCloud