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