xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.h (revision be691f3bb6417f04a68938fadbcaee2d5795e764)
1061da546Spatrick //===-- AppleGetItemInfoHandler.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_APPLEGETITEMINFOHANDLER_H
10dda28197Spatrick #define LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETITEMINFOHANDLER_H
11061da546Spatrick 
12061da546Spatrick #include <map>
13061da546Spatrick #include <mutex>
14061da546Spatrick #include <vector>
15061da546Spatrick 
16061da546Spatrick #include "lldb/Expression/UtilityFunction.h"
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_queue_item_get_info()
24061da546Spatrick // function.  The function in the inferior will return a struct by value
25061da546Spatrick // with these members:
26061da546Spatrick //
27061da546Spatrick //     struct get_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 AppleGetItemInfoHandler object should persist so that the UtilityFunction
38061da546Spatrick // can be reused multiple times.
39061da546Spatrick 
40061da546Spatrick namespace lldb_private {
41061da546Spatrick 
42061da546Spatrick class AppleGetItemInfoHandler {
43061da546Spatrick public:
44061da546Spatrick   AppleGetItemInfoHandler(lldb_private::Process *process);
45061da546Spatrick 
46061da546Spatrick   ~AppleGetItemInfoHandler();
47061da546Spatrick 
48061da546Spatrick   struct GetItemInfoReturnInfo {
49*be691f3bSpatrick     lldb::addr_t item_buffer_ptr = LLDB_INVALID_ADDRESS; /* the address of the
50*be691f3bSpatrick                                      item buffer from libBacktraceRecording */
51*be691f3bSpatrick     lldb::addr_t item_buffer_size = 0; /* the size of the item buffer from
52061da546Spatrick                                       libBacktraceRecording */
53061da546Spatrick 
54*be691f3bSpatrick     GetItemInfoReturnInfo() = default;
55061da546Spatrick   };
56061da546Spatrick 
57061da546Spatrick   /// Get the information about a work item by calling
58061da546Spatrick   /// __introspection_dispatch_queue_item_get_info.  If there's a page of
59061da546Spatrick   /// memory that needs to be freed, pass in the address and size and it will
60061da546Spatrick   /// be freed before getting the list of queues.
61061da546Spatrick   ///
62061da546Spatrick   /// \param [in] thread
63061da546Spatrick   ///     The thread to run this plan on.
64061da546Spatrick   ///
65061da546Spatrick   /// \param [in] item
66061da546Spatrick   ///     The introspection_dispatch_item_info_ref value for the item of
67061da546Spatrick   ///     interest.
68061da546Spatrick   ///
69061da546Spatrick   /// \param [in] page_to_free
70061da546Spatrick   ///     An address of an inferior process vm page that needs to be
71061da546Spatrick   ///     deallocated,
72061da546Spatrick   ///     LLDB_INVALID_ADDRESS if this is not needed.
73061da546Spatrick   ///
74061da546Spatrick   /// \param [in] page_to_free_size
75061da546Spatrick   ///     The size of the vm page that needs to be deallocated if an address was
76061da546Spatrick   ///     passed in to page_to_free.
77061da546Spatrick   ///
78061da546Spatrick   /// \param [out] error
79061da546Spatrick   ///     This object will be updated with the error status / error string from
80061da546Spatrick   ///     any failures encountered.
81061da546Spatrick   ///
82061da546Spatrick   /// \returns
83061da546Spatrick   ///     The result of the inferior function call execution.  If there was a
84061da546Spatrick   ///     failure of any kind while getting
85061da546Spatrick   ///     the information, the item_buffer_ptr value will be
86061da546Spatrick   ///     LLDB_INVALID_ADDRESS.
87061da546Spatrick   GetItemInfoReturnInfo GetItemInfo(Thread &thread, lldb::addr_t item,
88061da546Spatrick                                     lldb::addr_t page_to_free,
89061da546Spatrick                                     uint64_t page_to_free_size,
90061da546Spatrick                                     lldb_private::Status &error);
91061da546Spatrick 
92061da546Spatrick   void Detach();
93061da546Spatrick 
94061da546Spatrick private:
95061da546Spatrick   lldb::addr_t SetupGetItemInfoFunction(Thread &thread,
96061da546Spatrick                                         ValueList &get_item_info_arglist);
97061da546Spatrick 
98061da546Spatrick   static const char *g_get_item_info_function_name;
99061da546Spatrick   static const char *g_get_item_info_function_code;
100061da546Spatrick 
101061da546Spatrick   lldb_private::Process *m_process;
102061da546Spatrick   std::unique_ptr<UtilityFunction> m_get_item_info_impl_code;
103061da546Spatrick   std::mutex m_get_item_info_function_mutex;
104061da546Spatrick 
105061da546Spatrick   lldb::addr_t m_get_item_info_return_buffer_addr;
106061da546Spatrick   std::mutex m_get_item_info_retbuffer_mutex;
107061da546Spatrick };
108061da546Spatrick 
109061da546Spatrick } // using namespace lldb_private
110061da546Spatrick 
111dda28197Spatrick #endif // LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETITEMINFOHANDLER_H
112