Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Simulate breakpoints by patching locations in the target system, for GDB. |
f4f9705a AC |
2 | |
3 | Copyright 1990, 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2000, | |
4 | 2002 Free Software Foundation, Inc. | |
5 | ||
c906108c SS |
6 | Contributed by Cygnus Support. Written by John Gilmore. |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
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. | |
c906108c | 14 | |
c5aa993b JM |
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. | |
c906108c | 19 | |
c5aa993b JM |
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. */ | |
c906108c SS |
24 | |
25 | #include "defs.h" | |
26 | ||
aaab4dba AC |
27 | /* This file is only useful if BREAKPOINT_FROM_PC is set. If not, we |
28 | punt. */ | |
c906108c SS |
29 | |
30 | #include "symtab.h" | |
31 | #include "breakpoint.h" | |
32 | #include "inferior.h" | |
33 | #include "target.h" | |
34 | ||
35 | ||
c906108c SS |
36 | /* Insert a breakpoint on targets that don't have any better breakpoint |
37 | support. We read the contents of the target location and stash it, | |
38 | then overwrite it with a breakpoint instruction. ADDR is the target | |
39 | location in the target machine. CONTENTS_CACHE is a pointer to | |
40 | memory allocated for saving the target contents. It is guaranteed | |
41 | by the caller to be long enough to save BREAKPOINT_LEN bytes (this | |
42 | is accomplished via BREAKPOINT_MAX). */ | |
43 | ||
44 | int | |
5a168c78 | 45 | default_memory_insert_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache) |
c906108c SS |
46 | { |
47 | int val; | |
f4f9705a | 48 | const unsigned char *bp; |
c906108c SS |
49 | int bplen; |
50 | ||
51 | /* Determine appropriate breakpoint contents and size for this address. */ | |
52 | bp = BREAKPOINT_FROM_PC (&addr, &bplen); | |
53 | if (bp == NULL) | |
8a3fe4f8 | 54 | error (_("Software breakpoints not implemented for this target.")); |
c906108c SS |
55 | |
56 | /* Save the memory contents. */ | |
57 | val = target_read_memory (addr, contents_cache, bplen); | |
58 | ||
59 | /* Write the breakpoint. */ | |
60 | if (val == 0) | |
1b0ba102 | 61 | val = target_write_memory (addr, bp, bplen); |
c906108c SS |
62 | |
63 | return val; | |
64 | } | |
65 | ||
66 | ||
67 | int | |
5a168c78 | 68 | default_memory_remove_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache) |
c906108c | 69 | { |
5a168c78 | 70 | const bfd_byte *bp; |
c906108c SS |
71 | int bplen; |
72 | ||
73 | /* Determine appropriate breakpoint contents and size for this address. */ | |
74 | bp = BREAKPOINT_FROM_PC (&addr, &bplen); | |
75 | if (bp == NULL) | |
8a3fe4f8 | 76 | error (_("Software breakpoints not implemented for this target.")); |
c906108c SS |
77 | |
78 | return target_write_memory (addr, contents_cache, bplen); | |
79 | } | |
917317f4 JM |
80 | |
81 | ||
917317f4 | 82 | int |
5a168c78 | 83 | memory_insert_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache) |
917317f4 JM |
84 | { |
85 | return MEMORY_INSERT_BREAKPOINT(addr, contents_cache); | |
86 | } | |
87 | ||
917317f4 | 88 | int |
5a168c78 | 89 | memory_remove_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache) |
917317f4 JM |
90 | { |
91 | return MEMORY_REMOVE_BREAKPOINT(addr, contents_cache); | |
92 | } |