xref: /netbsd-src/external/gpl3/gdb/dist/gdbserver/mem-break.h (revision 2be465b09aca4bf6e67814eb0e0f409087138d90)
18dffb485Schristos /* Memory breakpoint interfaces for the remote server for GDB.
2*2be465b0Schristos    Copyright (C) 2002-2024 Free Software Foundation, Inc.
38dffb485Schristos 
48dffb485Schristos    Contributed by MontaVista Software.
58dffb485Schristos 
68dffb485Schristos    This file is part of GDB.
78dffb485Schristos 
88dffb485Schristos    This program is free software; you can redistribute it and/or modify
98dffb485Schristos    it under the terms of the GNU General Public License as published by
108dffb485Schristos    the Free Software Foundation; either version 3 of the License, or
118dffb485Schristos    (at your option) any later version.
128dffb485Schristos 
138dffb485Schristos    This program is distributed in the hope that it will be useful,
148dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
158dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
168dffb485Schristos    GNU General Public License for more details.
178dffb485Schristos 
188dffb485Schristos    You should have received a copy of the GNU General Public License
198dffb485Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
208dffb485Schristos 
218dffb485Schristos #ifndef GDBSERVER_MEM_BREAK_H
228dffb485Schristos #define GDBSERVER_MEM_BREAK_H
238dffb485Schristos 
248dffb485Schristos #include "gdbsupport/break-common.h"
258dffb485Schristos 
268dffb485Schristos /* Breakpoints are opaque.  */
278dffb485Schristos struct breakpoint;
288dffb485Schristos struct gdb_breakpoint;
298dffb485Schristos struct fast_tracepoint_jump;
308dffb485Schristos struct raw_breakpoint;
318dffb485Schristos struct process_info;
328dffb485Schristos 
338dffb485Schristos #define Z_PACKET_SW_BP '0'
348dffb485Schristos #define Z_PACKET_HW_BP '1'
358dffb485Schristos #define Z_PACKET_WRITE_WP '2'
368dffb485Schristos #define Z_PACKET_READ_WP '3'
378dffb485Schristos #define Z_PACKET_ACCESS_WP '4'
388dffb485Schristos 
398dffb485Schristos /* The low level breakpoint types.  */
408dffb485Schristos 
418dffb485Schristos enum raw_bkpt_type
428dffb485Schristos   {
438dffb485Schristos     /* Software/memory breakpoint.  */
448dffb485Schristos     raw_bkpt_type_sw,
458dffb485Schristos 
468dffb485Schristos     /* Hardware-assisted breakpoint.  */
478dffb485Schristos     raw_bkpt_type_hw,
488dffb485Schristos 
498dffb485Schristos     /* Hardware-assisted write watchpoint.  */
508dffb485Schristos     raw_bkpt_type_write_wp,
518dffb485Schristos 
528dffb485Schristos     /* Hardware-assisted read watchpoint.  */
538dffb485Schristos     raw_bkpt_type_read_wp,
548dffb485Schristos 
558dffb485Schristos     /* Hardware-assisted access watchpoint.  */
568dffb485Schristos     raw_bkpt_type_access_wp
578dffb485Schristos   };
588dffb485Schristos 
598dffb485Schristos /* Map the protocol breakpoint/watchpoint type Z_TYPE to the internal
608dffb485Schristos    raw breakpoint type.  */
618dffb485Schristos 
628dffb485Schristos enum raw_bkpt_type Z_packet_to_raw_bkpt_type (char z_type);
638dffb485Schristos 
648dffb485Schristos /* Map a raw breakpoint type to an enum target_hw_bp_type.  */
658dffb485Schristos 
668dffb485Schristos enum target_hw_bp_type raw_bkpt_type_to_target_hw_bp_type
678dffb485Schristos   (enum raw_bkpt_type raw_type);
688dffb485Schristos 
698dffb485Schristos /* Create a new GDB breakpoint of type Z_TYPE at ADDR with kind KIND.
708dffb485Schristos    Returns a pointer to the newly created breakpoint on success.  On
718dffb485Schristos    failure returns NULL and sets *ERR to either -1 for error, or 1 if
728dffb485Schristos    Z_TYPE breakpoints are not supported on this target.  */
738dffb485Schristos 
748dffb485Schristos struct gdb_breakpoint *set_gdb_breakpoint (char z_type, CORE_ADDR addr,
758dffb485Schristos 					   int kind, int *err);
768dffb485Schristos 
778dffb485Schristos /* Delete a GDB breakpoint of type Z_TYPE and kind KIND previously
788dffb485Schristos    inserted at ADDR with set_gdb_breakpoint_at.  Returns 0 on success,
798dffb485Schristos    -1 on error, and 1 if Z_TYPE breakpoints are not supported on this
808dffb485Schristos    target.  */
818dffb485Schristos 
828dffb485Schristos int delete_gdb_breakpoint (char z_type, CORE_ADDR addr, int kind);
838dffb485Schristos 
848dffb485Schristos /* Returns TRUE if there's a software or hardware (code) breakpoint at
858dffb485Schristos    ADDR in our tables, inserted, or not.  */
868dffb485Schristos 
878dffb485Schristos int breakpoint_here (CORE_ADDR addr);
888dffb485Schristos 
898dffb485Schristos /* Returns TRUE if there's any inserted software or hardware (code)
908dffb485Schristos    breakpoint set at ADDR.  */
918dffb485Schristos 
928dffb485Schristos int breakpoint_inserted_here (CORE_ADDR addr);
938dffb485Schristos 
948dffb485Schristos /* Returns TRUE if there's any inserted software breakpoint at
958dffb485Schristos    ADDR.  */
968dffb485Schristos 
978dffb485Schristos int software_breakpoint_inserted_here (CORE_ADDR addr);
988dffb485Schristos 
998dffb485Schristos /* Returns TRUE if there's any inserted hardware (code) breakpoint at
1008dffb485Schristos    ADDR.  */
1018dffb485Schristos 
1028dffb485Schristos int hardware_breakpoint_inserted_here (CORE_ADDR addr);
1038dffb485Schristos 
1048dffb485Schristos /* Returns TRUE if there's any single-step breakpoint at ADDR.  */
1058dffb485Schristos 
1068dffb485Schristos int single_step_breakpoint_inserted_here (CORE_ADDR addr);
1078dffb485Schristos 
1088dffb485Schristos /* Clear all breakpoint conditions and commands associated with a
1098dffb485Schristos    breakpoint.  */
1108dffb485Schristos 
1118dffb485Schristos void clear_breakpoint_conditions_and_commands (struct gdb_breakpoint *bp);
1128dffb485Schristos 
1138dffb485Schristos /* Set target-side condition CONDITION to the breakpoint at ADDR.
1148dffb485Schristos    Returns false on failure.  On success, advances CONDITION pointer
1158dffb485Schristos    past the condition and returns true.  */
1168dffb485Schristos 
1178dffb485Schristos int add_breakpoint_condition (struct gdb_breakpoint *bp,
1188dffb485Schristos 			      const char **condition);
1198dffb485Schristos 
1208dffb485Schristos /* Set target-side commands COMMANDS to the breakpoint at ADDR.
1218dffb485Schristos    Returns false on failure.  On success, advances COMMANDS past the
1228dffb485Schristos    commands and returns true.  If PERSIST, the commands should run
1238dffb485Schristos    even while GDB is disconnected.  */
1248dffb485Schristos 
1258dffb485Schristos int add_breakpoint_commands (struct gdb_breakpoint *bp, const char **commands,
1268dffb485Schristos 			     int persist);
1278dffb485Schristos 
1288dffb485Schristos /* Return true if PROC has any persistent command.  */
1298dffb485Schristos bool any_persistent_commands (process_info *proc);
1308dffb485Schristos 
1318dffb485Schristos /* Evaluation condition (if any) at breakpoint BP.  Return 1 if
1328dffb485Schristos    true and 0 otherwise.  */
1338dffb485Schristos 
1348dffb485Schristos int gdb_condition_true_at_breakpoint (CORE_ADDR where);
1358dffb485Schristos 
1368dffb485Schristos int gdb_no_commands_at_breakpoint (CORE_ADDR where);
1378dffb485Schristos 
1388dffb485Schristos void run_breakpoint_commands (CORE_ADDR where);
1398dffb485Schristos 
1408dffb485Schristos /* Returns TRUE if there's a GDB breakpoint (Z0 or Z1) set at
1418dffb485Schristos    WHERE.  */
1428dffb485Schristos 
1438dffb485Schristos int gdb_breakpoint_here (CORE_ADDR where);
1448dffb485Schristos 
1458dffb485Schristos /* Create a new breakpoint at WHERE, and call HANDLER when
1468dffb485Schristos    it is hit.  HANDLER should return 1 if the breakpoint
1478dffb485Schristos    should be deleted, 0 otherwise.  The type of the created
1488dffb485Schristos    breakpoint is other_breakpoint.  */
1498dffb485Schristos 
1508dffb485Schristos struct breakpoint *set_breakpoint_at (CORE_ADDR where,
1518dffb485Schristos 				      int (*handler) (CORE_ADDR));
1528dffb485Schristos 
1538dffb485Schristos /* Delete a breakpoint.  */
1548dffb485Schristos 
1558dffb485Schristos int delete_breakpoint (struct breakpoint *bkpt);
1568dffb485Schristos 
1578dffb485Schristos /* Set a single-step breakpoint at STOP_AT for thread represented by
1588dffb485Schristos    PTID.  */
1598dffb485Schristos 
1608dffb485Schristos void set_single_step_breakpoint (CORE_ADDR stop_at, ptid_t ptid);
1618dffb485Schristos 
1628dffb485Schristos /* Delete all single-step breakpoints of THREAD.  */
1638dffb485Schristos 
1648dffb485Schristos void delete_single_step_breakpoints (struct thread_info *thread);
1658dffb485Schristos 
1668dffb485Schristos /* Reinsert all single-step breakpoints of THREAD.  */
1678dffb485Schristos 
1688dffb485Schristos void reinsert_single_step_breakpoints (struct thread_info *thread);
1698dffb485Schristos 
1708dffb485Schristos /* Uninsert all single-step breakpoints of THREAD.  This still leaves
1718dffb485Schristos    the single-step breakpoints in the table.  */
1728dffb485Schristos 
1738dffb485Schristos void uninsert_single_step_breakpoints (struct thread_info *thread);
1748dffb485Schristos 
1758dffb485Schristos /* Reinsert breakpoints at WHERE (and change their status to
1768dffb485Schristos    inserted).  */
1778dffb485Schristos 
1788dffb485Schristos void reinsert_breakpoints_at (CORE_ADDR where);
1798dffb485Schristos 
1808dffb485Schristos /* The THREAD has single-step breakpoints or not.  */
1818dffb485Schristos 
1828dffb485Schristos int has_single_step_breakpoints (struct thread_info *thread);
1838dffb485Schristos 
1848dffb485Schristos /* Uninsert breakpoints at WHERE (and change their status to
1858dffb485Schristos    uninserted).  This still leaves the breakpoints in the table.  */
1868dffb485Schristos 
1878dffb485Schristos void uninsert_breakpoints_at (CORE_ADDR where);
1888dffb485Schristos 
1898dffb485Schristos /* Reinsert all breakpoints of the current process (and change their
1908dffb485Schristos    status to inserted).  */
1918dffb485Schristos 
1928dffb485Schristos void reinsert_all_breakpoints (void);
1938dffb485Schristos 
1948dffb485Schristos /* Uninsert all breakpoints of the current process (and change their
1958dffb485Schristos    status to uninserted).  This still leaves the breakpoints in the
1968dffb485Schristos    table.  */
1978dffb485Schristos 
1988dffb485Schristos void uninsert_all_breakpoints (void);
1998dffb485Schristos 
2008dffb485Schristos /* See if any breakpoint claims ownership of STOP_PC.  Call the handler for
2018dffb485Schristos    the breakpoint, if found.  */
2028dffb485Schristos 
2038dffb485Schristos void check_breakpoints (CORE_ADDR stop_pc);
2048dffb485Schristos 
2058dffb485Schristos /* See if any breakpoints shadow the target memory area from MEM_ADDR
2068dffb485Schristos    to MEM_ADDR + MEM_LEN.  Update the data already read from the target
2078dffb485Schristos    (in BUF) if necessary.  */
2088dffb485Schristos 
2098dffb485Schristos void check_mem_read (CORE_ADDR mem_addr, unsigned char *buf, int mem_len);
2108dffb485Schristos 
2118dffb485Schristos /* See if any breakpoints shadow the target memory area from MEM_ADDR
2128dffb485Schristos    to MEM_ADDR + MEM_LEN.  Update the data to be written to the target
2138dffb485Schristos    (in BUF, a copy of MYADDR on entry) if necessary, as well as the
2148dffb485Schristos    original data for any breakpoints.  */
2158dffb485Schristos 
2168dffb485Schristos void check_mem_write (CORE_ADDR mem_addr,
2178dffb485Schristos 		      unsigned char *buf, const unsigned char *myaddr, int mem_len);
2188dffb485Schristos 
219*2be465b0Schristos /* Delete all breakpoints, watchpoints, tracepoints, and catchpoints,
220*2be465b0Schristos    and un-insert them from the inferior.  */
2218dffb485Schristos 
2228dffb485Schristos void delete_all_breakpoints (void);
2238dffb485Schristos 
2248dffb485Schristos /* Clear the "inserted" flag in all breakpoints of PROC.  */
2258dffb485Schristos 
2268dffb485Schristos void mark_breakpoints_out (struct process_info *proc);
2278dffb485Schristos 
228*2be465b0Schristos /* Delete all breakpoints, watchpoints, tracepoints, and catchpoints,
229*2be465b0Schristos    but do not try to un-insert them from the inferior.  */
2308dffb485Schristos 
2318dffb485Schristos void free_all_breakpoints (struct process_info *proc);
2328dffb485Schristos 
2338dffb485Schristos /* Check if breakpoints still seem to be inserted in the inferior.  */
2348dffb485Schristos 
2358dffb485Schristos void validate_breakpoints (void);
2368dffb485Schristos 
2378dffb485Schristos /* Insert a fast tracepoint jump at WHERE, using instruction INSN, of
2388dffb485Schristos    LENGTH bytes.  */
2398dffb485Schristos 
2408dffb485Schristos struct fast_tracepoint_jump *set_fast_tracepoint_jump (CORE_ADDR where,
2418dffb485Schristos 						       unsigned char *insn,
2428dffb485Schristos 						       ULONGEST length);
2438dffb485Schristos 
2448dffb485Schristos /* Increment reference counter of JP.  */
2458dffb485Schristos void inc_ref_fast_tracepoint_jump (struct fast_tracepoint_jump *jp);
2468dffb485Schristos 
2478dffb485Schristos /* Delete fast tracepoint jump TODEL from our tables, and uninsert if
2488dffb485Schristos    from memory.  */
2498dffb485Schristos 
2508dffb485Schristos int delete_fast_tracepoint_jump (struct fast_tracepoint_jump *todel);
2518dffb485Schristos 
2528dffb485Schristos /* Returns true if there's fast tracepoint jump set at WHERE.  */
2538dffb485Schristos 
2548dffb485Schristos int fast_tracepoint_jump_here (CORE_ADDR);
2558dffb485Schristos 
2568dffb485Schristos /* Uninsert fast tracepoint jumps at WHERE (and change their status to
2578dffb485Schristos    uninserted).  This still leaves the tracepoints in the table.  */
2588dffb485Schristos 
2598dffb485Schristos void uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc);
2608dffb485Schristos 
2618dffb485Schristos /* Reinsert fast tracepoint jumps at WHERE (and change their status to
2628dffb485Schristos    inserted).  */
2638dffb485Schristos 
2648dffb485Schristos void reinsert_fast_tracepoint_jumps_at (CORE_ADDR where);
2658dffb485Schristos 
2668dffb485Schristos /* Insert a memory breakpoint.  */
2678dffb485Schristos 
2688dffb485Schristos int insert_memory_breakpoint (struct raw_breakpoint *bp);
2698dffb485Schristos 
2708dffb485Schristos /* Remove a previously inserted memory breakpoint.  */
2718dffb485Schristos 
2728dffb485Schristos int remove_memory_breakpoint (struct raw_breakpoint *bp);
2738dffb485Schristos 
2748dffb485Schristos /* Create a new breakpoint list in CHILD_THREAD's process that is a
2758dffb485Schristos    copy of breakpoint list in PARENT_THREAD's process.  */
2768dffb485Schristos 
2778dffb485Schristos void clone_all_breakpoints (struct thread_info *child_thread,
2788dffb485Schristos 			    const struct thread_info *parent_thread);
2798dffb485Schristos 
2808dffb485Schristos #endif /* GDBSERVER_MEM_BREAK_H */
281