Update copyright year in gdb/gdbserver/gdbreplay version output.
[deliverable/binutils-gdb.git] / gdb / mem-break.c
CommitLineData
c906108c 1/* Simulate breakpoints by patching locations in the target system, for GDB.
f4f9705a 2
0b302171
JB
3 Copyright (C) 1990-1993, 1995, 1997-2000, 2002, 2007-2012 Free
4 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
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
c5aa993b 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 20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
22
23#include "defs.h"
24
aaab4dba
AC
25/* This file is only useful if BREAKPOINT_FROM_PC is set. If not, we
26 punt. */
c906108c
SS
27
28#include "symtab.h"
29#include "breakpoint.h"
30#include "inferior.h"
31#include "target.h"
35c63cd8 32#include "gdb_string.h"
c906108c
SS
33
34
8181d85f
DJ
35/* Insert a breakpoint on targets that don't have any better
36 breakpoint support. We read the contents of the target location
37 and stash it, then overwrite it with a breakpoint instruction.
38 BP_TGT->placed_address is the target location in the target
39 machine. BP_TGT->shadow_contents is some memory allocated for
40 saving the target contents. It is guaranteed by the caller to be
41 long enough to save BREAKPOINT_LEN bytes (this is accomplished via
42 BREAKPOINT_MAX). */
c906108c
SS
43
44int
ae4b2284
MD
45default_memory_insert_breakpoint (struct gdbarch *gdbarch,
46 struct bp_target_info *bp_tgt)
c906108c
SS
47{
48 int val;
f4f9705a 49 const unsigned char *bp;
35c63cd8 50 gdb_byte *readbuf;
c906108c
SS
51
52 /* Determine appropriate breakpoint contents and size for this address. */
3b3b875c 53 bp = gdbarch_breakpoint_from_pc
ae4b2284 54 (gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size);
c906108c 55 if (bp == NULL)
8a3fe4f8 56 error (_("Software breakpoints not implemented for this target."));
c906108c 57
35c63cd8
JB
58 /* Save the memory contents in the shadow_contents buffer and then
59 write the breakpoint instruction. */
8181d85f 60 bp_tgt->shadow_len = bp_tgt->placed_size;
35c63cd8
JB
61 readbuf = alloca (bp_tgt->placed_size);
62 val = target_read_memory (bp_tgt->placed_address, readbuf,
8181d85f 63 bp_tgt->placed_size);
c906108c 64 if (val == 0)
35c63cd8
JB
65 {
66 memcpy (bp_tgt->shadow_contents, readbuf, bp_tgt->placed_size);
67 val = target_write_raw_memory (bp_tgt->placed_address, bp,
68 bp_tgt->placed_size);
69 }
c906108c
SS
70
71 return val;
72}
73
74
75int
ae4b2284
MD
76default_memory_remove_breakpoint (struct gdbarch *gdbarch,
77 struct bp_target_info *bp_tgt)
c906108c 78{
f0ba3972
PA
79 return target_write_raw_memory (bp_tgt->placed_address, bp_tgt->shadow_contents,
80 bp_tgt->placed_size);
c906108c 81}
917317f4
JM
82
83
917317f4 84int
a6d9a66e
UW
85memory_insert_breakpoint (struct gdbarch *gdbarch,
86 struct bp_target_info *bp_tgt)
917317f4 87{
a6d9a66e 88 return gdbarch_memory_insert_breakpoint (gdbarch, bp_tgt);
917317f4
JM
89}
90
917317f4 91int
a6d9a66e
UW
92memory_remove_breakpoint (struct gdbarch *gdbarch,
93 struct bp_target_info *bp_tgt)
917317f4 94{
a6d9a66e 95 return gdbarch_memory_remove_breakpoint (gdbarch, bp_tgt);
917317f4 96}
This page took 1.057677 seconds and 4 git commands to generate.