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