109 lines · c
1//===-- AppleGetQueuesHandler.h ----------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETQUEUESHANDLER_H10#define LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETQUEUESHANDLER_H11 12#include <map>13#include <mutex>14#include <vector>15 16#include "lldb/Symbol/CompilerType.h"17#include "lldb/Utility/Status.h"18#include "lldb/lldb-public.h"19 20// This class will insert a UtilityFunction into the inferior process for21// calling libBacktraceRecording's introspection_get_dispatch_queues()22// function. The function in the inferior will return a struct by value23// with these members:24//25// struct get_current_queues_return_values26// {27// introspection_dispatch_queue_info_t *queues_buffer;28// uint64_t queues_buffer_size;29// uint64_t count;30// };31//32// The queues_buffer pointer is an address in the inferior program's address33// space (queues_buffer_size in size) which must be mach_vm_deallocate'd by34// lldb. count is the number of queues that were stored in the buffer.35//36// The AppleGetQueuesHandler object should persist so that the UtilityFunction37// can be reused multiple times.38 39namespace lldb_private {40 41class AppleGetQueuesHandler {42public:43 AppleGetQueuesHandler(lldb_private::Process *process);44 45 ~AppleGetQueuesHandler();46 47 struct GetQueuesReturnInfo {48 lldb::addr_t queues_buffer_ptr =49 LLDB_INVALID_ADDRESS; /* the address of the queues buffer from50 libBacktraceRecording */51 lldb::addr_t queues_buffer_size = 0; /* the size of the queues buffer from52 libBacktraceRecording */53 uint64_t count = 0; /* the number of queues included in the queues buffer */54 55 GetQueuesReturnInfo() = default;56 };57 58 /// Get the list of queues that exist (with any active or pending items) via59 /// a call to introspection_get_dispatch_queues(). 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] thread64 /// The thread to run this plan on.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 queues_buffer_ptr value will be83 /// LLDB_INVALID_ADDRESS.84 GetQueuesReturnInfo GetCurrentQueues(Thread &thread,85 lldb::addr_t page_to_free,86 uint64_t page_to_free_size,87 lldb_private::Status &error);88 89 void Detach();90 91private:92 lldb::addr_t SetupGetQueuesFunction(Thread &thread,93 ValueList &get_queues_arglist);94 95 static const char *g_get_current_queues_function_name;96 static const char *g_get_current_queues_function_code;97 98 lldb_private::Process *m_process;99 std::unique_ptr<UtilityFunction> m_get_queues_impl_code_up;100 std::mutex m_get_queues_function_mutex;101 102 lldb::addr_t m_get_queues_return_buffer_addr;103 std::mutex m_get_queues_retbuffer_mutex;104};105 106} // using namespace lldb_private107 108#endif // LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETQUEUESHANDLER_H109