blob: 5762bd16e2b755edb1bd2762c13a151a5c173b93 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include <signal.h>
Kate Stoneb9c1b512016-09-06 20:57:50 +000018#include <stdint.h>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#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//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000026#if defined(__x86_64__) || defined(__ppc64__) || defined(__arm64__) || \
27 defined(__aarch64__)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
29//----------------------------------------------------------------------
30// 64 bit address architectures
31//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000032typedef uint64_t nub_addr_t;
33#define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035#elif defined(__i386__) || defined(__powerpc__) || defined(__ppc__) || \
36 defined(__arm__)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037
38//----------------------------------------------------------------------
39// 32 bit address architectures
40//----------------------------------------------------------------------
41
Kate Stoneb9c1b512016-09-06 20:57:50 +000042typedef uint32_t nub_addr_t;
43#define INVALID_NUB_ADDRESS ((nub_addr_t)~0ul)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044
45#else
46
47//----------------------------------------------------------------------
48// Default to 64 bit address for unrecognized architectures.
49//----------------------------------------------------------------------
50
51#warning undefined architecture, defaulting to 8 byte addresses
Kate Stoneb9c1b512016-09-06 20:57:50 +000052typedef uint64_t nub_addr_t;
53#define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55#endif
56
Kate Stoneb9c1b512016-09-06 20:57:50 +000057typedef size_t nub_size_t;
58typedef ssize_t nub_ssize_t;
59typedef uint32_t nub_index_t;
60typedef pid_t nub_process_t;
61typedef uint64_t nub_thread_t;
62typedef uint32_t nub_event_t;
63typedef uint32_t nub_bool_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065#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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072// Watchpoint types
Kate Stoneb9c1b512016-09-06 20:57:50 +000073#define WATCH_TYPE_READ (1u << 0)
74#define WATCH_TYPE_WRITE (1u << 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076typedef enum {
77 eStateInvalid = 0,
78 eStateUnloaded,
79 eStateAttaching,
80 eStateLaunching,
81 eStateStopped,
82 eStateRunning,
83 eStateStepping,
84 eStateCrashed,
85 eStateDetached,
86 eStateExited,
87 eStateSuspended
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088} nub_state_t;
89
Kate Stoneb9c1b512016-09-06 20:57:50 +000090typedef enum {
91 eLaunchFlavorDefault = 0,
92 eLaunchFlavorPosixSpawn = 1,
93 eLaunchFlavorForkExec = 2,
Jason Molenda42999a42012-02-22 02:18:59 +000094#ifdef WITH_SPRINGBOARD
Kate Stoneb9c1b512016-09-06 20:57:50 +000095 eLaunchFlavorSpringBoard = 3,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096#endif
Jason Molendaa3329782014-03-29 18:54:20 +000097#ifdef WITH_BKS
Kate Stoneb9c1b512016-09-06 20:57:50 +000098 eLaunchFlavorBKS = 4,
Jason Molendaa3329782014-03-29 18:54:20 +000099#endif
Jason Molendac611a742015-10-23 02:49:51 +0000100#ifdef WITH_FBS
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 eLaunchFlavorFBS = 5
Jason Molendac611a742015-10-23 02:49:51 +0000102#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103} nub_launch_flavor_t;
104
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105#define NUB_STATE_IS_RUNNING(s) \
106 ((s) == eStateAttaching || (s) == eStateLaunching || (s) == eStateRunning || \
107 (s) == eStateStepping || (s) == eStateDetached)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109#define NUB_STATE_IS_STOPPED(s) \
110 ((s) == eStateUnloaded || (s) == eStateStopped || (s) == eStateCrashed || \
111 (s) == eStateExited)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113enum {
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
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126};
127
Kate Stoneb9c1b512016-09-06 20:57:50 +0000128#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))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151#define REGISTER_SET_ALL 0
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000152// Generic Register set to be defined by each architecture for access to common
153// register values.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154#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)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176
Kate Stoneb9c1b512016-09-06 20:57:50 +0000177enum DNBRegisterType {
178 InvalidRegType = 0,
179 Uint, // unsigned integer
180 Sint, // signed integer
181 IEEE754, // float
182 Vector // vector registers
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183};
184
Kate Stoneb9c1b512016-09-06 20:57:50 +0000185enum 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199};
200
Kate Stoneb9c1b512016-09-06 20:57:50 +0000201struct 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000223};
224
Kate Stoneb9c1b512016-09-06 20:57:50 +0000225struct 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229};
230
Kate Stoneb9c1b512016-09-06 20:57:50 +0000231struct 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000239};
240
Kate Stoneb9c1b512016-09-06 20:57:50 +0000241enum DNBThreadStopType {
242 eStopTypeInvalid = 0,
243 eStopTypeSignal,
244 eStopTypeException,
245 eStopTypeExec
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246};
247
Kate Stoneb9c1b512016-09-06 20:57:50 +0000248enum DNBMemoryPermissions {
249 eMemoryPermissionsWritable = (1 << 0),
250 eMemoryPermissionsReadable = (1 << 1),
251 eMemoryPermissionsExecutable = (1 << 2)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252};
253
Kate Stoneb9c1b512016-09-06 20:57:50 +0000254#define DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH 256
255#define DNB_THREAD_STOP_INFO_MAX_EXC_DATA 8
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256
257//----------------------------------------------------------------------
258// DNBThreadStopInfo
259//
260// Describes the reason a thread stopped.
261//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000262struct 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270
Kate Stoneb9c1b512016-09-06 20:57:50 +0000271 // 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278};
279
Kate Stoneb9c1b512016-09-06 20:57:50 +0000280struct 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306};
307
Kate Stoneb9c1b512016-09-06 20:57:50 +0000308enum DNBSharedLibraryState { eShlibStateUnloaded = 0, eShlibStateLoaded = 1 };
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000309
310#ifndef DNB_MAX_SEGMENT_NAME_LENGTH
Kate Stoneb9c1b512016-09-06 20:57:50 +0000311#define DNB_MAX_SEGMENT_NAME_LENGTH 32
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312#endif
313
Kate Stoneb9c1b512016-09-06 20:57:50 +0000314struct DNBSegment {
315 char name[DNB_MAX_SEGMENT_NAME_LENGTH];
316 nub_addr_t addr;
317 nub_addr_t size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000318};
319
Kate Stoneb9c1b512016-09-06 20:57:50 +0000320struct 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329};
330
Kate Stoneb9c1b512016-09-06 20:57:50 +0000331struct DNBRegionInfo {
332 nub_addr_t addr;
333 nub_addr_t size;
334 uint32_t permissions;
Greg Clayton46fb5582011-11-18 07:03:08 +0000335};
336
Kate Stoneb9c1b512016-09-06 20:57:50 +0000337enum 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
Han Ming Ong8764fe72013-03-04 21:25:51 +0000359};
360
Kate Stoneb9c1b512016-09-06 20:57:50 +0000361typedef nub_addr_t (*DNBCallbackNameToAddress)(nub_process_t pid,
362 const char *name,
363 const char *shlib_regex,
364 void *baton);
365typedef nub_size_t (*DNBCallbackCopyExecutableImageInfos)(
366 nub_process_t pid, struct DNBExecutableImageInfo **image_infos,
367 nub_bool_t only_changed, void *baton);
368typedef void (*DNBCallbackLog)(void *baton, uint32_t flags, const char *format,
369 va_list args);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370
Bruce Mitchener8a67bf72015-07-24 00:23:29 +0000371#define UNUSED_IF_ASSERT_DISABLED(x) ((void)(x))
372
Kate Stoneb9c1b512016-09-06 20:57:50 +0000373#endif // #ifndef __DNBDefs_h__