1 //===-- DNBDefs.h -----------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Created by Greg Clayton on 6/26/07.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBDEFS_H
14 #define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBDEFS_H
20 #include <sys/syslimits.h>
24 // Define nub_addr_t and the invalid address value from the architecture
25 #if defined(__x86_64__) || defined(__arm64__) || defined(__aarch64__)
27 // 64 bit address architectures
28 typedef uint64_t nub_addr_t
;
29 #define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull)
31 #elif defined(__i386__) || defined(__powerpc__) || defined(__arm__)
33 // 32 bit address architectures
35 typedef uint32_t nub_addr_t
;
36 #define INVALID_NUB_ADDRESS ((nub_addr_t)~0ul)
40 // Default to 64 bit address for unrecognized architectures.
42 #warning undefined architecture, defaulting to 8 byte addresses
43 typedef uint64_t nub_addr_t
;
44 #define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull)
48 typedef size_t nub_size_t
;
49 typedef ssize_t nub_ssize_t
;
50 typedef uint32_t nub_index_t
;
51 typedef pid_t nub_process_t
;
52 typedef uint64_t nub_thread_t
;
53 typedef uint32_t nub_event_t
;
54 typedef uint32_t nub_bool_t
;
56 #define INVALID_NUB_PROCESS ((nub_process_t)0)
57 #define INVALID_NUB_THREAD ((nub_thread_t)0)
58 #define INVALID_NUB_WATCH_ID ((nub_watch_t)0)
59 #define INVALID_NUB_HW_INDEX UINT32_MAX
60 #define INVALID_NUB_REGNUM UINT32_MAX
61 #define NUB_GENERIC_ERROR UINT32_MAX
64 #define WATCH_TYPE_READ (1u << 0)
65 #define WATCH_TYPE_WRITE (1u << 1)
81 enum nub_launch_flavor_t
{
82 eLaunchFlavorDefault
= 0,
83 eLaunchFlavorPosixSpawn
= 1,
84 eLaunchFlavorForkExec
= 2,
85 #ifdef WITH_SPRINGBOARD
86 eLaunchFlavorSpringBoard
= 3,
96 #define NUB_STATE_IS_RUNNING(s) \
97 ((s) == eStateAttaching || (s) == eStateLaunching || (s) == eStateRunning || \
98 (s) == eStateStepping || (s) == eStateDetached)
100 #define NUB_STATE_IS_STOPPED(s) \
101 ((s) == eStateUnloaded || (s) == eStateStopped || (s) == eStateCrashed || \
105 eEventProcessRunningStateChanged
=
106 1 << 0, // The process has changed state to running
107 eEventProcessStoppedStateChanged
=
108 1 << 1, // The process has changed state to stopped
109 eEventSharedLibsStateChange
=
110 1 << 2, // Shared libraries loaded/unloaded state has changed
111 eEventStdioAvailable
= 1 << 3, // Something is available on stdout/stderr
112 eEventProfileDataAvailable
= 1 << 4, // Profile data ready for retrieval
113 kAllEventsMask
= eEventProcessRunningStateChanged
|
114 eEventProcessStoppedStateChanged
|
115 eEventSharedLibsStateChange
| eEventStdioAvailable
|
116 eEventProfileDataAvailable
119 #define LOG_VERBOSE (1u << 0)
120 #define LOG_PROCESS (1u << 1)
121 #define LOG_THREAD (1u << 2)
122 #define LOG_EXCEPTIONS (1u << 3)
123 #define LOG_SHLIB (1u << 4)
124 #define LOG_MEMORY (1u << 5) // Log memory reads/writes calls
125 #define LOG_MEMORY_DATA_SHORT (1u << 6) // Log short memory reads/writes bytes
126 #define LOG_MEMORY_DATA_LONG (1u << 7) // Log all memory reads/writes bytes
127 #define LOG_MEMORY_PROTECTIONS (1u << 8) // Log memory protection changes
128 #define LOG_BREAKPOINTS (1u << 9)
129 #define LOG_EVENTS (1u << 10)
130 #define LOG_WATCHPOINTS (1u << 11)
131 #define LOG_STEP (1u << 12)
132 #define LOG_TASK (1u << 13)
133 #define LOG_DARWIN_LOG (1u << 14)
134 #define LOG_LO_USER (1u << 16)
135 #define LOG_HI_USER (1u << 31)
136 #define LOG_ALL 0xFFFFFFFFu
137 #define LOG_DEFAULT \
138 ((LOG_PROCESS) | (LOG_TASK) | (LOG_THREAD) | (LOG_EXCEPTIONS) | \
139 (LOG_SHLIB) | (LOG_MEMORY) | (LOG_BREAKPOINTS) | (LOG_WATCHPOINTS) | \
142 #define REGISTER_SET_ALL 0
143 // Generic Register set to be defined by each architecture for access to common
145 #define REGISTER_SET_GENERIC ((uint32_t)0xFFFFFFFFu)
146 #define GENERIC_REGNUM_PC 0 // Program Counter
147 #define GENERIC_REGNUM_SP 1 // Stack Pointer
148 #define GENERIC_REGNUM_FP 2 // Frame Pointer
149 #define GENERIC_REGNUM_RA 3 // Return Address
150 #define GENERIC_REGNUM_FLAGS 4 // Processor flags register
151 #define GENERIC_REGNUM_ARG1 \
152 5 // The register that would contain pointer size or less argument 1 (if any)
153 #define GENERIC_REGNUM_ARG2 \
154 6 // The register that would contain pointer size or less argument 2 (if any)
155 #define GENERIC_REGNUM_ARG3 \
156 7 // The register that would contain pointer size or less argument 3 (if any)
157 #define GENERIC_REGNUM_ARG4 \
158 8 // The register that would contain pointer size or less argument 4 (if any)
159 #define GENERIC_REGNUM_ARG5 \
160 9 // The register that would contain pointer size or less argument 5 (if any)
161 #define GENERIC_REGNUM_ARG6 \
162 10 // The register that would contain pointer size or less argument 6 (if any)
163 #define GENERIC_REGNUM_ARG7 \
164 11 // The register that would contain pointer size or less argument 7 (if any)
165 #define GENERIC_REGNUM_ARG8 \
166 12 // The register that would contain pointer size or less argument 8 (if any)
168 enum DNBRegisterType
{
170 Uint
, // unsigned integer
171 Sint
, // signed integer
173 Vector
// vector registers
176 enum DNBRegisterFormat
{
177 InvalidRegFormat
= 0,
192 struct DNBRegisterInfo
{
193 uint32_t set
; // Register set
194 uint32_t reg
; // Register number
195 const char *name
; // Name of this register
196 const char *alt
; // Alternate name
197 uint16_t type
; // Type of the register bits (DNBRegisterType)
198 uint16_t format
; // Default format for display (DNBRegisterFormat),
199 uint32_t size
; // Size in bytes of the register
200 uint32_t offset
; // Offset from the beginning of the register context
202 reg_ehframe
; // eh_frame register number (INVALID_NUB_REGNUM when none)
203 uint32_t reg_dwarf
; // DWARF register number (INVALID_NUB_REGNUM when none)
205 reg_generic
; // Generic register number (INVALID_NUB_REGNUM when none)
206 uint32_t reg_debugserver
; // The debugserver register number we'll use over
207 // gdb-remote protocol (INVALID_NUB_REGNUM when
209 const char **value_regs
; // If this register is a part of other registers,
210 // list the register names terminated by NULL
211 const char **update_regs
; // If modifying this register will invalidate other
212 // registers, list the register names terminated by
216 struct DNBRegisterSetInfo
{
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
222 struct DNBThreadResumeAction
{
223 nub_thread_t tid
; // The thread ID that this action applies to,
224 // INVALID_NUB_THREAD for the default thread action
225 nub_state_t state
; // Valid values are eStateStopped/eStateSuspended,
226 // eStateRunning, and eStateStepping.
227 int signal
; // When resuming this thread, resume it with this signal
228 nub_addr_t addr
; // If not INVALID_NUB_ADDRESS, then set the PC for the thread
229 // to ADDR before resuming/stepping
232 enum DNBThreadStopType
{
233 eStopTypeInvalid
= 0,
239 enum DNBMemoryPermissions
{
240 eMemoryPermissionsWritable
= (1 << 0),
241 eMemoryPermissionsReadable
= (1 << 1),
242 eMemoryPermissionsExecutable
= (1 << 2)
245 #define DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH 256
246 #define DNB_THREAD_STOP_INFO_MAX_EXC_DATA 8
250 // Describes the reason a thread stopped.
251 struct DNBThreadStopInfo
{
252 DNBThreadStopType reason
;
253 char description
[DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH
];
260 // eStopTypeException
263 nub_size_t data_count
;
264 nub_addr_t data
[DNB_THREAD_STOP_INFO_MAX_EXC_DATA
];
269 struct DNBRegisterValue
{
270 struct DNBRegisterInfo info
; // Register information for this register
283 int16_t v_sint16
[32];
284 int32_t v_sint32
[16];
287 uint16_t v_uint16
[32];
288 uint32_t v_uint32
[16];
289 uint64_t v_uint64
[8];
297 enum DNBSharedLibraryState
{ eShlibStateUnloaded
= 0, eShlibStateLoaded
= 1 };
299 #ifndef DNB_MAX_SEGMENT_NAME_LENGTH
300 #define DNB_MAX_SEGMENT_NAME_LENGTH 32
304 char name
[DNB_MAX_SEGMENT_NAME_LENGTH
];
309 struct DNBExecutableImageInfo
{
310 char name
[PATH_MAX
]; // Name of the executable image (usually a full path)
312 state
; // State of the executable image (see enum DNBSharedLibraryState)
313 nub_addr_t header_addr
; // Executable header address
314 uuid_t uuid
; // Unique identifier for matching with symbols
316 num_segments
; // Number of contiguous memory segments to in SEGMENTS array
317 DNBSegment
*segments
; // Array of contiguous memory segments in executable
320 struct DNBRegionInfo
{
323 : addr(0), size(0), permissions(0), dirty_pages(), vm_types() {}
326 uint32_t permissions
;
327 std::vector
<nub_addr_t
> dirty_pages
;
328 std::vector
<std::string
> vm_types
;
331 enum DNBProfileDataScanType
{
332 eProfileHostCPU
= (1 << 0),
333 eProfileCPU
= (1 << 1),
336 (1 << 2), // By default excludes eProfileThreadName and eProfileQueueName.
338 (1 << 3), // Assume eProfileThreadsCPU, get thread name as well.
340 (1 << 4), // Assume eProfileThreadsCPU, get queue name as well.
342 eProfileHostMemory
= (1 << 5),
344 eProfileMemory
= (1 << 6),
345 eProfileMemoryAnonymous
=
346 (1 << 8), // Assume eProfileMemory, get Anonymous memory as well.
348 eProfileEnergy
= (1 << 9),
349 eProfileEnergyCPUCap
= (1 << 10),
351 eProfileMemoryCap
= (1 << 15),
353 eProfileAll
= 0xffffffff
356 typedef nub_addr_t (*DNBCallbackNameToAddress
)(nub_process_t pid
,
358 const char *shlib_regex
,
360 typedef nub_size_t (*DNBCallbackCopyExecutableImageInfos
)(
361 nub_process_t pid
, struct DNBExecutableImageInfo
**image_infos
,
362 nub_bool_t only_changed
, void *baton
);
363 typedef void (*DNBCallbackLog
)(void *baton
, uint32_t flags
, const char *format
,
366 #define UNUSED_IF_ASSERT_DISABLED(x) ((void)(x))
368 #endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBDEFS_H