1e93f7393Sniklas /* Simulate breakpoints by patching locations in the target system, for GDB.
2*b725ae77Skettenis
3*b725ae77Skettenis Copyright 1990, 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2000,
4*b725ae77Skettenis 2002 Free Software Foundation, Inc.
5*b725ae77Skettenis
6e93f7393Sniklas Contributed by Cygnus Support. Written by John Gilmore.
7e93f7393Sniklas
8e93f7393Sniklas This file is part of GDB.
9e93f7393Sniklas
10e93f7393Sniklas This program is free software; you can redistribute it and/or modify
11e93f7393Sniklas it under the terms of the GNU General Public License as published by
12e93f7393Sniklas the Free Software Foundation; either version 2 of the License, or
13e93f7393Sniklas (at your option) any later version.
14e93f7393Sniklas
15e93f7393Sniklas This program is distributed in the hope that it will be useful,
16e93f7393Sniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
17e93f7393Sniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18e93f7393Sniklas GNU General Public License for more details.
19e93f7393Sniklas
20e93f7393Sniklas You should have received a copy of the GNU General Public License
21e93f7393Sniklas along with this program; if not, write to the Free Software
22*b725ae77Skettenis Foundation, Inc., 59 Temple Place - Suite 330,
23*b725ae77Skettenis Boston, MA 02111-1307, USA. */
24e93f7393Sniklas
25e93f7393Sniklas #include "defs.h"
26e93f7393Sniklas
27*b725ae77Skettenis /* This file is only useful if BREAKPOINT_FROM_PC is set. If not, we
28*b725ae77Skettenis punt. */
29e93f7393Sniklas
30e93f7393Sniklas #include "symtab.h"
31e93f7393Sniklas #include "breakpoint.h"
32e93f7393Sniklas #include "inferior.h"
33e93f7393Sniklas #include "target.h"
34e93f7393Sniklas
35e93f7393Sniklas
36e93f7393Sniklas /* Insert a breakpoint on targets that don't have any better breakpoint
37e93f7393Sniklas support. We read the contents of the target location and stash it,
38e93f7393Sniklas then overwrite it with a breakpoint instruction. ADDR is the target
39e93f7393Sniklas location in the target machine. CONTENTS_CACHE is a pointer to
40e93f7393Sniklas memory allocated for saving the target contents. It is guaranteed
41e93f7393Sniklas by the caller to be long enough to save BREAKPOINT_LEN bytes (this
42e93f7393Sniklas is accomplished via BREAKPOINT_MAX). */
43e93f7393Sniklas
44e93f7393Sniklas int
default_memory_insert_breakpoint(CORE_ADDR addr,char * contents_cache)45*b725ae77Skettenis default_memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
46e93f7393Sniklas {
47e93f7393Sniklas int val;
48*b725ae77Skettenis const unsigned char *bp;
49*b725ae77Skettenis int bplen;
50e93f7393Sniklas
51*b725ae77Skettenis /* Determine appropriate breakpoint contents and size for this address. */
52*b725ae77Skettenis bp = BREAKPOINT_FROM_PC (&addr, &bplen);
53*b725ae77Skettenis if (bp == NULL)
54*b725ae77Skettenis error ("Software breakpoints not implemented for this target.");
55e93f7393Sniklas
56*b725ae77Skettenis /* Save the memory contents. */
57*b725ae77Skettenis val = target_read_memory (addr, contents_cache, bplen);
58*b725ae77Skettenis
59*b725ae77Skettenis /* Write the breakpoint. */
60e93f7393Sniklas if (val == 0)
61*b725ae77Skettenis val = target_write_memory (addr, (char *) bp, bplen);
62e93f7393Sniklas
63e93f7393Sniklas return val;
64e93f7393Sniklas }
65e93f7393Sniklas
66e93f7393Sniklas
67e93f7393Sniklas int
default_memory_remove_breakpoint(CORE_ADDR addr,char * contents_cache)68*b725ae77Skettenis default_memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
69e93f7393Sniklas {
70*b725ae77Skettenis const unsigned char *bp;
71*b725ae77Skettenis int bplen;
72*b725ae77Skettenis
73*b725ae77Skettenis /* Determine appropriate breakpoint contents and size for this address. */
74*b725ae77Skettenis bp = BREAKPOINT_FROM_PC (&addr, &bplen);
75*b725ae77Skettenis if (bp == NULL)
76*b725ae77Skettenis error ("Software breakpoints not implemented for this target.");
77*b725ae77Skettenis
78*b725ae77Skettenis return target_write_memory (addr, contents_cache, bplen);
79e93f7393Sniklas }
80e93f7393Sniklas
81e93f7393Sniklas
82e93f7393Sniklas int
memory_insert_breakpoint(CORE_ADDR addr,char * contents_cache)83*b725ae77Skettenis memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
84e93f7393Sniklas {
85*b725ae77Skettenis return MEMORY_INSERT_BREAKPOINT(addr, contents_cache);
86e93f7393Sniklas }
87e93f7393Sniklas
88e93f7393Sniklas int
memory_remove_breakpoint(CORE_ADDR addr,char * contents_cache)89*b725ae77Skettenis memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
90e93f7393Sniklas {
91*b725ae77Skettenis return MEMORY_REMOVE_BREAKPOINT(addr, contents_cache);
92e93f7393Sniklas }
93