Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 1 | //===-- AppleGetItemInfoHandler.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 "AppleGetItemInfoHandler.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 *AppleGetItemInfoHandler::g_get_item_info_function_name = "__lldb_backtrace_recording_get_item_info"; |
| 36 | const char *AppleGetItemInfoHandler::g_get_item_info_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_item_get_info (introspection_dispatch_item_info_ref item_info_ref, \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_item_info_return_values \n\ |
| 73 | { \n\ |
| 74 | uint64_t item_info_buffer_ptr; /* the address of the items buffer from libBacktraceRecording */ \n\ |
| 75 | uint64_t item_info_buffer_size; /* the size of the items buffer from libBacktraceRecording */ \n\ |
| 76 | }; \n\ |
| 77 | \n\ |
| 78 | void __lldb_backtrace_recording_get_item_info \n\ |
| 79 | (struct get_item_info_return_values *return_buffer, \n\ |
| 80 | int debug, \n\ |
| 81 | uint64_t /* introspection_dispatch_item_info_ref item_info_ref */ item, \n\ |
| 82 | void *page_to_free, \n\ |
| 83 | uint64_t page_to_free_size) \n\ |
| 84 | { \n\ |
| 85 | if (debug) \n\ |
| 86 | printf (\"entering get_item_info with args return_buffer == %p, debug == %d, item == 0x%llx, page_to_free == %p, page_to_free_size == 0x%llx\\n\", return_buffer, debug, item, page_to_free, page_to_free_size); \n\ |
| 87 | if (page_to_free != 0) \n\ |
| 88 | { \n\ |
| 89 | mach_vm_deallocate (mach_task_self(), (mach_vm_address_t) page_to_free, (mach_vm_size_t) page_to_free_size); \n\ |
| 90 | } \n\ |
| 91 | \n\ |
| 92 | __introspection_dispatch_queue_item_get_info ((void*) item, \n\ |
| 93 | (void**)&return_buffer->item_info_buffer_ptr, \n\ |
| 94 | &return_buffer->item_info_buffer_size); \n\ |
| 95 | } \n\ |
| 96 | } \n\ |
| 97 | "; |
| 98 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 99 | AppleGetItemInfoHandler::AppleGetItemInfoHandler(Process *process) |
| 100 | : m_process(process), |
| 101 | m_get_item_info_impl_code(), |
| 102 | m_get_item_info_function_mutex(), |
| 103 | m_get_item_info_return_buffer_addr(LLDB_INVALID_ADDRESS), |
| 104 | m_get_item_info_retbuffer_mutex() |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 105 | { |
| 106 | } |
| 107 | |
| 108 | AppleGetItemInfoHandler::~AppleGetItemInfoHandler () |
| 109 | { |
| 110 | } |
| 111 | |
| 112 | void |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 113 | AppleGetItemInfoHandler::Detach() |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 114 | { |
| 115 | |
| 116 | if (m_process && m_process->IsAlive() && m_get_item_info_return_buffer_addr != LLDB_INVALID_ADDRESS) |
| 117 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 118 | std::unique_lock<std::mutex> lock(m_get_item_info_retbuffer_mutex, std::defer_lock); |
| 119 | lock.try_lock(); // Even if we don't get the lock, deallocate the buffer |
| 120 | m_process->DeallocateMemory(m_get_item_info_return_buffer_addr); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | // Compile our __lldb_backtrace_recording_get_item_info() function (from the |
| 125 | // source above in g_get_item_info_function_code) if we don't find that function in the inferior |
| 126 | // already with USE_BUILTIN_FUNCTION defined. (e.g. this would be the case for testing.) |
| 127 | // |
| 128 | // Insert the __lldb_backtrace_recording_get_item_info into the inferior process if needed. |
| 129 | // |
| 130 | // Write the get_item_info_arglist into the inferior's memory space to prepare for the call. |
| 131 | // |
| 132 | // Returns the address of the arguments written down in the inferior process, which can be used to |
| 133 | // make the function call. |
| 134 | |
| 135 | lldb::addr_t |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 136 | AppleGetItemInfoHandler::SetupGetItemInfoFunction(Thread &thread, ValueList &get_item_info_arglist) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 137 | { |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 138 | ExecutionContext exe_ctx(thread.shared_from_this()); |
| 139 | DiagnosticManager diagnostics; |
| 140 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 141 | lldb::addr_t args_addr = LLDB_INVALID_ADDRESS; |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 142 | FunctionCaller *get_item_info_caller = nullptr; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 143 | |
| 144 | // Scope for mutex locker: |
| 145 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 146 | std::lock_guard<std::mutex> guard(m_get_item_info_function_mutex); |
| 147 | |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 148 | // First stage is to make the UtilityFunction to hold our injected function: |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 149 | |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 150 | if (!m_get_item_info_impl_code.get()) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 151 | { |
| 152 | if (g_get_item_info_function_code != NULL) |
| 153 | { |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 154 | Error error; |
| 155 | m_get_item_info_impl_code.reset(exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage (g_get_item_info_function_code, |
| 156 | eLanguageTypeObjC, |
| 157 | g_get_item_info_function_name, |
| 158 | error)); |
| 159 | if (error.Fail()) |
| 160 | { |
| 161 | if (log) |
| 162 | log->Printf ("Failed to get utility function: %s.", error.AsCString()); |
| 163 | return args_addr; |
| 164 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 165 | |
| 166 | if (!m_get_item_info_impl_code->Install(diagnostics, exe_ctx)) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 167 | { |
| 168 | if (log) |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 169 | { |
| 170 | log->Printf("Failed to install get-item-info introspection."); |
| 171 | diagnostics.Dump(log); |
| 172 | } |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 173 | m_get_item_info_impl_code.reset(); |
| 174 | return args_addr; |
| 175 | } |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | if (log) |
| 180 | log->Printf("No get-item-info introspection code found."); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 181 | return LLDB_INVALID_ADDRESS; |
| 182 | } |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 183 | |
| 184 | // Next make the runner function for our implementation utility function. |
| 185 | Error error; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 186 | |
Sean Callanan | a994b0b | 2015-10-02 18:40:30 +0000 | [diff] [blame] | 187 | TypeSystem *type_system = thread.GetProcess()->GetTarget().GetScratchTypeSystemForLanguage(nullptr, eLanguageTypeC); |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 188 | CompilerType get_item_info_return_type = type_system->GetBasicTypeFromAST(eBasicTypeVoid).GetPointerType(); |
| 189 | |
| 190 | get_item_info_caller = m_get_item_info_impl_code->MakeFunctionCaller(get_item_info_return_type, |
| 191 | get_item_info_arglist, |
Jim Ingham | 6896b35 | 2016-03-21 19:21:13 +0000 | [diff] [blame] | 192 | thread.shared_from_this(), |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 193 | error); |
| 194 | if (error.Fail()) |
| 195 | { |
| 196 | if (log) |
| 197 | log->Printf ("Error Inserting get-item-info function: \"%s\".", error.AsCString()); |
| 198 | return args_addr; |
| 199 | } |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 200 | } |
| 201 | else |
| 202 | { |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 203 | // If it's already made, then we can just retrieve the caller: |
| 204 | get_item_info_caller = m_get_item_info_impl_code->GetFunctionCaller(); |
| 205 | if (!get_item_info_caller) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 206 | { |
| 207 | if (log) |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 208 | log->Printf ("Failed to get get-item-info introspection caller."); |
| 209 | m_get_item_info_impl_code.reset(); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 210 | return args_addr; |
| 211 | } |
| 212 | } |
| 213 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 214 | |
| 215 | diagnostics.Clear(); |
| 216 | |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 217 | // Now write down the argument values for this particular call. This looks like it might be a race condition |
| 218 | // if other threads were calling into here, but actually it isn't because we allocate a new args structure for |
| 219 | // this call by passing args_addr = LLDB_INVALID_ADDRESS... |
| 220 | |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 221 | if (!get_item_info_caller->WriteFunctionArguments(exe_ctx, args_addr, get_item_info_arglist, diagnostics)) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 222 | { |
| 223 | if (log) |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 224 | { |
| 225 | log->Printf("Error writing get-item-info function arguments."); |
| 226 | diagnostics.Dump(log); |
| 227 | } |
| 228 | |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 229 | return args_addr; |
| 230 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 231 | |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 232 | return args_addr; |
| 233 | } |
| 234 | |
| 235 | AppleGetItemInfoHandler::GetItemInfoReturnInfo |
| 236 | AppleGetItemInfoHandler::GetItemInfo (Thread &thread, uint64_t item, addr_t page_to_free, uint64_t page_to_free_size, Error &error) |
| 237 | { |
| 238 | lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); |
| 239 | ProcessSP process_sp (thread.CalculateProcess()); |
| 240 | TargetSP target_sp (thread.CalculateTarget()); |
| 241 | ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext(); |
| 242 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME)); |
| 243 | |
| 244 | GetItemInfoReturnInfo return_value; |
| 245 | return_value.item_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 246 | return_value.item_buffer_size = 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_item_info_return_values |
| 261 | // { |
| 262 | // uint64_t item_info_buffer_ptr; /* the address of the items buffer from libBacktraceRecording */ |
| 263 | // uint64_t item_info_buffer_size; /* the size of the items buffer from libBacktraceRecording */ |
| 264 | // }; |
| 265 | // |
| 266 | // void __lldb_backtrace_recording_get_item_info |
| 267 | // (struct get_item_info_return_values *return_buffer, |
| 268 | // int debug, |
| 269 | // uint64_t item, |
| 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 already allocated by lldb in |
| 274 | // the inferior process. |
| 275 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 276 | CompilerType clang_void_ptr_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 277 | Value return_buffer_ptr_value; |
| 278 | return_buffer_ptr_value.SetValueType (Value::eValueTypeScalar); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 279 | return_buffer_ptr_value.SetCompilerType (clang_void_ptr_type); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 280 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 281 | CompilerType clang_int_type = clang_ast_context->GetBasicType(eBasicTypeInt); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 282 | Value debug_value; |
| 283 | debug_value.SetValueType (Value::eValueTypeScalar); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 284 | debug_value.SetCompilerType (clang_int_type); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 285 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 286 | CompilerType clang_uint64_type = clang_ast_context->GetBasicType(eBasicTypeUnsignedLongLong); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 287 | Value item_value; |
| 288 | item_value.SetValueType (Value::eValueTypeScalar); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 289 | item_value.SetCompilerType (clang_uint64_type); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 290 | |
| 291 | Value page_to_free_value; |
| 292 | page_to_free_value.SetValueType (Value::eValueTypeScalar); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 293 | page_to_free_value.SetCompilerType (clang_void_ptr_type); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 294 | |
| 295 | Value page_to_free_size_value; |
| 296 | page_to_free_size_value.SetValueType (Value::eValueTypeScalar); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 297 | page_to_free_size_value.SetCompilerType (clang_uint64_type); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 298 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 299 | std::lock_guard<std::mutex> guard(m_get_item_info_retbuffer_mutex); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 300 | if (m_get_item_info_return_buffer_addr == LLDB_INVALID_ADDRESS) |
| 301 | { |
| 302 | addr_t bufaddr = process_sp->AllocateMemory (32, ePermissionsReadable | ePermissionsWritable, error); |
| 303 | if (!error.Success() || bufaddr == LLDB_INVALID_ADDRESS) |
| 304 | { |
| 305 | if (log) |
| 306 | log->Printf ("Failed to allocate memory for return buffer for get current queues func call"); |
| 307 | return return_value; |
| 308 | } |
| 309 | m_get_item_info_return_buffer_addr = bufaddr; |
| 310 | } |
| 311 | |
| 312 | ValueList argument_values; |
| 313 | |
| 314 | return_buffer_ptr_value.GetScalar() = m_get_item_info_return_buffer_addr; |
| 315 | argument_values.PushValue (return_buffer_ptr_value); |
| 316 | |
| 317 | debug_value.GetScalar() = 0; |
| 318 | argument_values.PushValue (debug_value); |
| 319 | |
| 320 | item_value.GetScalar() = item; |
| 321 | argument_values.PushValue (item_value); |
| 322 | |
| 323 | if (page_to_free != LLDB_INVALID_ADDRESS) |
| 324 | page_to_free_value.GetScalar() = page_to_free; |
| 325 | else |
| 326 | page_to_free_value.GetScalar() = 0; |
| 327 | argument_values.PushValue (page_to_free_value); |
| 328 | |
| 329 | page_to_free_size_value.GetScalar() = page_to_free_size; |
| 330 | argument_values.PushValue (page_to_free_size_value); |
| 331 | |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 332 | addr_t args_addr = SetupGetItemInfoFunction(thread, argument_values); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 333 | |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 334 | DiagnosticManager diagnostics; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 335 | ExecutionContext exe_ctx; |
| 336 | EvaluateExpressionOptions options; |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 337 | options.SetUnwindOnError(true); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 338 | options.SetIgnoreBreakpoints (true); |
| 339 | options.SetStopOthers (true); |
Jason Molenda | a056015 | 2014-04-25 00:06:26 +0000 | [diff] [blame] | 340 | options.SetTimeoutUsec(500000); |
| 341 | options.SetTryAllThreads (false); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 342 | thread.CalculateExecutionContext (exe_ctx); |
| 343 | |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 344 | if (!m_get_item_info_impl_code) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 345 | { |
| 346 | error.SetErrorString ("Unable to compile function to call __introspection_dispatch_queue_item_get_info"); |
| 347 | return return_value; |
| 348 | } |
| 349 | |
| 350 | |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 351 | ExpressionResults func_call_ret; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 352 | Value results; |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 353 | FunctionCaller *func_caller = m_get_item_info_impl_code->GetFunctionCaller(); |
| 354 | if (!func_caller) |
| 355 | { |
| 356 | if (log) |
| 357 | log->Printf ("Could not retrieve function caller for __introspection_dispatch_queue_item_get_info."); |
| 358 | error.SetErrorString("Could not retrieve function caller for __introspection_dispatch_queue_item_get_info."); |
| 359 | return return_value; |
| 360 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 361 | |
| 362 | func_call_ret = func_caller->ExecuteFunction(exe_ctx, &args_addr, options, diagnostics, results); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 363 | if (func_call_ret != eExpressionCompleted || !error.Success()) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 364 | { |
| 365 | if (log) |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 366 | log->Printf ("Unable to call __introspection_dispatch_queue_item_get_info(), got ExpressionResults %d, error contains %s", func_call_ret, error.AsCString("")); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 367 | error.SetErrorString ("Unable to call __introspection_dispatch_queue_get_item_info() for list of queues"); |
| 368 | return return_value; |
| 369 | } |
| 370 | |
| 371 | return_value.item_buffer_ptr = m_process->ReadUnsignedIntegerFromMemory (m_get_item_info_return_buffer_addr, 8, LLDB_INVALID_ADDRESS, error); |
| 372 | if (!error.Success() || return_value.item_buffer_ptr == LLDB_INVALID_ADDRESS) |
| 373 | { |
| 374 | return_value.item_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 375 | return return_value; |
| 376 | } |
| 377 | |
| 378 | return_value.item_buffer_size = m_process->ReadUnsignedIntegerFromMemory (m_get_item_info_return_buffer_addr + 8, 8, 0, error); |
| 379 | |
| 380 | if (!error.Success()) |
| 381 | { |
| 382 | return_value.item_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 383 | return return_value; |
| 384 | } |
Jason Molenda | 2a6c252 | 2014-02-15 00:20:40 +0000 | [diff] [blame] | 385 | if (log) |
| 386 | log->Printf ("AppleGetItemInfoHandler called __introspection_dispatch_queue_item_get_info (page_to_free == 0x%" PRIx64 ", size = %" PRId64 "), returned page is at 0x%" PRIx64 ", size %" PRId64, page_to_free, page_to_free_size, return_value.item_buffer_ptr, return_value.item_buffer_size); |
| 387 | |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 388 | |
| 389 | return return_value; |
| 390 | } |