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