• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETQUEUESHANDLER_H
10 #define LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETQUEUESHANDLER_H
11 
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 for
21 // calling libBacktraceRecording's introspection_get_dispatch_queues()
22 // function.  The function in the inferior will return a struct by value
23 // with these members:
24 //
25 //     struct get_current_queues_return_values
26 //     {
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 address
33 // space (queues_buffer_size in size) which must be mach_vm_deallocate'd by
34 // lldb.  count is the number of queues that were stored in the buffer.
35 //
36 // The AppleGetQueuesHandler object should persist so that the UtilityFunction
37 // can be reused multiple times.
38 
39 namespace lldb_private {
40 
41 class AppleGetQueuesHandler {
42 public:
43   AppleGetQueuesHandler(lldb_private::Process *process);
44 
45   ~AppleGetQueuesHandler();
46 
47   struct GetQueuesReturnInfo {
48     lldb::addr_t queues_buffer_ptr;  /* the address of the queues buffer from
49                                         libBacktraceRecording */
50     lldb::addr_t queues_buffer_size; /* the size of the queues buffer from
51                                         libBacktraceRecording */
52     uint64_t count; /* the number of queues included in the queues buffer */
53 
GetQueuesReturnInfoGetQueuesReturnInfo54     GetQueuesReturnInfo()
55         : queues_buffer_ptr(LLDB_INVALID_ADDRESS), queues_buffer_size(0),
56           count(0) {}
57   };
58 
59   /// Get the list of queues that exist (with any active or pending items) via
60   /// a call to introspection_get_dispatch_queues().  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
65   ///     The thread to run this plan on.
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 queues_buffer_ptr value will be
84   ///     LLDB_INVALID_ADDRESS.
85   GetQueuesReturnInfo GetCurrentQueues(Thread &thread,
86                                        lldb::addr_t page_to_free,
87                                        uint64_t page_to_free_size,
88                                        lldb_private::Status &error);
89 
90   void Detach();
91 
92 private:
93   lldb::addr_t SetupGetQueuesFunction(Thread &thread,
94                                       ValueList &get_queues_arglist);
95 
96   static const char *g_get_current_queues_function_name;
97   static const char *g_get_current_queues_function_code;
98 
99   lldb_private::Process *m_process;
100   std::unique_ptr<UtilityFunction> m_get_queues_impl_code_up;
101   std::mutex m_get_queues_function_mutex;
102 
103   lldb::addr_t m_get_queues_return_buffer_addr;
104   std::mutex m_get_queues_retbuffer_mutex;
105 };
106 
107 } // using namespace lldb_private
108 
109 #endif // LLDB_SOURCE_PLUGINS_SYSTEMRUNTIME_MACOSX_APPLEGETQUEUESHANDLER_H
110