Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 1 | //===-- AppleGetQueuesHandler.cpp -------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "AppleGetQueuesHandler.h" |
| 10 | |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 11 | #include "lldb/Core/Module.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Value.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 13 | #include "lldb/Expression/DiagnosticManager.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 14 | #include "lldb/Expression/FunctionCaller.h" |
| 15 | #include "lldb/Expression/UtilityFunction.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/ClangASTContext.h" |
| 17 | #include "lldb/Symbol/Symbol.h" |
| 18 | #include "lldb/Target/ExecutionContext.h" |
| 19 | #include "lldb/Target/Process.h" |
Bruce Mitchener | cfe7d6c | 2015-09-03 23:57:09 +0000 | [diff] [blame] | 20 | #include "lldb/Target/Target.h" |
| 21 | #include "lldb/Target/Thread.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 22 | #include "lldb/Utility/ConstString.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 23 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 24 | #include "lldb/Utility/StreamString.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace lldb; |
| 27 | using namespace lldb_private; |
| 28 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | const char *AppleGetQueuesHandler::g_get_current_queues_function_name = |
| 30 | "__lldb_backtrace_recording_get_current_queues"; |
| 31 | const char *AppleGetQueuesHandler::g_get_current_queues_function_code = |
| 32 | " \n\ |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 33 | extern \"C\" \n\ |
| 34 | { \n\ |
| 35 | /* \n\ |
| 36 | * mach defines \n\ |
| 37 | */ \n\ |
| 38 | \n\ |
| 39 | typedef unsigned int uint32_t; \n\ |
| 40 | typedef unsigned long long uint64_t; \n\ |
| 41 | typedef uint32_t mach_port_t; \n\ |
| 42 | typedef mach_port_t vm_map_t; \n\ |
| 43 | typedef int kern_return_t; \n\ |
| 44 | typedef uint64_t mach_vm_address_t; \n\ |
| 45 | typedef uint64_t mach_vm_size_t; \n\ |
| 46 | \n\ |
| 47 | mach_port_t mach_task_self (); \n\ |
| 48 | kern_return_t mach_vm_deallocate (vm_map_t target, mach_vm_address_t address, mach_vm_size_t size); \n\ |
| 49 | \n\ |
| 50 | /* \n\ |
| 51 | * libBacktraceRecording defines \n\ |
| 52 | */ \n\ |
| 53 | \n\ |
| 54 | typedef uint32_t queue_list_scope_t; \n\ |
| 55 | typedef void *introspection_dispatch_queue_info_t; \n\ |
| 56 | \n\ |
| 57 | extern uint64_t __introspection_dispatch_get_queues (queue_list_scope_t scope, \n\ |
| 58 | introspection_dispatch_queue_info_t *returned_queues_buffer, \n\ |
| 59 | uint64_t *returned_queues_buffer_size); \n\ |
| 60 | extern int printf(const char *format, ...); \n\ |
| 61 | \n\ |
| 62 | /* \n\ |
| 63 | * return type define \n\ |
| 64 | */ \n\ |
| 65 | \n\ |
| 66 | struct get_current_queues_return_values \n\ |
| 67 | { \n\ |
| 68 | uint64_t queues_buffer_ptr; /* the address of the queues buffer from libBacktraceRecording */ \n\ |
| 69 | uint64_t queues_buffer_size; /* the size of the queues buffer from libBacktraceRecording */ \n\ |
| 70 | uint64_t count; /* the number of queues included in the queues buffer */ \n\ |
| 71 | }; \n\ |
| 72 | \n\ |
| 73 | void __lldb_backtrace_recording_get_current_queues \n\ |
| 74 | (struct get_current_queues_return_values *return_buffer, \n\ |
| 75 | int debug, \n\ |
| 76 | void *page_to_free, \n\ |
| 77 | uint64_t page_to_free_size) \n\ |
| 78 | { \n\ |
| 79 | if (debug) \n\ |
| 80 | printf (\"entering get_current_queues with args %p, %d, 0x%p, 0x%llx\\n\", return_buffer, debug, page_to_free, page_to_free_size); \n\ |
| 81 | if (page_to_free != 0) \n\ |
| 82 | { \n\ |
| 83 | mach_vm_deallocate (mach_task_self(), (mach_vm_address_t) page_to_free, (mach_vm_size_t) page_to_free_size); \n\ |
| 84 | } \n\ |
| 85 | \n\ |
| 86 | return_buffer->count = __introspection_dispatch_get_queues ( \n\ |
| 87 | /* QUEUES_WITH_ANY_ITEMS */ 2, \n\ |
| 88 | (void**)&return_buffer->queues_buffer_ptr, \n\ |
| 89 | &return_buffer->queues_buffer_size); \n\ |
| 90 | if (debug) \n\ |
| 91 | printf(\"result was count %lld\\n\", return_buffer->count); \n\ |
| 92 | } \n\ |
| 93 | } \n\ |
| 94 | "; |
| 95 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 96 | AppleGetQueuesHandler::AppleGetQueuesHandler(Process *process) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | : m_process(process), m_get_queues_impl_code_up(), |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 98 | m_get_queues_function_mutex(), |
| 99 | m_get_queues_return_buffer_addr(LLDB_INVALID_ADDRESS), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | m_get_queues_retbuffer_mutex() {} |
| 101 | |
| 102 | AppleGetQueuesHandler::~AppleGetQueuesHandler() {} |
| 103 | |
| 104 | void AppleGetQueuesHandler::Detach() { |
| 105 | |
| 106 | if (m_process && m_process->IsAlive() && |
| 107 | m_get_queues_return_buffer_addr != LLDB_INVALID_ADDRESS) { |
| 108 | std::unique_lock<std::mutex> lock(m_get_queues_retbuffer_mutex, |
| 109 | std::defer_lock); |
| 110 | lock.try_lock(); // Even if we don't get the lock, deallocate the buffer |
| 111 | m_process->DeallocateMemory(m_get_queues_return_buffer_addr); |
| 112 | } |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | // Construct a CompilerType for the structure that |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 116 | // g_get_current_queues_function_code will return by value so we can extract |
| 117 | // the fields after performing the function call. i.e. we are getting this |
| 118 | // struct returned to us: |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 119 | // |
| 120 | // struct get_current_queues_return_values |
| 121 | // { |
| 122 | // introspection_dispatch_queue_info_t *queues_buffer; |
| 123 | // uint64_t queues_buffer_size; |
| 124 | // uint64_t count; |
| 125 | // }; |
| 126 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 127 | // Compile our __lldb_backtrace_recording_get_current_queues() function (from |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 128 | // the source above in g_get_current_queues_function_code) if we don't find |
| 129 | // that function in the inferior already with USE_BUILTIN_FUNCTION defined. |
| 130 | // (e.g. this would be the case for testing.) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 131 | // |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | // Insert the __lldb_backtrace_recording_get_current_queues into the inferior |
| 133 | // process if needed. |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 134 | // |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 135 | // Write the get_queues_arglist into the inferior's memory space to prepare for |
| 136 | // the call. |
| 137 | // |
| 138 | // Returns the address of the arguments written down in the inferior process, |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 139 | // which can be used to make the function call. |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 140 | |
| 141 | lldb::addr_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | AppleGetQueuesHandler::SetupGetQueuesFunction(Thread &thread, |
| 143 | ValueList &get_queues_arglist) { |
| 144 | ThreadSP thread_sp(thread.shared_from_this()); |
| 145 | ExecutionContext exe_ctx(thread_sp); |
Jim Ingham | 6896b35 | 2016-03-21 19:21:13 +0000 | [diff] [blame] | 146 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 147 | Address impl_code_address; |
| 148 | DiagnosticManager diagnostics; |
| 149 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); |
| 150 | lldb::addr_t args_addr = LLDB_INVALID_ADDRESS; |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 151 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | FunctionCaller *get_queues_caller = nullptr; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 153 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | // Scope for mutex locker: |
| 155 | { |
| 156 | std::lock_guard<std::mutex> guard(m_get_queues_function_mutex); |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 157 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | // First stage is to make the ClangUtility to hold our injected function: |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 159 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | if (!m_get_queues_impl_code_up.get()) { |
| 161 | if (g_get_current_queues_function_code != NULL) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 162 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | m_get_queues_impl_code_up.reset( |
| 164 | exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage( |
| 165 | g_get_current_queues_function_code, eLanguageTypeC, |
| 166 | g_get_current_queues_function_name, error)); |
| 167 | if (error.Fail()) { |
| 168 | if (log) |
| 169 | log->Printf( |
| 170 | "Failed to get UtilityFunction for queues introspection: %s.", |
| 171 | error.AsCString()); |
| 172 | return args_addr; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 173 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 174 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 175 | if (!m_get_queues_impl_code_up->Install(diagnostics, exe_ctx)) { |
| 176 | if (log) { |
| 177 | log->Printf("Failed to install queues introspection"); |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 178 | diagnostics.Dump(log); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 179 | } |
| 180 | m_get_queues_impl_code_up.reset(); |
| 181 | return args_addr; |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 182 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 183 | } else { |
| 184 | if (log) { |
| 185 | log->Printf("No queues introspection code found."); |
| 186 | diagnostics.Dump(log); |
| 187 | } |
| 188 | return LLDB_INVALID_ADDRESS; |
| 189 | } |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 190 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 191 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 192 | // Next make the runner function for our implementation utility function. |
| 193 | ClangASTContext *clang_ast_context = |
| 194 | thread.GetProcess()->GetTarget().GetScratchClangASTContext(); |
| 195 | CompilerType get_queues_return_type = |
| 196 | clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 197 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 198 | get_queues_caller = m_get_queues_impl_code_up->MakeFunctionCaller( |
| 199 | get_queues_return_type, get_queues_arglist, thread_sp, error); |
Jason Molenda | ed2977f | 2016-10-27 23:52:46 +0000 | [diff] [blame] | 200 | if (error.Fail() || get_queues_caller == nullptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | if (log) |
| 202 | log->Printf( |
| 203 | "Could not get function caller for get-queues function: %s.", |
| 204 | error.AsCString()); |
| 205 | return args_addr; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | diagnostics.Clear(); |
| 210 | |
| 211 | // Now write down the argument values for this particular call. This looks |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 212 | // like it might be a race condition if other threads were calling into here, |
| 213 | // but actually it isn't because we allocate a new args structure for this |
| 214 | // call by passing args_addr = LLDB_INVALID_ADDRESS... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 215 | |
| 216 | if (!get_queues_caller->WriteFunctionArguments( |
| 217 | exe_ctx, args_addr, get_queues_arglist, diagnostics)) { |
| 218 | if (log) { |
| 219 | log->Printf("Error writing get-queues function arguments."); |
| 220 | diagnostics.Dump(log); |
| 221 | } |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 222 | return args_addr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | return args_addr; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | AppleGetQueuesHandler::GetQueuesReturnInfo |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 229 | AppleGetQueuesHandler::GetCurrentQueues(Thread &thread, addr_t page_to_free, |
| 230 | uint64_t page_to_free_size, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 231 | Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 232 | lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); |
| 233 | ProcessSP process_sp(thread.CalculateProcess()); |
| 234 | TargetSP target_sp(thread.CalculateTarget()); |
| 235 | ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext(); |
| 236 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 237 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 238 | GetQueuesReturnInfo return_value; |
| 239 | return_value.queues_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 240 | return_value.queues_buffer_size = 0; |
| 241 | return_value.count = 0; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 242 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 243 | error.Clear(); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 244 | |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 245 | if (!thread.SafeToCallFunctions()) { |
Jason Molenda | 2a6c252 | 2014-02-15 00:20:40 +0000 | [diff] [blame] | 246 | if (log) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 247 | log->Printf("Not safe to call functions on thread 0x%" PRIx64, |
| 248 | thread.GetID()); |
| 249 | error.SetErrorString("Not safe to call functions on this thread."); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 250 | return return_value; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | // Set up the arguments for a call to |
| 254 | |
| 255 | // struct get_current_queues_return_values |
| 256 | // { |
| 257 | // uint64_t queues_buffer_ptr; /* the address of the queues buffer from |
| 258 | // libBacktraceRecording */ |
| 259 | // uint64_t queues_buffer_size; /* the size of the queues buffer from |
| 260 | // libBacktraceRecording */ |
| 261 | // uint64_t count; /* the number of queues included in the |
| 262 | // queues buffer */ |
| 263 | // }; |
| 264 | // |
| 265 | // void |
| 266 | // __lldb_backtrace_recording_get_current_queues |
| 267 | // (struct |
| 268 | // get_current_queues_return_values |
| 269 | // *return_buffer, |
| 270 | // void *page_to_free, |
| 271 | // uint64_t page_to_free_size); |
| 272 | |
| 273 | // Where the return_buffer argument points to a 24 byte region of memory |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 274 | // already allocated by lldb in the inferior process. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 275 | |
| 276 | CompilerType clang_void_ptr_type = |
| 277 | clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); |
| 278 | Value return_buffer_ptr_value; |
| 279 | return_buffer_ptr_value.SetValueType(Value::eValueTypeScalar); |
| 280 | return_buffer_ptr_value.SetCompilerType(clang_void_ptr_type); |
| 281 | |
| 282 | CompilerType clang_int_type = clang_ast_context->GetBasicType(eBasicTypeInt); |
| 283 | Value debug_value; |
| 284 | debug_value.SetValueType(Value::eValueTypeScalar); |
| 285 | debug_value.SetCompilerType(clang_int_type); |
| 286 | |
| 287 | Value page_to_free_value; |
| 288 | page_to_free_value.SetValueType(Value::eValueTypeScalar); |
| 289 | page_to_free_value.SetCompilerType(clang_void_ptr_type); |
| 290 | |
| 291 | CompilerType clang_uint64_type = |
| 292 | clang_ast_context->GetBasicType(eBasicTypeUnsignedLongLong); |
| 293 | Value page_to_free_size_value; |
| 294 | page_to_free_size_value.SetValueType(Value::eValueTypeScalar); |
| 295 | page_to_free_size_value.SetCompilerType(clang_uint64_type); |
| 296 | |
| 297 | std::lock_guard<std::mutex> guard(m_get_queues_retbuffer_mutex); |
| 298 | if (m_get_queues_return_buffer_addr == LLDB_INVALID_ADDRESS) { |
| 299 | addr_t bufaddr = process_sp->AllocateMemory( |
| 300 | 32, ePermissionsReadable | ePermissionsWritable, error); |
| 301 | if (!error.Success() || bufaddr == LLDB_INVALID_ADDRESS) { |
| 302 | if (log) |
| 303 | log->Printf("Failed to allocate memory for return buffer for get " |
| 304 | "current queues func call"); |
| 305 | return return_value; |
| 306 | } |
| 307 | m_get_queues_return_buffer_addr = bufaddr; |
| 308 | } |
| 309 | |
| 310 | ValueList argument_values; |
| 311 | |
| 312 | return_buffer_ptr_value.GetScalar() = m_get_queues_return_buffer_addr; |
| 313 | argument_values.PushValue(return_buffer_ptr_value); |
| 314 | |
| 315 | debug_value.GetScalar() = 0; |
| 316 | argument_values.PushValue(debug_value); |
| 317 | |
| 318 | if (page_to_free != LLDB_INVALID_ADDRESS) |
| 319 | page_to_free_value.GetScalar() = page_to_free; |
| 320 | else |
| 321 | page_to_free_value.GetScalar() = 0; |
| 322 | argument_values.PushValue(page_to_free_value); |
| 323 | |
| 324 | page_to_free_size_value.GetScalar() = page_to_free_size; |
| 325 | argument_values.PushValue(page_to_free_size_value); |
| 326 | |
| 327 | addr_t args_addr = SetupGetQueuesFunction(thread, argument_values); |
| 328 | |
| 329 | if (!m_get_queues_impl_code_up) { |
| 330 | error.SetErrorString( |
| 331 | "Unable to compile __introspection_dispatch_get_queues."); |
| 332 | return return_value; |
| 333 | } |
| 334 | |
| 335 | FunctionCaller *get_queues_caller = |
| 336 | m_get_queues_impl_code_up->GetFunctionCaller(); |
| 337 | |
| 338 | if (get_queues_caller == NULL) { |
| 339 | error.SetErrorString( |
| 340 | "Unable to get caller for call __introspection_dispatch_get_queues"); |
| 341 | return return_value; |
| 342 | } |
| 343 | |
| 344 | DiagnosticManager diagnostics; |
| 345 | ExecutionContext exe_ctx; |
| 346 | EvaluateExpressionOptions options; |
| 347 | options.SetUnwindOnError(true); |
| 348 | options.SetIgnoreBreakpoints(true); |
| 349 | options.SetStopOthers(true); |
Pavel Labath | 43d3541 | 2016-12-06 11:24:51 +0000 | [diff] [blame] | 350 | options.SetTimeout(std::chrono::milliseconds(500)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 351 | options.SetTryAllThreads(false); |
Raphael Isemann | c01783a | 2018-08-29 22:50:54 +0000 | [diff] [blame] | 352 | options.SetIsForUtilityExpr(true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 353 | thread.CalculateExecutionContext(exe_ctx); |
| 354 | |
| 355 | ExpressionResults func_call_ret; |
| 356 | Value results; |
| 357 | func_call_ret = get_queues_caller->ExecuteFunction( |
| 358 | exe_ctx, &args_addr, options, diagnostics, results); |
| 359 | if (func_call_ret != eExpressionCompleted || !error.Success()) { |
| 360 | if (log) |
| 361 | log->Printf("Unable to call introspection_get_dispatch_queues(), got " |
| 362 | "ExpressionResults %d, error contains %s", |
| 363 | func_call_ret, error.AsCString("")); |
| 364 | error.SetErrorString("Unable to call introspection_get_dispatch_queues() " |
| 365 | "for list of queues"); |
| 366 | return return_value; |
| 367 | } |
| 368 | |
| 369 | return_value.queues_buffer_ptr = m_process->ReadUnsignedIntegerFromMemory( |
| 370 | m_get_queues_return_buffer_addr, 8, LLDB_INVALID_ADDRESS, error); |
| 371 | if (!error.Success() || |
| 372 | return_value.queues_buffer_ptr == LLDB_INVALID_ADDRESS) { |
| 373 | return_value.queues_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 374 | return return_value; |
| 375 | } |
| 376 | |
| 377 | return_value.queues_buffer_size = m_process->ReadUnsignedIntegerFromMemory( |
| 378 | m_get_queues_return_buffer_addr + 8, 8, 0, error); |
| 379 | |
| 380 | if (!error.Success()) { |
| 381 | return_value.queues_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 382 | return return_value; |
| 383 | } |
| 384 | |
| 385 | return_value.count = m_process->ReadUnsignedIntegerFromMemory( |
| 386 | m_get_queues_return_buffer_addr + 16, 8, 0, error); |
| 387 | if (!error.Success()) { |
| 388 | return_value.queues_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 389 | return return_value; |
| 390 | } |
| 391 | |
| 392 | if (log) |
| 393 | log->Printf("AppleGetQueuesHandler called " |
| 394 | "__introspection_dispatch_get_queues (page_to_free == " |
| 395 | "0x%" PRIx64 ", size = %" PRId64 |
| 396 | "), returned page is at 0x%" PRIx64 ", size %" PRId64 |
| 397 | ", count = %" PRId64, |
| 398 | page_to_free, page_to_free_size, return_value.queues_buffer_ptr, |
| 399 | return_value.queues_buffer_size, return_value.count); |
| 400 | |
| 401 | return return_value; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 402 | } |