[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / lldb / tools / debugserver / source / DNB.h
blobc04249d672611f0c630b62289b302fed455647c9
1 //===-- DNB.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 // Created by Greg Clayton on 3/23/07.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNB_H
14 #define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNB_H
16 #include "DNBDefs.h"
17 #include "JSONGenerator.h"
18 #include "MacOSX/Genealogy.h"
19 #include "MacOSX/ThreadInfo.h"
20 #include "RNBContext.h"
21 #include <Availability.h>
22 #include <mach/machine.h>
23 #include <mach/thread_info.h>
24 #include <string>
26 #define DNB_EXPORT __attribute__((visibility("default")))
28 #ifndef CPU_TYPE_ARM64
29 #define CPU_TYPE_ARM64 ((cpu_type_t)12 | 0x01000000)
30 #endif
32 #ifndef CPU_TYPE_ARM64_32
33 #define CPU_TYPE_ARM64_32 ((cpu_type_t)12 | 0x02000000)
34 #endif
36 typedef bool (*DNBShouldCancelCallback)(void *);
38 void DNBInitialize();
39 void DNBTerminate();
41 nub_bool_t DNBSetArchitecture(const char *arch);
43 // Process control
44 nub_process_t DNBProcessLaunch(
45 RNBContext *ctx, const char *path, char const *argv[], const char *envp[],
46 const char *working_directory, // NULL => don't change, non-NULL => set
47 // working directory for inferior to this
48 const char *stdin_path, const char *stdout_path, const char *stderr_path,
49 bool no_stdio, int disable_aslr, const char *event_data, char *err_str,
50 size_t err_len);
52 nub_process_t DNBProcessGetPIDByName(const char *name);
53 nub_process_t DNBProcessAttach(nub_process_t pid, struct timespec *timeout,
54 bool unmask_signals, char *err_str,
55 size_t err_len);
56 nub_process_t DNBProcessAttachByName(const char *name, struct timespec *timeout,
57 bool unmask_signals, char *err_str,
58 size_t err_len);
59 nub_process_t DNBProcessAttachWait(RNBContext *ctx, const char *wait_name,
60 bool ignore_existing,
61 struct timespec *timeout,
62 useconds_t interval, char *err_str,
63 size_t err_len,
64 DNBShouldCancelCallback should_cancel = NULL,
65 void *callback_data = NULL);
66 // Resume a process with exact instructions on what to do with each thread:
67 // - If no thread actions are supplied (actions is NULL or num_actions is zero),
68 // then all threads are continued.
69 // - If any thread actions are supplied, then each thread will do as it is told
70 // by the action. A default actions for any threads that don't have an
71 // explicit thread action can be made by making a thread action with a tid of
72 // INVALID_NUB_THREAD. If there is no default action, those threads will
73 // remain stopped.
74 nub_bool_t DNBProcessResume(nub_process_t pid,
75 const DNBThreadResumeAction *actions,
76 size_t num_actions) DNB_EXPORT;
77 nub_bool_t DNBProcessHalt(nub_process_t pid) DNB_EXPORT;
78 nub_bool_t DNBProcessDetach(nub_process_t pid) DNB_EXPORT;
79 nub_bool_t DNBProcessSignal(nub_process_t pid, int signal) DNB_EXPORT;
80 nub_bool_t DNBProcessInterrupt(nub_process_t pid) DNB_EXPORT;
81 nub_bool_t DNBProcessKill(nub_process_t pid) DNB_EXPORT;
82 nub_bool_t DNBProcessSendEvent(nub_process_t pid, const char *event) DNB_EXPORT;
83 nub_size_t DNBProcessMemoryRead(nub_process_t pid, nub_addr_t addr,
84 nub_size_t size, void *buf) DNB_EXPORT;
85 uint64_t DNBProcessMemoryReadInteger(nub_process_t pid, nub_addr_t addr,
86 nub_size_t integer_size,
87 uint64_t fail_value) DNB_EXPORT;
88 nub_addr_t DNBProcessMemoryReadPointer(nub_process_t pid,
89 nub_addr_t addr) DNB_EXPORT;
90 std::string DNBProcessMemoryReadCString(nub_process_t pid,
91 nub_addr_t addr) DNB_EXPORT;
92 std::string
93 DNBProcessMemoryReadCStringFixed(nub_process_t pid, nub_addr_t addr,
94 nub_size_t fixed_length) DNB_EXPORT;
95 nub_size_t DNBProcessMemoryWrite(nub_process_t pid, nub_addr_t addr,
96 nub_size_t size, const void *buf) DNB_EXPORT;
97 nub_addr_t DNBProcessMemoryAllocate(nub_process_t pid, nub_size_t size,
98 uint32_t permissions) DNB_EXPORT;
99 nub_bool_t DNBProcessMemoryDeallocate(nub_process_t pid,
100 nub_addr_t addr) DNB_EXPORT;
101 int DNBProcessMemoryRegionInfo(nub_process_t pid, nub_addr_t addr,
102 DNBRegionInfo *region_info) DNB_EXPORT;
103 std::string
104 DNBProcessGetProfileData(nub_process_t pid,
105 DNBProfileDataScanType scanType) DNB_EXPORT;
106 nub_bool_t
107 DNBProcessSetEnableAsyncProfiling(nub_process_t pid, nub_bool_t enable,
108 uint64_t interval_usec,
109 DNBProfileDataScanType scan_type) DNB_EXPORT;
111 // Process status
112 nub_bool_t DNBProcessIsAlive(nub_process_t pid) DNB_EXPORT;
113 nub_state_t DNBProcessGetState(nub_process_t pid) DNB_EXPORT;
114 nub_bool_t DNBProcessGetExitStatus(nub_process_t pid, int *status) DNB_EXPORT;
115 nub_bool_t DNBProcessSetExitStatus(nub_process_t pid, int status) DNB_EXPORT;
116 const char *DNBProcessGetExitInfo(nub_process_t pid) DNB_EXPORT;
117 nub_bool_t DNBProcessSetExitInfo(nub_process_t pid,
118 const char *info) DNB_EXPORT;
119 nub_size_t DNBProcessGetNumThreads(nub_process_t pid) DNB_EXPORT;
120 nub_thread_t DNBProcessGetCurrentThread(nub_process_t pid) DNB_EXPORT;
121 nub_thread_t DNBProcessGetCurrentThreadMachPort(nub_process_t pid) DNB_EXPORT;
122 nub_thread_t DNBProcessSetCurrentThread(nub_process_t pid,
123 nub_thread_t tid) DNB_EXPORT;
124 nub_thread_t DNBProcessGetThreadAtIndex(nub_process_t pid,
125 nub_size_t thread_idx) DNB_EXPORT;
126 nub_bool_t DNBProcessSyncThreadState(nub_process_t pid,
127 nub_thread_t tid) DNB_EXPORT;
128 nub_addr_t DNBProcessGetSharedLibraryInfoAddress(nub_process_t pid) DNB_EXPORT;
129 nub_bool_t DNBProcessSharedLibrariesUpdated(nub_process_t pid) DNB_EXPORT;
130 nub_size_t
131 DNBProcessGetSharedLibraryInfo(nub_process_t pid, nub_bool_t only_changed,
132 DNBExecutableImageInfo **image_infos) DNB_EXPORT;
133 const char *DNBGetDeploymentInfo(nub_process_t pid, bool is_executable,
134 const struct load_command &lc,
135 uint64_t load_command_address,
136 uint32_t &major_version,
137 uint32_t &minor_version,
138 uint32_t &patch_version);
139 nub_bool_t DNBProcessSetNameToAddressCallback(nub_process_t pid,
140 DNBCallbackNameToAddress callback,
141 void *baton) DNB_EXPORT;
142 nub_bool_t DNBProcessSetSharedLibraryInfoCallback(
143 nub_process_t pid, DNBCallbackCopyExecutableImageInfos callback,
144 void *baton) DNB_EXPORT;
145 nub_addr_t DNBProcessLookupAddress(nub_process_t pid, const char *name,
146 const char *shlib) DNB_EXPORT;
147 nub_size_t DNBProcessGetAvailableSTDOUT(nub_process_t pid, char *buf,
148 nub_size_t buf_size) DNB_EXPORT;
149 nub_size_t DNBProcessGetAvailableSTDERR(nub_process_t pid, char *buf,
150 nub_size_t buf_size) DNB_EXPORT;
151 nub_size_t DNBProcessGetAvailableProfileData(nub_process_t pid, char *buf,
152 nub_size_t buf_size) DNB_EXPORT;
153 nub_size_t DNBProcessGetStopCount(nub_process_t pid) DNB_EXPORT;
154 uint32_t DNBProcessGetCPUType(nub_process_t pid) DNB_EXPORT;
155 size_t DNBGetAllInfos(std::vector<struct kinfo_proc> &proc_infos);
157 // Process executable and arguments
158 const char *DNBProcessGetExecutablePath(nub_process_t pid);
159 const char *DNBProcessGetArgumentAtIndex(nub_process_t pid, nub_size_t idx);
160 nub_size_t DNBProcessGetArgumentCount(nub_process_t pid);
162 // Process events
163 nub_event_t DNBProcessWaitForEvents(nub_process_t pid, nub_event_t event_mask,
164 bool wait_for_set,
165 struct timespec *timeout);
166 void DNBProcessResetEvents(nub_process_t pid, nub_event_t event_mask);
168 // Thread functions
169 const char *DNBThreadGetName(nub_process_t pid, nub_thread_t tid);
170 nub_bool_t
171 DNBThreadGetIdentifierInfo(nub_process_t pid, nub_thread_t tid,
172 thread_identifier_info_data_t *ident_info);
173 nub_state_t DNBThreadGetState(nub_process_t pid, nub_thread_t tid);
174 nub_bool_t DNBThreadGetRegisterValueByID(nub_process_t pid, nub_thread_t tid,
175 uint32_t set, uint32_t reg,
176 DNBRegisterValue *value);
177 nub_bool_t DNBThreadSetRegisterValueByID(nub_process_t pid, nub_thread_t tid,
178 uint32_t set, uint32_t reg,
179 const DNBRegisterValue *value);
180 nub_size_t DNBThreadGetRegisterContext(nub_process_t pid, nub_thread_t tid,
181 void *buf, size_t buf_len);
182 nub_size_t DNBThreadSetRegisterContext(nub_process_t pid, nub_thread_t tid,
183 const void *buf, size_t buf_len);
184 uint32_t DNBThreadSaveRegisterState(nub_process_t pid, nub_thread_t tid);
185 nub_bool_t DNBThreadRestoreRegisterState(nub_process_t pid, nub_thread_t tid,
186 uint32_t save_id);
187 nub_bool_t DNBThreadGetRegisterValueByName(nub_process_t pid, nub_thread_t tid,
188 uint32_t set, const char *name,
189 DNBRegisterValue *value);
190 nub_bool_t DNBThreadGetStopReason(nub_process_t pid, nub_thread_t tid,
191 DNBThreadStopInfo *stop_info);
192 const char *DNBThreadGetInfo(nub_process_t pid, nub_thread_t tid);
193 Genealogy::ThreadActivitySP DNBGetGenealogyInfoForThread(nub_process_t pid,
194 nub_thread_t tid,
195 bool &timed_out);
196 Genealogy::ProcessExecutableInfoSP DNBGetGenealogyImageInfo(nub_process_t pid,
197 size_t idx);
198 ThreadInfo::QoS DNBGetRequestedQoSForThread(nub_process_t pid, nub_thread_t tid,
199 nub_addr_t tsd,
200 uint64_t dti_qos_class_index);
201 nub_addr_t DNBGetPThreadT(nub_process_t pid, nub_thread_t tid);
202 nub_addr_t DNBGetDispatchQueueT(nub_process_t pid, nub_thread_t tid);
203 nub_addr_t
204 DNBGetTSDAddressForThread(nub_process_t pid, nub_thread_t tid,
205 uint64_t plo_pthread_tsd_base_address_offset,
206 uint64_t plo_pthread_tsd_base_offset,
207 uint64_t plo_pthread_tsd_entry_size);
208 JSONGenerator::ObjectSP DNBGetLoadedDynamicLibrariesInfos(
209 nub_process_t pid, nub_addr_t image_list_address, nub_addr_t image_count);
210 JSONGenerator::ObjectSP DNBGetAllLoadedLibrariesInfos(nub_process_t pid);
211 JSONGenerator::ObjectSP
212 DNBGetLibrariesInfoForAddresses(nub_process_t pid,
213 std::vector<uint64_t> &macho_addresses);
214 JSONGenerator::ObjectSP DNBGetSharedCacheInfo(nub_process_t pid);
217 // Breakpoint functions
218 nub_bool_t DNBBreakpointSet(nub_process_t pid, nub_addr_t addr, nub_size_t size,
219 nub_bool_t hardware);
220 nub_bool_t DNBBreakpointClear(nub_process_t pid, nub_addr_t addr);
222 // Watchpoint functions
223 nub_bool_t DNBWatchpointSet(nub_process_t pid, nub_addr_t addr, nub_size_t size,
224 uint32_t watch_flags, nub_bool_t hardware);
225 nub_bool_t DNBWatchpointClear(nub_process_t pid, nub_addr_t addr);
226 uint32_t DNBWatchpointGetNumSupportedHWP(nub_process_t pid);
228 uint32_t DNBGetRegisterCPUType();
229 const DNBRegisterSetInfo *DNBGetRegisterSetInfo(nub_size_t *num_reg_sets);
230 nub_bool_t DNBGetRegisterInfoByName(const char *reg_name,
231 DNBRegisterInfo *info);
233 // Other static nub information calls.
234 const char *DNBStateAsString(nub_state_t state);
235 nub_bool_t DNBResolveExecutablePath(const char *path, char *resolved_path,
236 size_t resolved_path_size);
237 bool DNBGetOSVersionNumbers(uint64_t *major, uint64_t *minor, uint64_t *patch);
238 /// \return the iOSSupportVersion of the host OS.
239 std::string DNBGetMacCatalystVersionString();
241 /// \return true if debugserver is running in translation
242 /// (is an x86_64 process on arm64)
243 bool DNBDebugserverIsTranslated();
244 #endif