Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Simulate breakpoints by patching locations in the target system, for GDB. |
f4f9705a | 2 | |
6aba47ca DJ |
3 | Copyright (C) 1990, 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2000, 2002, |
4 | 2007 Free Software Foundation, Inc. | |
f4f9705a | 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 | |
197e01b6 EZ |
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | Boston, MA 02110-1301, 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 | ||
8181d85f DJ |
36 | /* Insert a breakpoint on targets that don't have any better |
37 | breakpoint support. We read the contents of the target location | |
38 | and stash it, then overwrite it with a breakpoint instruction. | |
39 | BP_TGT->placed_address is the target location in the target | |
40 | machine. BP_TGT->shadow_contents is some memory allocated for | |
41 | saving the target contents. It is guaranteed by the caller to be | |
42 | long enough to save BREAKPOINT_LEN bytes (this is accomplished via | |
43 | BREAKPOINT_MAX). */ | |
c906108c SS |
44 | |
45 | int | |
8181d85f | 46 | default_memory_insert_breakpoint (struct bp_target_info *bp_tgt) |
c906108c SS |
47 | { |
48 | int val; | |
f4f9705a | 49 | const unsigned char *bp; |
c906108c SS |
50 | int bplen; |
51 | ||
52 | /* Determine appropriate breakpoint contents and size for this address. */ | |
8181d85f | 53 | bp = BREAKPOINT_FROM_PC (&bp_tgt->placed_address, &bp_tgt->placed_size); |
c906108c | 54 | if (bp == NULL) |
8a3fe4f8 | 55 | error (_("Software breakpoints not implemented for this target.")); |
c906108c SS |
56 | |
57 | /* Save the memory contents. */ | |
8181d85f DJ |
58 | bp_tgt->shadow_len = bp_tgt->placed_size; |
59 | val = target_read_memory (bp_tgt->placed_address, bp_tgt->shadow_contents, | |
60 | bp_tgt->placed_size); | |
c906108c SS |
61 | |
62 | /* Write the breakpoint. */ | |
63 | if (val == 0) | |
8181d85f DJ |
64 | val = target_write_memory (bp_tgt->placed_address, bp, |
65 | bp_tgt->placed_size); | |
c906108c SS |
66 | |
67 | return val; | |
68 | } | |
69 | ||
70 | ||
71 | int | |
8181d85f | 72 | default_memory_remove_breakpoint (struct bp_target_info *bp_tgt) |
c906108c | 73 | { |
8181d85f DJ |
74 | return target_write_memory (bp_tgt->placed_address, bp_tgt->shadow_contents, |
75 | bp_tgt->placed_size); | |
c906108c | 76 | } |
917317f4 JM |
77 | |
78 | ||
917317f4 | 79 | int |
8181d85f | 80 | memory_insert_breakpoint (struct bp_target_info *bp_tgt) |
917317f4 | 81 | { |
8da95a30 | 82 | return gdbarch_memory_insert_breakpoint (current_gdbarch, bp_tgt); |
917317f4 JM |
83 | } |
84 | ||
917317f4 | 85 | int |
8181d85f | 86 | memory_remove_breakpoint (struct bp_target_info *bp_tgt) |
917317f4 | 87 | { |
8da95a30 | 88 | return gdbarch_memory_remove_breakpoint (current_gdbarch, bp_tgt); |
917317f4 | 89 | } |