xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.h (revision be691f3bb6417f04a68938fadbcaee2d5795e764)
1061da546Spatrick //===-- AppleGetQueuesHandler.h ----------------------------*- C++ -*-===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9dda28197Spatrick #ifndef LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETQUEUESHANDLER_H
10dda28197Spatrick #define LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETQUEUESHANDLER_H
11061da546Spatrick 
12061da546Spatrick #include <map>
13061da546Spatrick #include <mutex>
14061da546Spatrick #include <vector>
15061da546Spatrick 
16061da546Spatrick #include "lldb/Symbol/CompilerType.h"
17061da546Spatrick #include "lldb/Utility/Status.h"
18061da546Spatrick #include "lldb/lldb-public.h"
19061da546Spatrick 
20061da546Spatrick // This class will insert a UtilityFunction into the inferior process for
21061da546Spatrick // calling libBacktraceRecording's introspection_get_dispatch_queues()
22061da546Spatrick // function.  The function in the inferior will return a struct by value
23061da546Spatrick // with these members:
24061da546Spatrick //
25061da546Spatrick //     struct get_current_queues_return_values
26061da546Spatrick //     {
27061da546Spatrick //         introspection_dispatch_queue_info_t *queues_buffer;
28061da546Spatrick //         uint64_t queues_buffer_size;
29061da546Spatrick //         uint64_t count;
30061da546Spatrick //     };
31061da546Spatrick //
32061da546Spatrick // The queues_buffer pointer is an address in the inferior program's address
33061da546Spatrick // space (queues_buffer_size in size) which must be mach_vm_deallocate'd by
34061da546Spatrick // lldb.  count is the number of queues that were stored in the buffer.
35061da546Spatrick //
36061da546Spatrick // The AppleGetQueuesHandler object should persist so that the UtilityFunction
37061da546Spatrick // can be reused multiple times.
38061da546Spatrick 
39061da546Spatrick namespace lldb_private {
40061da546Spatrick 
41061da546Spatrick class AppleGetQueuesHandler {
42061da546Spatrick public:
43061da546Spatrick   AppleGetQueuesHandler(lldb_private::Process *process);
44061da546Spatrick 
45061da546Spatrick   ~AppleGetQueuesHandler();
46061da546Spatrick 
47061da546Spatrick   struct GetQueuesReturnInfo {
48*be691f3bSpatrick     lldb::addr_t queues_buffer_ptr =
49*be691f3bSpatrick         LLDB_INVALID_ADDRESS; /* the address of the queues buffer from
50061da546Spatrick           libBacktraceRecording */
51*be691f3bSpatrick     lldb::addr_t queues_buffer_size = 0; /* the size of the queues buffer from
52061da546Spatrick                                         libBacktraceRecording */
53*be691f3bSpatrick     uint64_t count = 0; /* the number of queues included in the queues buffer */
54061da546Spatrick 
55*be691f3bSpatrick     GetQueuesReturnInfo() = default;
56061da546Spatrick   };
57061da546Spatrick 
58061da546Spatrick   /// Get the list of queues that exist (with any active or pending items) via
59061da546Spatrick   /// a call to introspection_get_dispatch_queues().  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
64061da546Spatrick   ///     The thread to run this plan on.
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 queues_buffer_ptr value will be
83061da546Spatrick   ///     LLDB_INVALID_ADDRESS.
84061da546Spatrick   GetQueuesReturnInfo GetCurrentQueues(Thread &thread,
85061da546Spatrick                                        lldb::addr_t page_to_free,
86061da546Spatrick                                        uint64_t page_to_free_size,
87061da546Spatrick                                        lldb_private::Status &error);
88061da546Spatrick 
89061da546Spatrick   void Detach();
90061da546Spatrick 
91061da546Spatrick private:
92061da546Spatrick   lldb::addr_t SetupGetQueuesFunction(Thread &thread,
93061da546Spatrick                                       ValueList &get_queues_arglist);
94061da546Spatrick 
95061da546Spatrick   static const char *g_get_current_queues_function_name;
96061da546Spatrick   static const char *g_get_current_queues_function_code;
97061da546Spatrick 
98061da546Spatrick   lldb_private::Process *m_process;
99061da546Spatrick   std::unique_ptr<UtilityFunction> m_get_queues_impl_code_up;
100061da546Spatrick   std::mutex m_get_queues_function_mutex;
101061da546Spatrick 
102061da546Spatrick   lldb::addr_t m_get_queues_return_buffer_addr;
103061da546Spatrick   std::mutex m_get_queues_retbuffer_mutex;
104061da546Spatrick };
105061da546Spatrick 
106061da546Spatrick } // using namespace lldb_private
107061da546Spatrick 
108dda28197Spatrick #endif // LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETQUEUESHANDLER_H
109