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