]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/mem-break.c
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / mem-break.c
1 /* Simulate breakpoints by patching locations in the target system, for GDB.
2
3 Copyright (C) 1990-2013 Free Software Foundation, Inc.
4
5 Contributed by Cygnus Support. Written by John Gilmore.
6
7 This file is part of GDB.
8
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.
13
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.
18
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/>. */
21
22 #include "defs.h"
23
24 /* This file is only useful if BREAKPOINT_FROM_PC is set. If not, we
25 punt. */
26
27 #include "symtab.h"
28 #include "breakpoint.h"
29 #include "inferior.h"
30 #include "target.h"
31 #include "gdb_string.h"
32
33
34 /* Insert a breakpoint on targets that don't have any better
35 breakpoint support. We read the contents of the target location
36 and stash it, then overwrite it with a breakpoint instruction.
37 BP_TGT->placed_address is the target location in the target
38 machine. BP_TGT->shadow_contents is some memory allocated for
39 saving the target contents. It is guaranteed by the caller to be
40 long enough to save BREAKPOINT_LEN bytes (this is accomplished via
41 BREAKPOINT_MAX). */
42
43 int
44 default_memory_insert_breakpoint (struct gdbarch *gdbarch,
45 struct bp_target_info *bp_tgt)
46 {
47 int val;
48 const unsigned char *bp;
49 gdb_byte *readbuf;
50
51 /* Determine appropriate breakpoint contents and size for this address. */
52 bp = gdbarch_breakpoint_from_pc
53 (gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size);
54 if (bp == NULL)
55 error (_("Software breakpoints not implemented for this target."));
56
57 /* Save the memory contents in the shadow_contents buffer and then
58 write the breakpoint instruction. */
59 bp_tgt->shadow_len = bp_tgt->placed_size;
60 readbuf = alloca (bp_tgt->placed_size);
61 val = target_read_memory (bp_tgt->placed_address, readbuf,
62 bp_tgt->placed_size);
63 if (val == 0)
64 {
65 memcpy (bp_tgt->shadow_contents, readbuf, bp_tgt->placed_size);
66 val = target_write_raw_memory (bp_tgt->placed_address, bp,
67 bp_tgt->placed_size);
68 }
69
70 return val;
71 }
72
73
74 int
75 default_memory_remove_breakpoint (struct gdbarch *gdbarch,
76 struct bp_target_info *bp_tgt)
77 {
78 return target_write_raw_memory (bp_tgt->placed_address, bp_tgt->shadow_contents,
79 bp_tgt->placed_size);
80 }
81
82
83 int
84 memory_insert_breakpoint (struct gdbarch *gdbarch,
85 struct bp_target_info *bp_tgt)
86 {
87 return gdbarch_memory_insert_breakpoint (gdbarch, bp_tgt);
88 }
89
90 int
91 memory_remove_breakpoint (struct gdbarch *gdbarch,
92 struct bp_target_info *bp_tgt)
93 {
94 return gdbarch_memory_remove_breakpoint (gdbarch, bp_tgt);
95 }