aboutsummaryrefslogtreecommitdiff
path: root/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp')
-rw-r--r--source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp75
1 files changed, 43 insertions, 32 deletions
diff --git a/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp b/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
index 3370b3257a25..e90fe6d5d17d 100644
--- a/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
+++ b/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp
@@ -18,6 +18,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"
@@ -95,12 +96,12 @@ extern \"C\"
} \n\
";
-AppleGetQueuesHandler::AppleGetQueuesHandler (Process *process) :
- m_process (process),
- 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()
+AppleGetQueuesHandler::AppleGetQueuesHandler(Process *process)
+ : m_process(process),
+ 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()
{
}
@@ -109,14 +110,14 @@ AppleGetQueuesHandler::~AppleGetQueuesHandler ()
}
void
-AppleGetQueuesHandler::Detach ()
+AppleGetQueuesHandler::Detach()
{
if (m_process && m_process->IsAlive() && m_get_queues_return_buffer_addr != LLDB_INVALID_ADDRESS)
{
- Mutex::Locker locker;
- locker.TryLock (m_get_queues_retbuffer_mutex); // Even if we don't get the lock, deallocate the buffer
- m_process->DeallocateMemory (m_get_queues_return_buffer_addr);
+ std::unique_lock<std::mutex> lock(m_get_queues_retbuffer_mutex, std::defer_lock);
+ lock.try_lock(); // Even if we don't get the lock, deallocate the buffer
+ m_process->DeallocateMemory(m_get_queues_return_buffer_addr);
}
}
@@ -146,18 +147,20 @@ AppleGetQueuesHandler::Detach ()
lldb::addr_t
AppleGetQueuesHandler::SetupGetQueuesFunction (Thread &thread, ValueList &get_queues_arglist)
{
- ExecutionContext exe_ctx (thread.shared_from_this());
+ ThreadSP thread_sp(thread.shared_from_this());
+ ExecutionContext exe_ctx (thread_sp);
+
Address impl_code_address;
- StreamString errors;
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME));
+ DiagnosticManager diagnostics;
+ 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:
{
- Mutex::Locker locker(m_get_queues_function_mutex);
-
+ std::lock_guard<std::mutex> guard(m_get_queues_function_mutex);
+
// First stage is to make the ClangUtility to hold our injected function:
if (!m_get_queues_impl_code_up.get())
@@ -175,11 +178,14 @@ AppleGetQueuesHandler::SetupGetQueuesFunction (Thread &thread, ValueList &get_qu
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 (!m_get_queues_impl_code_up->Install(diagnostics, exe_ctx))
{
if (log)
- log->Printf ("Failed to install queues introspection: %s.", errors.GetData());
+ {
+ log->Printf("Failed to install queues introspection");
+ diagnostics.Dump(log);
+ }
m_get_queues_impl_code_up.reset();
return args_addr;
}
@@ -187,18 +193,21 @@ AppleGetQueuesHandler::SetupGetQueuesFunction (Thread &thread, ValueList &get_qu
else
{
if (log)
+ {
log->Printf("No queues introspection code found.");
- errors.Printf ("No queues introspection code found.");
+ diagnostics.Dump(log);
+ }
return LLDB_INVALID_ADDRESS;
}
}
-
+
// Next make the runner function for our implementation utility function.
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,
+ thread_sp,
error);
if (error.Fail())
{
@@ -207,20 +216,23 @@ AppleGetQueuesHandler::SetupGetQueuesFunction (Thread &thread, ValueList &get_qu
return args_addr;
}
}
-
- errors.Clear();
-
+
+ diagnostics.Clear();
+
// Now write down the argument values for this particular call. This looks like it might be a race condition
// 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_queues_caller->WriteFunctionArguments (exe_ctx, args_addr, get_queues_arglist, errors))
+ if (!get_queues_caller->WriteFunctionArguments(exe_ctx, args_addr, get_queues_arglist, diagnostics))
{
if (log)
- log->Printf ("Error writing get-queues function arguments: \"%s\".", errors.GetData());
+ {
+ log->Printf("Error writing get-queues function arguments.");
+ diagnostics.Dump(log);
+ }
return args_addr;
}
-
+
return args_addr;
}
@@ -285,8 +297,7 @@ AppleGetQueuesHandler::GetCurrentQueues (Thread &thread, addr_t page_to_free, ui
page_to_free_size_value.SetValueType (Value::eValueTypeScalar);
page_to_free_size_value.SetCompilerType (clang_uint64_type);
-
- Mutex::Locker locker(m_get_queues_retbuffer_mutex);
+ std::lock_guard<std::mutex> guard(m_get_queues_retbuffer_mutex);
if (m_get_queues_return_buffer_addr == LLDB_INVALID_ADDRESS)
{
addr_t bufaddr = process_sp->AllocateMemory (32, ePermissionsReadable | ePermissionsWritable, error);
@@ -332,10 +343,10 @@ AppleGetQueuesHandler::GetCurrentQueues (Thread &thread, addr_t page_to_free, ui
return return_value;
}
- StreamString errors;
+ DiagnosticManager diagnostics;
ExecutionContext exe_ctx;
EvaluateExpressionOptions options;
- options.SetUnwindOnError (true);
+ options.SetUnwindOnError(true);
options.SetIgnoreBreakpoints (true);
options.SetStopOthers (true);
options.SetTimeoutUsec(500000);
@@ -344,7 +355,7 @@ AppleGetQueuesHandler::GetCurrentQueues (Thread &thread, addr_t page_to_free, ui
ExpressionResults func_call_ret;
Value results;
- func_call_ret = get_queues_caller->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
+ func_call_ret = get_queues_caller->ExecuteFunction(exe_ctx, &args_addr, options, diagnostics, results);
if (func_call_ret != eExpressionCompleted || !error.Success())
{
if (log)