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