1 //===-- DNBDefs.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 6/26/07. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef __DNBDefs_h__ 15 #define __DNBDefs_h__ 16 17 #include <signal.h> 18 #include <stdint.h> 19 #include <stdio.h> 20 #include <sys/syslimits.h> 21 #include <unistd.h> 22 23 //---------------------------------------------------------------------- 24 // Define nub_addr_t and the invalid address value from the architecture 25 //---------------------------------------------------------------------- 26 #if defined(__x86_64__) || defined(__ppc64__) || defined(__arm64__) || \ 27 defined(__aarch64__) 28 29 //---------------------------------------------------------------------- 30 // 64 bit address architectures 31 //---------------------------------------------------------------------- 32 typedef uint64_t nub_addr_t; 33 #define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull) 34 35 #elif defined(__i386__) || defined(__powerpc__) || defined(__ppc__) || \ 36 defined(__arm__) 37 38 //---------------------------------------------------------------------- 39 // 32 bit address architectures 40 //---------------------------------------------------------------------- 41 42 typedef uint32_t nub_addr_t; 43 #define INVALID_NUB_ADDRESS ((nub_addr_t)~0ul) 44 45 #else 46 47 //---------------------------------------------------------------------- 48 // Default to 64 bit address for unrecognized architectures. 49 //---------------------------------------------------------------------- 50 51 #warning undefined architecture, defaulting to 8 byte addresses 52 typedef uint64_t nub_addr_t; 53 #define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull) 54 55 #endif 56 57 typedef size_t nub_size_t; 58 typedef ssize_t nub_ssize_t; 59 typedef uint32_t nub_index_t; 60 typedef pid_t nub_process_t; 61 typedef uint64_t nub_thread_t; 62 typedef uint32_t nub_event_t; 63 typedef uint32_t nub_bool_t; 64 65 #define INVALID_NUB_PROCESS ((nub_process_t)0) 66 #define INVALID_NUB_THREAD ((nub_thread_t)0) 67 #define INVALID_NUB_WATCH_ID ((nub_watch_t)0) 68 #define INVALID_NUB_HW_INDEX UINT32_MAX 69 #define INVALID_NUB_REGNUM UINT32_MAX 70 #define NUB_GENERIC_ERROR UINT32_MAX 71 72 // Watchpoint types 73 #define WATCH_TYPE_READ (1u << 0) 74 #define WATCH_TYPE_WRITE (1u << 1) 75 76 typedef enum { 77 eStateInvalid = 0, 78 eStateUnloaded, 79 eStateAttaching, 80 eStateLaunching, 81 eStateStopped, 82 eStateRunning, 83 eStateStepping, 84 eStateCrashed, 85 eStateDetached, 86 eStateExited, 87 eStateSuspended 88 } nub_state_t; 89 90 typedef enum { 91 eLaunchFlavorDefault = 0, 92 eLaunchFlavorPosixSpawn = 1, 93 eLaunchFlavorForkExec = 2, 94 #ifdef WITH_SPRINGBOARD 95 eLaunchFlavorSpringBoard = 3, 96 #endif 97 #ifdef WITH_BKS 98 eLaunchFlavorBKS = 4, 99 #endif 100 #ifdef WITH_FBS 101 eLaunchFlavorFBS = 5 102 #endif 103 } nub_launch_flavor_t; 104 105 #define NUB_STATE_IS_RUNNING(s) \ 106 ((s) == eStateAttaching || (s) == eStateLaunching || (s) == eStateRunning || \ 107 (s) == eStateStepping || (s) == eStateDetached) 108 109 #define NUB_STATE_IS_STOPPED(s) \ 110 ((s) == eStateUnloaded || (s) == eStateStopped || (s) == eStateCrashed || \ 111 (s) == eStateExited) 112 113 enum { 114 eEventProcessRunningStateChanged = 115 1 << 0, // The process has changed state to running 116 eEventProcessStoppedStateChanged = 117 1 << 1, // The process has changed state to stopped 118 eEventSharedLibsStateChange = 119 1 << 2, // Shared libraries loaded/unloaded state has changed 120 eEventStdioAvailable = 1 << 3, // Something is available on stdout/stderr 121 eEventProfileDataAvailable = 1 << 4, // Profile data ready for retrieval 122 kAllEventsMask = eEventProcessRunningStateChanged | 123 eEventProcessStoppedStateChanged | 124 eEventSharedLibsStateChange | eEventStdioAvailable | 125 eEventProfileDataAvailable 126 }; 127 128 #define LOG_VERBOSE (1u << 0) 129 #define LOG_PROCESS (1u << 1) 130 #define LOG_THREAD (1u << 2) 131 #define LOG_EXCEPTIONS (1u << 3) 132 #define LOG_SHLIB (1u << 4) 133 #define LOG_MEMORY (1u << 5) // Log memory reads/writes calls 134 #define LOG_MEMORY_DATA_SHORT (1u << 6) // Log short memory reads/writes bytes 135 #define LOG_MEMORY_DATA_LONG (1u << 7) // Log all memory reads/writes bytes 136 #define LOG_MEMORY_PROTECTIONS (1u << 8) // Log memory protection changes 137 #define LOG_BREAKPOINTS (1u << 9) 138 #define LOG_EVENTS (1u << 10) 139 #define LOG_WATCHPOINTS (1u << 11) 140 #define LOG_STEP (1u << 12) 141 #define LOG_TASK (1u << 13) 142 #define LOG_DARWIN_LOG (1u << 14) 143 #define LOG_LO_USER (1u << 16) 144 #define LOG_HI_USER (1u << 31) 145 #define LOG_ALL 0xFFFFFFFFu 146 #define LOG_DEFAULT \ 147 ((LOG_PROCESS) | (LOG_TASK) | (LOG_THREAD) | (LOG_EXCEPTIONS) | \ 148 (LOG_SHLIB) | (LOG_MEMORY) | (LOG_BREAKPOINTS) | (LOG_WATCHPOINTS) | \ 149 (LOG_STEP)) 150 151 #define REGISTER_SET_ALL 0 152 // Generic Register set to be defined by each architecture for access to common 153 // register values. 154 #define REGISTER_SET_GENERIC ((uint32_t)0xFFFFFFFFu) 155 #define GENERIC_REGNUM_PC 0 // Program Counter 156 #define GENERIC_REGNUM_SP 1 // Stack Pointer 157 #define GENERIC_REGNUM_FP 2 // Frame Pointer 158 #define GENERIC_REGNUM_RA 3 // Return Address 159 #define GENERIC_REGNUM_FLAGS 4 // Processor flags register 160 #define GENERIC_REGNUM_ARG1 \ 161 5 // The register that would contain pointer size or less argument 1 (if any) 162 #define GENERIC_REGNUM_ARG2 \ 163 6 // The register that would contain pointer size or less argument 2 (if any) 164 #define GENERIC_REGNUM_ARG3 \ 165 7 // The register that would contain pointer size or less argument 3 (if any) 166 #define GENERIC_REGNUM_ARG4 \ 167 8 // The register that would contain pointer size or less argument 4 (if any) 168 #define GENERIC_REGNUM_ARG5 \ 169 9 // The register that would contain pointer size or less argument 5 (if any) 170 #define GENERIC_REGNUM_ARG6 \ 171 10 // The register that would contain pointer size or less argument 6 (if any) 172 #define GENERIC_REGNUM_ARG7 \ 173 11 // The register that would contain pointer size or less argument 7 (if any) 174 #define GENERIC_REGNUM_ARG8 \ 175 12 // The register that would contain pointer size or less argument 8 (if any) 176 177 enum DNBRegisterType { 178 InvalidRegType = 0, 179 Uint, // unsigned integer 180 Sint, // signed integer 181 IEEE754, // float 182 Vector // vector registers 183 }; 184 185 enum DNBRegisterFormat { 186 InvalidRegFormat = 0, 187 Binary, 188 Decimal, 189 Hex, 190 Float, 191 VectorOfSInt8, 192 VectorOfUInt8, 193 VectorOfSInt16, 194 VectorOfUInt16, 195 VectorOfSInt32, 196 VectorOfUInt32, 197 VectorOfFloat32, 198 VectorOfUInt128 199 }; 200 201 struct DNBRegisterInfo { 202 uint32_t set; // Register set 203 uint32_t reg; // Register number 204 const char *name; // Name of this register 205 const char *alt; // Alternate name 206 uint16_t type; // Type of the register bits (DNBRegisterType) 207 uint16_t format; // Default format for display (DNBRegisterFormat), 208 uint32_t size; // Size in bytes of the register 209 uint32_t offset; // Offset from the beginning of the register context 210 uint32_t 211 reg_ehframe; // eh_frame register number (INVALID_NUB_REGNUM when none) 212 uint32_t reg_dwarf; // DWARF register number (INVALID_NUB_REGNUM when none) 213 uint32_t 214 reg_generic; // Generic register number (INVALID_NUB_REGNUM when none) 215 uint32_t reg_debugserver; // The debugserver register number we'll use over 216 // gdb-remote protocol (INVALID_NUB_REGNUM when 217 // none) 218 const char **value_regs; // If this register is a part of other registers, 219 // list the register names terminated by NULL 220 const char **update_regs; // If modifying this register will invalidate other 221 // registers, list the register names terminated by 222 // NULL 223 }; 224 225 struct DNBRegisterSetInfo { 226 const char *name; // Name of this register set 227 const struct DNBRegisterInfo *registers; // An array of register descriptions 228 nub_size_t num_registers; // The number of registers in REGISTERS array above 229 }; 230 231 struct DNBThreadResumeAction { 232 nub_thread_t tid; // The thread ID that this action applies to, 233 // INVALID_NUB_THREAD for the default thread action 234 nub_state_t state; // Valid values are eStateStopped/eStateSuspended, 235 // eStateRunning, and eStateStepping. 236 int signal; // When resuming this thread, resume it with this signal 237 nub_addr_t addr; // If not INVALID_NUB_ADDRESS, then set the PC for the thread 238 // to ADDR before resuming/stepping 239 }; 240 241 enum DNBThreadStopType { 242 eStopTypeInvalid = 0, 243 eStopTypeSignal, 244 eStopTypeException, 245 eStopTypeExec 246 }; 247 248 enum DNBMemoryPermissions { 249 eMemoryPermissionsWritable = (1 << 0), 250 eMemoryPermissionsReadable = (1 << 1), 251 eMemoryPermissionsExecutable = (1 << 2) 252 }; 253 254 #define DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH 256 255 #define DNB_THREAD_STOP_INFO_MAX_EXC_DATA 8 256 257 //---------------------------------------------------------------------- 258 // DNBThreadStopInfo 259 // 260 // Describes the reason a thread stopped. 261 //---------------------------------------------------------------------- 262 struct DNBThreadStopInfo { 263 DNBThreadStopType reason; 264 char description[DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH]; 265 union { 266 // eStopTypeSignal 267 struct { 268 uint32_t signo; 269 } signal; 270 271 // eStopTypeException 272 struct { 273 uint32_t type; 274 nub_size_t data_count; 275 nub_addr_t data[DNB_THREAD_STOP_INFO_MAX_EXC_DATA]; 276 } exception; 277 } details; 278 }; 279 280 struct DNBRegisterValue { 281 struct DNBRegisterInfo info; // Register information for this register 282 union { 283 int8_t sint8; 284 int16_t sint16; 285 int32_t sint32; 286 int64_t sint64; 287 uint8_t uint8; 288 uint16_t uint16; 289 uint32_t uint32; 290 uint64_t uint64; 291 float float32; 292 double float64; 293 int8_t v_sint8[32]; 294 int16_t v_sint16[16]; 295 int32_t v_sint32[8]; 296 int64_t v_sint64[4]; 297 uint8_t v_uint8[32]; 298 uint16_t v_uint16[16]; 299 uint32_t v_uint32[8]; 300 uint64_t v_uint64[4]; 301 float v_float32[8]; 302 double v_float64[4]; 303 void *pointer; 304 char *c_str; 305 } value; 306 }; 307 308 enum DNBSharedLibraryState { eShlibStateUnloaded = 0, eShlibStateLoaded = 1 }; 309 310 #ifndef DNB_MAX_SEGMENT_NAME_LENGTH 311 #define DNB_MAX_SEGMENT_NAME_LENGTH 32 312 #endif 313 314 struct DNBSegment { 315 char name[DNB_MAX_SEGMENT_NAME_LENGTH]; 316 nub_addr_t addr; 317 nub_addr_t size; 318 }; 319 320 struct DNBExecutableImageInfo { 321 char name[PATH_MAX]; // Name of the executable image (usually a full path) 322 uint32_t 323 state; // State of the executable image (see enum DNBSharedLibraryState) 324 nub_addr_t header_addr; // Executable header address 325 uuid_t uuid; // Unique identifier for matching with symbols 326 uint32_t 327 num_segments; // Number of contiguous memory segments to in SEGMENTS array 328 DNBSegment *segments; // Array of contiguous memory segments in executable 329 }; 330 331 struct DNBRegionInfo { 332 nub_addr_t addr; 333 nub_addr_t size; 334 uint32_t permissions; 335 }; 336 337 enum DNBProfileDataScanType { 338 eProfileHostCPU = (1 << 0), 339 eProfileCPU = (1 << 1), 340 341 eProfileThreadsCPU = 342 (1 << 2), // By default excludes eProfileThreadName and eProfileQueueName. 343 eProfileThreadName = 344 (1 << 3), // Assume eProfileThreadsCPU, get thread name as well. 345 eProfileQueueName = 346 (1 << 4), // Assume eProfileThreadsCPU, get queue name as well. 347 348 eProfileHostMemory = (1 << 5), 349 350 eProfileMemory = (1 << 6), // By default, excludes eProfileMemoryDirtyPage. 351 eProfileMemoryDirtyPage = 352 (1 << 7), // Assume eProfileMemory, get Dirty Page size as well. 353 eProfileMemoryAnonymous = 354 (1 << 8), // Assume eProfileMemory, get Anonymous memory as well. 355 356 eProfileEnergy = (1 << 9), 357 358 eProfileAll = 0xffffffff 359 }; 360 361 typedef nub_addr_t (*DNBCallbackNameToAddress)(nub_process_t pid, 362 const char *name, 363 const char *shlib_regex, 364 void *baton); 365 typedef nub_size_t (*DNBCallbackCopyExecutableImageInfos)( 366 nub_process_t pid, struct DNBExecutableImageInfo **image_infos, 367 nub_bool_t only_changed, void *baton); 368 typedef void (*DNBCallbackLog)(void *baton, uint32_t flags, const char *format, 369 va_list args); 370 371 #define UNUSED_IF_ASSERT_DISABLED(x) ((void)(x)) 372 373 #endif // #ifndef __DNBDefs_h__ 374