12fd83355SJason Molenda //===-- AppleGetItemInfoHandler.cpp -------------------------------*- C++ -*-===//
22fd83355SJason Molenda //
32fd83355SJason Molenda //                     The LLVM Compiler Infrastructure
42fd83355SJason Molenda //
52fd83355SJason Molenda // This file is distributed under the University of Illinois Open Source
62fd83355SJason Molenda // License. See LICENSE.TXT for details.
72fd83355SJason Molenda //
82fd83355SJason Molenda //===----------------------------------------------------------------------===//
92fd83355SJason Molenda 
102fd83355SJason Molenda #include "AppleGetItemInfoHandler.h"
112fd83355SJason Molenda 
122fd83355SJason Molenda // C Includes
132fd83355SJason Molenda // C++ Includes
142fd83355SJason Molenda // Other libraries and framework includes
152fd83355SJason Molenda // Project includes
162fd83355SJason Molenda 
172fd83355SJason Molenda #include "lldb/Core/ConstString.h"
182fd83355SJason Molenda #include "lldb/Core/Log.h"
192fd83355SJason Molenda #include "lldb/Core/Module.h"
202fd83355SJason Molenda #include "lldb/Core/StreamString.h"
212fd83355SJason Molenda #include "lldb/Core/Value.h"
22151c032cSJim Ingham #include "lldb/Expression/FunctionCaller.h"
23151c032cSJim Ingham #include "lldb/Expression/UtilityFunction.h"
242fd83355SJason Molenda #include "lldb/Symbol/ClangASTContext.h"
252fd83355SJason Molenda #include "lldb/Symbol/Symbol.h"
262fd83355SJason Molenda #include "lldb/Target/ExecutionContext.h"
272fd83355SJason Molenda #include "lldb/Target/Process.h"
282fd83355SJason Molenda #include "lldb/Target/Target.h"
292fd83355SJason Molenda #include "lldb/Target/Thread.h"
302fd83355SJason Molenda 
312fd83355SJason Molenda using namespace lldb;
322fd83355SJason Molenda using namespace lldb_private;
332fd83355SJason Molenda 
342fd83355SJason Molenda const char *AppleGetItemInfoHandler::g_get_item_info_function_name = "__lldb_backtrace_recording_get_item_info";
352fd83355SJason Molenda const char *AppleGetItemInfoHandler::g_get_item_info_function_code = "                                  \n\
362fd83355SJason Molenda extern \"C\"                                                                                                    \n\
372fd83355SJason Molenda {                                                                                                               \n\
382fd83355SJason Molenda     /*                                                                                                          \n\
392fd83355SJason Molenda      * mach defines                                                                                             \n\
402fd83355SJason Molenda      */                                                                                                         \n\
412fd83355SJason Molenda                                                                                                                 \n\
422fd83355SJason Molenda     typedef unsigned int uint32_t;                                                                              \n\
432fd83355SJason Molenda     typedef unsigned long long uint64_t;                                                                        \n\
442fd83355SJason Molenda     typedef uint32_t mach_port_t;                                                                               \n\
452fd83355SJason Molenda     typedef mach_port_t vm_map_t;                                                                               \n\
462fd83355SJason Molenda     typedef int kern_return_t;                                                                                  \n\
472fd83355SJason Molenda     typedef uint64_t mach_vm_address_t;                                                                         \n\
482fd83355SJason Molenda     typedef uint64_t mach_vm_size_t;                                                                            \n\
492fd83355SJason Molenda                                                                                                                 \n\
502fd83355SJason Molenda     mach_port_t mach_task_self ();                                                                              \n\
512fd83355SJason Molenda     kern_return_t mach_vm_deallocate (vm_map_t target, mach_vm_address_t address, mach_vm_size_t size);         \n\
522fd83355SJason Molenda                                                                                                                 \n\
532fd83355SJason Molenda     /*                                                                                                          \n\
542fd83355SJason Molenda      * libBacktraceRecording defines                                                                            \n\
552fd83355SJason Molenda      */                                                                                                         \n\
562fd83355SJason Molenda                                                                                                                 \n\
572fd83355SJason Molenda     typedef uint32_t queue_list_scope_t;                                                                        \n\
582fd83355SJason Molenda     typedef void *dispatch_queue_t;                                                                             \n\
592fd83355SJason Molenda     typedef void *introspection_dispatch_queue_info_t;                                                          \n\
602fd83355SJason Molenda     typedef void *introspection_dispatch_item_info_ref;                                                         \n\
612fd83355SJason Molenda                                                                                                                 \n\
622fd83355SJason Molenda     extern uint64_t __introspection_dispatch_queue_item_get_info (introspection_dispatch_item_info_ref item_info_ref, \n\
632fd83355SJason Molenda                                                  introspection_dispatch_item_info_ref *returned_queues_buffer,  \n\
642fd83355SJason Molenda                                                  uint64_t *returned_queues_buffer_size);                        \n\
652fd83355SJason Molenda     extern int printf(const char *format, ...);                                                                 \n\
662fd83355SJason Molenda                                                                                                                 \n\
672fd83355SJason Molenda     /*                                                                                                          \n\
682fd83355SJason Molenda      * return type define                                                                                       \n\
692fd83355SJason Molenda      */                                                                                                         \n\
702fd83355SJason Molenda                                                                                                                 \n\
712fd83355SJason Molenda     struct get_item_info_return_values                                                                      \n\
722fd83355SJason Molenda     {                                                                                                           \n\
732fd83355SJason Molenda         uint64_t item_info_buffer_ptr;    /* the address of the items buffer from libBacktraceRecording */  \n\
742fd83355SJason Molenda         uint64_t item_info_buffer_size;   /* the size of the items buffer from libBacktraceRecording */     \n\
752fd83355SJason Molenda     };                                                                                                          \n\
762fd83355SJason Molenda                                                                                                                 \n\
772fd83355SJason Molenda     void  __lldb_backtrace_recording_get_item_info                                                          \n\
782fd83355SJason Molenda                                                (struct get_item_info_return_values *return_buffer,          \n\
792fd83355SJason Molenda                                                 int debug,                                                      \n\
802fd83355SJason Molenda                                                 uint64_t /* introspection_dispatch_item_info_ref item_info_ref */ item, \n\
812fd83355SJason Molenda                                                 void *page_to_free,                                             \n\
822fd83355SJason Molenda                                                 uint64_t page_to_free_size)                                     \n\
832fd83355SJason Molenda {                                                                                                               \n\
842fd83355SJason Molenda     if (debug)                                                                                                  \n\
852fd83355SJason Molenda       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\
862fd83355SJason Molenda     if (page_to_free != 0)                                                                                      \n\
872fd83355SJason Molenda     {                                                                                                           \n\
882fd83355SJason Molenda         mach_vm_deallocate (mach_task_self(), (mach_vm_address_t) page_to_free, (mach_vm_size_t) page_to_free_size); \n\
892fd83355SJason Molenda     }                                                                                                           \n\
902fd83355SJason Molenda                                                                                                                 \n\
912fd83355SJason Molenda     __introspection_dispatch_queue_item_get_info ((void*) item,                                                 \n\
922fd83355SJason Molenda                                                   (void**)&return_buffer->item_info_buffer_ptr,                 \n\
932fd83355SJason Molenda                                                   &return_buffer->item_info_buffer_size);                       \n\
942fd83355SJason Molenda }                                                                                                               \n\
952fd83355SJason Molenda }                                                                                                               \n\
962fd83355SJason Molenda ";
972fd83355SJason Molenda 
982fd83355SJason Molenda AppleGetItemInfoHandler::AppleGetItemInfoHandler (Process *process) :
992fd83355SJason Molenda     m_process (process),
1002fd83355SJason Molenda     m_get_item_info_impl_code (),
1012fd83355SJason Molenda     m_get_item_info_function_mutex(),
1022fd83355SJason Molenda     m_get_item_info_return_buffer_addr (LLDB_INVALID_ADDRESS),
1032fd83355SJason Molenda     m_get_item_info_retbuffer_mutex()
1042fd83355SJason Molenda {
1052fd83355SJason Molenda }
1062fd83355SJason Molenda 
1072fd83355SJason Molenda AppleGetItemInfoHandler::~AppleGetItemInfoHandler ()
1082fd83355SJason Molenda {
1092fd83355SJason Molenda }
1102fd83355SJason Molenda 
1112fd83355SJason Molenda void
1122fd83355SJason Molenda AppleGetItemInfoHandler::Detach ()
1132fd83355SJason Molenda {
1142fd83355SJason Molenda 
1152fd83355SJason Molenda     if (m_process && m_process->IsAlive() && m_get_item_info_return_buffer_addr != LLDB_INVALID_ADDRESS)
1162fd83355SJason Molenda     {
1172fd83355SJason Molenda         Mutex::Locker locker;
1182fd83355SJason Molenda         locker.TryLock (m_get_item_info_retbuffer_mutex);  // Even if we don't get the lock, deallocate the buffer
1192fd83355SJason Molenda         m_process->DeallocateMemory (m_get_item_info_return_buffer_addr);
1202fd83355SJason Molenda     }
1212fd83355SJason Molenda }
1222fd83355SJason Molenda 
1232fd83355SJason Molenda // Compile our __lldb_backtrace_recording_get_item_info() function (from the
1242fd83355SJason Molenda // source above in g_get_item_info_function_code) if we don't find that function in the inferior
1252fd83355SJason Molenda // already with USE_BUILTIN_FUNCTION defined.  (e.g. this would be the case for testing.)
1262fd83355SJason Molenda //
1272fd83355SJason Molenda // Insert the __lldb_backtrace_recording_get_item_info into the inferior process if needed.
1282fd83355SJason Molenda //
1292fd83355SJason Molenda // Write the get_item_info_arglist into the inferior's memory space to prepare for the call.
1302fd83355SJason Molenda //
1312fd83355SJason Molenda // Returns the address of the arguments written down in the inferior process, which can be used to
1322fd83355SJason Molenda // make the function call.
1332fd83355SJason Molenda 
1342fd83355SJason Molenda lldb::addr_t
1352fd83355SJason Molenda AppleGetItemInfoHandler::SetupGetItemInfoFunction (Thread &thread, ValueList &get_item_info_arglist)
1362fd83355SJason Molenda {
1372fd83355SJason Molenda     ExecutionContext exe_ctx (thread.shared_from_this());
1382fd83355SJason Molenda     StreamString errors;
1392fd83355SJason Molenda     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME));
1402fd83355SJason Molenda     lldb::addr_t args_addr = LLDB_INVALID_ADDRESS;
141151c032cSJim Ingham     FunctionCaller *get_item_info_caller = nullptr;
1422fd83355SJason Molenda 
1432fd83355SJason Molenda     // Scope for mutex locker:
1442fd83355SJason Molenda     {
1452fd83355SJason Molenda         Mutex::Locker locker(m_get_item_info_function_mutex);
1462fd83355SJason Molenda 
147151c032cSJim Ingham         // First stage is to make the UtilityFunction to hold our injected function:
1482fd83355SJason Molenda 
149151c032cSJim Ingham         if (!m_get_item_info_impl_code.get())
1502fd83355SJason Molenda         {
1512fd83355SJason Molenda             if (g_get_item_info_function_code != NULL)
1522fd83355SJason Molenda             {
153151c032cSJim Ingham                 Error error;
154151c032cSJim Ingham                 m_get_item_info_impl_code.reset(exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage (g_get_item_info_function_code,
155151c032cSJim Ingham                                                                                                       eLanguageTypeObjC,
156151c032cSJim Ingham                                                                                                       g_get_item_info_function_name,
157151c032cSJim Ingham                                                                                                       error));
158151c032cSJim Ingham                 if (error.Fail())
159151c032cSJim Ingham                 {
160151c032cSJim Ingham                     if (log)
161151c032cSJim Ingham                         log->Printf ("Failed to get utility function: %s.", error.AsCString());
162151c032cSJim Ingham                     return args_addr;
163151c032cSJim Ingham                 }
164151c032cSJim Ingham 
1652fd83355SJason Molenda                 if (!m_get_item_info_impl_code->Install(errors, exe_ctx))
1662fd83355SJason Molenda                 {
1672fd83355SJason Molenda                     if (log)
1682fd83355SJason Molenda                         log->Printf ("Failed to install get-item-info introspection: %s.", errors.GetData());
1692fd83355SJason Molenda                     m_get_item_info_impl_code.reset();
1702fd83355SJason Molenda                     return args_addr;
1712fd83355SJason Molenda                 }
1722fd83355SJason Molenda             }
1732fd83355SJason Molenda             else
1742fd83355SJason Molenda             {
1752fd83355SJason Molenda                 if (log)
1762fd83355SJason Molenda                     log->Printf("No get-item-info introspection code found.");
1772fd83355SJason Molenda                 errors.Printf ("No get-item-info introspection code found.");
1782fd83355SJason Molenda                 return LLDB_INVALID_ADDRESS;
1792fd83355SJason Molenda             }
1802fd83355SJason Molenda 
181151c032cSJim Ingham             // Next make the runner function for our implementation utility function.
182151c032cSJim Ingham             Error error;
183151c032cSJim Ingham 
184*a994b0b2SSean Callanan             TypeSystem *type_system = thread.GetProcess()->GetTarget().GetScratchTypeSystemForLanguage(nullptr, eLanguageTypeC);
185151c032cSJim Ingham             CompilerType get_item_info_return_type = type_system->GetBasicTypeFromAST(eBasicTypeVoid).GetPointerType();
186151c032cSJim Ingham 
187151c032cSJim Ingham             get_item_info_caller = m_get_item_info_impl_code->MakeFunctionCaller(get_item_info_return_type,
188151c032cSJim Ingham                                                                                  get_item_info_arglist,
189151c032cSJim Ingham                                                                                  error);
190151c032cSJim Ingham             if (error.Fail())
191151c032cSJim Ingham             {
192151c032cSJim Ingham                 if (log)
193151c032cSJim Ingham                     log->Printf ("Error Inserting get-item-info function: \"%s\".", error.AsCString());
194151c032cSJim Ingham                 return args_addr;
195151c032cSJim Ingham             }
1962fd83355SJason Molenda         }
1972fd83355SJason Molenda         else
1982fd83355SJason Molenda         {
199151c032cSJim Ingham             // If it's already made, then we can just retrieve the caller:
200151c032cSJim Ingham             get_item_info_caller = m_get_item_info_impl_code->GetFunctionCaller();
201151c032cSJim Ingham             if (!get_item_info_caller)
2022fd83355SJason Molenda             {
2032fd83355SJason Molenda                 if (log)
204151c032cSJim Ingham                     log->Printf ("Failed to get get-item-info introspection caller.");
205151c032cSJim Ingham                 m_get_item_info_impl_code.reset();
2062fd83355SJason Molenda                 return args_addr;
2072fd83355SJason Molenda             }
2082fd83355SJason Molenda         }
2092fd83355SJason Molenda     }
2102fd83355SJason Molenda 
2112fd83355SJason Molenda     errors.Clear();
2122fd83355SJason Molenda 
2132fd83355SJason Molenda     // Now write down the argument values for this particular call.  This looks like it might be a race condition
2142fd83355SJason Molenda     // if other threads were calling into here, but actually it isn't because we allocate a new args structure for
2152fd83355SJason Molenda     // this call by passing args_addr = LLDB_INVALID_ADDRESS...
2162fd83355SJason Molenda 
217151c032cSJim Ingham     if (!get_item_info_caller->WriteFunctionArguments (exe_ctx, args_addr, get_item_info_arglist, errors))
2182fd83355SJason Molenda     {
2192fd83355SJason Molenda         if (log)
2202fd83355SJason Molenda             log->Printf ("Error writing get-item-info function arguments: \"%s\".", errors.GetData());
2212fd83355SJason Molenda         return args_addr;
2222fd83355SJason Molenda     }
2232fd83355SJason Molenda 
2242fd83355SJason Molenda     return args_addr;
2252fd83355SJason Molenda }
2262fd83355SJason Molenda 
2272fd83355SJason Molenda AppleGetItemInfoHandler::GetItemInfoReturnInfo
2282fd83355SJason Molenda AppleGetItemInfoHandler::GetItemInfo (Thread &thread, uint64_t item, addr_t page_to_free, uint64_t page_to_free_size, Error &error)
2292fd83355SJason Molenda {
2302fd83355SJason Molenda     lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0);
2312fd83355SJason Molenda     ProcessSP process_sp (thread.CalculateProcess());
2322fd83355SJason Molenda     TargetSP target_sp (thread.CalculateTarget());
2332fd83355SJason Molenda     ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext();
2342fd83355SJason Molenda     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYSTEM_RUNTIME));
2352fd83355SJason Molenda 
2362fd83355SJason Molenda     GetItemInfoReturnInfo return_value;
2372fd83355SJason Molenda     return_value.item_buffer_ptr = LLDB_INVALID_ADDRESS;
2382fd83355SJason Molenda     return_value.item_buffer_size = 0;
2392fd83355SJason Molenda 
2402fd83355SJason Molenda     error.Clear();
2412fd83355SJason Molenda 
242b4892cd2SJason Molenda     if (thread.SafeToCallFunctions() == false)
243b4892cd2SJason Molenda     {
244b4892cd2SJason Molenda         if (log)
245b4892cd2SJason Molenda             log->Printf ("Not safe to call functions on thread 0x%" PRIx64, thread.GetID());
246b4892cd2SJason Molenda         error.SetErrorString ("Not safe to call functions on this thread.");
247b4892cd2SJason Molenda         return return_value;
248b4892cd2SJason Molenda     }
249b4892cd2SJason Molenda 
2502fd83355SJason Molenda     // Set up the arguments for a call to
2512fd83355SJason Molenda 
2522fd83355SJason Molenda     // struct get_item_info_return_values
2532fd83355SJason Molenda     // {
2542fd83355SJason Molenda     //     uint64_t item_info_buffer_ptr;    /* the address of the items buffer from libBacktraceRecording */
2552fd83355SJason Molenda     //     uint64_t item_info_buffer_size;   /* the size of the items buffer from libBacktraceRecording */
2562fd83355SJason Molenda     // };
2572fd83355SJason Molenda     //
2582fd83355SJason Molenda     // void  __lldb_backtrace_recording_get_item_info
2592fd83355SJason Molenda     //                                            (struct get_item_info_return_values *return_buffer,
2602fd83355SJason Molenda     //                                             int debug,
2612fd83355SJason Molenda     //                                             uint64_t item,
2622fd83355SJason Molenda     //                                             void *page_to_free,
2632fd83355SJason Molenda     //                                             uint64_t page_to_free_size)
2642fd83355SJason Molenda 
2652fd83355SJason Molenda     // Where the return_buffer argument points to a 24 byte region of memory already allocated by lldb in
2662fd83355SJason Molenda     // the inferior process.
2672fd83355SJason Molenda 
268a1e5dc86SGreg Clayton     CompilerType clang_void_ptr_type = clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
2692fd83355SJason Molenda     Value return_buffer_ptr_value;
2702fd83355SJason Molenda     return_buffer_ptr_value.SetValueType (Value::eValueTypeScalar);
27199558cc4SGreg Clayton     return_buffer_ptr_value.SetCompilerType (clang_void_ptr_type);
2722fd83355SJason Molenda 
273a1e5dc86SGreg Clayton     CompilerType clang_int_type = clang_ast_context->GetBasicType(eBasicTypeInt);
2742fd83355SJason Molenda     Value debug_value;
2752fd83355SJason Molenda     debug_value.SetValueType (Value::eValueTypeScalar);
27699558cc4SGreg Clayton     debug_value.SetCompilerType (clang_int_type);
2772fd83355SJason Molenda 
278a1e5dc86SGreg Clayton     CompilerType clang_uint64_type = clang_ast_context->GetBasicType(eBasicTypeUnsignedLongLong);
2792fd83355SJason Molenda     Value item_value;
2802fd83355SJason Molenda     item_value.SetValueType (Value::eValueTypeScalar);
28199558cc4SGreg Clayton     item_value.SetCompilerType (clang_uint64_type);
2822fd83355SJason Molenda 
2832fd83355SJason Molenda     Value page_to_free_value;
2842fd83355SJason Molenda     page_to_free_value.SetValueType (Value::eValueTypeScalar);
28599558cc4SGreg Clayton     page_to_free_value.SetCompilerType (clang_void_ptr_type);
2862fd83355SJason Molenda 
2872fd83355SJason Molenda     Value page_to_free_size_value;
2882fd83355SJason Molenda     page_to_free_size_value.SetValueType (Value::eValueTypeScalar);
28999558cc4SGreg Clayton     page_to_free_size_value.SetCompilerType (clang_uint64_type);
2902fd83355SJason Molenda 
2912fd83355SJason Molenda 
2922fd83355SJason Molenda     Mutex::Locker locker(m_get_item_info_retbuffer_mutex);
2932fd83355SJason Molenda     if (m_get_item_info_return_buffer_addr == LLDB_INVALID_ADDRESS)
2942fd83355SJason Molenda     {
2952fd83355SJason Molenda         addr_t bufaddr = process_sp->AllocateMemory (32, ePermissionsReadable | ePermissionsWritable, error);
2962fd83355SJason Molenda         if (!error.Success() || bufaddr == LLDB_INVALID_ADDRESS)
2972fd83355SJason Molenda         {
2982fd83355SJason Molenda             if (log)
2992fd83355SJason Molenda                 log->Printf ("Failed to allocate memory for return buffer for get current queues func call");
3002fd83355SJason Molenda             return return_value;
3012fd83355SJason Molenda         }
3022fd83355SJason Molenda         m_get_item_info_return_buffer_addr = bufaddr;
3032fd83355SJason Molenda     }
3042fd83355SJason Molenda 
3052fd83355SJason Molenda     ValueList argument_values;
3062fd83355SJason Molenda 
3072fd83355SJason Molenda     return_buffer_ptr_value.GetScalar() = m_get_item_info_return_buffer_addr;
3082fd83355SJason Molenda     argument_values.PushValue (return_buffer_ptr_value);
3092fd83355SJason Molenda 
3102fd83355SJason Molenda     debug_value.GetScalar() = 0;
3112fd83355SJason Molenda     argument_values.PushValue (debug_value);
3122fd83355SJason Molenda 
3132fd83355SJason Molenda     item_value.GetScalar() = item;
3142fd83355SJason Molenda     argument_values.PushValue (item_value);
3152fd83355SJason Molenda 
3162fd83355SJason Molenda     if (page_to_free != LLDB_INVALID_ADDRESS)
3172fd83355SJason Molenda         page_to_free_value.GetScalar() = page_to_free;
3182fd83355SJason Molenda     else
3192fd83355SJason Molenda         page_to_free_value.GetScalar() = 0;
3202fd83355SJason Molenda     argument_values.PushValue (page_to_free_value);
3212fd83355SJason Molenda 
3222fd83355SJason Molenda     page_to_free_size_value.GetScalar() = page_to_free_size;
3232fd83355SJason Molenda     argument_values.PushValue (page_to_free_size_value);
3242fd83355SJason Molenda 
3252fd83355SJason Molenda     addr_t args_addr = SetupGetItemInfoFunction (thread, argument_values);
3262fd83355SJason Molenda 
3272fd83355SJason Molenda     StreamString errors;
3282fd83355SJason Molenda     ExecutionContext exe_ctx;
3292fd83355SJason Molenda     EvaluateExpressionOptions options;
3302fd83355SJason Molenda     options.SetUnwindOnError (true);
3312fd83355SJason Molenda     options.SetIgnoreBreakpoints (true);
3322fd83355SJason Molenda     options.SetStopOthers (true);
333a0560152SJason Molenda     options.SetTimeoutUsec(500000);
334a0560152SJason Molenda     options.SetTryAllThreads (false);
3352fd83355SJason Molenda     thread.CalculateExecutionContext (exe_ctx);
3362fd83355SJason Molenda 
337151c032cSJim Ingham     if (!m_get_item_info_impl_code)
3382fd83355SJason Molenda     {
3392fd83355SJason Molenda         error.SetErrorString ("Unable to compile function to call __introspection_dispatch_queue_item_get_info");
3402fd83355SJason Molenda         return return_value;
3412fd83355SJason Molenda     }
3422fd83355SJason Molenda 
3432fd83355SJason Molenda 
3441624a2d3SJim Ingham     ExpressionResults func_call_ret;
3452fd83355SJason Molenda     Value results;
346151c032cSJim Ingham     FunctionCaller *func_caller = m_get_item_info_impl_code->GetFunctionCaller();
347151c032cSJim Ingham     if (!func_caller)
348151c032cSJim Ingham     {
349151c032cSJim Ingham         if (log)
350151c032cSJim Ingham             log->Printf ("Could not retrieve function caller for __introspection_dispatch_queue_item_get_info.");
351151c032cSJim Ingham         error.SetErrorString("Could not retrieve function caller for __introspection_dispatch_queue_item_get_info.");
352151c032cSJim Ingham         return return_value;
353151c032cSJim Ingham     }
354151c032cSJim Ingham 
355151c032cSJim Ingham     func_call_ret =  func_caller->ExecuteFunction (exe_ctx, &args_addr, options, errors, results);
3568646d3c1SJim Ingham     if (func_call_ret != eExpressionCompleted || !error.Success())
3572fd83355SJason Molenda     {
3582fd83355SJason Molenda         if (log)
3591624a2d3SJim Ingham             log->Printf ("Unable to call __introspection_dispatch_queue_item_get_info(), got ExpressionResults %d, error contains %s", func_call_ret, error.AsCString(""));
3602fd83355SJason Molenda         error.SetErrorString ("Unable to call __introspection_dispatch_queue_get_item_info() for list of queues");
3612fd83355SJason Molenda         return return_value;
3622fd83355SJason Molenda     }
3632fd83355SJason Molenda 
3642fd83355SJason Molenda     return_value.item_buffer_ptr = m_process->ReadUnsignedIntegerFromMemory (m_get_item_info_return_buffer_addr, 8, LLDB_INVALID_ADDRESS, error);
3652fd83355SJason Molenda     if (!error.Success() || return_value.item_buffer_ptr == LLDB_INVALID_ADDRESS)
3662fd83355SJason Molenda     {
3672fd83355SJason Molenda         return_value.item_buffer_ptr = LLDB_INVALID_ADDRESS;
3682fd83355SJason Molenda         return return_value;
3692fd83355SJason Molenda     }
3702fd83355SJason Molenda 
3712fd83355SJason Molenda     return_value.item_buffer_size = m_process->ReadUnsignedIntegerFromMemory (m_get_item_info_return_buffer_addr + 8, 8, 0, error);
3722fd83355SJason Molenda 
3732fd83355SJason Molenda     if (!error.Success())
3742fd83355SJason Molenda     {
3752fd83355SJason Molenda         return_value.item_buffer_ptr = LLDB_INVALID_ADDRESS;
3762fd83355SJason Molenda         return return_value;
3772fd83355SJason Molenda     }
3782a6c252dSJason Molenda     if (log)
3792a6c252dSJason Molenda         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);
3802a6c252dSJason Molenda 
3812fd83355SJason Molenda 
3822fd83355SJason Molenda     return return_value;
3832fd83355SJason Molenda }
384