diff options
Diffstat (limited to 'source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp')
-rw-r--r-- | source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp b/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp index 97699878f5ee..d311f5fb5f6e 100644 --- a/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp +++ b/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp @@ -19,6 +19,7 @@ #include "lldb/Core/Module.h" #include "lldb/Core/StreamString.h" #include "lldb/Core/Value.h" +#include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/FunctionCaller.h" #include "lldb/Expression/UtilityFunction.h" #include "lldb/Symbol/ClangASTContext.h" @@ -99,12 +100,12 @@ extern \"C\" } \n\ "; -AppleGetPendingItemsHandler::AppleGetPendingItemsHandler (Process *process) : - m_process (process), - m_get_pending_items_impl_code (), - m_get_pending_items_function_mutex(), - m_get_pending_items_return_buffer_addr (LLDB_INVALID_ADDRESS), - m_get_pending_items_retbuffer_mutex() +AppleGetPendingItemsHandler::AppleGetPendingItemsHandler(Process *process) + : m_process(process), + m_get_pending_items_impl_code(), + m_get_pending_items_function_mutex(), + m_get_pending_items_return_buffer_addr(LLDB_INVALID_ADDRESS), + m_get_pending_items_retbuffer_mutex() { } @@ -113,14 +114,13 @@ AppleGetPendingItemsHandler::~AppleGetPendingItemsHandler () } void -AppleGetPendingItemsHandler::Detach () +AppleGetPendingItemsHandler::Detach() { - if (m_process && m_process->IsAlive() && m_get_pending_items_return_buffer_addr != LLDB_INVALID_ADDRESS) { - Mutex::Locker locker; - locker.TryLock (m_get_pending_items_retbuffer_mutex); // Even if we don't get the lock, deallocate the buffer - m_process->DeallocateMemory (m_get_pending_items_return_buffer_addr); + std::unique_lock<std::mutex> lock(m_get_pending_items_retbuffer_mutex, std::defer_lock); + lock.try_lock(); // Even if we don't get the lock, deallocate the buffer + m_process->DeallocateMemory(m_get_pending_items_return_buffer_addr); } } @@ -136,18 +136,20 @@ AppleGetPendingItemsHandler::Detach () // make the function call. lldb::addr_t -AppleGetPendingItemsHandler::SetupGetPendingItemsFunction (Thread &thread, ValueList &get_pending_items_arglist) +AppleGetPendingItemsHandler::SetupGetPendingItemsFunction(Thread &thread, ValueList &get_pending_items_arglist) { - ExecutionContext exe_ctx (thread.shared_from_this()); - StreamString errors; - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME)); + ThreadSP thread_sp (thread.shared_from_this()); + ExecutionContext exe_ctx (thread_sp); + DiagnosticManager diagnostics; + 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); - + std::lock_guard<std::mutex> guard(m_get_pending_items_function_mutex); + // First stage is to make the ClangUtility to hold our injected function: if (!m_get_pending_items_impl_code.get()) @@ -165,11 +167,14 @@ AppleGetPendingItemsHandler::SetupGetPendingItemsFunction (Thread &thread, Value 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 (!m_get_pending_items_impl_code->Install(diagnostics, exe_ctx)) { if (log) - log->Printf ("Failed to install pending-items introspection: %s.", errors.GetData()); + { + log->Printf("Failed to install pending-items introspection."); + diagnostics.Dump(log); + } m_get_pending_items_impl_code.reset(); return args_addr; } @@ -187,6 +192,7 @@ AppleGetPendingItemsHandler::SetupGetPendingItemsFunction (Thread &thread, Value CompilerType get_pending_items_return_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); get_pending_items_caller = m_get_pending_items_impl_code->MakeFunctionCaller (get_pending_items_return_type, get_pending_items_arglist, + thread_sp, error); if (error.Fail()) { @@ -196,11 +202,10 @@ AppleGetPendingItemsHandler::SetupGetPendingItemsFunction (Thread &thread, Value return args_addr; } } - } - - errors.Clear(); - + + diagnostics.Clear(); + if (get_pending_items_caller == nullptr) { if (log) @@ -212,13 +217,17 @@ 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 (!get_pending_items_caller->WriteFunctionArguments (exe_ctx, args_addr, get_pending_items_arglist, errors)) + if (!get_pending_items_caller->WriteFunctionArguments(exe_ctx, args_addr, get_pending_items_arglist, diagnostics)) { if (log) - log->Printf ("Error writing pending-items function arguments: \"%s\".", errors.GetData()); + { + log->Printf("Error writing pending-items function arguments."); + diagnostics.Dump(log); + } + return args_addr; } - + return args_addr; } @@ -288,8 +297,7 @@ AppleGetPendingItemsHandler::GetPendingItems (Thread &thread, addr_t queue, addr page_to_free_size_value.SetValueType (Value::eValueTypeScalar); page_to_free_size_value.SetCompilerType (clang_uint64_type); - - Mutex::Locker locker(m_get_pending_items_retbuffer_mutex); + std::lock_guard<std::mutex> guard(m_get_pending_items_retbuffer_mutex); if (m_get_pending_items_return_buffer_addr == LLDB_INVALID_ADDRESS) { addr_t bufaddr = process_sp->AllocateMemory (32, ePermissionsReadable | ePermissionsWritable, error); @@ -322,12 +330,12 @@ AppleGetPendingItemsHandler::GetPendingItems (Thread &thread, addr_t queue, addr page_to_free_size_value.GetScalar() = page_to_free_size; argument_values.PushValue (page_to_free_size_value); - addr_t args_addr = SetupGetPendingItemsFunction (thread, argument_values); + addr_t args_addr = SetupGetPendingItemsFunction(thread, argument_values); - StreamString errors; + DiagnosticManager diagnostics; ExecutionContext exe_ctx; FunctionCaller *get_pending_items_caller = m_get_pending_items_impl_code->GetFunctionCaller(); - + EvaluateExpressionOptions options; options.SetUnwindOnError (true); options.SetIgnoreBreakpoints (true); @@ -342,10 +350,9 @@ AppleGetPendingItemsHandler::GetPendingItems (Thread &thread, addr_t queue, addr return return_value; } - ExpressionResults func_call_ret; Value results; - func_call_ret = get_pending_items_caller->ExecuteFunction (exe_ctx, &args_addr, options, errors, results); + func_call_ret = get_pending_items_caller->ExecuteFunction(exe_ctx, &args_addr, options, diagnostics, results); if (func_call_ret != eExpressionCompleted || !error.Success()) { if (log) |