blob: c1798fb515b44bc61f8d3507c22249ab49c9bbe4 [file] [log] [blame]
Jason Molenda2fd83352014-02-05 05:44:54 +00001//===-- AppleGetThreadItemInfoHandler.h ----------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef lldb_AppleGetThreadItemInfoHandler_h_
11#define lldb_AppleGetThreadItemInfoHandler_h_
12
13// C Includes
14// C++ Includes
15#include <map>
16#include <vector>
17// Other libraries and framework includes
18// Project includes
19#include "lldb/lldb-public.h"
20#include "lldb/Core/Error.h"
Jason Molenda2fd83352014-02-05 05:44:54 +000021#include "lldb/Host/Mutex.h"
Greg Claytona1e5dc82015-08-11 22:53:00 +000022#include "lldb/Symbol/CompilerType.h"
Jason Molenda2fd83352014-02-05 05:44:54 +000023
Jim Ingham151c0322015-09-15 21:13:50 +000024// This class will insert a UtilityFunction into the inferior process for
Jason Molenda2fd83352014-02-05 05:44:54 +000025// calling libBacktraceRecording's __introspection_dispatch_thread_get_item_info()
26// function. The function in the inferior will return a struct by value
27// with these members:
28//
29// struct get_thread_item_info_return_values
30// {
31// introspection_dispatch_item_info_ref *item_buffer;
32// uint64_t item_buffer_size;
33// };
34//
35// The item_buffer pointer is an address in the inferior program's address
36// space (item_buffer_size in size) which must be mach_vm_deallocate'd by
37// lldb.
38//
Jim Ingham151c0322015-09-15 21:13:50 +000039// The AppleGetThreadItemInfoHandler object should persist so that the UtilityFunction
Jason Molenda2fd83352014-02-05 05:44:54 +000040// can be reused multiple times.
41
42namespace lldb_private
43{
44
45class AppleGetThreadItemInfoHandler {
46public:
47
48 AppleGetThreadItemInfoHandler (lldb_private::Process *process);
49
50 ~AppleGetThreadItemInfoHandler();
51
52 struct GetThreadItemInfoReturnInfo
53 {
54 lldb::addr_t item_buffer_ptr; /* the address of the item buffer from libBacktraceRecording */
55 lldb::addr_t item_buffer_size; /* the size of the item buffer from libBacktraceRecording */
56
57 GetThreadItemInfoReturnInfo() :
58 item_buffer_ptr(LLDB_INVALID_ADDRESS),
59 item_buffer_size(0)
60 {}
61 };
62
63 //----------------------------------------------------------
64 /// Get the information about a work item by calling
65 /// __introspection_dispatch_thread_get_item_info. 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 ///
Jason Molendada276f92014-02-11 00:36:18 +000069 /// @param [in] thread_id
70 /// The thread to get the extended backtrace for.
Jason Molenda2fd83352014-02-05 05:44:54 +000071 ///
72 /// @param [in] page_to_free
73 /// An address of an inferior process vm page that needs to be deallocated,
74 /// LLDB_INVALID_ADDRESS if this is not needed.
75 ///
76 /// @param [in] page_to_free_size
77 /// The size of the vm page that needs to be deallocated if an address was
78 /// passed in to page_to_free.
79 ///
80 /// @param [out] error
81 /// This object will be updated with the error status / error string from any failures encountered.
82 ///
83 /// @returns
84 /// The result of the inferior function call execution. If there was a failure of any kind while getting
85 /// the information, the item_buffer_ptr value will be LLDB_INVALID_ADDRESS.
86 //----------------------------------------------------------
87 GetThreadItemInfoReturnInfo
Jason Molendada276f92014-02-11 00:36:18 +000088 GetThreadItemInfo (Thread &thread, lldb::tid_t thread_id, lldb::addr_t page_to_free, uint64_t page_to_free_size, lldb_private::Error &error);
Jason Molenda2fd83352014-02-05 05:44:54 +000089
90
91 void
92 Detach ();
93
94private:
95
96 lldb::addr_t
97 SetupGetThreadItemInfoFunction (Thread &thread, ValueList &get_thread_item_info_arglist);
98
99 static const char *g_get_thread_item_info_function_name;
100 static const char *g_get_thread_item_info_function_code;
101
102 lldb_private::Process *m_process;
Jim Ingham151c0322015-09-15 21:13:50 +0000103 std::unique_ptr<UtilityFunction> m_get_thread_item_info_impl_code;
Jason Molenda2fd83352014-02-05 05:44:54 +0000104 Mutex m_get_thread_item_info_function_mutex;
105
106 lldb::addr_t m_get_thread_item_info_return_buffer_addr;
107 Mutex m_get_thread_item_info_retbuffer_mutex;
108
109};
110
111} // using namespace lldb_private
112
113#endif // lldb_AppleGetThreadItemInfoHandler_h_