1 /* Simulate breakpoints by patching locations in the target system, for GDB.
2 Copyright 1990, 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support. Written by John Gilmore.
6 This file is part of GDB.
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 2 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 /* This file is only useful if BREAKPOINT is set. If not, we punt. */
28 #include "breakpoint.h"
33 /* Use the program counter to determine the contents and size
34 of a breakpoint instruction. If no target-dependent macro
35 BREAKPOINT_FROM_PC has been defined to implement this function,
36 assume that the breakpoint doesn't depend on the PC, and
37 use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
38 Return a pointer to a string of bytes that encode a breakpoint
39 instruction, stores the length of the string to *lenptr,
40 and optionally adjust the pc to point to the correct memory location
41 for inserting the breakpoint. */
44 memory_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
46 /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
47 breakpoint. On some machines, breakpoints are handled by the
48 target environment and we don't have to worry about them here. */
50 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
52 static unsigned char big_break_insn[] = BIG_BREAKPOINT;
53 *lenptr = sizeof (big_break_insn);
54 return big_break_insn;
57 #ifdef LITTLE_BREAKPOINT
58 if (TARGET_BYTE_ORDER != BIG_ENDIAN)
60 static unsigned char little_break_insn[] = LITTLE_BREAKPOINT;
61 *lenptr = sizeof (little_break_insn);
62 return little_break_insn;
67 static unsigned char break_insn[] = BREAKPOINT;
68 *lenptr = sizeof (break_insn);
77 /* Insert a breakpoint on targets that don't have any better breakpoint
78 support. We read the contents of the target location and stash it,
79 then overwrite it with a breakpoint instruction. ADDR is the target
80 location in the target machine. CONTENTS_CACHE is a pointer to
81 memory allocated for saving the target contents. It is guaranteed
82 by the caller to be long enough to save BREAKPOINT_LEN bytes (this
83 is accomplished via BREAKPOINT_MAX). */
86 default_memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
92 /* Determine appropriate breakpoint contents and size for this address. */
93 bp = BREAKPOINT_FROM_PC (&addr, &bplen);
95 error ("Software breakpoints not implemented for this target.");
97 /* Save the memory contents. */
98 val = target_read_memory (addr, contents_cache, bplen);
100 /* Write the breakpoint. */
102 val = target_write_memory (addr, (char *) bp, bplen);
109 default_memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
114 /* Determine appropriate breakpoint contents and size for this address. */
115 bp = BREAKPOINT_FROM_PC (&addr, &bplen);
117 error ("Software breakpoints not implemented for this target.");
119 return target_write_memory (addr, contents_cache, bplen);
124 memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
126 return MEMORY_INSERT_BREAKPOINT(addr, contents_cache);
130 memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
132 return MEMORY_REMOVE_BREAKPOINT(addr, contents_cache);