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