1 /* Simulate breakpoints by patching locations in the target system, for GDB.
3 Copyright (C) 1990-2014 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 /* Insert a breakpoint on targets that don't have any better
28 breakpoint support. We read the contents of the target location
29 and stash it, then overwrite it with a breakpoint instruction.
30 BP_TGT->placed_address is the target location in the target
31 machine. BP_TGT->shadow_contents is some memory allocated for
32 saving the target contents. It is guaranteed by the caller to be
33 long enough to save BREAKPOINT_LEN bytes (this is accomplished via
37 default_memory_insert_breakpoint (struct gdbarch
*gdbarch
,
38 struct bp_target_info
*bp_tgt
)
40 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
41 const unsigned char *bp
;
46 /* Determine appropriate breakpoint contents and size for this address. */
47 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &bplen
);
49 error (_("Software breakpoints not implemented for this target."));
51 bp_tgt
->placed_address
= addr
;
52 bp_tgt
->placed_size
= bplen
;
54 /* Save the memory contents in the shadow_contents buffer and then
55 write the breakpoint instruction. */
56 bp_tgt
->shadow_len
= bplen
;
57 readbuf
= alloca (bplen
);
58 val
= target_read_memory (addr
, readbuf
, bplen
);
61 memcpy (bp_tgt
->shadow_contents
, readbuf
, bplen
);
62 val
= target_write_raw_memory (addr
, bp
, bplen
);
70 default_memory_remove_breakpoint (struct gdbarch
*gdbarch
,
71 struct bp_target_info
*bp_tgt
)
73 return target_write_raw_memory (bp_tgt
->placed_address
, bp_tgt
->shadow_contents
,
79 memory_insert_breakpoint (struct target_ops
*ops
, struct gdbarch
*gdbarch
,
80 struct bp_target_info
*bp_tgt
)
82 return gdbarch_memory_insert_breakpoint (gdbarch
, bp_tgt
);
86 memory_remove_breakpoint (struct target_ops
*ops
, struct gdbarch
*gdbarch
,
87 struct bp_target_info
*bp_tgt
)
89 return gdbarch_memory_remove_breakpoint (gdbarch
, bp_tgt
);
93 memory_validate_breakpoint (struct gdbarch
*gdbarch
,
94 struct bp_target_info
*bp_tgt
)
96 CORE_ADDR addr
= bp_tgt
->placed_address
;
100 gdb_byte cur_contents
[BREAKPOINT_MAX
];
101 struct cleanup
*cleanup
;
104 /* Determine appropriate breakpoint contents and size for this
106 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &bplen
);
108 if (bp
== NULL
|| bp_tgt
->placed_size
!= bplen
)
111 /* Make sure we see the memory breakpoints. */
112 cleanup
= make_show_memory_breakpoints_cleanup (1);
113 val
= target_read_memory (addr
, cur_contents
, bplen
);
115 /* If our breakpoint is no longer at the address, this means that
116 the program modified the code on us, so it is wrong to put back
118 ret
= (val
== 0 && memcmp (bp
, cur_contents
, bplen
) == 0);
120 do_cleanups (cleanup
);
This page took 0.032628 seconds and 4 git commands to generate.