1*061da546Spatrick //===-- AppleGetThreadItemInfoHandler.h ----------------------------*- C++ 2*061da546Spatrick //-*-===// 3*061da546Spatrick // 4*061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 6*061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*061da546Spatrick // 8*061da546Spatrick //===----------------------------------------------------------------------===// 9*061da546Spatrick 10*061da546Spatrick #ifndef lldb_AppleGetThreadItemInfoHandler_h_ 11*061da546Spatrick #define lldb_AppleGetThreadItemInfoHandler_h_ 12*061da546Spatrick 13*061da546Spatrick #include <map> 14*061da546Spatrick #include <mutex> 15*061da546Spatrick #include <vector> 16*061da546Spatrick 17*061da546Spatrick #include "lldb/Symbol/CompilerType.h" 18*061da546Spatrick #include "lldb/Utility/Status.h" 19*061da546Spatrick #include "lldb/lldb-public.h" 20*061da546Spatrick 21*061da546Spatrick // This class will insert a UtilityFunction into the inferior process for 22*061da546Spatrick // calling libBacktraceRecording's 23*061da546Spatrick // __introspection_dispatch_thread_get_item_info() 24*061da546Spatrick // function. The function in the inferior will return a struct by value 25*061da546Spatrick // with these members: 26*061da546Spatrick // 27*061da546Spatrick // struct get_thread_item_info_return_values 28*061da546Spatrick // { 29*061da546Spatrick // introspection_dispatch_item_info_ref *item_buffer; 30*061da546Spatrick // uint64_t item_buffer_size; 31*061da546Spatrick // }; 32*061da546Spatrick // 33*061da546Spatrick // The item_buffer pointer is an address in the inferior program's address 34*061da546Spatrick // space (item_buffer_size in size) which must be mach_vm_deallocate'd by 35*061da546Spatrick // lldb. 36*061da546Spatrick // 37*061da546Spatrick // The AppleGetThreadItemInfoHandler object should persist so that the 38*061da546Spatrick // UtilityFunction 39*061da546Spatrick // can be reused multiple times. 40*061da546Spatrick 41*061da546Spatrick namespace lldb_private { 42*061da546Spatrick 43*061da546Spatrick class AppleGetThreadItemInfoHandler { 44*061da546Spatrick public: 45*061da546Spatrick AppleGetThreadItemInfoHandler(lldb_private::Process *process); 46*061da546Spatrick 47*061da546Spatrick ~AppleGetThreadItemInfoHandler(); 48*061da546Spatrick 49*061da546Spatrick struct GetThreadItemInfoReturnInfo { 50*061da546Spatrick lldb::addr_t item_buffer_ptr; /* the address of the item buffer from 51*061da546Spatrick libBacktraceRecording */ 52*061da546Spatrick lldb::addr_t item_buffer_size; /* the size of the item buffer from 53*061da546Spatrick libBacktraceRecording */ 54*061da546Spatrick 55*061da546Spatrick GetThreadItemInfoReturnInfo() 56*061da546Spatrick : item_buffer_ptr(LLDB_INVALID_ADDRESS), item_buffer_size(0) {} 57*061da546Spatrick }; 58*061da546Spatrick 59*061da546Spatrick /// Get the information about a work item by calling 60*061da546Spatrick /// __introspection_dispatch_thread_get_item_info. If there's a page of 61*061da546Spatrick /// memory that needs to be freed, pass in the address and size and it will 62*061da546Spatrick /// be freed before getting the list of queues. 63*061da546Spatrick /// 64*061da546Spatrick /// \param [in] thread_id 65*061da546Spatrick /// The thread to get the extended backtrace for. 66*061da546Spatrick /// 67*061da546Spatrick /// \param [in] page_to_free 68*061da546Spatrick /// An address of an inferior process vm page that needs to be 69*061da546Spatrick /// deallocated, 70*061da546Spatrick /// LLDB_INVALID_ADDRESS if this is not needed. 71*061da546Spatrick /// 72*061da546Spatrick /// \param [in] page_to_free_size 73*061da546Spatrick /// The size of the vm page that needs to be deallocated if an address was 74*061da546Spatrick /// passed in to page_to_free. 75*061da546Spatrick /// 76*061da546Spatrick /// \param [out] error 77*061da546Spatrick /// This object will be updated with the error status / error string from 78*061da546Spatrick /// any failures encountered. 79*061da546Spatrick /// 80*061da546Spatrick /// \returns 81*061da546Spatrick /// The result of the inferior function call execution. If there was a 82*061da546Spatrick /// failure of any kind while getting 83*061da546Spatrick /// the information, the item_buffer_ptr value will be 84*061da546Spatrick /// LLDB_INVALID_ADDRESS. 85*061da546Spatrick GetThreadItemInfoReturnInfo GetThreadItemInfo(Thread &thread, 86*061da546Spatrick lldb::tid_t thread_id, 87*061da546Spatrick lldb::addr_t page_to_free, 88*061da546Spatrick uint64_t page_to_free_size, 89*061da546Spatrick lldb_private::Status &error); 90*061da546Spatrick 91*061da546Spatrick void Detach(); 92*061da546Spatrick 93*061da546Spatrick private: 94*061da546Spatrick lldb::addr_t 95*061da546Spatrick SetupGetThreadItemInfoFunction(Thread &thread, 96*061da546Spatrick ValueList &get_thread_item_info_arglist); 97*061da546Spatrick 98*061da546Spatrick static const char *g_get_thread_item_info_function_name; 99*061da546Spatrick static const char *g_get_thread_item_info_function_code; 100*061da546Spatrick 101*061da546Spatrick lldb_private::Process *m_process; 102*061da546Spatrick std::unique_ptr<UtilityFunction> m_get_thread_item_info_impl_code; 103*061da546Spatrick std::mutex m_get_thread_item_info_function_mutex; 104*061da546Spatrick 105*061da546Spatrick lldb::addr_t m_get_thread_item_info_return_buffer_addr; 106*061da546Spatrick std::mutex m_get_thread_item_info_retbuffer_mutex; 107*061da546Spatrick }; 108*061da546Spatrick 109*061da546Spatrick } // using namespace lldb_private 110*061da546Spatrick 111*061da546Spatrick #endif // lldb_AppleGetThreadItemInfoHandler_h_ 112