1 /* Simulate breakpoints by patching locations in the target system, for GDB.
3 Copyright 1990, 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2000,
4 2002 Free Software Foundation, Inc.
6 Contributed by Cygnus Support. Written by John Gilmore.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
27 /* This file is only useful if BREAKPOINT is set. If not, we punt. */
30 #include "breakpoint.h"
35 /* Use the program counter to determine the contents and size
36 of a breakpoint instruction. If no target-dependent macro
37 BREAKPOINT_FROM_PC has been defined to implement this function,
38 assume that the breakpoint doesn't depend on the PC, and
39 use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
40 Return a pointer to a string of bytes that encode a breakpoint
41 instruction, stores the length of the string to *lenptr,
42 and optionally adjust the pc to point to the correct memory location
43 for inserting the breakpoint. */
46 memory_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
48 /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
49 breakpoint. On some machines, breakpoints are handled by the
50 target environment and we don't have to worry about them here. */
52 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
54 static unsigned char big_break_insn[] = BIG_BREAKPOINT;
55 *lenptr = sizeof (big_break_insn);
56 return big_break_insn;
59 #ifdef LITTLE_BREAKPOINT
60 if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
62 static unsigned char little_break_insn[] = LITTLE_BREAKPOINT;
63 *lenptr = sizeof (little_break_insn);
64 return little_break_insn;
69 static unsigned char break_insn[] = BREAKPOINT;
70 *lenptr = sizeof (break_insn);
79 /* Insert a breakpoint on targets that don't have any better breakpoint
80 support. We read the contents of the target location and stash it,
81 then overwrite it with a breakpoint instruction. ADDR is the target
82 location in the target machine. CONTENTS_CACHE is a pointer to
83 memory allocated for saving the target contents. It is guaranteed
84 by the caller to be long enough to save BREAKPOINT_LEN bytes (this
85 is accomplished via BREAKPOINT_MAX). */
88 default_memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
91 const unsigned char *bp;
94 /* Determine appropriate breakpoint contents and size for this address. */
95 bp = BREAKPOINT_FROM_PC (&addr, &bplen);
97 error ("Software breakpoints not implemented for this target.");
99 /* Save the memory contents. */
100 val = target_read_memory (addr, contents_cache, bplen);
102 /* Write the breakpoint. */
104 val = target_write_memory (addr, (char *) bp, bplen);
111 default_memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
113 const unsigned char *bp;
116 /* Determine appropriate breakpoint contents and size for this address. */
117 bp = BREAKPOINT_FROM_PC (&addr, &bplen);
119 error ("Software breakpoints not implemented for this target.");
121 return target_write_memory (addr, contents_cache, bplen);
126 memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
128 return MEMORY_INSERT_BREAKPOINT(addr, contents_cache);
132 memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
134 return MEMORY_REMOVE_BREAKPOINT(addr, contents_cache);