brintos

brintos / llvm-project-archived public Read only

0
0
Text · 13.6 KiB · d98399a Raw
408 lines · c
1//===-- DNBDefs.h -----------------------------------------------*- C++ -*-===//2//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-exception6//7//===----------------------------------------------------------------------===//8//9//  Created by Greg Clayton on 6/26/07.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBDEFS_H14#define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBDEFS_H15 16#include <csignal>17#include <cstdint>18#include <cstdio>19#include <string>20#include <sys/syslimits.h>21#include <unistd.h>22#include <vector>23 24// Define nub_addr_t and the invalid address value from the architecture25#if defined(__x86_64__) || defined(__arm64__) || defined(__aarch64__)26 27// 64 bit address architectures28typedef uint64_t nub_addr_t;29#define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull)30 31#elif defined(__i386__) || defined(__powerpc__) || defined(__arm__)32 33// 32 bit address architectures34 35typedef uint32_t nub_addr_t;36#define INVALID_NUB_ADDRESS ((nub_addr_t)~0ul)37 38#else39 40// Default to 64 bit address for unrecognized architectures.41 42#warning undefined architecture, defaulting to 8 byte addresses43typedef uint64_t nub_addr_t;44#define INVALID_NUB_ADDRESS ((nub_addr_t)~0ull)45 46#endif47 48typedef size_t nub_size_t;49typedef ssize_t nub_ssize_t;50typedef uint32_t nub_index_t;51typedef pid_t nub_process_t;52typedef uint64_t nub_thread_t;53typedef uint32_t nub_event_t;54typedef uint32_t nub_bool_t;55 56#define INVALID_NUB_PROCESS ((nub_process_t)0)57#define INVALID_NUB_PROCESS_ARCH ((nub_process_t)-1)58#define INVALID_NUB_THREAD ((nub_thread_t)0)59#define INVALID_NUB_WATCH_ID ((nub_watch_t)0)60#define INVALID_NUB_HW_INDEX UINT32_MAX61#define INVALID_NUB_REGNUM UINT32_MAX62#define NUB_GENERIC_ERROR UINT32_MAX63 64// Watchpoint types65#define WATCH_TYPE_READ (1u << 0)66#define WATCH_TYPE_WRITE (1u << 1)67 68enum nub_state_t {69  eStateInvalid = 0,70  eStateUnloaded,71  eStateAttaching,72  eStateLaunching,73  eStateStopped,74  eStateRunning,75  eStateStepping,76  eStateCrashed,77  eStateDetached,78  eStateExited,79  eStateSuspended80};81 82enum nub_launch_flavor_t {83  eLaunchFlavorDefault = 0,84  eLaunchFlavorPosixSpawn = 1,85  eLaunchFlavorForkExec = 2,86#ifdef WITH_SPRINGBOARD87  eLaunchFlavorSpringBoard = 3,88#endif89#ifdef WITH_BKS90  eLaunchFlavorBKS = 4,91#endif92#ifdef WITH_FBS93  eLaunchFlavorFBS = 594#endif95};96 97#define NUB_STATE_IS_RUNNING(s)                                                \98  ((s) == eStateAttaching || (s) == eStateLaunching || (s) == eStateRunning || \99   (s) == eStateStepping || (s) == eStateDetached)100 101#define NUB_STATE_IS_STOPPED(s)                                                \102  ((s) == eStateUnloaded || (s) == eStateStopped || (s) == eStateCrashed ||    \103   (s) == eStateExited)104 105enum {106  eEventProcessRunningStateChanged =107      1 << 0, // The process has changed state to running108  eEventProcessStoppedStateChanged =109      1 << 1, // The process has changed state to stopped110  eEventSharedLibsStateChange =111      1 << 2, // Shared libraries loaded/unloaded state has changed112  eEventStdioAvailable = 1 << 3, // Something is available on stdout/stderr113  eEventProfileDataAvailable = 1 << 4, // Profile data ready for retrieval114  kAllEventsMask = eEventProcessRunningStateChanged |115                   eEventProcessStoppedStateChanged |116                   eEventSharedLibsStateChange | eEventStdioAvailable |117                   eEventProfileDataAvailable118};119 120#define LOG_VERBOSE (1u << 0)121#define LOG_PROCESS (1u << 1)122#define LOG_THREAD (1u << 2)123#define LOG_EXCEPTIONS (1u << 3)124#define LOG_SHLIB (1u << 4)125#define LOG_MEMORY (1u << 5)             // Log memory reads/writes calls126#define LOG_MEMORY_DATA_SHORT (1u << 6)  // Log short memory reads/writes bytes127#define LOG_MEMORY_DATA_LONG (1u << 7)   // Log all memory reads/writes bytes128#define LOG_MEMORY_PROTECTIONS (1u << 8) // Log memory protection changes129#define LOG_BREAKPOINTS (1u << 9)130#define LOG_EVENTS (1u << 10)131#define LOG_WATCHPOINTS (1u << 11)132#define LOG_STEP (1u << 12)133#define LOG_TASK (1u << 13)134#define LOG_DARWIN_LOG (1u << 14)135#define LOG_LO_USER (1u << 16)136#define LOG_HI_USER (1u << 31)137#define LOG_ALL 0xFFFFFFFFu138#define LOG_DEFAULT                                                            \139  ((LOG_PROCESS) | (LOG_TASK) | (LOG_THREAD) | (LOG_EXCEPTIONS) |              \140   (LOG_SHLIB) | (LOG_MEMORY) | (LOG_BREAKPOINTS) | (LOG_WATCHPOINTS) |        \141   (LOG_STEP))142 143#define REGISTER_SET_ALL 0144// Generic Register set to be defined by each architecture for access to common145// register values.146#define REGISTER_SET_GENERIC ((uint32_t)0xFFFFFFFFu)147#define GENERIC_REGNUM_PC 0    // Program Counter148#define GENERIC_REGNUM_SP 1    // Stack Pointer149#define GENERIC_REGNUM_FP 2    // Frame Pointer150#define GENERIC_REGNUM_RA 3    // Return Address151#define GENERIC_REGNUM_FLAGS 4 // Processor flags register152#define GENERIC_REGNUM_ARG1                                                    \153  5 // The register that would contain pointer size or less argument 1 (if any)154#define GENERIC_REGNUM_ARG2                                                    \155  6 // The register that would contain pointer size or less argument 2 (if any)156#define GENERIC_REGNUM_ARG3                                                    \157  7 // The register that would contain pointer size or less argument 3 (if any)158#define GENERIC_REGNUM_ARG4                                                    \159  8 // The register that would contain pointer size or less argument 4 (if any)160#define GENERIC_REGNUM_ARG5                                                    \161  9 // The register that would contain pointer size or less argument 5 (if any)162#define GENERIC_REGNUM_ARG6                                                    \163  10 // The register that would contain pointer size or less argument 6 (if any)164#define GENERIC_REGNUM_ARG7                                                    \165  11 // The register that would contain pointer size or less argument 7 (if any)166#define GENERIC_REGNUM_ARG8                                                    \167  12 // The register that would contain pointer size or less argument 8 (if any)168 169enum DNBRegisterType {170  InvalidRegType = 0,171  Uint,    // unsigned integer172  Sint,    // signed integer173  IEEE754, // float174  Vector   // vector registers175};176 177enum DNBRegisterFormat {178  InvalidRegFormat = 0,179  Binary,180  Decimal,181  Hex,182  Float,183  VectorOfSInt8,184  VectorOfUInt8,185  VectorOfSInt16,186  VectorOfUInt16,187  VectorOfSInt32,188  VectorOfUInt32,189  VectorOfFloat32,190  VectorOfUInt128191};192 193struct DNBRegisterInfo {194  uint32_t set;     // Register set195  uint32_t reg;     // Register number196  const char *name; // Name of this register197  const char *alt;  // Alternate name198  uint16_t type;    // Type of the register bits (DNBRegisterType)199  uint16_t format;  // Default format for display (DNBRegisterFormat),200  uint32_t size;    // Size in bytes of the register201  uint32_t offset;  // Offset from the beginning of the register context202  uint32_t203      reg_ehframe;    // eh_frame register number (INVALID_NUB_REGNUM when none)204  uint32_t reg_dwarf; // DWARF register number (INVALID_NUB_REGNUM when none)205  uint32_t206      reg_generic; // Generic register number (INVALID_NUB_REGNUM when none)207  uint32_t reg_debugserver; // The debugserver register number we'll use over208                            // gdb-remote protocol (INVALID_NUB_REGNUM when209                            // none)210  const char **value_regs;  // If this register is a part of other registers,211                            // list the register names terminated by NULL212  const char **update_regs; // If modifying this register will invalidate other213                            // registers, list the register names terminated by214                            // NULL215};216 217struct DNBRegisterSetInfo {218  const char *name;                        // Name of this register set219  const struct DNBRegisterInfo *registers; // An array of register descriptions220  nub_size_t num_registers; // The number of registers in REGISTERS array above221};222 223struct DNBThreadResumeAction {224  nub_thread_t tid;  // The thread ID that this action applies to,225                     // INVALID_NUB_THREAD for the default thread action226  nub_state_t state; // Valid values are eStateStopped/eStateSuspended,227                     // eStateRunning, and eStateStepping.228  int signal;        // When resuming this thread, resume it with this signal229  nub_addr_t addr; // If not INVALID_NUB_ADDRESS, then set the PC for the thread230                   // to ADDR before resuming/stepping231};232 233enum DNBThreadStopType {234  eStopTypeInvalid = 0,235  eStopTypeSignal,236  eStopTypeException,237  eStopTypeExec,238  eStopTypeWatchpoint239};240 241enum DNBMemoryPermissions {242  eMemoryPermissionsWritable = (1 << 0),243  eMemoryPermissionsReadable = (1 << 1),244  eMemoryPermissionsExecutable = (1 << 2)245};246 247#define DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH 256248#define DNB_THREAD_STOP_INFO_MAX_EXC_DATA 8249 250// DNBThreadStopInfo251//252// Describes the reason a thread stopped.253struct DNBThreadStopInfo {254  DNBThreadStopType reason;255  char description[DNB_THREAD_STOP_INFO_MAX_DESC_LENGTH];256  union {257    // eStopTypeSignal258    struct {259      uint32_t signo;260    } signal;261 262    // eStopTypeException263    struct {264      uint32_t type;265      nub_size_t data_count;266      nub_addr_t data[DNB_THREAD_STOP_INFO_MAX_EXC_DATA];267    } exception;268 269    // eStopTypeWatchpoint270    struct {271      // The trigger address from the mach exception272      // (likely the contents of the FAR register)273      nub_addr_t mach_exception_addr;274 275      // The trigger address, adjusted to be the start276      // address of one of the existing watchpoints for277      // lldb's benefit.278      nub_addr_t addr;279 280      // The watchpoint hardware index.281      uint32_t hw_idx;282 283      // If the esr_fields bitfields have been filled in.284      bool esr_fields_set;285      struct {286        uint32_t287            iss; // "ISS encoding for an exception from a Watchpoint exception"288        uint32_t wpt;  // Watchpoint number289        bool wptv;     // Watchpoint number Valid290        bool wpf;      // Watchpoint might be false-positive291        bool fnp;      // FAR not Precise292        bool vncr;     // watchpoint from use of VNCR_EL2 reg by EL1293        bool fnv;      // FAR not Valid294        bool cm;       // Cache maintenance295        bool wnr;      // Write not Read296        uint32_t dfsc; // Data Fault Status Code297      } esr_fields;298    } watchpoint;299  } details;300};301 302struct DNBRegisterValue {303  struct DNBRegisterInfo info; // Register information for this register304  union {305    int8_t sint8;306    int16_t sint16;307    int32_t sint32;308    int64_t sint64;309    uint8_t uint8;310    uint16_t uint16;311    uint32_t uint32;312    uint64_t uint64;313    float float32;314    double float64;315    // AArch64 SME's ZA register max size is 64k, this object must be316    // large enough to hold that much data.  The current Apple cores317    // have a much smaller maximum ZA reg size, but there are not318    // multiple copies of this object so increase the static size to319    // maximum possible.320    int8_t v_sint8[65536];321    int16_t v_sint16[32768];322    int32_t v_sint32[16384];323    int64_t v_sint64[8192];324    uint8_t v_uint8[65536];325    uint16_t v_uint16[32768];326    uint32_t v_uint32[16384];327    uint64_t v_uint64[8192];328    float v_float32[16384];329    double v_float64[8192];330    void *pointer;331    char *c_str;332  } value;333};334 335enum DNBSharedLibraryState { eShlibStateUnloaded = 0, eShlibStateLoaded = 1 };336 337#ifndef DNB_MAX_SEGMENT_NAME_LENGTH338#define DNB_MAX_SEGMENT_NAME_LENGTH 32339#endif340 341struct DNBSegment {342  char name[DNB_MAX_SEGMENT_NAME_LENGTH];343  nub_addr_t addr;344  nub_addr_t size;345};346 347struct DNBExecutableImageInfo {348  char name[PATH_MAX]; // Name of the executable image (usually a full path)349  uint32_t350      state; // State of the executable image (see enum DNBSharedLibraryState)351  nub_addr_t header_addr; // Executable header address352  uuid_t uuid;            // Unique identifier for matching with symbols353  uint32_t354      num_segments; // Number of contiguous memory segments to in SEGMENTS array355  DNBSegment *segments; // Array of contiguous memory segments in executable356};357 358struct DNBRegionInfo {359public:360  DNBRegionInfo()361      : addr(0), size(0), permissions(0), flags(), dirty_pages(), vm_types() {}362  nub_addr_t addr;363  nub_addr_t size;364  uint32_t permissions;365  std::vector<std::string> flags;366  std::vector<nub_addr_t> dirty_pages;367  std::vector<std::string> vm_types;368};369 370enum DNBProfileDataScanType {371  eProfileHostCPU = (1 << 0),372  eProfileCPU = (1 << 1),373 374  eProfileThreadsCPU =375      (1 << 2), // By default excludes eProfileThreadName and eProfileQueueName.376  eProfileThreadName =377      (1 << 3), // Assume eProfileThreadsCPU, get thread name as well.378  eProfileQueueName =379      (1 << 4), // Assume eProfileThreadsCPU, get queue name as well.380 381  eProfileHostMemory = (1 << 5),382 383  eProfileMemory = (1 << 6),384  eProfileMemoryAnonymous =385      (1 << 8), // Assume eProfileMemory, get Anonymous memory as well.386 387  eProfileEnergy = (1 << 9),388  eProfileEnergyCPUCap = (1 << 10),389 390  eProfileMemoryCap = (1 << 15),391 392  eProfileAll = 0xffffffff393};394 395typedef nub_addr_t (*DNBCallbackNameToAddress)(nub_process_t pid,396                                               const char *name,397                                               const char *shlib_regex,398                                               void *baton);399typedef nub_size_t (*DNBCallbackCopyExecutableImageInfos)(400    nub_process_t pid, struct DNBExecutableImageInfo **image_infos,401    nub_bool_t only_changed, void *baton);402typedef void (*DNBCallbackLog)(void *baton, uint32_t flags, const char *format,403                               va_list args);404 405#define UNUSED_IF_ASSERT_DISABLED(x) ((void)(x))406 407#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBDEFS_H408