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