blob: 742e09d92a5bd6d738bf2a6af4fa81661da2953b [file] [log] [blame]
Kate Stoneb9c1b512016-09-06 20:57:50 +00001//===-- AppleGetPendingItemsHandler.h ----------------------------*- C++
2//-*-===//
Jason Molenda2fd83352014-02-05 05:44:54 +00003//
Chandler Carruth2946cd72019-01-19 08:50:56 +00004// 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-exception
Jason Molenda2fd83352014-02-05 05:44:54 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef lldb_AppleGetPendingItemsHandler_h_
11#define lldb_AppleGetPendingItemsHandler_h_
12
Jason Molenda2fd83352014-02-05 05:44:54 +000013#include <map>
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +000014#include <mutex>
Jason Molenda2fd83352014-02-05 05:44:54 +000015#include <vector>
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +000016
Greg Claytona1e5dc82015-08-11 22:53:00 +000017#include "lldb/Symbol/CompilerType.h"
Zachary Turner97206d52017-05-12 04:51:55 +000018#include "lldb/Utility/Status.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000019#include "lldb/lldb-public.h"
Jason Molenda2fd83352014-02-05 05:44:54 +000020
Jim Ingham151c0322015-09-15 21:13:50 +000021// This class will insert a UtilityFunction into the inferior process for
Kate Stoneb9c1b512016-09-06 20:57:50 +000022// calling libBacktraceRecording's
23// __introspection_dispatch_queue_get_pending_items()
Jason Molenda2fd83352014-02-05 05:44:54 +000024// function. The function in the inferior will return a struct by value
25// with these members:
26//
27// struct get_pending_items_return_values
28// {
29// introspection_dispatch_item_info_ref *items_buffer;
30// uint64_t items_buffer_size;
31// uint64_t count;
32// };
33//
34// The items_buffer pointer is an address in the inferior program's address
35// space (items_buffer_size in size) which must be mach_vm_deallocate'd by
36// lldb. count is the number of items that were stored in the buffer.
37//
Kate Stoneb9c1b512016-09-06 20:57:50 +000038// The AppleGetPendingItemsHandler object should persist so that the
39// UtilityFunction
Jason Molenda2fd83352014-02-05 05:44:54 +000040// can be reused multiple times.
41
Kate Stoneb9c1b512016-09-06 20:57:50 +000042namespace lldb_private {
Jason Molenda2fd83352014-02-05 05:44:54 +000043
44class AppleGetPendingItemsHandler {
45public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 AppleGetPendingItemsHandler(lldb_private::Process *process);
Jason Molenda2fd83352014-02-05 05:44:54 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 ~AppleGetPendingItemsHandler();
Jason Molenda2fd83352014-02-05 05:44:54 +000049
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 struct GetPendingItemsReturnInfo {
51 lldb::addr_t items_buffer_ptr; /* the address of the pending items buffer
52 from libBacktraceRecording */
53 lldb::addr_t
54 items_buffer_size; /* the size of the pending items buffer from
55 libBacktraceRecording */
56 uint64_t count; /* the number of pending items included in the buffer */
Jason Molenda2fd83352014-02-05 05:44:54 +000057
Kate Stoneb9c1b512016-09-06 20:57:50 +000058 GetPendingItemsReturnInfo()
59 : items_buffer_ptr(LLDB_INVALID_ADDRESS), items_buffer_size(0),
60 count(0) {}
61 };
Jason Molenda2fd83352014-02-05 05:44:54 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 //----------------------------------------------------------
64 /// Get the list of pending items for a given queue via a call to
65 /// __introspection_dispatch_queue_get_pending_items. If there's a page of
66 /// memory that needs to be freed, pass in the address and size and it will
67 /// be freed before getting the list of queues.
68 ///
69 /// @param [in] thread
70 /// The thread to run this plan on.
71 ///
72 /// @param [in] queue
73 /// The dispatch_queue_t value for the queue of interest.
74 ///
75 /// @param [in] page_to_free
76 /// An address of an inferior process vm page that needs to be
77 /// deallocated,
78 /// LLDB_INVALID_ADDRESS if this is not needed.
79 ///
80 /// @param [in] page_to_free_size
81 /// The size of the vm page that needs to be deallocated if an address was
82 /// passed in to page_to_free.
83 ///
84 /// @param [out] error
85 /// This object will be updated with the error status / error string from
86 /// any failures encountered.
87 ///
88 /// @returns
89 /// The result of the inferior function call execution. If there was a
90 /// failure of any kind while getting
91 /// the information, the items_buffer_ptr value will be
92 /// LLDB_INVALID_ADDRESS.
93 //----------------------------------------------------------
94 GetPendingItemsReturnInfo GetPendingItems(Thread &thread, lldb::addr_t queue,
95 lldb::addr_t page_to_free,
96 uint64_t page_to_free_size,
Zachary Turner97206d52017-05-12 04:51:55 +000097 lldb_private::Status &error);
Jason Molenda2fd83352014-02-05 05:44:54 +000098
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 void Detach();
Jason Molenda2fd83352014-02-05 05:44:54 +0000100
101private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 lldb::addr_t
103 SetupGetPendingItemsFunction(Thread &thread,
104 ValueList &get_pending_items_arglist);
Jason Molenda2fd83352014-02-05 05:44:54 +0000105
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106 static const char *g_get_pending_items_function_name;
107 static const char *g_get_pending_items_function_code;
Jason Molenda2fd83352014-02-05 05:44:54 +0000108
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109 lldb_private::Process *m_process;
110 std::unique_ptr<UtilityFunction> m_get_pending_items_impl_code;
111 std::mutex m_get_pending_items_function_mutex;
Jason Molenda2fd83352014-02-05 05:44:54 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 lldb::addr_t m_get_pending_items_return_buffer_addr;
114 std::mutex m_get_pending_items_retbuffer_mutex;
Jason Molenda2fd83352014-02-05 05:44:54 +0000115};
116
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117} // using namespace lldb_private
Jason Molenda2fd83352014-02-05 05:44:54 +0000118
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119#endif // lldb_AppleGetPendingItemsHandler_h_