1 //===-- DNB.h ---------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Created by Greg Clayton on 3/23/07.
12 //===----------------------------------------------------------------------===//
18 #include "JSONGenerator.h"
19 #include "MacOSX/DarwinLog/DarwinLogEvent.h"
20 #include "MacOSX/Genealogy.h"
21 #include "MacOSX/ThreadInfo.h"
22 #include <mach/thread_info.h>
25 #define DNB_EXPORT __attribute__((visibility("default")))
27 #ifndef CPU_TYPE_ARM64
28 #define CPU_TYPE_ARM64 ((cpu_type_t)12 | 0x01000000)
31 typedef bool (*DNBShouldCancelCallback)(void *);
36 nub_bool_t DNBSetArchitecture(const char *arch);
38 //----------------------------------------------------------------------
40 //----------------------------------------------------------------------
41 nub_process_t DNBProcessLaunch(
42 const char *path, char const *argv[], const char *envp[],
43 const char *working_directory, // NULL => don't change, non-NULL => set
44 // working directory for inferior to this
45 const char *stdin_path, const char *stdout_path, const char *stderr_path,
46 bool no_stdio, nub_launch_flavor_t launch_flavor, int disable_aslr,
47 const char *event_data, char *err_str, size_t err_len);
49 nub_process_t DNBProcessGetPIDByName(const char *name);
50 nub_process_t DNBProcessAttach(nub_process_t pid, struct timespec *timeout,
51 char *err_str, size_t err_len);
52 nub_process_t DNBProcessAttachByName(const char *name, struct timespec *timeout,
53 char *err_str, size_t err_len);
55 DNBProcessAttachWait(const char *wait_name, nub_launch_flavor_t launch_flavor,
56 bool ignore_existing, struct timespec *timeout,
57 useconds_t interval, char *err_str, size_t err_len,
58 DNBShouldCancelCallback should_cancel = NULL,
59 void *callback_data = NULL);
60 // Resume a process with exact instructions on what to do with each thread:
61 // - If no thread actions are supplied (actions is NULL or num_actions is zero),
62 // then all threads are continued.
63 // - If any thread actions are supplied, then each thread will do as it is told
64 // by the action. A default actions for any threads that don't have an
65 // explicit thread action can be made by making a thread action with a tid of
66 // INVALID_NUB_THREAD. If there is no default action, those threads will
68 nub_bool_t DNBProcessResume(nub_process_t pid,
69 const DNBThreadResumeAction *actions,
70 size_t num_actions) DNB_EXPORT;
71 nub_bool_t DNBProcessHalt(nub_process_t pid) DNB_EXPORT;
72 nub_bool_t DNBProcessDetach(nub_process_t pid) DNB_EXPORT;
73 nub_bool_t DNBProcessSignal(nub_process_t pid, int signal) DNB_EXPORT;
74 nub_bool_t DNBProcessInterrupt(nub_process_t pid) DNB_EXPORT;
75 nub_bool_t DNBProcessKill(nub_process_t pid) DNB_EXPORT;
76 nub_bool_t DNBProcessSendEvent(nub_process_t pid, const char *event) DNB_EXPORT;
77 nub_size_t DNBProcessMemoryRead(nub_process_t pid, nub_addr_t addr,
78 nub_size_t size, void *buf) DNB_EXPORT;
79 uint64_t DNBProcessMemoryReadInteger(nub_process_t pid, nub_addr_t addr,
80 nub_size_t integer_size,
81 uint64_t fail_value) DNB_EXPORT;
82 nub_addr_t DNBProcessMemoryReadPointer(nub_process_t pid,
83 nub_addr_t addr) DNB_EXPORT;
84 std::string DNBProcessMemoryReadCString(nub_process_t pid,
85 nub_addr_t addr) DNB_EXPORT;
87 DNBProcessMemoryReadCStringFixed(nub_process_t pid, nub_addr_t addr,
88 nub_size_t fixed_length) DNB_EXPORT;
89 nub_size_t DNBProcessMemoryWrite(nub_process_t pid, nub_addr_t addr,
90 nub_size_t size, const void *buf) DNB_EXPORT;
91 nub_addr_t DNBProcessMemoryAllocate(nub_process_t pid, nub_size_t size,
92 uint32_t permissions) DNB_EXPORT;
93 nub_bool_t DNBProcessMemoryDeallocate(nub_process_t pid,
94 nub_addr_t addr) DNB_EXPORT;
95 int DNBProcessMemoryRegionInfo(nub_process_t pid, nub_addr_t addr,
96 DNBRegionInfo *region_info) DNB_EXPORT;
98 DNBProcessGetProfileData(nub_process_t pid,
99 DNBProfileDataScanType scanType) DNB_EXPORT;
101 DNBProcessSetEnableAsyncProfiling(nub_process_t pid, nub_bool_t enable,
102 uint64_t interval_usec,
103 DNBProfileDataScanType scan_type) DNB_EXPORT;
104 DarwinLogEventVector DNBProcessGetAvailableDarwinLogEvents(nub_process_t pid);
106 //----------------------------------------------------------------------
108 //----------------------------------------------------------------------
109 nub_bool_t DNBProcessIsAlive(nub_process_t pid) DNB_EXPORT;
110 nub_state_t DNBProcessGetState(nub_process_t pid) DNB_EXPORT;
111 nub_bool_t DNBProcessGetExitStatus(nub_process_t pid, int *status) DNB_EXPORT;
112 nub_bool_t DNBProcessSetExitStatus(nub_process_t pid, int status) DNB_EXPORT;
113 const char *DNBProcessGetExitInfo(nub_process_t pid) DNB_EXPORT;
114 nub_bool_t DNBProcessSetExitInfo(nub_process_t pid,
115 const char *info) DNB_EXPORT;
116 nub_size_t DNBProcessGetNumThreads(nub_process_t pid) DNB_EXPORT;
117 nub_thread_t DNBProcessGetCurrentThread(nub_process_t pid) DNB_EXPORT;
118 nub_thread_t DNBProcessGetCurrentThreadMachPort(nub_process_t pid) DNB_EXPORT;
119 nub_thread_t DNBProcessSetCurrentThread(nub_process_t pid,
120 nub_thread_t tid) DNB_EXPORT;
121 nub_thread_t DNBProcessGetThreadAtIndex(nub_process_t pid,
122 nub_size_t thread_idx) DNB_EXPORT;
123 nub_bool_t DNBProcessSyncThreadState(nub_process_t pid,
124 nub_thread_t tid) DNB_EXPORT;
125 nub_addr_t DNBProcessGetSharedLibraryInfoAddress(nub_process_t pid) DNB_EXPORT;
126 nub_bool_t DNBProcessSharedLibrariesUpdated(nub_process_t pid) DNB_EXPORT;
128 DNBProcessGetSharedLibraryInfo(nub_process_t pid, nub_bool_t only_changed,
129 DNBExecutableImageInfo **image_infos) DNB_EXPORT;
130 const char *DNBGetDeploymentInfo(nub_process_t pid,
131 const struct load_command& lc,
132 uint64_t load_command_address,
133 uint32_t& major_version,
134 uint32_t& minor_version,
135 uint32_t& patch_version);
136 nub_bool_t DNBProcessSetNameToAddressCallback(nub_process_t pid,
137 DNBCallbackNameToAddress callback,
138 void *baton) DNB_EXPORT;
139 nub_bool_t DNBProcessSetSharedLibraryInfoCallback(
140 nub_process_t pid, DNBCallbackCopyExecutableImageInfos callback,
141 void *baton) DNB_EXPORT;
142 nub_addr_t DNBProcessLookupAddress(nub_process_t pid, const char *name,
143 const char *shlib) DNB_EXPORT;
144 nub_size_t DNBProcessGetAvailableSTDOUT(nub_process_t pid, char *buf,
145 nub_size_t buf_size) DNB_EXPORT;
146 nub_size_t DNBProcessGetAvailableSTDERR(nub_process_t pid, char *buf,
147 nub_size_t buf_size) DNB_EXPORT;
148 nub_size_t DNBProcessGetAvailableProfileData(nub_process_t pid, char *buf,
149 nub_size_t buf_size) DNB_EXPORT;
150 nub_size_t DNBProcessGetStopCount(nub_process_t pid) DNB_EXPORT;
151 uint32_t DNBProcessGetCPUType(nub_process_t pid) DNB_EXPORT;
153 //----------------------------------------------------------------------
154 // Process executable and arguments
155 //----------------------------------------------------------------------
156 const char *DNBProcessGetExecutablePath(nub_process_t pid);
157 const char *DNBProcessGetArgumentAtIndex(nub_process_t pid, nub_size_t idx);
158 nub_size_t DNBProcessGetArgumentCount(nub_process_t pid);
160 //----------------------------------------------------------------------
162 //----------------------------------------------------------------------
163 nub_event_t DNBProcessWaitForEvents(nub_process_t pid, nub_event_t event_mask,
165 struct timespec *timeout);
166 void DNBProcessResetEvents(nub_process_t pid, nub_event_t event_mask);
168 //----------------------------------------------------------------------
170 //----------------------------------------------------------------------
171 const char *DNBThreadGetName(nub_process_t pid, nub_thread_t tid);
173 DNBThreadGetIdentifierInfo(nub_process_t pid, nub_thread_t tid,
174 thread_identifier_info_data_t *ident_info);
175 nub_state_t DNBThreadGetState(nub_process_t pid, nub_thread_t tid);
176 nub_bool_t DNBThreadGetRegisterValueByID(nub_process_t pid, nub_thread_t tid,
177 uint32_t set, uint32_t reg,
178 DNBRegisterValue *value);
179 nub_bool_t DNBThreadSetRegisterValueByID(nub_process_t pid, nub_thread_t tid,
180 uint32_t set, uint32_t reg,
181 const DNBRegisterValue *value);
182 nub_size_t DNBThreadGetRegisterContext(nub_process_t pid, nub_thread_t tid,
183 void *buf, size_t buf_len);
184 nub_size_t DNBThreadSetRegisterContext(nub_process_t pid, nub_thread_t tid,
185 const void *buf, size_t buf_len);
186 uint32_t DNBThreadSaveRegisterState(nub_process_t pid, nub_thread_t tid);
187 nub_bool_t DNBThreadRestoreRegisterState(nub_process_t pid, nub_thread_t tid,
189 nub_bool_t DNBThreadGetRegisterValueByName(nub_process_t pid, nub_thread_t tid,
190 uint32_t set, const char *name,
191 DNBRegisterValue *value);
192 nub_bool_t DNBThreadGetStopReason(nub_process_t pid, nub_thread_t tid,
193 DNBThreadStopInfo *stop_info);
194 const char *DNBThreadGetInfo(nub_process_t pid, nub_thread_t tid);
195 Genealogy::ThreadActivitySP DNBGetGenealogyInfoForThread(nub_process_t pid,
198 Genealogy::ProcessExecutableInfoSP DNBGetGenealogyImageInfo(nub_process_t pid,
200 ThreadInfo::QoS DNBGetRequestedQoSForThread(nub_process_t pid, nub_thread_t tid,
202 uint64_t dti_qos_class_index);
203 nub_addr_t DNBGetPThreadT(nub_process_t pid, nub_thread_t tid);
204 nub_addr_t DNBGetDispatchQueueT(nub_process_t pid, nub_thread_t tid);
206 DNBGetTSDAddressForThread(nub_process_t pid, nub_thread_t tid,
207 uint64_t plo_pthread_tsd_base_address_offset,
208 uint64_t plo_pthread_tsd_base_offset,
209 uint64_t plo_pthread_tsd_entry_size);
210 JSONGenerator::ObjectSP DNBGetLoadedDynamicLibrariesInfos(
211 nub_process_t pid, nub_addr_t image_list_address, nub_addr_t image_count);
212 JSONGenerator::ObjectSP DNBGetAllLoadedLibrariesInfos(nub_process_t pid);
213 JSONGenerator::ObjectSP
214 DNBGetLibrariesInfoForAddresses(nub_process_t pid,
215 std::vector<uint64_t> &macho_addresses);
216 JSONGenerator::ObjectSP DNBGetSharedCacheInfo(nub_process_t pid);
219 //----------------------------------------------------------------------
220 // Breakpoint functions
221 //----------------------------------------------------------------------
222 nub_bool_t DNBBreakpointSet(nub_process_t pid, nub_addr_t addr, nub_size_t size,
223 nub_bool_t hardware);
224 nub_bool_t DNBBreakpointClear(nub_process_t pid, nub_addr_t addr);
226 //----------------------------------------------------------------------
227 // Watchpoint functions
228 //----------------------------------------------------------------------
229 nub_bool_t DNBWatchpointSet(nub_process_t pid, nub_addr_t addr, nub_size_t size,
230 uint32_t watch_flags, nub_bool_t hardware);
231 nub_bool_t DNBWatchpointClear(nub_process_t pid, nub_addr_t addr);
232 uint32_t DNBWatchpointGetNumSupportedHWP(nub_process_t pid);
234 uint32_t DNBGetRegisterCPUType();
235 const DNBRegisterSetInfo *DNBGetRegisterSetInfo(nub_size_t *num_reg_sets);
236 nub_bool_t DNBGetRegisterInfoByName(const char *reg_name,
237 DNBRegisterInfo *info);
239 //----------------------------------------------------------------------
240 // Other static nub information calls.
241 //----------------------------------------------------------------------
242 const char *DNBStateAsString(nub_state_t state);
243 nub_bool_t DNBResolveExecutablePath(const char *path, char *resolved_path,
244 size_t resolved_path_size);
245 bool DNBGetOSVersionNumbers(uint64_t *major, uint64_t *minor, uint64_t *patch);