]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/mem-break.c
2001-01-16 Michael Snyder <msnyder@cleaver.cygnus.com>
[thirdparty/binutils-gdb.git] / gdb / mem-break.c
CommitLineData
c906108c
SS
1/* Simulate breakpoints by patching locations in the target system, for GDB.
2 Copyright 1990, 1991, 1995 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by John Gilmore.
4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b
JM
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22#include "defs.h"
23
24/* This file is only useful if BREAKPOINT is set. If not, we punt. */
25
26#include "symtab.h"
27#include "breakpoint.h"
28#include "inferior.h"
29#include "target.h"
30
31
32/* Use the program counter to determine the contents and size
33 of a breakpoint instruction. If no target-dependent macro
34 BREAKPOINT_FROM_PC has been defined to implement this function,
35 assume that the breakpoint doesn't depend on the PC, and
36 use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
37 Return a pointer to a string of bytes that encode a breakpoint
38 instruction, stores the length of the string to *lenptr,
39 and optionally adjust the pc to point to the correct memory location
40 for inserting the breakpoint. */
41
42unsigned char *
fba45db2 43memory_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
c906108c
SS
44{
45 /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
46 breakpoint. On some machines, breakpoints are handled by the
47 target environment and we don't have to worry about them here. */
48#ifdef BIG_BREAKPOINT
49 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
50 {
51 static unsigned char big_break_insn[] = BIG_BREAKPOINT;
52 *lenptr = sizeof (big_break_insn);
53 return big_break_insn;
54 }
55#endif
56#ifdef LITTLE_BREAKPOINT
57 if (TARGET_BYTE_ORDER != BIG_ENDIAN)
58 {
59 static unsigned char little_break_insn[] = LITTLE_BREAKPOINT;
60 *lenptr = sizeof (little_break_insn);
61 return little_break_insn;
62 }
63#endif
64#ifdef BREAKPOINT
65 {
66 static unsigned char break_insn[] = BREAKPOINT;
67 *lenptr = sizeof (break_insn);
68 return break_insn;
69 }
70#endif
71 *lenptr = 0;
72 return NULL;
73}
74
75
76/* Insert a breakpoint on targets that don't have any better breakpoint
77 support. We read the contents of the target location and stash it,
78 then overwrite it with a breakpoint instruction. ADDR is the target
79 location in the target machine. CONTENTS_CACHE is a pointer to
80 memory allocated for saving the target contents. It is guaranteed
81 by the caller to be long enough to save BREAKPOINT_LEN bytes (this
82 is accomplished via BREAKPOINT_MAX). */
83
84int
fba45db2 85default_memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
c906108c
SS
86{
87 int val;
88 unsigned char *bp;
89 int bplen;
90
91 /* Determine appropriate breakpoint contents and size for this address. */
92 bp = BREAKPOINT_FROM_PC (&addr, &bplen);
93 if (bp == NULL)
94 error ("Software breakpoints not implemented for this target.");
95
96 /* Save the memory contents. */
97 val = target_read_memory (addr, contents_cache, bplen);
98
99 /* Write the breakpoint. */
100 if (val == 0)
c5aa993b 101 val = target_write_memory (addr, (char *) bp, bplen);
c906108c
SS
102
103 return val;
104}
105
106
107int
fba45db2 108default_memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
c906108c
SS
109{
110 unsigned char *bp;
111 int bplen;
112
113 /* Determine appropriate breakpoint contents and size for this address. */
114 bp = BREAKPOINT_FROM_PC (&addr, &bplen);
115 if (bp == NULL)
116 error ("Software breakpoints not implemented for this target.");
117
118 return target_write_memory (addr, contents_cache, bplen);
119}
917317f4
JM
120
121
917317f4 122int
fba45db2 123memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
917317f4
JM
124{
125 return MEMORY_INSERT_BREAKPOINT(addr, contents_cache);
126}
127
917317f4 128int
fba45db2 129memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
917317f4
JM
130{
131 return MEMORY_REMOVE_BREAKPOINT(addr, contents_cache);
132}