1 //===-- AppleGetQueuesHandler.h ----------------------------*- 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 #ifndef lldb_AppleGetQueuesHandler_h_ 11 #define lldb_AppleGetQueuesHandler_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <map> 16 #include <vector> 17 // Other libraries and framework includes 18 // Project includes 19 #include "lldb/lldb-public.h" 20 #include "lldb/Core/Error.h" 21 #include "lldb/Expression/ClangFunction.h" 22 #include "lldb/Host/Mutex.h" 23 #include "lldb/Symbol/ClangASTType.h" 24 25 // This class will insert a ClangUtilityFunction into the inferior process for 26 // calling libBacktraceRecording's introspection_get_dispatch_queues() 27 // function. The function in the inferior will return a struct by value 28 // with these members: 29 // 30 // struct get_current_queues_return_values 31 // { 32 // introspection_dispatch_queue_info_t *queues_buffer; 33 // uint64_t queues_buffer_size; 34 // uint64_t count; 35 // }; 36 // 37 // The queues_buffer pointer is an address in the inferior program's address 38 // space (queues_buffer_size in size) which must be mach_vm_deallocate'd by 39 // lldb. count is the number of queues that were stored in the buffer. 40 // 41 // The AppleGetQueuesHandler object should persist so that the ClangUtilityFunction 42 // can be reused multiple times. 43 44 namespace lldb_private 45 { 46 47 class AppleGetQueuesHandler { 48 public: 49 50 AppleGetQueuesHandler (lldb_private::Process *process); 51 52 ~AppleGetQueuesHandler(); 53 54 struct GetQueuesReturnInfo 55 { 56 lldb::addr_t queues_buffer_ptr; /* the address of the queues buffer from libBacktraceRecording */ 57 lldb::addr_t queues_buffer_size; /* the size of the queues buffer from libBacktraceRecording */ 58 uint64_t count; /* the number of queues included in the queues buffer */ 59 60 GetQueuesReturnInfo() : 61 queues_buffer_ptr(LLDB_INVALID_ADDRESS), 62 queues_buffer_size(0), 63 count(0) 64 {} 65 }; 66 67 //---------------------------------------------------------- 68 /// Get the list of queues that exist (with any active or pending items) via 69 /// a call to introspection_get_dispatch_queues(). If there's a page of 70 /// memory that needs to be freed, pass in the address and size and it will 71 /// be freed before getting the list of queues. 72 /// 73 /// @param [in] thread 74 /// The thread to run this plan on. 75 /// 76 /// @param [in] page_to_free 77 /// An address of an inferior process vm page that needs to be deallocated, 78 /// LLDB_INVALID_ADDRESS if this is not needed. 79 /// 80 /// @param [in] page_to_free_size 81 /// The size of the vm page that needs to be deallocated if an address was 82 /// passed in to page_to_free. 83 /// 84 /// @param [out] error 85 /// This object will be updated with the error status / error string from any failures encountered. 86 /// 87 /// @returns 88 /// The result of the inferior function call execution. If there was a failure of any kind while getting 89 /// the information, the queues_buffer_ptr value will be LLDB_INVALID_ADDRESS. 90 //---------------------------------------------------------- 91 GetQueuesReturnInfo 92 GetCurrentQueues (Thread &thread, lldb::addr_t page_to_free, uint64_t page_to_free_size, lldb_private::Error &error); 93 94 95 void 96 Detach (); 97 98 private: 99 100 lldb::addr_t 101 SetupGetQueuesFunction (Thread &thread, ValueList &get_queues_arglist); 102 103 static const char *g_get_current_queues_function_name; 104 static const char *g_get_current_queues_function_code; 105 106 lldb_private::Process *m_process; 107 std::unique_ptr<ClangFunction> m_get_queues_function; 108 std::unique_ptr<ClangUtilityFunction> m_get_queues_impl_code; 109 Mutex m_get_queues_function_mutex; 110 111 lldb::addr_t m_get_queues_return_buffer_addr; 112 Mutex m_get_queues_retbuffer_mutex; 113 114 }; 115 116 } // using namespace lldb_private 117 118 #endif // lldb_AppleGetQueuesHandler_h_ 119