261 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// Created by Greg Clayton on 3/23/07.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNB_H14#define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNB_H15 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 <optional>25#include <string>26 27#define DNB_EXPORT __attribute__((visibility("default")))28 29#ifndef CPU_TYPE_ARM6430#define CPU_TYPE_ARM64 ((cpu_type_t)12 | 0x01000000)31#endif32 33#ifndef CPU_TYPE_ARM64_3234#define CPU_TYPE_ARM64_32 ((cpu_type_t)12 | 0x02000000)35#endif36 37typedef bool (*DNBShouldCancelCallback)(void *);38 39void DNBInitialize();40void DNBTerminate();41 42nub_bool_t DNBSetArchitecture(const char *arch);43 44// Process control45nub_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 => set48 // working directory for inferior to this49 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 53nub_process_t DNBProcessGetPIDByName(const char *name);54nub_process_t DNBProcessAttach(nub_process_t pid, struct timespec *timeout,55 const RNBContext::IgnoredExceptions 56 &ignored_exceptions, 57 char *err_str,58 size_t err_len);59nub_process_t DNBProcessAttachByName(const char *name, struct timespec *timeout,60 const RNBContext::IgnoredExceptions 61 &ignored_exceptions, 62 char *err_str,63 size_t err_len);64nub_process_t DNBProcessAttachWait(RNBContext *ctx, const char *wait_name,65 bool ignore_existing,66 struct timespec *timeout,67 useconds_t interval, char *err_str,68 size_t err_len,69 DNBShouldCancelCallback should_cancel = NULL,70 void *callback_data = NULL);71// Resume a process with exact instructions on what to do with each thread:72// - If no thread actions are supplied (actions is NULL or num_actions is zero),73// then all threads are continued.74// - If any thread actions are supplied, then each thread will do as it is told75// by the action. A default actions for any threads that don't have an76// explicit thread action can be made by making a thread action with a tid of77// INVALID_NUB_THREAD. If there is no default action, those threads will78// remain stopped.79nub_bool_t DNBProcessResume(nub_process_t pid,80 const DNBThreadResumeAction *actions,81 size_t num_actions) DNB_EXPORT;82nub_bool_t DNBProcessHalt(nub_process_t pid) DNB_EXPORT;83nub_bool_t DNBProcessDetach(nub_process_t pid) DNB_EXPORT;84nub_bool_t DNBProcessSignal(nub_process_t pid, int signal) DNB_EXPORT;85nub_bool_t DNBProcessInterrupt(nub_process_t pid) DNB_EXPORT;86nub_bool_t DNBProcessKill(nub_process_t pid) DNB_EXPORT;87nub_bool_t DNBProcessSendEvent(nub_process_t pid, const char *event) DNB_EXPORT;88nub_size_t DNBProcessMemoryRead(nub_process_t pid, nub_addr_t addr,89 nub_size_t size, void *buf) DNB_EXPORT;90uint64_t DNBProcessMemoryReadInteger(nub_process_t pid, nub_addr_t addr,91 nub_size_t integer_size,92 uint64_t fail_value) DNB_EXPORT;93nub_addr_t DNBProcessMemoryReadPointer(nub_process_t pid,94 nub_addr_t addr) DNB_EXPORT;95std::string DNBProcessMemoryReadCString(nub_process_t pid,96 nub_addr_t addr) DNB_EXPORT;97std::string98DNBProcessMemoryReadCStringFixed(nub_process_t pid, nub_addr_t addr,99 nub_size_t fixed_length) DNB_EXPORT;100nub_size_t DNBProcessMemoryWrite(nub_process_t pid, nub_addr_t addr,101 nub_size_t size, const void *buf) DNB_EXPORT;102nub_addr_t DNBProcessMemoryAllocate(nub_process_t pid, nub_size_t size,103 uint32_t permissions) DNB_EXPORT;104nub_bool_t DNBProcessMemoryDeallocate(nub_process_t pid,105 nub_addr_t addr) DNB_EXPORT;106int DNBProcessMemoryRegionInfo(nub_process_t pid, nub_addr_t addr,107 DNBRegionInfo *region_info) DNB_EXPORT;108nub_bool_t DNBProcessGetMemoryTags(nub_process_t pid, nub_addr_t addr,109 nub_size_t size,110 std::vector<uint8_t> &tags) DNB_EXPORT;111std::string112DNBProcessGetProfileData(nub_process_t pid,113 DNBProfileDataScanType scanType) DNB_EXPORT;114nub_bool_t115DNBProcessSetEnableAsyncProfiling(nub_process_t pid, nub_bool_t enable,116 uint64_t interval_usec,117 DNBProfileDataScanType scan_type) DNB_EXPORT;118 119// Process status120nub_bool_t DNBProcessIsAlive(nub_process_t pid) DNB_EXPORT;121nub_state_t DNBProcessGetState(nub_process_t pid) DNB_EXPORT;122nub_bool_t DNBProcessGetExitStatus(nub_process_t pid, int *status) DNB_EXPORT;123nub_bool_t DNBProcessSetExitStatus(nub_process_t pid, int status) DNB_EXPORT;124const char *DNBProcessGetExitInfo(nub_process_t pid) DNB_EXPORT;125nub_bool_t DNBProcessSetExitInfo(nub_process_t pid,126 const char *info) DNB_EXPORT;127nub_size_t DNBProcessGetNumThreads(nub_process_t pid) DNB_EXPORT;128nub_thread_t DNBProcessGetCurrentThread(nub_process_t pid) DNB_EXPORT;129nub_thread_t DNBProcessGetCurrentThreadMachPort(nub_process_t pid) DNB_EXPORT;130nub_thread_t DNBProcessSetCurrentThread(nub_process_t pid,131 nub_thread_t tid) DNB_EXPORT;132nub_thread_t DNBProcessGetThreadAtIndex(nub_process_t pid,133 nub_size_t thread_idx) DNB_EXPORT;134nub_bool_t DNBProcessSyncThreadState(nub_process_t pid,135 nub_thread_t tid) DNB_EXPORT;136nub_addr_t DNBProcessGetSharedLibraryInfoAddress(nub_process_t pid) DNB_EXPORT;137nub_bool_t DNBProcessSharedLibrariesUpdated(nub_process_t pid) DNB_EXPORT;138nub_size_t139DNBProcessGetSharedLibraryInfo(nub_process_t pid, nub_bool_t only_changed,140 DNBExecutableImageInfo **image_infos) DNB_EXPORT;141std::optional<std::string>142DNBGetDeploymentInfo(nub_process_t pid, bool is_executable,143 const struct load_command &lc,144 uint64_t load_command_address, uint32_t &major_version,145 uint32_t &minor_version, uint32_t &patch_version);146nub_bool_t DNBProcessSetNameToAddressCallback(nub_process_t pid,147 DNBCallbackNameToAddress callback,148 void *baton) DNB_EXPORT;149nub_bool_t DNBProcessSetSharedLibraryInfoCallback(150 nub_process_t pid, DNBCallbackCopyExecutableImageInfos callback,151 void *baton) DNB_EXPORT;152nub_addr_t DNBProcessLookupAddress(nub_process_t pid, const char *name,153 const char *shlib) DNB_EXPORT;154nub_size_t DNBProcessGetAvailableSTDOUT(nub_process_t pid, char *buf,155 nub_size_t buf_size) DNB_EXPORT;156nub_size_t DNBProcessGetAvailableSTDERR(nub_process_t pid, char *buf,157 nub_size_t buf_size) DNB_EXPORT;158nub_size_t DNBProcessGetAvailableProfileData(nub_process_t pid, char *buf,159 nub_size_t buf_size) DNB_EXPORT;160nub_size_t DNBProcessGetStopCount(nub_process_t pid) DNB_EXPORT;161uint32_t DNBProcessGetCPUType(nub_process_t pid) DNB_EXPORT;162size_t DNBGetAllInfos(std::vector<struct kinfo_proc> &proc_infos);163JSONGenerator::ObjectSP DNBGetDyldProcessState(nub_process_t pid);164 165// Process executable and arguments166const char *DNBProcessGetExecutablePath(nub_process_t pid);167const char *DNBProcessGetArgumentAtIndex(nub_process_t pid, nub_size_t idx);168nub_size_t DNBProcessGetArgumentCount(nub_process_t pid);169 170// Process events171nub_event_t DNBProcessWaitForEvents(nub_process_t pid, nub_event_t event_mask,172 bool wait_for_set,173 struct timespec *timeout);174void DNBProcessResetEvents(nub_process_t pid, nub_event_t event_mask);175 176// Thread functions177const char *DNBThreadGetName(nub_process_t pid, nub_thread_t tid);178nub_bool_t179DNBThreadGetIdentifierInfo(nub_process_t pid, nub_thread_t tid,180 thread_identifier_info_data_t *ident_info);181nub_state_t DNBThreadGetState(nub_process_t pid, nub_thread_t tid);182nub_bool_t DNBThreadGetRegisterValueByID(nub_process_t pid, nub_thread_t tid,183 uint32_t set, uint32_t reg,184 DNBRegisterValue *value);185nub_bool_t DNBThreadSetRegisterValueByID(nub_process_t pid, nub_thread_t tid,186 uint32_t set, uint32_t reg,187 const DNBRegisterValue *value);188nub_size_t DNBThreadGetRegisterContext(nub_process_t pid, nub_thread_t tid,189 void *buf, size_t buf_len);190nub_size_t DNBThreadSetRegisterContext(nub_process_t pid, nub_thread_t tid,191 const void *buf, size_t buf_len);192uint32_t DNBThreadSaveRegisterState(nub_process_t pid, nub_thread_t tid);193nub_bool_t DNBThreadRestoreRegisterState(nub_process_t pid, nub_thread_t tid,194 uint32_t save_id);195nub_bool_t DNBThreadGetRegisterValueByName(nub_process_t pid, nub_thread_t tid,196 uint32_t set, const char *name,197 DNBRegisterValue *value);198nub_bool_t DNBThreadGetStopReason(nub_process_t pid, nub_thread_t tid,199 DNBThreadStopInfo *stop_info);200const char *DNBThreadGetInfo(nub_process_t pid, nub_thread_t tid);201Genealogy::ThreadActivitySP DNBGetGenealogyInfoForThread(nub_process_t pid,202 nub_thread_t tid,203 bool &timed_out);204Genealogy::ProcessExecutableInfoSP DNBGetGenealogyImageInfo(nub_process_t pid,205 size_t idx);206ThreadInfo::QoS DNBGetRequestedQoSForThread(nub_process_t pid, nub_thread_t tid,207 nub_addr_t tsd,208 uint64_t dti_qos_class_index);209nub_addr_t DNBGetPThreadT(nub_process_t pid, nub_thread_t tid);210nub_addr_t DNBGetDispatchQueueT(nub_process_t pid, nub_thread_t tid);211nub_addr_t212DNBGetTSDAddressForThread(nub_process_t pid, nub_thread_t tid,213 uint64_t plo_pthread_tsd_base_address_offset,214 uint64_t plo_pthread_tsd_base_offset,215 uint64_t plo_pthread_tsd_entry_size);216std::optional<std::pair<cpu_type_t, cpu_subtype_t>>217DNBGetMainBinaryCPUTypes(nub_process_t pid);218JSONGenerator::ObjectSP219DNBGetAllLoadedLibrariesInfos(nub_process_t pid, bool report_load_commands);220JSONGenerator::ObjectSP221DNBGetLibrariesInfoForAddresses(nub_process_t pid,222 std::vector<uint64_t> &macho_addresses);223JSONGenerator::ObjectSP DNBGetSharedCacheInfo(nub_process_t pid);224 225//226// Breakpoint functions227nub_bool_t DNBBreakpointSet(nub_process_t pid, nub_addr_t addr, nub_size_t size,228 nub_bool_t hardware);229nub_bool_t DNBBreakpointClear(nub_process_t pid, nub_addr_t addr);230 231// Watchpoint functions232nub_bool_t DNBWatchpointSet(nub_process_t pid, nub_addr_t addr, nub_size_t size,233 uint32_t watch_flags, nub_bool_t hardware);234nub_bool_t DNBWatchpointClear(nub_process_t pid, nub_addr_t addr);235uint32_t DNBWatchpointGetNumSupportedHWP(nub_process_t pid);236 237uint32_t DNBGetRegisterCPUType();238const DNBRegisterSetInfo *DNBGetRegisterSetInfo(nub_size_t *num_reg_sets);239nub_bool_t DNBGetRegisterInfoByName(const char *reg_name,240 DNBRegisterInfo *info);241 242// Other static nub information calls.243const char *DNBStateAsString(nub_state_t state);244nub_bool_t DNBResolveExecutablePath(const char *path, char *resolved_path,245 size_t resolved_path_size);246bool DNBGetOSVersionNumbers(uint64_t *major, uint64_t *minor, uint64_t *patch);247/// \return the iOSSupportVersion of the host OS.248std::string DNBGetMacCatalystVersionString();249 250/// \return true if debugserver is running in translation251/// (is an x86_64 process on arm64)252bool DNBDebugserverIsTranslated();253 254bool DNBGetAddressingBits(uint32_t &addressing_bits);255 256nub_process_t DNBGetParentProcessID(nub_process_t child_pid);257 258bool DNBProcessIsBeingDebugged(nub_process_t pid);259 260#endif261