Fix dwarf2loc.h::dwarf2_evaluate_property function description.
[deliverable/binutils-gdb.git] / gdb / mem-break.c
CommitLineData
c906108c 1/* Simulate breakpoints by patching locations in the target system, for GDB.
f4f9705a 2
ecd75fc8 3 Copyright (C) 1990-2014 Free Software Foundation, Inc.
f4f9705a 4
c906108c
SS
5 Contributed by Cygnus Support. Written by John Gilmore.
6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
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.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
c906108c
SS
23#include "symtab.h"
24#include "breakpoint.h"
25#include "inferior.h"
26#include "target.h"
8181d85f
DJ
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
34 BREAKPOINT_MAX). */
c906108c
SS
35
36int
ae4b2284
MD
37default_memory_insert_breakpoint (struct gdbarch *gdbarch,
38 struct bp_target_info *bp_tgt)
c906108c
SS
39{
40 int val;
f4f9705a 41 const unsigned char *bp;
35c63cd8 42 gdb_byte *readbuf;
c906108c
SS
43
44 /* Determine appropriate breakpoint contents and size for this address. */
3b3b875c 45 bp = gdbarch_breakpoint_from_pc
ae4b2284 46 (gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size);
c906108c 47 if (bp == NULL)
8a3fe4f8 48 error (_("Software breakpoints not implemented for this target."));
c906108c 49
35c63cd8
JB
50 /* Save the memory contents in the shadow_contents buffer and then
51 write the breakpoint instruction. */
8181d85f 52 bp_tgt->shadow_len = bp_tgt->placed_size;
35c63cd8
JB
53 readbuf = alloca (bp_tgt->placed_size);
54 val = target_read_memory (bp_tgt->placed_address, readbuf,
8181d85f 55 bp_tgt->placed_size);
c906108c 56 if (val == 0)
35c63cd8
JB
57 {
58 memcpy (bp_tgt->shadow_contents, readbuf, bp_tgt->placed_size);
59 val = target_write_raw_memory (bp_tgt->placed_address, bp,
60 bp_tgt->placed_size);
61 }
c906108c
SS
62
63 return val;
64}
65
66
67int
ae4b2284
MD
68default_memory_remove_breakpoint (struct gdbarch *gdbarch,
69 struct bp_target_info *bp_tgt)
c906108c 70{
f0ba3972
PA
71 return target_write_raw_memory (bp_tgt->placed_address, bp_tgt->shadow_contents,
72 bp_tgt->placed_size);
c906108c 73}
917317f4
JM
74
75
917317f4 76int
3db08215 77memory_insert_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
a6d9a66e 78 struct bp_target_info *bp_tgt)
917317f4 79{
a6d9a66e 80 return gdbarch_memory_insert_breakpoint (gdbarch, bp_tgt);
917317f4
JM
81}
82
917317f4 83int
3db08215 84memory_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
a6d9a66e 85 struct bp_target_info *bp_tgt)
917317f4 86{
a6d9a66e 87 return gdbarch_memory_remove_breakpoint (gdbarch, bp_tgt);
917317f4 88}
08351840
PA
89
90int
91memory_validate_breakpoint (struct gdbarch *gdbarch,
92 struct bp_target_info *bp_tgt)
93{
94 CORE_ADDR addr = bp_tgt->placed_address;
95 const gdb_byte *bp;
96 int val;
97 int bplen;
98 gdb_byte cur_contents[BREAKPOINT_MAX];
99 struct cleanup *cleanup;
100 int ret;
101
102 /* Determine appropriate breakpoint contents and size for this
103 address. */
104 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
105
106 if (bp == NULL || bp_tgt->placed_size != bplen)
107 return 0;
108
109 /* Make sure we see the memory breakpoints. */
110 cleanup = make_show_memory_breakpoints_cleanup (1);
111 val = target_read_memory (addr, cur_contents, bplen);
112
113 /* If our breakpoint is no longer at the address, this means that
114 the program modified the code on us, so it is wrong to put back
115 the old value. */
116 ret = (val == 0 && memcmp (bp, cur_contents, bplen) == 0);
117
118 do_cleanups (cleanup);
119 return ret;
120}
This page took 1.250659 seconds and 4 git commands to generate.