Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame^] | 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 <stdint.h> |
| 18 | #include <signal.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__) |
| 27 | |
| 28 | //---------------------------------------------------------------------- |
| 29 | // 64 bit address architectures |
| 30 | //---------------------------------------------------------------------- |
| 31 | typedef uint64_t nub_addr_t; |
| 32 | #define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull) |
| 33 | |
| 34 | #elif defined (__i386__) || defined (__powerpc__) || defined (__ppc__) || defined (__arm__) |
| 35 | |
| 36 | //---------------------------------------------------------------------- |
| 37 | // 32 bit address architectures |
| 38 | //---------------------------------------------------------------------- |
| 39 | |
| 40 | typedef uint32_t nub_addr_t; |
| 41 | #define INVALID_NUB_ADDRESS ((nub_addr_t)~0ul) |
| 42 | |
| 43 | #else |
| 44 | |
| 45 | //---------------------------------------------------------------------- |
| 46 | // Default to 64 bit address for unrecognized architectures. |
| 47 | //---------------------------------------------------------------------- |
| 48 | |
| 49 | #warning undefined architecture, defaulting to 8 byte addresses |
| 50 | typedef uint64_t nub_addr_t; |
| 51 | #define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull) |
| 52 | |
| 53 | |
| 54 | #endif |
| 55 | |
| 56 | typedef size_t nub_size_t; |
| 57 | typedef ssize_t nub_ssize_t; |
| 58 | typedef uint32_t nub_break_t; |
| 59 | typedef uint32_t nub_watch_t; |
| 60 | typedef uint32_t nub_index_t; |
| 61 | typedef pid_t nub_process_t; |
| 62 | typedef unsigned int nub_thread_t; |
| 63 | typedef uint32_t nub_event_t; |
| 64 | typedef uint32_t nub_bool_t; |
| 65 | |
| 66 | #define INVALID_NUB_BREAK_ID ((nub_break_t)0) |
| 67 | #define INVALID_NUB_PROCESS ((nub_process_t)0) |
| 68 | #define INVALID_NUB_THREAD ((nub_thread_t)0) |
| 69 | #define INVALID_NUB_HW_INDEX UINT32_MAX |
| 70 | #define INVALID_NUB_REGNUM UINT32_MAX |
| 71 | #define NUB_GENERIC_ERROR UINT32_MAX |
| 72 | |
| 73 | #define NUB_BREAK_ID_IS_VALID(breakID) ((breakID) != (INVALID_NUB_BREAK_ID)) |
| 74 | |
| 75 | // Watchpoint types |
| 76 | #define WATCH_TYPE_READ (1u << 0) |
| 77 | #define WATCH_TYPE_WRITE (1u << 1) |
| 78 | |
| 79 | typedef enum |
| 80 | { |
| 81 | eStateInvalid = 0, |
| 82 | eStateUnloaded, |
| 83 | eStateAttaching, |
| 84 | eStateLaunching, |
| 85 | eStateStopped, |
| 86 | eStateRunning, |
| 87 | eStateStepping, |
| 88 | eStateCrashed, |
| 89 | eStateDetached, |
| 90 | eStateExited, |
| 91 | eStateSuspended |
| 92 | } nub_state_t; |
| 93 | |
| 94 | typedef enum |
| 95 | { |
| 96 | eLaunchFlavorDefault = 0, |
| 97 | eLaunchFlavorPosixSpawn, |
| 98 | eLaunchFlavorForkExec, |
| 99 | #if defined (__arm__) |
| 100 | eLaunchFlavorSpringBoard, |
| 101 | #endif |
| 102 | } nub_launch_flavor_t; |
| 103 | |
| 104 | #define NUB_STATE_IS_RUNNING(s) ((s) == eStateAttaching ||\ |
| 105 | (s) == eStateLaunching ||\ |
| 106 | (s) == eStateRunning ||\ |
| 107 | (s) == eStateStepping ||\ |
| 108 | (s) == eStateDetached) |
| 109 | |
| 110 | #define NUB_STATE_IS_STOPPED(s) ((s) == eStateUnloaded ||\ |
| 111 | (s) == eStateStopped ||\ |
| 112 | (s) == eStateCrashed ||\ |
| 113 | (s) == eStateExited) |
| 114 | |
| 115 | enum |
| 116 | { |
| 117 | eEventProcessRunningStateChanged = 1 << 0, // The process has changed state to running |
| 118 | eEventProcessStoppedStateChanged = 1 << 1, // The process has changed state to stopped |
| 119 | eEventSharedLibsStateChange = 1 << 2, // Shared libraries loaded/unloaded state has changed |
| 120 | eEventStdioAvailable = 1 << 3, // Something is available on stdout/stderr |
| 121 | eEventProcessAsyncInterrupt = 1 << 4, // Gives the ability for any infinite wait calls to be interrupted |
| 122 | kAllEventsMask = eEventProcessRunningStateChanged | |
| 123 | eEventProcessStoppedStateChanged | |
| 124 | eEventSharedLibsStateChange | |
| 125 | eEventStdioAvailable | |
| 126 | eEventProcessAsyncInterrupt |
| 127 | }; |
| 128 | |
| 129 | #define LOG_VERBOSE (1u << 0) |
| 130 | #define LOG_PROCESS (1u << 1) |
| 131 | #define LOG_THREAD (1u << 2) |
| 132 | #define LOG_EXCEPTIONS (1u << 3) |
| 133 | #define LOG_SHLIB (1u << 4) |
| 134 | #define LOG_MEMORY (1u << 5) // Log memory reads/writes calls |
| 135 | #define LOG_MEMORY_DATA_SHORT (1u << 6) // Log short memory reads/writes bytes |
| 136 | #define LOG_MEMORY_DATA_LONG (1u << 7) // Log all memory reads/writes bytes |
| 137 | #define LOG_MEMORY_PROTECTIONS (1u << 8) // Log memory protection changes |
| 138 | #define LOG_BREAKPOINTS (1u << 9) |
| 139 | #define LOG_EVENTS (1u << 10) |
| 140 | #define LOG_WATCHPOINTS (1u << 11) |
| 141 | #define LOG_STEP (1u << 12) |
| 142 | #define LOG_TASK (1u << 13) |
| 143 | #define LOG_LO_USER (1u << 16) |
| 144 | #define LOG_HI_USER (1u << 31) |
| 145 | #define LOG_ALL 0xFFFFFFFFu |
| 146 | #define LOG_DEFAULT ((LOG_PROCESS) |\ |
| 147 | (LOG_TASK) |\ |
| 148 | (LOG_THREAD) |\ |
| 149 | (LOG_EXCEPTIONS) |\ |
| 150 | (LOG_SHLIB) |\ |
| 151 | (LOG_MEMORY) |\ |
| 152 | (LOG_BREAKPOINTS) |\ |
| 153 | (LOG_WATCHPOINTS) |\ |
| 154 | (LOG_STEP)) |
| 155 | |
| 156 | |
| 157 | #define REGISTER_SET_ALL 0 |
| 158 | // Generic Register set to be defined by each architecture for access to common |
| 159 | // register values. |
| 160 | #define REGISTER_SET_GENERIC ((uint32_t)0xFFFFFFFFu) |
| 161 | #define GENERIC_REGNUM_PC 0 // Program Counter |
| 162 | #define GENERIC_REGNUM_SP 1 // Stack Pointer |
| 163 | #define GENERIC_REGNUM_FP 2 // Frame Pointer |
| 164 | #define GENERIC_REGNUM_RA 3 // Return Address |
| 165 | #define GENERIC_REGNUM_FLAGS 4 // Processor flags register |
| 166 | |
| 167 | enum DNBRegisterType |
| 168 | { |
| 169 | InvalidRegType = 0, |
| 170 | Uint, // unsigned integer |
| 171 | Sint, // signed integer |
| 172 | IEEE754, // float |
| 173 | Vector // vector registers |
| 174 | }; |
| 175 | |
| 176 | enum DNBRegisterFormat |
| 177 | { |
| 178 | InvalidRegFormat = 0, |
| 179 | Binary, |
| 180 | Decimal, |
| 181 | Hex, |
| 182 | Float, |
| 183 | VectorOfSInt8, |
| 184 | VectorOfUInt8, |
| 185 | VectorOfSInt16, |
| 186 | VectorOfUInt16, |
| 187 | VectorOfSInt32, |
| 188 | VectorOfUInt32, |
| 189 | VectorOfFloat32, |
| 190 | VectorOfUInt128 |
| 191 | }; |
| 192 | |
| 193 | struct DNBRegisterInfo |
| 194 | { |
| 195 | uint32_t set; // Register set |
| 196 | uint32_t reg; // Register number |
| 197 | const char *name; // Name of this register |
| 198 | const char *alt; // Alternate name |
| 199 | uint16_t type; // Type of the register bits (DNBRegisterType) |
| 200 | uint16_t format; // Default format for display (DNBRegisterFormat), |
| 201 | uint32_t size; // Size in bytes of the register |
| 202 | uint32_t offset; // Offset from the beginning of the register context |
| 203 | uint32_t reg_gcc; // GCC register number (INVALID_NUB_REGNUM when none) |
| 204 | uint32_t reg_dwarf; // DWARF register number (INVALID_NUB_REGNUM when none) |
| 205 | uint32_t reg_generic; // Generic register number (INVALID_NUB_REGNUM when none) |
| 206 | uint32_t reg_gdb; // The GDB register number (INVALID_NUB_REGNUM when none) |
| 207 | }; |
| 208 | |
| 209 | struct DNBRegisterSetInfo |
| 210 | { |
| 211 | const char *name; // Name of this register set |
| 212 | const struct DNBRegisterInfo *registers; // An array of register descriptions |
| 213 | nub_size_t num_registers; // The number of registers in REGISTERS array above |
| 214 | }; |
| 215 | |
| 216 | struct DNBThreadResumeAction |
| 217 | { |
| 218 | nub_thread_t tid; // The thread ID that this action applies to, INVALID_NUB_THREAD for the default thread action |
| 219 | nub_state_t state; // Valid values are eStateStopped/eStateSuspended, eStateRunning, and eStateStepping. |
| 220 | int signal; // When resuming this thread, resume it with this signal |
| 221 | nub_addr_t addr; // If not INVALID_NUB_ADDRESS, then set the PC for the thread to ADDR before resuming/stepping |
| 222 | }; |
| 223 | |
| 224 | enum DNBThreadStopType |
| 225 | { |
| 226 | eStopTypeInvalid = 0, |
| 227 | eStopTypeSignal, |
| 228 | eStopTypeException |
| 229 | }; |
| 230 | |
| 231 | enum DNBMemoryPermissions |
| 232 | { |
| 233 | eMemoryPermissionsWritable = (1 << 0), |
| 234 | eMemoryPermissionsReadable = (1 << 1), |
| 235 | eMemoryPermissionsExecutable = (1 << 2) |
| 236 | }; |
| 237 | |
| 238 | #define DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH 256 |
| 239 | #define DNB_THREAD_STOP_INFO_MAX_EXC_DATA 8 |
| 240 | |
| 241 | //---------------------------------------------------------------------- |
| 242 | // DNBThreadStopInfo |
| 243 | // |
| 244 | // Describes the reason a thread stopped. |
| 245 | //---------------------------------------------------------------------- |
| 246 | struct DNBThreadStopInfo |
| 247 | { |
| 248 | DNBThreadStopType reason; |
| 249 | char description[DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH]; |
| 250 | union |
| 251 | { |
| 252 | // eStopTypeSignal |
| 253 | struct |
| 254 | { |
| 255 | uint32_t signo; |
| 256 | } signal; |
| 257 | |
| 258 | // eStopTypeException |
| 259 | struct |
| 260 | { |
| 261 | uint32_t type; |
| 262 | nub_size_t data_count; |
| 263 | nub_addr_t data[DNB_THREAD_STOP_INFO_MAX_EXC_DATA]; |
| 264 | } exception; |
| 265 | } details; |
| 266 | }; |
| 267 | |
| 268 | |
| 269 | struct DNBRegisterValue |
| 270 | { |
| 271 | struct DNBRegisterInfo info; // Register information for this register |
| 272 | union |
| 273 | { |
| 274 | int8_t sint8; |
| 275 | int16_t sint16; |
| 276 | int32_t sint32; |
| 277 | int64_t sint64; |
| 278 | uint8_t uint8; |
| 279 | uint16_t uint16; |
| 280 | uint32_t uint32; |
| 281 | uint64_t uint64; |
| 282 | float float32; |
| 283 | double float64; |
| 284 | int8_t v_sint8[16]; |
| 285 | int16_t v_sint16[8]; |
| 286 | int32_t v_sint32[4]; |
| 287 | int64_t v_sint64[2]; |
| 288 | uint8_t v_uint8[16]; |
| 289 | uint16_t v_uint16[8]; |
| 290 | uint32_t v_uint32[4]; |
| 291 | uint64_t v_uint64[2]; |
| 292 | float v_float32[4]; |
| 293 | double v_float64[2]; |
| 294 | void *pointer; |
| 295 | char *c_str; |
| 296 | } value; |
| 297 | }; |
| 298 | |
| 299 | enum DNBSharedLibraryState |
| 300 | { |
| 301 | eShlibStateUnloaded = 0, |
| 302 | eShlibStateLoaded = 1 |
| 303 | }; |
| 304 | |
| 305 | #ifndef DNB_MAX_SEGMENT_NAME_LENGTH |
| 306 | #define DNB_MAX_SEGMENT_NAME_LENGTH 32 |
| 307 | #endif |
| 308 | |
| 309 | struct DNBSegment |
| 310 | { |
| 311 | char name[DNB_MAX_SEGMENT_NAME_LENGTH]; |
| 312 | nub_addr_t addr; |
| 313 | nub_addr_t size; |
| 314 | }; |
| 315 | |
| 316 | struct DNBExecutableImageInfo |
| 317 | { |
| 318 | char name[PATH_MAX]; // Name of the executable image (usually a full path) |
| 319 | uint32_t state; // State of the executable image (see enum DNBSharedLibraryState) |
| 320 | nub_addr_t header_addr; // Executable header address |
| 321 | uuid_t uuid; // Unique indentifier for matching with symbols |
| 322 | uint32_t num_segments; // Number of contiguous memory segments to in SEGMENTS array |
| 323 | DNBSegment *segments; // Array of contiguous memory segments in executable |
| 324 | }; |
| 325 | |
| 326 | typedef nub_bool_t (*DNBCallbackBreakpointHit)(nub_process_t pid, nub_thread_t tid, nub_break_t breakID, void *baton); |
| 327 | typedef nub_addr_t (*DNBCallbackNameToAddress)(nub_process_t pid, const char *name, const char *shlib_regex, void *baton); |
| 328 | typedef nub_size_t (*DNBCallbackCopyExecutableImageInfos)(nub_process_t pid, struct DNBExecutableImageInfo **image_infos, nub_bool_t only_changed, void *baton); |
| 329 | typedef void (*DNBCallbackLog)(void *baton, uint32_t flags, const char *format, va_list args); |
| 330 | |
| 331 | #endif // #ifndef __DNBDefs_h__ |