111 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETTHREADITEMINFOHANDLER_H11#define LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETTHREADITEMINFOHANDLER_H12 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 for22// calling libBacktraceRecording's23// __introspection_dispatch_thread_get_item_info()24// function. The function in the inferior will return a struct by value25// with these members:26//27// struct get_thread_item_info_return_values28// {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 address34// space (item_buffer_size in size) which must be mach_vm_deallocate'd by35// lldb.36//37// The AppleGetThreadItemInfoHandler object should persist so that the38// UtilityFunction39// can be reused multiple times.40 41namespace lldb_private {42 43class AppleGetThreadItemInfoHandler {44public:45 AppleGetThreadItemInfoHandler(lldb_private::Process *process);46 47 ~AppleGetThreadItemInfoHandler();48 49 struct GetThreadItemInfoReturnInfo {50 lldb::addr_t item_buffer_ptr = LLDB_INVALID_ADDRESS; /* the address of the51 item buffer from libBacktraceRecording */52 lldb::addr_t item_buffer_size = 0; /* the size of the item buffer from53 libBacktraceRecording */54 55 GetThreadItemInfoReturnInfo() = default;56 };57 58 /// Get the information about a work item by calling59 /// __introspection_dispatch_thread_get_item_info. If there's a page of60 /// memory that needs to be freed, pass in the address and size and it will61 /// be freed before getting the list of queues.62 ///63 /// \param [in] thread_id64 /// The thread to get the extended backtrace for.65 ///66 /// \param [in] page_to_free67 /// An address of an inferior process vm page that needs to be68 /// deallocated,69 /// LLDB_INVALID_ADDRESS if this is not needed.70 ///71 /// \param [in] page_to_free_size72 /// The size of the vm page that needs to be deallocated if an address was73 /// passed in to page_to_free.74 ///75 /// \param [out] error76 /// This object will be updated with the error status / error string from77 /// any failures encountered.78 ///79 /// \returns80 /// The result of the inferior function call execution. If there was a81 /// failure of any kind while getting82 /// the information, the item_buffer_ptr value will be83 /// LLDB_INVALID_ADDRESS.84 GetThreadItemInfoReturnInfo GetThreadItemInfo(Thread &thread,85 lldb::tid_t thread_id,86 lldb::addr_t page_to_free,87 uint64_t page_to_free_size,88 lldb_private::Status &error);89 90 void Detach();91 92private:93 lldb::addr_t94 SetupGetThreadItemInfoFunction(Thread &thread,95 ValueList &get_thread_item_info_arglist);96 97 static const char *g_get_thread_item_info_function_name;98 static const char *g_get_thread_item_info_function_code;99 100 lldb_private::Process *m_process;101 std::unique_ptr<UtilityFunction> m_get_thread_item_info_impl_code;102 std::mutex m_get_thread_item_info_function_mutex;103 104 lldb::addr_t m_get_thread_item_info_return_buffer_addr;105 std::mutex m_get_thread_item_info_retbuffer_mutex;106};107 108} // using namespace lldb_private109 110#endif // LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETTHREADITEMINFOHANDLER_H111