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