* win32-nat.c (get_relocated_section_addrs): New function. Find section load
[deliverable/binutils-gdb.git] / gdb / mem-break.c
CommitLineData
c906108c 1/* Simulate breakpoints by patching locations in the target system, for GDB.
f4f9705a
AC
2
3 Copyright 1990, 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2000,
4 2002 Free Software Foundation, Inc.
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
12 the Free Software Foundation; either version 2 of the License, or
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
JM
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
c906108c
SS
24
25#include "defs.h"
26
27/* This file is only useful if BREAKPOINT is set. If not, we punt. */
28
29#include "symtab.h"
30#include "breakpoint.h"
31#include "inferior.h"
32#include "target.h"
33
34
35/* Use the program counter to determine the contents and size
36 of a breakpoint instruction. If no target-dependent macro
37 BREAKPOINT_FROM_PC has been defined to implement this function,
38 assume that the breakpoint doesn't depend on the PC, and
39 use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
40 Return a pointer to a string of bytes that encode a breakpoint
41 instruction, stores the length of the string to *lenptr,
42 and optionally adjust the pc to point to the correct memory location
43 for inserting the breakpoint. */
44
f4f9705a 45const unsigned char *
fba45db2 46memory_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
c906108c
SS
47{
48 /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
49 breakpoint. On some machines, breakpoints are handled by the
50 target environment and we don't have to worry about them here. */
51#ifdef BIG_BREAKPOINT
d7449b42 52 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
c906108c
SS
53 {
54 static unsigned char big_break_insn[] = BIG_BREAKPOINT;
55 *lenptr = sizeof (big_break_insn);
56 return big_break_insn;
57 }
58#endif
59#ifdef LITTLE_BREAKPOINT
d7449b42 60 if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
c906108c
SS
61 {
62 static unsigned char little_break_insn[] = LITTLE_BREAKPOINT;
63 *lenptr = sizeof (little_break_insn);
64 return little_break_insn;
65 }
66#endif
67#ifdef BREAKPOINT
68 {
69 static unsigned char break_insn[] = BREAKPOINT;
70 *lenptr = sizeof (break_insn);
71 return break_insn;
72 }
73#endif
74 *lenptr = 0;
75 return NULL;
76}
77
78
79/* Insert a breakpoint on targets that don't have any better breakpoint
80 support. We read the contents of the target location and stash it,
81 then overwrite it with a breakpoint instruction. ADDR is the target
82 location in the target machine. CONTENTS_CACHE is a pointer to
83 memory allocated for saving the target contents. It is guaranteed
84 by the caller to be long enough to save BREAKPOINT_LEN bytes (this
85 is accomplished via BREAKPOINT_MAX). */
86
87int
fba45db2 88default_memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
c906108c
SS
89{
90 int val;
f4f9705a 91 const unsigned char *bp;
c906108c
SS
92 int bplen;
93
94 /* Determine appropriate breakpoint contents and size for this address. */
95 bp = BREAKPOINT_FROM_PC (&addr, &bplen);
96 if (bp == NULL)
97 error ("Software breakpoints not implemented for this target.");
98
99 /* Save the memory contents. */
100 val = target_read_memory (addr, contents_cache, bplen);
101
102 /* Write the breakpoint. */
103 if (val == 0)
c5aa993b 104 val = target_write_memory (addr, (char *) bp, bplen);
c906108c
SS
105
106 return val;
107}
108
109
110int
fba45db2 111default_memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
c906108c 112{
f4f9705a 113 const unsigned char *bp;
c906108c
SS
114 int bplen;
115
116 /* Determine appropriate breakpoint contents and size for this address. */
117 bp = BREAKPOINT_FROM_PC (&addr, &bplen);
118 if (bp == NULL)
119 error ("Software breakpoints not implemented for this target.");
120
121 return target_write_memory (addr, contents_cache, bplen);
122}
917317f4
JM
123
124
917317f4 125int
fba45db2 126memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
917317f4
JM
127{
128 return MEMORY_INSERT_BREAKPOINT(addr, contents_cache);
129}
130
917317f4 131int
fba45db2 132memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
917317f4
JM
133{
134 return MEMORY_REMOVE_BREAKPOINT(addr, contents_cache);
135}
This page took 0.266094 seconds and 4 git commands to generate.