blob: 1b8d11f595be40fae1f06b24aac9f1fc080640f1 [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
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//----------------------------------------------------------------------
31typedef 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
40typedef 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
50typedef uint64_t nub_addr_t;
51#define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull)
52
53
54#endif
55
56typedef size_t nub_size_t;
57typedef ssize_t nub_ssize_t;
58typedef uint32_t nub_break_t;
59typedef uint32_t nub_watch_t;
60typedef uint32_t nub_index_t;
61typedef pid_t nub_process_t;
Jason Molenda1c739112013-02-22 07:27:08 +000062typedef uint64_t nub_thread_t;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063typedef uint32_t nub_event_t;
64typedef 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)
Johnny Chen86f97a42011-09-06 19:52:49 +000069#define INVALID_NUB_WATCH_ID ((nub_watch_t)0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070#define INVALID_NUB_HW_INDEX UINT32_MAX
71#define INVALID_NUB_REGNUM UINT32_MAX
72#define NUB_GENERIC_ERROR UINT32_MAX
73
74#define NUB_BREAK_ID_IS_VALID(breakID) ((breakID) != (INVALID_NUB_BREAK_ID))
Johnny Chen86f97a42011-09-06 19:52:49 +000075#define NUB_WATCH_ID_IS_VALID(watchID) ((watchID) != (INVALID_NUB_WATCH_ID))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076
77// Watchpoint types
78#define WATCH_TYPE_READ (1u << 0)
79#define WATCH_TYPE_WRITE (1u << 1)
80
81typedef enum
82{
83 eStateInvalid = 0,
84 eStateUnloaded,
85 eStateAttaching,
86 eStateLaunching,
87 eStateStopped,
88 eStateRunning,
89 eStateStepping,
90 eStateCrashed,
91 eStateDetached,
92 eStateExited,
93 eStateSuspended
94} nub_state_t;
95
96typedef enum
97{
98 eLaunchFlavorDefault = 0,
99 eLaunchFlavorPosixSpawn,
100 eLaunchFlavorForkExec,
Jason Molenda42999a42012-02-22 02:18:59 +0000101#ifdef WITH_SPRINGBOARD
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102 eLaunchFlavorSpringBoard,
103#endif
104} nub_launch_flavor_t;
105
106#define NUB_STATE_IS_RUNNING(s) ((s) == eStateAttaching ||\
107 (s) == eStateLaunching ||\
108 (s) == eStateRunning ||\
109 (s) == eStateStepping ||\
110 (s) == eStateDetached)
111
112#define NUB_STATE_IS_STOPPED(s) ((s) == eStateUnloaded ||\
113 (s) == eStateStopped ||\
114 (s) == eStateCrashed ||\
115 (s) == eStateExited)
116
117enum
118{
119 eEventProcessRunningStateChanged = 1 << 0, // The process has changed state to running
120 eEventProcessStoppedStateChanged = 1 << 1, // The process has changed state to stopped
121 eEventSharedLibsStateChange = 1 << 2, // Shared libraries loaded/unloaded state has changed
122 eEventStdioAvailable = 1 << 3, // Something is available on stdout/stderr
Han Ming Ongab3b8b22012-11-17 00:21:04 +0000123 eEventProfileDataAvailable = 1 << 4, // Profile data ready for retrieval
124 eEventProcessAsyncInterrupt = 1 << 5, // Gives the ability for any infinite wait calls to be interrupted
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125 kAllEventsMask = eEventProcessRunningStateChanged |
126 eEventProcessStoppedStateChanged |
127 eEventSharedLibsStateChange |
128 eEventStdioAvailable |
Han Ming Ongab3b8b22012-11-17 00:21:04 +0000129 eEventProfileDataAvailable |
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130 eEventProcessAsyncInterrupt
131};
132
133#define LOG_VERBOSE (1u << 0)
134#define LOG_PROCESS (1u << 1)
135#define LOG_THREAD (1u << 2)
136#define LOG_EXCEPTIONS (1u << 3)
137#define LOG_SHLIB (1u << 4)
138#define LOG_MEMORY (1u << 5) // Log memory reads/writes calls
139#define LOG_MEMORY_DATA_SHORT (1u << 6) // Log short memory reads/writes bytes
140#define LOG_MEMORY_DATA_LONG (1u << 7) // Log all memory reads/writes bytes
141#define LOG_MEMORY_PROTECTIONS (1u << 8) // Log memory protection changes
142#define LOG_BREAKPOINTS (1u << 9)
143#define LOG_EVENTS (1u << 10)
144#define LOG_WATCHPOINTS (1u << 11)
145#define LOG_STEP (1u << 12)
146#define LOG_TASK (1u << 13)
147#define LOG_LO_USER (1u << 16)
148#define LOG_HI_USER (1u << 31)
149#define LOG_ALL 0xFFFFFFFFu
150#define LOG_DEFAULT ((LOG_PROCESS) |\
151 (LOG_TASK) |\
152 (LOG_THREAD) |\
153 (LOG_EXCEPTIONS) |\
154 (LOG_SHLIB) |\
155 (LOG_MEMORY) |\
156 (LOG_BREAKPOINTS) |\
157 (LOG_WATCHPOINTS) |\
158 (LOG_STEP))
159
160
161#define REGISTER_SET_ALL 0
162// Generic Register set to be defined by each architecture for access to common
163// register values.
164#define REGISTER_SET_GENERIC ((uint32_t)0xFFFFFFFFu)
165#define GENERIC_REGNUM_PC 0 // Program Counter
166#define GENERIC_REGNUM_SP 1 // Stack Pointer
167#define GENERIC_REGNUM_FP 2 // Frame Pointer
168#define GENERIC_REGNUM_RA 3 // Return Address
169#define GENERIC_REGNUM_FLAGS 4 // Processor flags register
Greg Clayton9a8fa912011-05-15 04:12:07 +0000170#define GENERIC_REGNUM_ARG1 5 // The register that would contain pointer size or less argument 1 (if any)
171#define GENERIC_REGNUM_ARG2 6 // The register that would contain pointer size or less argument 2 (if any)
172#define GENERIC_REGNUM_ARG3 7 // The register that would contain pointer size or less argument 3 (if any)
173#define GENERIC_REGNUM_ARG4 8 // The register that would contain pointer size or less argument 4 (if any)
174#define GENERIC_REGNUM_ARG5 9 // The register that would contain pointer size or less argument 5 (if any)
175#define GENERIC_REGNUM_ARG6 10 // The register that would contain pointer size or less argument 6 (if any)
176#define GENERIC_REGNUM_ARG7 11 // The register that would contain pointer size or less argument 7 (if any)
177#define GENERIC_REGNUM_ARG8 12 // The register that would contain pointer size or less argument 8 (if any)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178
179enum DNBRegisterType
180{
181 InvalidRegType = 0,
182 Uint, // unsigned integer
183 Sint, // signed integer
184 IEEE754, // float
185 Vector // vector registers
186};
187
188enum DNBRegisterFormat
189{
190 InvalidRegFormat = 0,
191 Binary,
192 Decimal,
193 Hex,
194 Float,
195 VectorOfSInt8,
196 VectorOfUInt8,
197 VectorOfSInt16,
198 VectorOfUInt16,
199 VectorOfSInt32,
200 VectorOfUInt32,
201 VectorOfFloat32,
202 VectorOfUInt128
203};
204
205struct DNBRegisterInfo
206{
207 uint32_t set; // Register set
208 uint32_t reg; // Register number
209 const char *name; // Name of this register
210 const char *alt; // Alternate name
211 uint16_t type; // Type of the register bits (DNBRegisterType)
212 uint16_t format; // Default format for display (DNBRegisterFormat),
213 uint32_t size; // Size in bytes of the register
214 uint32_t offset; // Offset from the beginning of the register context
215 uint32_t reg_gcc; // GCC register number (INVALID_NUB_REGNUM when none)
216 uint32_t reg_dwarf; // DWARF register number (INVALID_NUB_REGNUM when none)
217 uint32_t reg_generic; // Generic register number (INVALID_NUB_REGNUM when none)
218 uint32_t reg_gdb; // The GDB register number (INVALID_NUB_REGNUM when none)
Greg Claytonce1ffcf2013-01-21 22:17:50 +0000219 uint32_t *pseudo_regs; // If this register is a part of another register, list the one or more registers
220 uint32_t *update_regs; // If modifying this register will invalidate other registers, list them here
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221};
222
223struct DNBRegisterSetInfo
224{
225 const char *name; // Name of this register set
226 const struct DNBRegisterInfo *registers; // An array of register descriptions
227 nub_size_t num_registers; // The number of registers in REGISTERS array above
228};
229
230struct DNBThreadResumeAction
231{
232 nub_thread_t tid; // The thread ID that this action applies to, INVALID_NUB_THREAD for the default thread action
233 nub_state_t state; // Valid values are eStateStopped/eStateSuspended, eStateRunning, and eStateStepping.
234 int signal; // When resuming this thread, resume it with this signal
235 nub_addr_t addr; // If not INVALID_NUB_ADDRESS, then set the PC for the thread to ADDR before resuming/stepping
236};
237
238enum DNBThreadStopType
239{
240 eStopTypeInvalid = 0,
241 eStopTypeSignal,
242 eStopTypeException
243};
244
245enum DNBMemoryPermissions
246{
247 eMemoryPermissionsWritable = (1 << 0),
248 eMemoryPermissionsReadable = (1 << 1),
249 eMemoryPermissionsExecutable = (1 << 2)
250};
251
252#define DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH 256
253#define DNB_THREAD_STOP_INFO_MAX_EXC_DATA 8
254
255//----------------------------------------------------------------------
256// DNBThreadStopInfo
257//
258// Describes the reason a thread stopped.
259//----------------------------------------------------------------------
260struct DNBThreadStopInfo
261{
262 DNBThreadStopType reason;
263 char description[DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH];
264 union
265 {
266 // eStopTypeSignal
267 struct
268 {
269 uint32_t signo;
270 } signal;
271
272 // eStopTypeException
273 struct
274 {
275 uint32_t type;
276 nub_size_t data_count;
277 nub_addr_t data[DNB_THREAD_STOP_INFO_MAX_EXC_DATA];
278 } exception;
279 } details;
280};
281
282
283struct DNBRegisterValue
284{
285 struct DNBRegisterInfo info; // Register information for this register
286 union
287 {
288 int8_t sint8;
289 int16_t sint16;
290 int32_t sint32;
291 int64_t sint64;
292 uint8_t uint8;
293 uint16_t uint16;
294 uint32_t uint32;
295 uint64_t uint64;
296 float float32;
297 double float64;
Sean Callananc530af02011-03-22 21:45:30 +0000298 int8_t v_sint8[32];
299 int16_t v_sint16[16];
300 int32_t v_sint32[8];
301 int64_t v_sint64[4];
302 uint8_t v_uint8[32];
303 uint16_t v_uint16[16];
304 uint32_t v_uint32[8];
305 uint64_t v_uint64[4];
306 float v_float32[8];
307 double v_float64[4];
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308 void *pointer;
309 char *c_str;
310 } value;
311};
312
313enum DNBSharedLibraryState
314{
315 eShlibStateUnloaded = 0,
316 eShlibStateLoaded = 1
317};
318
319#ifndef DNB_MAX_SEGMENT_NAME_LENGTH
320#define DNB_MAX_SEGMENT_NAME_LENGTH 32
321#endif
322
323struct DNBSegment
324{
325 char name[DNB_MAX_SEGMENT_NAME_LENGTH];
326 nub_addr_t addr;
327 nub_addr_t size;
328};
329
330struct DNBExecutableImageInfo
331{
332 char name[PATH_MAX]; // Name of the executable image (usually a full path)
333 uint32_t state; // State of the executable image (see enum DNBSharedLibraryState)
334 nub_addr_t header_addr; // Executable header address
335 uuid_t uuid; // Unique indentifier for matching with symbols
336 uint32_t num_segments; // Number of contiguous memory segments to in SEGMENTS array
337 DNBSegment *segments; // Array of contiguous memory segments in executable
338};
339
Greg Clayton46fb5582011-11-18 07:03:08 +0000340struct DNBRegionInfo
341{
342 nub_addr_t addr;
343 nub_addr_t size;
344 uint32_t permissions;
345};
346
Han Ming Ong8764fe72013-03-04 21:25:51 +0000347enum DNBProfileDataScanType
348{
349 eProfileHostCPU = (1 << 0),
350 eProfileCPU = (1 << 1),
351
352 eProfileThreadsCPU = (1 << 2), // By default excludes eProfileThreadName and eProfileQueueName.
353 eProfileThreadName = (1 << 3), // Assume eProfileThreadsCPU, get thread name as well.
354 eProfileQueueName = (1 << 4), // Assume eProfileThreadsCPU, get queue name as well.
355
356 eProfileHostMemory = (1 << 5),
357
358 eProfileMemory = (1 << 6), // By default, excludes eProfileMemoryDirtyPage.
359 eProfileMemoryDirtyPage = (1 << 7), // Assume eProfileMemory, get Dirty Page size as well.
360
361 eProfileAll = 0xffffffff
362};
363
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364typedef nub_bool_t (*DNBCallbackBreakpointHit)(nub_process_t pid, nub_thread_t tid, nub_break_t breakID, void *baton);
365typedef nub_addr_t (*DNBCallbackNameToAddress)(nub_process_t pid, const char *name, const char *shlib_regex, void *baton);
366typedef nub_size_t (*DNBCallbackCopyExecutableImageInfos)(nub_process_t pid, struct DNBExecutableImageInfo **image_infos, nub_bool_t only_changed, void *baton);
367typedef void (*DNBCallbackLog)(void *baton, uint32_t flags, const char *format, va_list args);
368
369#endif // #ifndef __DNBDefs_h__