1 /* Simulate breakpoints by patching locations in the target system, for GDB.
3 Copyright (C) 1990-2013 Free Software Foundation, Inc.
5 Contributed by Cygnus Support. Written by John Gilmore.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "breakpoint.h"
27 #include "gdb_string.h"
30 /* Insert a breakpoint on targets that don't have any better
31 breakpoint support. We read the contents of the target location
32 and stash it, then overwrite it with a breakpoint instruction.
33 BP_TGT->placed_address is the target location in the target
34 machine. BP_TGT->shadow_contents is some memory allocated for
35 saving the target contents. It is guaranteed by the caller to be
36 long enough to save BREAKPOINT_LEN bytes (this is accomplished via
40 default_memory_insert_breakpoint (struct gdbarch
*gdbarch
,
41 struct bp_target_info
*bp_tgt
)
44 const unsigned char *bp
;
47 /* Determine appropriate breakpoint contents and size for this address. */
48 bp
= gdbarch_breakpoint_from_pc
49 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
51 error (_("Software breakpoints not implemented for this target."));
53 /* Save the memory contents in the shadow_contents buffer and then
54 write the breakpoint instruction. */
55 bp_tgt
->shadow_len
= bp_tgt
->placed_size
;
56 readbuf
= alloca (bp_tgt
->placed_size
);
57 val
= target_read_memory (bp_tgt
->placed_address
, readbuf
,
61 memcpy (bp_tgt
->shadow_contents
, readbuf
, bp_tgt
->placed_size
);
62 val
= target_write_raw_memory (bp_tgt
->placed_address
, bp
,
71 default_memory_remove_breakpoint (struct gdbarch
*gdbarch
,
72 struct bp_target_info
*bp_tgt
)
74 return target_write_raw_memory (bp_tgt
->placed_address
, bp_tgt
->shadow_contents
,
80 memory_insert_breakpoint (struct gdbarch
*gdbarch
,
81 struct bp_target_info
*bp_tgt
)
83 return gdbarch_memory_insert_breakpoint (gdbarch
, bp_tgt
);
87 memory_remove_breakpoint (struct gdbarch
*gdbarch
,
88 struct bp_target_info
*bp_tgt
)
90 return gdbarch_memory_remove_breakpoint (gdbarch
, bp_tgt
);