Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1 | //===-- AppleGetItemInfoHandler.cpp -------------------------------*- C++ |
| 2 | //-*-===// |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #include "AppleGetItemInfoHandler.h" |
| 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
| 15 | // Other libraries and framework includes |
| 16 | // Project includes |
| 17 | |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Module.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Value.h" |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 20 | #include "lldb/Expression/DiagnosticManager.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 21 | #include "lldb/Expression/FunctionCaller.h" |
| 22 | #include "lldb/Expression/UtilityFunction.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/ClangASTContext.h" |
| 24 | #include "lldb/Symbol/Symbol.h" |
| 25 | #include "lldb/Target/ExecutionContext.h" |
| 26 | #include "lldb/Target/Process.h" |
| 27 | #include "lldb/Target/Target.h" |
| 28 | #include "lldb/Target/Thread.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 29 | #include "lldb/Utility/ConstString.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 30 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 31 | #include "lldb/Utility/StreamString.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 32 | |
| 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
| 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | const char *AppleGetItemInfoHandler::g_get_item_info_function_name = |
| 37 | "__lldb_backtrace_recording_get_item_info"; |
| 38 | const char *AppleGetItemInfoHandler::g_get_item_info_function_code = |
| 39 | " \n\ |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 40 | extern \"C\" \n\ |
| 41 | { \n\ |
| 42 | /* \n\ |
| 43 | * mach defines \n\ |
| 44 | */ \n\ |
| 45 | \n\ |
| 46 | typedef unsigned int uint32_t; \n\ |
| 47 | typedef unsigned long long uint64_t; \n\ |
| 48 | typedef uint32_t mach_port_t; \n\ |
| 49 | typedef mach_port_t vm_map_t; \n\ |
| 50 | typedef int kern_return_t; \n\ |
| 51 | typedef uint64_t mach_vm_address_t; \n\ |
| 52 | typedef uint64_t mach_vm_size_t; \n\ |
| 53 | \n\ |
| 54 | mach_port_t mach_task_self (); \n\ |
| 55 | kern_return_t mach_vm_deallocate (vm_map_t target, mach_vm_address_t address, mach_vm_size_t size); \n\ |
| 56 | \n\ |
| 57 | /* \n\ |
| 58 | * libBacktraceRecording defines \n\ |
| 59 | */ \n\ |
| 60 | \n\ |
| 61 | typedef uint32_t queue_list_scope_t; \n\ |
| 62 | typedef void *dispatch_queue_t; \n\ |
| 63 | typedef void *introspection_dispatch_queue_info_t; \n\ |
| 64 | typedef void *introspection_dispatch_item_info_ref; \n\ |
| 65 | \n\ |
| 66 | extern uint64_t __introspection_dispatch_queue_item_get_info (introspection_dispatch_item_info_ref item_info_ref, \n\ |
| 67 | introspection_dispatch_item_info_ref *returned_queues_buffer, \n\ |
| 68 | uint64_t *returned_queues_buffer_size); \n\ |
| 69 | extern int printf(const char *format, ...); \n\ |
| 70 | \n\ |
| 71 | /* \n\ |
| 72 | * return type define \n\ |
| 73 | */ \n\ |
| 74 | \n\ |
| 75 | struct get_item_info_return_values \n\ |
| 76 | { \n\ |
| 77 | uint64_t item_info_buffer_ptr; /* the address of the items buffer from libBacktraceRecording */ \n\ |
| 78 | uint64_t item_info_buffer_size; /* the size of the items buffer from libBacktraceRecording */ \n\ |
| 79 | }; \n\ |
| 80 | \n\ |
| 81 | void __lldb_backtrace_recording_get_item_info \n\ |
| 82 | (struct get_item_info_return_values *return_buffer, \n\ |
| 83 | int debug, \n\ |
| 84 | uint64_t /* introspection_dispatch_item_info_ref item_info_ref */ item, \n\ |
| 85 | void *page_to_free, \n\ |
| 86 | uint64_t page_to_free_size) \n\ |
| 87 | { \n\ |
| 88 | if (debug) \n\ |
| 89 | 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\ |
| 90 | if (page_to_free != 0) \n\ |
| 91 | { \n\ |
| 92 | mach_vm_deallocate (mach_task_self(), (mach_vm_address_t) page_to_free, (mach_vm_size_t) page_to_free_size); \n\ |
| 93 | } \n\ |
| 94 | \n\ |
| 95 | __introspection_dispatch_queue_item_get_info ((void*) item, \n\ |
| 96 | (void**)&return_buffer->item_info_buffer_ptr, \n\ |
| 97 | &return_buffer->item_info_buffer_size); \n\ |
| 98 | } \n\ |
| 99 | } \n\ |
| 100 | "; |
| 101 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 102 | AppleGetItemInfoHandler::AppleGetItemInfoHandler(Process *process) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 103 | : m_process(process), m_get_item_info_impl_code(), |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 104 | m_get_item_info_function_mutex(), |
| 105 | m_get_item_info_return_buffer_addr(LLDB_INVALID_ADDRESS), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | m_get_item_info_retbuffer_mutex() {} |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 107 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | AppleGetItemInfoHandler::~AppleGetItemInfoHandler() {} |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 109 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 110 | void AppleGetItemInfoHandler::Detach() { |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | if (m_process && m_process->IsAlive() && |
| 113 | m_get_item_info_return_buffer_addr != LLDB_INVALID_ADDRESS) { |
| 114 | std::unique_lock<std::mutex> lock(m_get_item_info_retbuffer_mutex, |
| 115 | std::defer_lock); |
| 116 | lock.try_lock(); // Even if we don't get the lock, deallocate the buffer |
| 117 | m_process->DeallocateMemory(m_get_item_info_return_buffer_addr); |
| 118 | } |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // Compile our __lldb_backtrace_recording_get_item_info() function (from the |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 122 | // source above in g_get_item_info_function_code) if we don't find that |
| 123 | // function in the inferior already with USE_BUILTIN_FUNCTION defined. (e.g. |
| 124 | // this would be the case for testing.) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 125 | // |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 126 | // Insert the __lldb_backtrace_recording_get_item_info into the inferior |
| 127 | // process if needed. |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 128 | // |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 129 | // Write the get_item_info_arglist into the inferior's memory space to prepare |
| 130 | // for the call. |
| 131 | // |
| 132 | // Returns the address of the arguments written down in the inferior process, |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 133 | // which can be used to make the function call. |
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 | lldb::addr_t AppleGetItemInfoHandler::SetupGetItemInfoFunction( |
| 136 | Thread &thread, ValueList &get_item_info_arglist) { |
| 137 | ExecutionContext exe_ctx(thread.shared_from_this()); |
| 138 | DiagnosticManager diagnostics; |
| 139 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); |
| 140 | lldb::addr_t args_addr = LLDB_INVALID_ADDRESS; |
| 141 | FunctionCaller *get_item_info_caller = nullptr; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 142 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 143 | // Scope for mutex locker: |
| 144 | { |
| 145 | std::lock_guard<std::mutex> guard(m_get_item_info_function_mutex); |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 146 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 147 | // First stage is to make the UtilityFunction to hold our injected |
| 148 | // function: |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 149 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | if (!m_get_item_info_impl_code.get()) { |
| 151 | if (g_get_item_info_function_code != NULL) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 152 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | m_get_item_info_impl_code.reset( |
| 154 | exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage( |
| 155 | g_get_item_info_function_code, eLanguageTypeObjC, |
| 156 | g_get_item_info_function_name, error)); |
| 157 | if (error.Fail()) { |
| 158 | if (log) |
| 159 | log->Printf("Failed to get utility function: %s.", |
| 160 | error.AsCString()); |
| 161 | return args_addr; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 162 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 163 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 164 | if (!m_get_item_info_impl_code->Install(diagnostics, exe_ctx)) { |
| 165 | if (log) { |
| 166 | log->Printf("Failed to install get-item-info introspection."); |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 167 | diagnostics.Dump(log); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 168 | } |
| 169 | m_get_item_info_impl_code.reset(); |
| 170 | return args_addr; |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 171 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 172 | } else { |
| 173 | if (log) |
| 174 | log->Printf("No get-item-info introspection code found."); |
| 175 | return LLDB_INVALID_ADDRESS; |
| 176 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 177 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | // Next make the runner function for our implementation utility function. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 179 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 180 | |
| 181 | TypeSystem *type_system = |
| 182 | thread.GetProcess()->GetTarget().GetScratchTypeSystemForLanguage( |
| 183 | nullptr, eLanguageTypeC); |
| 184 | CompilerType get_item_info_return_type = |
| 185 | type_system->GetBasicTypeFromAST(eBasicTypeVoid).GetPointerType(); |
| 186 | |
| 187 | get_item_info_caller = m_get_item_info_impl_code->MakeFunctionCaller( |
| 188 | get_item_info_return_type, get_item_info_arglist, |
| 189 | thread.shared_from_this(), error); |
Jason Molenda | ed2977f | 2016-10-27 23:52:46 +0000 | [diff] [blame] | 190 | if (error.Fail() || get_item_info_caller == nullptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 191 | if (log) |
| 192 | log->Printf("Error Inserting get-item-info function: \"%s\".", |
| 193 | error.AsCString()); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 194 | return args_addr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 195 | } |
| 196 | } else { |
| 197 | // If it's already made, then we can just retrieve the caller: |
| 198 | get_item_info_caller = m_get_item_info_impl_code->GetFunctionCaller(); |
| 199 | if (!get_item_info_caller) { |
| 200 | if (log) |
| 201 | log->Printf("Failed to get get-item-info introspection caller."); |
| 202 | m_get_item_info_impl_code.reset(); |
| 203 | return args_addr; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | diagnostics.Clear(); |
| 209 | |
| 210 | // Now write down the argument values for this particular call. This looks |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 211 | // like it might be a race condition if other threads were calling into here, |
| 212 | // but actually it isn't because we allocate a new args structure for this |
| 213 | // call by passing args_addr = LLDB_INVALID_ADDRESS... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 214 | |
| 215 | if (!get_item_info_caller->WriteFunctionArguments( |
| 216 | exe_ctx, args_addr, get_item_info_arglist, diagnostics)) { |
| 217 | if (log) { |
| 218 | log->Printf("Error writing get-item-info function arguments."); |
| 219 | diagnostics.Dump(log); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 220 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 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 | AppleGetItemInfoHandler::GetItemInfoReturnInfo |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 229 | AppleGetItemInfoHandler::GetItemInfo(Thread &thread, uint64_t item, |
| 230 | addr_t page_to_free, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 231 | uint64_t page_to_free_size, |
| 232 | Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 233 | lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); |
| 234 | ProcessSP process_sp(thread.CalculateProcess()); |
| 235 | TargetSP target_sp(thread.CalculateTarget()); |
| 236 | ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext(); |
| 237 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME)); |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 238 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 239 | GetItemInfoReturnInfo return_value; |
| 240 | return_value.item_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 241 | return_value.item_buffer_size = 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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 245 | if (thread.SafeToCallFunctions() == false) { |
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_item_info_return_values |
| 256 | // { |
| 257 | // uint64_t item_info_buffer_ptr; /* the address of the items buffer |
| 258 | // from libBacktraceRecording */ |
| 259 | // uint64_t item_info_buffer_size; /* the size of the items buffer from |
| 260 | // libBacktraceRecording */ |
| 261 | // }; |
| 262 | // |
| 263 | // void __lldb_backtrace_recording_get_item_info |
| 264 | // (struct |
| 265 | // get_item_info_return_values |
| 266 | // *return_buffer, |
| 267 | // int debug, |
| 268 | // uint64_t item, |
| 269 | // void *page_to_free, |
| 270 | // uint64_t page_to_free_size) |
| 271 | |
| 272 | // 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] | 273 | // already allocated by lldb in the inferior process. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | |
| 275 | CompilerType clang_void_ptr_type = |
| 276 | clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType(); |
| 277 | Value return_buffer_ptr_value; |
| 278 | return_buffer_ptr_value.SetValueType(Value::eValueTypeScalar); |
| 279 | return_buffer_ptr_value.SetCompilerType(clang_void_ptr_type); |
| 280 | |
| 281 | CompilerType clang_int_type = clang_ast_context->GetBasicType(eBasicTypeInt); |
| 282 | Value debug_value; |
| 283 | debug_value.SetValueType(Value::eValueTypeScalar); |
| 284 | debug_value.SetCompilerType(clang_int_type); |
| 285 | |
| 286 | CompilerType clang_uint64_type = |
| 287 | clang_ast_context->GetBasicType(eBasicTypeUnsignedLongLong); |
| 288 | Value item_value; |
| 289 | item_value.SetValueType(Value::eValueTypeScalar); |
| 290 | item_value.SetCompilerType(clang_uint64_type); |
| 291 | |
| 292 | Value page_to_free_value; |
| 293 | page_to_free_value.SetValueType(Value::eValueTypeScalar); |
| 294 | page_to_free_value.SetCompilerType(clang_void_ptr_type); |
| 295 | |
| 296 | Value page_to_free_size_value; |
| 297 | page_to_free_size_value.SetValueType(Value::eValueTypeScalar); |
| 298 | page_to_free_size_value.SetCompilerType(clang_uint64_type); |
| 299 | |
| 300 | std::lock_guard<std::mutex> guard(m_get_item_info_retbuffer_mutex); |
| 301 | if (m_get_item_info_return_buffer_addr == LLDB_INVALID_ADDRESS) { |
| 302 | addr_t bufaddr = process_sp->AllocateMemory( |
| 303 | 32, ePermissionsReadable | ePermissionsWritable, error); |
| 304 | if (!error.Success() || bufaddr == LLDB_INVALID_ADDRESS) { |
| 305 | if (log) |
| 306 | log->Printf("Failed to allocate memory for return buffer for get " |
| 307 | "current queues func call"); |
| 308 | return return_value; |
| 309 | } |
| 310 | m_get_item_info_return_buffer_addr = bufaddr; |
| 311 | } |
| 312 | |
| 313 | ValueList argument_values; |
| 314 | |
| 315 | return_buffer_ptr_value.GetScalar() = m_get_item_info_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 | item_value.GetScalar() = item; |
| 322 | argument_values.PushValue(item_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 | |
| 333 | addr_t args_addr = SetupGetItemInfoFunction(thread, argument_values); |
| 334 | |
| 335 | DiagnosticManager diagnostics; |
| 336 | ExecutionContext exe_ctx; |
| 337 | EvaluateExpressionOptions options; |
| 338 | options.SetUnwindOnError(true); |
| 339 | options.SetIgnoreBreakpoints(true); |
| 340 | options.SetStopOthers(true); |
Pavel Labath | 43d3541 | 2016-12-06 11:24:51 +0000 | [diff] [blame] | 341 | options.SetTimeout(std::chrono::milliseconds(500)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 342 | options.SetTryAllThreads(false); |
Raphael Isemann | c01783a | 2018-08-29 22:50:54 +0000 | [diff] [blame^] | 343 | options.SetIsForUtilityExpr(true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 344 | thread.CalculateExecutionContext(exe_ctx); |
| 345 | |
| 346 | if (!m_get_item_info_impl_code) { |
| 347 | error.SetErrorString("Unable to compile function to call " |
| 348 | "__introspection_dispatch_queue_item_get_info"); |
| 349 | return return_value; |
| 350 | } |
| 351 | |
| 352 | ExpressionResults func_call_ret; |
| 353 | Value results; |
| 354 | FunctionCaller *func_caller = m_get_item_info_impl_code->GetFunctionCaller(); |
| 355 | if (!func_caller) { |
| 356 | if (log) |
| 357 | log->Printf("Could not retrieve function caller for " |
| 358 | "__introspection_dispatch_queue_item_get_info."); |
| 359 | error.SetErrorString("Could not retrieve function caller for " |
| 360 | "__introspection_dispatch_queue_item_get_info."); |
| 361 | return return_value; |
| 362 | } |
| 363 | |
| 364 | func_call_ret = func_caller->ExecuteFunction(exe_ctx, &args_addr, options, |
| 365 | diagnostics, results); |
| 366 | if (func_call_ret != eExpressionCompleted || !error.Success()) { |
| 367 | if (log) |
| 368 | log->Printf("Unable to call " |
| 369 | "__introspection_dispatch_queue_item_get_info(), got " |
| 370 | "ExpressionResults %d, error contains %s", |
| 371 | func_call_ret, error.AsCString("")); |
| 372 | error.SetErrorString("Unable to call " |
| 373 | "__introspection_dispatch_queue_get_item_info() for " |
| 374 | "list of queues"); |
| 375 | return return_value; |
| 376 | } |
| 377 | |
| 378 | return_value.item_buffer_ptr = m_process->ReadUnsignedIntegerFromMemory( |
| 379 | m_get_item_info_return_buffer_addr, 8, LLDB_INVALID_ADDRESS, error); |
| 380 | if (!error.Success() || |
| 381 | return_value.item_buffer_ptr == LLDB_INVALID_ADDRESS) { |
| 382 | return_value.item_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 383 | return return_value; |
| 384 | } |
| 385 | |
| 386 | return_value.item_buffer_size = m_process->ReadUnsignedIntegerFromMemory( |
| 387 | m_get_item_info_return_buffer_addr + 8, 8, 0, error); |
| 388 | |
| 389 | if (!error.Success()) { |
| 390 | return_value.item_buffer_ptr = LLDB_INVALID_ADDRESS; |
| 391 | return return_value; |
| 392 | } |
| 393 | if (log) |
| 394 | log->Printf("AppleGetItemInfoHandler called " |
| 395 | "__introspection_dispatch_queue_item_get_info (page_to_free == " |
| 396 | "0x%" PRIx64 ", size = %" PRId64 |
| 397 | "), returned page is at 0x%" PRIx64 ", size %" PRId64, |
| 398 | page_to_free, page_to_free_size, return_value.item_buffer_ptr, |
| 399 | return_value.item_buffer_size); |
| 400 | |
| 401 | return return_value; |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 402 | } |