0001 ======
0002 Ptrace
0003 ======
0004
0005 GDB intends to support the following hardware debug features of BookE
0006 processors:
0007
0008 4 hardware breakpoints (IAC)
0009 2 hardware watchpoints (read, write and read-write) (DAC)
0010 2 value conditions for the hardware watchpoints (DVC)
0011
0012 For that, we need to extend ptrace so that GDB can query and set these
0013 resources. Since we're extending, we're trying to create an interface
0014 that's extendable and that covers both BookE and server processors, so
0015 that GDB doesn't need to special-case each of them. We added the
0016 following 3 new ptrace requests.
0017
0018 1. PTRACE_PPC_GETHWDEBUGINFO
0019 ============================
0020
0021 Query for GDB to discover the hardware debug features. The main info to
0022 be returned here is the minimum alignment for the hardware watchpoints.
0023 BookE processors don't have restrictions here, but server processors have
0024 an 8-byte alignment restriction for hardware watchpoints. We'd like to avoid
0025 adding special cases to GDB based on what it sees in AUXV.
0026
0027 Since we're at it, we added other useful info that the kernel can return to
0028 GDB: this query will return the number of hardware breakpoints, hardware
0029 watchpoints and whether it supports a range of addresses and a condition.
0030 The query will fill the following structure provided by the requesting process::
0031
0032 struct ppc_debug_info {
0033 unit32_t version;
0034 unit32_t num_instruction_bps;
0035 unit32_t num_data_bps;
0036 unit32_t num_condition_regs;
0037 unit32_t data_bp_alignment;
0038 unit32_t sizeof_condition; /* size of the DVC register */
0039 uint64_t features; /* bitmask of the individual flags */
0040 };
0041
0042 features will have bits indicating whether there is support for::
0043
0044 #define PPC_DEBUG_FEATURE_INSN_BP_RANGE 0x1
0045 #define PPC_DEBUG_FEATURE_INSN_BP_MASK 0x2
0046 #define PPC_DEBUG_FEATURE_DATA_BP_RANGE 0x4
0047 #define PPC_DEBUG_FEATURE_DATA_BP_MASK 0x8
0048 #define PPC_DEBUG_FEATURE_DATA_BP_DAWR 0x10
0049 #define PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 0x20
0050
0051 2. PTRACE_SETHWDEBUG
0052
0053 Sets a hardware breakpoint or watchpoint, according to the provided structure::
0054
0055 struct ppc_hw_breakpoint {
0056 uint32_t version;
0057 #define PPC_BREAKPOINT_TRIGGER_EXECUTE 0x1
0058 #define PPC_BREAKPOINT_TRIGGER_READ 0x2
0059 #define PPC_BREAKPOINT_TRIGGER_WRITE 0x4
0060 uint32_t trigger_type; /* only some combinations allowed */
0061 #define PPC_BREAKPOINT_MODE_EXACT 0x0
0062 #define PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE 0x1
0063 #define PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE 0x2
0064 #define PPC_BREAKPOINT_MODE_MASK 0x3
0065 uint32_t addr_mode; /* address match mode */
0066
0067 #define PPC_BREAKPOINT_CONDITION_MODE 0x3
0068 #define PPC_BREAKPOINT_CONDITION_NONE 0x0
0069 #define PPC_BREAKPOINT_CONDITION_AND 0x1
0070 #define PPC_BREAKPOINT_CONDITION_EXACT 0x1 /* different name for the same thing as above */
0071 #define PPC_BREAKPOINT_CONDITION_OR 0x2
0072 #define PPC_BREAKPOINT_CONDITION_AND_OR 0x3
0073 #define PPC_BREAKPOINT_CONDITION_BE_ALL 0x00ff0000 /* byte enable bits */
0074 #define PPC_BREAKPOINT_CONDITION_BE(n) (1<<((n)+16))
0075 uint32_t condition_mode; /* break/watchpoint condition flags */
0076
0077 uint64_t addr;
0078 uint64_t addr2;
0079 uint64_t condition_value;
0080 };
0081
0082 A request specifies one event, not necessarily just one register to be set.
0083 For instance, if the request is for a watchpoint with a condition, both the
0084 DAC and DVC registers will be set in the same request.
0085
0086 With this GDB can ask for all kinds of hardware breakpoints and watchpoints
0087 that the BookE supports. COMEFROM breakpoints available in server processors
0088 are not contemplated, but that is out of the scope of this work.
0089
0090 ptrace will return an integer (handle) uniquely identifying the breakpoint or
0091 watchpoint just created. This integer will be used in the PTRACE_DELHWDEBUG
0092 request to ask for its removal. Return -ENOSPC if the requested breakpoint
0093 can't be allocated on the registers.
0094
0095 Some examples of using the structure to:
0096
0097 - set a breakpoint in the first breakpoint register::
0098
0099 p.version = PPC_DEBUG_CURRENT_VERSION;
0100 p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
0101 p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
0102 p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
0103 p.addr = (uint64_t) address;
0104 p.addr2 = 0;
0105 p.condition_value = 0;
0106
0107 - set a watchpoint which triggers on reads in the second watchpoint register::
0108
0109 p.version = PPC_DEBUG_CURRENT_VERSION;
0110 p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
0111 p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
0112 p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
0113 p.addr = (uint64_t) address;
0114 p.addr2 = 0;
0115 p.condition_value = 0;
0116
0117 - set a watchpoint which triggers only with a specific value::
0118
0119 p.version = PPC_DEBUG_CURRENT_VERSION;
0120 p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
0121 p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
0122 p.condition_mode = PPC_BREAKPOINT_CONDITION_AND | PPC_BREAKPOINT_CONDITION_BE_ALL;
0123 p.addr = (uint64_t) address;
0124 p.addr2 = 0;
0125 p.condition_value = (uint64_t) condition;
0126
0127 - set a ranged hardware breakpoint::
0128
0129 p.version = PPC_DEBUG_CURRENT_VERSION;
0130 p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
0131 p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
0132 p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
0133 p.addr = (uint64_t) begin_range;
0134 p.addr2 = (uint64_t) end_range;
0135 p.condition_value = 0;
0136
0137 - set a watchpoint in server processors (BookS)::
0138
0139 p.version = 1;
0140 p.trigger_type = PPC_BREAKPOINT_TRIGGER_RW;
0141 p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
0142 or
0143 p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
0144
0145 p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
0146 p.addr = (uint64_t) begin_range;
0147 /* For PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE addr2 needs to be specified, where
0148 * addr2 - addr <= 8 Bytes.
0149 */
0150 p.addr2 = (uint64_t) end_range;
0151 p.condition_value = 0;
0152
0153 3. PTRACE_DELHWDEBUG
0154
0155 Takes an integer which identifies an existing breakpoint or watchpoint
0156 (i.e., the value returned from PTRACE_SETHWDEBUG), and deletes the
0157 corresponding breakpoint or watchpoint..