1 //===-- DNB.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 // Created by Greg Clayton on 3/23/07. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef __DNB_h__ 15 #define __DNB_h__ 16 17 #include "MacOSX/Genealogy.h" 18 #include "MacOSX/ThreadInfo.h" 19 #include "DNBDefs.h" 20 #include <mach/thread_info.h> 21 #include <string> 22 23 #define DNB_EXPORT __attribute__((visibility("default"))) 24 25 #ifndef CPU_TYPE_ARM64 26 #define CPU_TYPE_ARM64 ((cpu_type_t) 12 | 0x01000000) 27 #endif 28 29 typedef bool (*DNBShouldCancelCallback) (void *); 30 31 void DNBInitialize (); 32 void DNBTerminate (); 33 34 nub_bool_t DNBSetArchitecture (const char *arch); 35 36 //---------------------------------------------------------------------- 37 // Process control 38 //---------------------------------------------------------------------- 39 nub_process_t DNBProcessLaunch (const char *path, 40 char const *argv[], 41 const char *envp[], 42 const char *working_directory, // NULL => dont' change, non-NULL => set working directory for inferior to this 43 const char *stdin_path, 44 const char *stdout_path, 45 const char *stderr_path, 46 bool no_stdio, 47 nub_launch_flavor_t launch_flavor, 48 int disable_aslr, 49 const char *event_data, 50 char *err_str, 51 size_t err_len); 52 53 nub_process_t DNBProcessAttach (nub_process_t pid, struct timespec *timeout, char *err_str, size_t err_len); 54 nub_process_t DNBProcessAttachByName (const char *name, struct timespec *timeout, char *err_str, size_t err_len); 55 nub_process_t DNBProcessAttachWait (const char *wait_name, nub_launch_flavor_t launch_flavor, bool ignore_existing, struct timespec *timeout, useconds_t interval, char *err_str, size_t err_len, DNBShouldCancelCallback should_cancel = NULL, void *callback_data = NULL); 56 // Resume a process with exact instructions on what to do with each thread: 57 // - If no thread actions are supplied (actions is NULL or num_actions is zero), 58 // then all threads are continued. 59 // - If any thread actions are supplied, then each thread will do as it is told 60 // by the action. A default actions for any threads that don't have an 61 // explicit thread action can be made by making a thread action with a tid of 62 // INVALID_NUB_THREAD. If there is no default action, those threads will 63 // remain stopped. 64 nub_bool_t DNBProcessResume (nub_process_t pid, const DNBThreadResumeAction *actions, size_t num_actions) DNB_EXPORT; 65 nub_bool_t DNBProcessHalt (nub_process_t pid) DNB_EXPORT; 66 nub_bool_t DNBProcessDetach (nub_process_t pid) DNB_EXPORT; 67 nub_bool_t DNBProcessSignal (nub_process_t pid, int signal) DNB_EXPORT; 68 nub_bool_t DNBProcessInterrupt (nub_process_t pid) DNB_EXPORT; 69 nub_bool_t DNBProcessKill (nub_process_t pid) DNB_EXPORT; 70 nub_bool_t DNBProcessSendEvent (nub_process_t pid, const char *event) DNB_EXPORT; 71 nub_size_t DNBProcessMemoryRead (nub_process_t pid, nub_addr_t addr, nub_size_t size, void *buf) DNB_EXPORT; 72 nub_size_t DNBProcessMemoryWrite (nub_process_t pid, nub_addr_t addr, nub_size_t size, const void *buf) DNB_EXPORT; 73 nub_addr_t DNBProcessMemoryAllocate (nub_process_t pid, nub_size_t size, uint32_t permissions) DNB_EXPORT; 74 nub_bool_t DNBProcessMemoryDeallocate (nub_process_t pid, nub_addr_t addr) DNB_EXPORT; 75 int DNBProcessMemoryRegionInfo (nub_process_t pid, nub_addr_t addr, DNBRegionInfo *region_info) DNB_EXPORT; 76 std::string DNBProcessGetProfileData (nub_process_t pid, DNBProfileDataScanType scanType) DNB_EXPORT; 77 nub_bool_t DNBProcessSetEnableAsyncProfiling (nub_process_t pid, nub_bool_t enable, uint64_t interval_usec, DNBProfileDataScanType scan_type) DNB_EXPORT; 78 79 //---------------------------------------------------------------------- 80 // Process status 81 //---------------------------------------------------------------------- 82 nub_bool_t DNBProcessIsAlive (nub_process_t pid) DNB_EXPORT; 83 nub_state_t DNBProcessGetState (nub_process_t pid) DNB_EXPORT; 84 nub_bool_t DNBProcessGetExitStatus (nub_process_t pid, int *status) DNB_EXPORT; 85 nub_bool_t DNBProcessSetExitStatus (nub_process_t pid, int status) DNB_EXPORT; 86 const char * DNBProcessGetExitInfo (nub_process_t pid) DNB_EXPORT; 87 nub_bool_t DNBProcessSetExitInfo (nub_process_t pid, const char *info) DNB_EXPORT; 88 nub_size_t DNBProcessGetNumThreads (nub_process_t pid) DNB_EXPORT; 89 nub_thread_t DNBProcessGetCurrentThread (nub_process_t pid) DNB_EXPORT; 90 nub_thread_t DNBProcessGetCurrentThreadMachPort (nub_process_t pid) DNB_EXPORT; 91 nub_thread_t DNBProcessSetCurrentThread (nub_process_t pid, nub_thread_t tid) DNB_EXPORT; 92 nub_thread_t DNBProcessGetThreadAtIndex (nub_process_t pid, nub_size_t thread_idx) DNB_EXPORT; 93 nub_bool_t DNBProcessSyncThreadState (nub_process_t pid, nub_thread_t tid) DNB_EXPORT; 94 nub_addr_t DNBProcessGetSharedLibraryInfoAddress (nub_process_t pid) DNB_EXPORT; 95 nub_bool_t DNBProcessSharedLibrariesUpdated (nub_process_t pid) DNB_EXPORT; 96 nub_size_t DNBProcessGetSharedLibraryInfo (nub_process_t pid, nub_bool_t only_changed, DNBExecutableImageInfo **image_infos) DNB_EXPORT; 97 nub_bool_t DNBProcessSetNameToAddressCallback (nub_process_t pid, DNBCallbackNameToAddress callback, void *baton) DNB_EXPORT; 98 nub_bool_t DNBProcessSetSharedLibraryInfoCallback (nub_process_t pid, DNBCallbackCopyExecutableImageInfos callback, void *baton) DNB_EXPORT; 99 nub_addr_t DNBProcessLookupAddress (nub_process_t pid, const char *name, const char *shlib) DNB_EXPORT; 100 nub_size_t DNBProcessGetAvailableSTDOUT (nub_process_t pid, char *buf, nub_size_t buf_size) DNB_EXPORT; 101 nub_size_t DNBProcessGetAvailableSTDERR (nub_process_t pid, char *buf, nub_size_t buf_size) DNB_EXPORT; 102 nub_size_t DNBProcessGetAvailableProfileData (nub_process_t pid, char *buf, nub_size_t buf_size) DNB_EXPORT; 103 nub_size_t DNBProcessGetStopCount (nub_process_t pid) DNB_EXPORT; 104 uint32_t DNBProcessGetCPUType (nub_process_t pid) DNB_EXPORT; 105 106 //---------------------------------------------------------------------- 107 // Process executable and arguments 108 //---------------------------------------------------------------------- 109 const char * DNBProcessGetExecutablePath (nub_process_t pid); 110 const char * DNBProcessGetArgumentAtIndex (nub_process_t pid, nub_size_t idx); 111 nub_size_t DNBProcessGetArgumentCount (nub_process_t pid); 112 113 //---------------------------------------------------------------------- 114 // Process events 115 //---------------------------------------------------------------------- 116 nub_event_t DNBProcessWaitForEvents (nub_process_t pid, nub_event_t event_mask, bool wait_for_set, struct timespec* timeout); 117 void DNBProcessResetEvents (nub_process_t pid, nub_event_t event_mask); 118 119 //---------------------------------------------------------------------- 120 // Thread functions 121 //---------------------------------------------------------------------- 122 const char * DNBThreadGetName (nub_process_t pid, nub_thread_t tid); 123 nub_bool_t DNBThreadGetIdentifierInfo (nub_process_t pid, nub_thread_t tid, thread_identifier_info_data_t *ident_info); 124 nub_state_t DNBThreadGetState (nub_process_t pid, nub_thread_t tid); 125 nub_bool_t DNBThreadGetRegisterValueByID (nub_process_t pid, nub_thread_t tid, uint32_t set, uint32_t reg, DNBRegisterValue *value); 126 nub_bool_t DNBThreadSetRegisterValueByID (nub_process_t pid, nub_thread_t tid, uint32_t set, uint32_t reg, const DNBRegisterValue *value); 127 nub_size_t DNBThreadGetRegisterContext (nub_process_t pid, nub_thread_t tid, void *buf, size_t buf_len); 128 nub_size_t DNBThreadSetRegisterContext (nub_process_t pid, nub_thread_t tid, const void *buf, size_t buf_len); 129 uint32_t DNBThreadSaveRegisterState (nub_process_t pid, nub_thread_t tid); 130 nub_bool_t DNBThreadRestoreRegisterState (nub_process_t pid, nub_thread_t tid, uint32_t save_id); 131 nub_bool_t DNBThreadGetRegisterValueByName (nub_process_t pid, nub_thread_t tid, uint32_t set, const char *name, DNBRegisterValue *value); 132 nub_bool_t DNBThreadGetStopReason (nub_process_t pid, nub_thread_t tid, DNBThreadStopInfo *stop_info); 133 const char * DNBThreadGetInfo (nub_process_t pid, nub_thread_t tid); 134 Genealogy::ThreadActivitySP DNBGetGenealogyInfoForThread (nub_process_t pid, nub_thread_t tid, bool &timed_out); 135 Genealogy::ProcessExecutableInfoSP DNBGetGenealogyImageInfo (nub_process_t pid, size_t idx); 136 ThreadInfo::QoS DNBGetRequestedQoSForThread (nub_process_t pid, nub_thread_t tid, nub_addr_t tsd, uint64_t dti_qos_class_index); 137 nub_addr_t DNBGetPThreadT (nub_process_t pid, nub_thread_t tid); 138 nub_addr_t DNBGetDispatchQueueT (nub_process_t pid, nub_thread_t tid); 139 nub_addr_t DNBGetTSDAddressForThread (nub_process_t pid, nub_thread_t tid, uint64_t plo_pthread_tsd_base_address_offset, uint64_t plo_pthread_tsd_base_offset, uint64_t plo_pthread_tsd_entry_size); 140 // 141 //---------------------------------------------------------------------- 142 // Breakpoint functions 143 //---------------------------------------------------------------------- 144 nub_bool_t DNBBreakpointSet (nub_process_t pid, nub_addr_t addr, nub_size_t size, nub_bool_t hardware); 145 nub_bool_t DNBBreakpointClear (nub_process_t pid, nub_addr_t addr); 146 147 //---------------------------------------------------------------------- 148 // Watchpoint functions 149 //---------------------------------------------------------------------- 150 nub_bool_t DNBWatchpointSet (nub_process_t pid, nub_addr_t addr, nub_size_t size, uint32_t watch_flags, nub_bool_t hardware); 151 nub_bool_t DNBWatchpointClear (nub_process_t pid, nub_addr_t addr); 152 uint32_t DNBWatchpointGetNumSupportedHWP (nub_process_t pid); 153 154 const DNBRegisterSetInfo * 155 DNBGetRegisterSetInfo (nub_size_t *num_reg_sets); 156 nub_bool_t DNBGetRegisterInfoByName (const char *reg_name, DNBRegisterInfo* info); 157 158 //---------------------------------------------------------------------- 159 // Printf style formatting for printing values in the inferior memory 160 // space and registers. 161 //---------------------------------------------------------------------- 162 nub_size_t DNBPrintf (nub_process_t pid, nub_thread_t tid, nub_addr_t addr, FILE *file, const char *format); 163 164 //---------------------------------------------------------------------- 165 // Other static nub information calls. 166 //---------------------------------------------------------------------- 167 const char * DNBStateAsString (nub_state_t state); 168 nub_bool_t DNBResolveExecutablePath (const char *path, char *resolved_path, size_t resolved_path_size); 169 170 #endif 171