1061da546Spatrick //===-- AppleGetThreadItemInfoHandler.h ----------------------------*- C++ 2061da546Spatrick //-*-===// 3061da546Spatrick // 4061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 6061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7061da546Spatrick // 8061da546Spatrick //===----------------------------------------------------------------------===// 9061da546Spatrick 10dda28197Spatrick #ifndef LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETTHREADITEMINFOHANDLER_H 11dda28197Spatrick #define LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETTHREADITEMINFOHANDLER_H 12061da546Spatrick 13061da546Spatrick #include <map> 14061da546Spatrick #include <mutex> 15061da546Spatrick #include <vector> 16061da546Spatrick 17061da546Spatrick #include "lldb/Symbol/CompilerType.h" 18061da546Spatrick #include "lldb/Utility/Status.h" 19061da546Spatrick #include "lldb/lldb-public.h" 20061da546Spatrick 21061da546Spatrick // This class will insert a UtilityFunction into the inferior process for 22061da546Spatrick // calling libBacktraceRecording's 23061da546Spatrick // __introspection_dispatch_thread_get_item_info() 24061da546Spatrick // function. The function in the inferior will return a struct by value 25061da546Spatrick // with these members: 26061da546Spatrick // 27061da546Spatrick // struct get_thread_item_info_return_values 28061da546Spatrick // { 29061da546Spatrick // introspection_dispatch_item_info_ref *item_buffer; 30061da546Spatrick // uint64_t item_buffer_size; 31061da546Spatrick // }; 32061da546Spatrick // 33061da546Spatrick // The item_buffer pointer is an address in the inferior program's address 34061da546Spatrick // space (item_buffer_size in size) which must be mach_vm_deallocate'd by 35061da546Spatrick // lldb. 36061da546Spatrick // 37061da546Spatrick // The AppleGetThreadItemInfoHandler object should persist so that the 38061da546Spatrick // UtilityFunction 39061da546Spatrick // can be reused multiple times. 40061da546Spatrick 41061da546Spatrick namespace lldb_private { 42061da546Spatrick 43061da546Spatrick class AppleGetThreadItemInfoHandler { 44061da546Spatrick public: 45061da546Spatrick AppleGetThreadItemInfoHandler(lldb_private::Process *process); 46061da546Spatrick 47061da546Spatrick ~AppleGetThreadItemInfoHandler(); 48061da546Spatrick 49061da546Spatrick struct GetThreadItemInfoReturnInfo { 50*be691f3bSpatrick lldb::addr_t item_buffer_ptr = LLDB_INVALID_ADDRESS; /* the address of the 51*be691f3bSpatrick item buffer from libBacktraceRecording */ 52*be691f3bSpatrick lldb::addr_t item_buffer_size = 0; /* the size of the item buffer from 53061da546Spatrick libBacktraceRecording */ 54061da546Spatrick 55*be691f3bSpatrick GetThreadItemInfoReturnInfo() = default; 56061da546Spatrick }; 57061da546Spatrick 58061da546Spatrick /// Get the information about a work item by calling 59061da546Spatrick /// __introspection_dispatch_thread_get_item_info. If there's a page of 60061da546Spatrick /// memory that needs to be freed, pass in the address and size and it will 61061da546Spatrick /// be freed before getting the list of queues. 62061da546Spatrick /// 63061da546Spatrick /// \param [in] thread_id 64061da546Spatrick /// The thread to get the extended backtrace for. 65061da546Spatrick /// 66061da546Spatrick /// \param [in] page_to_free 67061da546Spatrick /// An address of an inferior process vm page that needs to be 68061da546Spatrick /// deallocated, 69061da546Spatrick /// LLDB_INVALID_ADDRESS if this is not needed. 70061da546Spatrick /// 71061da546Spatrick /// \param [in] page_to_free_size 72061da546Spatrick /// The size of the vm page that needs to be deallocated if an address was 73061da546Spatrick /// passed in to page_to_free. 74061da546Spatrick /// 75061da546Spatrick /// \param [out] error 76061da546Spatrick /// This object will be updated with the error status / error string from 77061da546Spatrick /// any failures encountered. 78061da546Spatrick /// 79061da546Spatrick /// \returns 80061da546Spatrick /// The result of the inferior function call execution. If there was a 81061da546Spatrick /// failure of any kind while getting 82061da546Spatrick /// the information, the item_buffer_ptr value will be 83061da546Spatrick /// LLDB_INVALID_ADDRESS. 84061da546Spatrick GetThreadItemInfoReturnInfo GetThreadItemInfo(Thread &thread, 85061da546Spatrick lldb::tid_t thread_id, 86061da546Spatrick lldb::addr_t page_to_free, 87061da546Spatrick uint64_t page_to_free_size, 88061da546Spatrick lldb_private::Status &error); 89061da546Spatrick 90061da546Spatrick void Detach(); 91061da546Spatrick 92061da546Spatrick private: 93061da546Spatrick lldb::addr_t 94061da546Spatrick SetupGetThreadItemInfoFunction(Thread &thread, 95061da546Spatrick ValueList &get_thread_item_info_arglist); 96061da546Spatrick 97061da546Spatrick static const char *g_get_thread_item_info_function_name; 98061da546Spatrick static const char *g_get_thread_item_info_function_code; 99061da546Spatrick 100061da546Spatrick lldb_private::Process *m_process; 101061da546Spatrick std::unique_ptr<UtilityFunction> m_get_thread_item_info_impl_code; 102061da546Spatrick std::mutex m_get_thread_item_info_function_mutex; 103061da546Spatrick 104061da546Spatrick lldb::addr_t m_get_thread_item_info_return_buffer_addr; 105061da546Spatrick std::mutex m_get_thread_item_info_retbuffer_mutex; 106061da546Spatrick }; 107061da546Spatrick 108061da546Spatrick } // using namespace lldb_private 109061da546Spatrick 110dda28197Spatrick #endif // LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETTHREADITEMINFOHANDLER_H 111