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