| 1 | /* Memory breakpoint interfaces for the remote server for GDB. |
| 2 | Copyright (C) 2002-2018 Free Software Foundation, Inc. |
| 3 | |
| 4 | Contributed by MontaVista Software. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | #ifndef MEM_BREAK_H |
| 22 | #define MEM_BREAK_H |
| 23 | |
| 24 | #include "break-common.h" |
| 25 | |
| 26 | /* Breakpoints are opaque. */ |
| 27 | struct breakpoint; |
| 28 | struct gdb_breakpoint; |
| 29 | struct fast_tracepoint_jump; |
| 30 | struct raw_breakpoint; |
| 31 | struct process_info; |
| 32 | |
| 33 | #define Z_PACKET_SW_BP '0' |
| 34 | #define Z_PACKET_HW_BP '1' |
| 35 | #define Z_PACKET_WRITE_WP '2' |
| 36 | #define Z_PACKET_READ_WP '3' |
| 37 | #define Z_PACKET_ACCESS_WP '4' |
| 38 | |
| 39 | /* The low level breakpoint types. */ |
| 40 | |
| 41 | enum raw_bkpt_type |
| 42 | { |
| 43 | /* Software/memory breakpoint. */ |
| 44 | raw_bkpt_type_sw, |
| 45 | |
| 46 | /* Hardware-assisted breakpoint. */ |
| 47 | raw_bkpt_type_hw, |
| 48 | |
| 49 | /* Hardware-assisted write watchpoint. */ |
| 50 | raw_bkpt_type_write_wp, |
| 51 | |
| 52 | /* Hardware-assisted read watchpoint. */ |
| 53 | raw_bkpt_type_read_wp, |
| 54 | |
| 55 | /* Hardware-assisted access watchpoint. */ |
| 56 | raw_bkpt_type_access_wp |
| 57 | }; |
| 58 | |
| 59 | /* Map the protocol breakpoint/watchpoint type Z_TYPE to the internal |
| 60 | raw breakpoint type. */ |
| 61 | |
| 62 | enum raw_bkpt_type Z_packet_to_raw_bkpt_type (char z_type); |
| 63 | |
| 64 | /* Map a raw breakpoint type to an enum target_hw_bp_type. */ |
| 65 | |
| 66 | enum target_hw_bp_type raw_bkpt_type_to_target_hw_bp_type |
| 67 | (enum raw_bkpt_type raw_type); |
| 68 | |
| 69 | /* Create a new GDB breakpoint of type Z_TYPE at ADDR with kind KIND. |
| 70 | Returns a pointer to the newly created breakpoint on success. On |
| 71 | failure returns NULL and sets *ERR to either -1 for error, or 1 if |
| 72 | Z_TYPE breakpoints are not supported on this target. */ |
| 73 | |
| 74 | struct gdb_breakpoint *set_gdb_breakpoint (char z_type, CORE_ADDR addr, |
| 75 | int kind, int *err); |
| 76 | |
| 77 | /* Delete a GDB breakpoint of type Z_TYPE and kind KIND previously |
| 78 | inserted at ADDR with set_gdb_breakpoint_at. Returns 0 on success, |
| 79 | -1 on error, and 1 if Z_TYPE breakpoints are not supported on this |
| 80 | target. */ |
| 81 | |
| 82 | int delete_gdb_breakpoint (char z_type, CORE_ADDR addr, int kind); |
| 83 | |
| 84 | /* Returns TRUE if there's a software or hardware (code) breakpoint at |
| 85 | ADDR in our tables, inserted, or not. */ |
| 86 | |
| 87 | int breakpoint_here (CORE_ADDR addr); |
| 88 | |
| 89 | /* Returns TRUE if there's any inserted software or hardware (code) |
| 90 | breakpoint set at ADDR. */ |
| 91 | |
| 92 | int breakpoint_inserted_here (CORE_ADDR addr); |
| 93 | |
| 94 | /* Returns TRUE if there's any inserted software breakpoint at |
| 95 | ADDR. */ |
| 96 | |
| 97 | int software_breakpoint_inserted_here (CORE_ADDR addr); |
| 98 | |
| 99 | /* Returns TRUE if there's any inserted hardware (code) breakpoint at |
| 100 | ADDR. */ |
| 101 | |
| 102 | int hardware_breakpoint_inserted_here (CORE_ADDR addr); |
| 103 | |
| 104 | /* Returns TRUE if there's any single-step breakpoint at ADDR. */ |
| 105 | |
| 106 | int single_step_breakpoint_inserted_here (CORE_ADDR addr); |
| 107 | |
| 108 | /* Clear all breakpoint conditions and commands associated with a |
| 109 | breakpoint. */ |
| 110 | |
| 111 | void clear_breakpoint_conditions_and_commands (struct gdb_breakpoint *bp); |
| 112 | |
| 113 | /* Set target-side condition CONDITION to the breakpoint at ADDR. |
| 114 | Returns false on failure. On success, advances CONDITION pointer |
| 115 | past the condition and returns true. */ |
| 116 | |
| 117 | int add_breakpoint_condition (struct gdb_breakpoint *bp, |
| 118 | const char **condition); |
| 119 | |
| 120 | /* Set target-side commands COMMANDS to the breakpoint at ADDR. |
| 121 | Returns false on failure. On success, advances COMMANDS past the |
| 122 | commands and returns true. If PERSIST, the commands should run |
| 123 | even while GDB is disconnected. */ |
| 124 | |
| 125 | int add_breakpoint_commands (struct gdb_breakpoint *bp, const char **commands, |
| 126 | int persist); |
| 127 | |
| 128 | int any_persistent_commands (void); |
| 129 | |
| 130 | /* Evaluation condition (if any) at breakpoint BP. Return 1 if |
| 131 | true and 0 otherwise. */ |
| 132 | |
| 133 | int gdb_condition_true_at_breakpoint (CORE_ADDR where); |
| 134 | |
| 135 | int gdb_no_commands_at_breakpoint (CORE_ADDR where); |
| 136 | |
| 137 | void run_breakpoint_commands (CORE_ADDR where); |
| 138 | |
| 139 | /* Returns TRUE if there's a GDB breakpoint (Z0 or Z1) set at |
| 140 | WHERE. */ |
| 141 | |
| 142 | int gdb_breakpoint_here (CORE_ADDR where); |
| 143 | |
| 144 | /* Create a new breakpoint at WHERE, and call HANDLER when |
| 145 | it is hit. HANDLER should return 1 if the breakpoint |
| 146 | should be deleted, 0 otherwise. The type of the created |
| 147 | breakpoint is other_breakpoint. */ |
| 148 | |
| 149 | struct breakpoint *set_breakpoint_at (CORE_ADDR where, |
| 150 | int (*handler) (CORE_ADDR)); |
| 151 | |
| 152 | /* Delete a breakpoint. */ |
| 153 | |
| 154 | int delete_breakpoint (struct breakpoint *bkpt); |
| 155 | |
| 156 | /* Set a single-step breakpoint at STOP_AT for thread represented by |
| 157 | PTID. */ |
| 158 | |
| 159 | void set_single_step_breakpoint (CORE_ADDR stop_at, ptid_t ptid); |
| 160 | |
| 161 | /* Delete all single-step breakpoints of THREAD. */ |
| 162 | |
| 163 | void delete_single_step_breakpoints (struct thread_info *thread); |
| 164 | |
| 165 | /* Reinsert all single-step breakpoints of THREAD. */ |
| 166 | |
| 167 | void reinsert_single_step_breakpoints (struct thread_info *thread); |
| 168 | |
| 169 | /* Uninsert all single-step breakpoints of THREAD. This still leaves |
| 170 | the single-step breakpoints in the table. */ |
| 171 | |
| 172 | void uninsert_single_step_breakpoints (struct thread_info *thread); |
| 173 | |
| 174 | /* Reinsert breakpoints at WHERE (and change their status to |
| 175 | inserted). */ |
| 176 | |
| 177 | void reinsert_breakpoints_at (CORE_ADDR where); |
| 178 | |
| 179 | /* The THREAD has single-step breakpoints or not. */ |
| 180 | |
| 181 | int has_single_step_breakpoints (struct thread_info *thread); |
| 182 | |
| 183 | /* Uninsert breakpoints at WHERE (and change their status to |
| 184 | uninserted). This still leaves the breakpoints in the table. */ |
| 185 | |
| 186 | void uninsert_breakpoints_at (CORE_ADDR where); |
| 187 | |
| 188 | /* Reinsert all breakpoints of the current process (and change their |
| 189 | status to inserted). */ |
| 190 | |
| 191 | void reinsert_all_breakpoints (void); |
| 192 | |
| 193 | /* Uninsert all breakpoints of the current process (and change their |
| 194 | status to uninserted). This still leaves the breakpoints in the |
| 195 | table. */ |
| 196 | |
| 197 | void uninsert_all_breakpoints (void); |
| 198 | |
| 199 | /* See if any breakpoint claims ownership of STOP_PC. Call the handler for |
| 200 | the breakpoint, if found. */ |
| 201 | |
| 202 | void check_breakpoints (CORE_ADDR stop_pc); |
| 203 | |
| 204 | /* See if any breakpoints shadow the target memory area from MEM_ADDR |
| 205 | to MEM_ADDR + MEM_LEN. Update the data already read from the target |
| 206 | (in BUF) if necessary. */ |
| 207 | |
| 208 | void check_mem_read (CORE_ADDR mem_addr, unsigned char *buf, int mem_len); |
| 209 | |
| 210 | /* See if any breakpoints shadow the target memory area from MEM_ADDR |
| 211 | to MEM_ADDR + MEM_LEN. Update the data to be written to the target |
| 212 | (in BUF, a copy of MYADDR on entry) if necessary, as well as the |
| 213 | original data for any breakpoints. */ |
| 214 | |
| 215 | void check_mem_write (CORE_ADDR mem_addr, |
| 216 | unsigned char *buf, const unsigned char *myaddr, int mem_len); |
| 217 | |
| 218 | /* Delete all breakpoints. */ |
| 219 | |
| 220 | void delete_all_breakpoints (void); |
| 221 | |
| 222 | /* Clear the "inserted" flag in all breakpoints of PROC. */ |
| 223 | |
| 224 | void mark_breakpoints_out (struct process_info *proc); |
| 225 | |
| 226 | /* Delete all breakpoints, but do not try to un-insert them from the |
| 227 | inferior. */ |
| 228 | |
| 229 | void free_all_breakpoints (struct process_info *proc); |
| 230 | |
| 231 | /* Check if breakpoints still seem to be inserted in the inferior. */ |
| 232 | |
| 233 | void validate_breakpoints (void); |
| 234 | |
| 235 | /* Insert a fast tracepoint jump at WHERE, using instruction INSN, of |
| 236 | LENGTH bytes. */ |
| 237 | |
| 238 | struct fast_tracepoint_jump *set_fast_tracepoint_jump (CORE_ADDR where, |
| 239 | unsigned char *insn, |
| 240 | ULONGEST length); |
| 241 | |
| 242 | /* Increment reference counter of JP. */ |
| 243 | void inc_ref_fast_tracepoint_jump (struct fast_tracepoint_jump *jp); |
| 244 | |
| 245 | /* Delete fast tracepoint jump TODEL from our tables, and uninsert if |
| 246 | from memory. */ |
| 247 | |
| 248 | int delete_fast_tracepoint_jump (struct fast_tracepoint_jump *todel); |
| 249 | |
| 250 | /* Returns true if there's fast tracepoint jump set at WHERE. */ |
| 251 | |
| 252 | int fast_tracepoint_jump_here (CORE_ADDR); |
| 253 | |
| 254 | /* Uninsert fast tracepoint jumps at WHERE (and change their status to |
| 255 | uninserted). This still leaves the tracepoints in the table. */ |
| 256 | |
| 257 | void uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc); |
| 258 | |
| 259 | /* Reinsert fast tracepoint jumps at WHERE (and change their status to |
| 260 | inserted). */ |
| 261 | |
| 262 | void reinsert_fast_tracepoint_jumps_at (CORE_ADDR where); |
| 263 | |
| 264 | /* Insert a memory breakpoint. */ |
| 265 | |
| 266 | int insert_memory_breakpoint (struct raw_breakpoint *bp); |
| 267 | |
| 268 | /* Remove a previously inserted memory breakpoint. */ |
| 269 | |
| 270 | int remove_memory_breakpoint (struct raw_breakpoint *bp); |
| 271 | |
| 272 | /* Create a new breakpoint list in CHILD_THREAD's process that is a |
| 273 | copy of breakpoint list in PARENT_THREAD's process. */ |
| 274 | |
| 275 | void clone_all_breakpoints (struct thread_info *child_thread, |
| 276 | const struct thread_info *parent_thread); |
| 277 | |
| 278 | #endif /* MEM_BREAK_H */ |