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