1 /* Memory breakpoint operations for the remote server for GDB.
2 Copyright (C) 2002-2003, 2005, 2007-2012 Free Software Foundation,
5 Contributed by MontaVista Software.
7 This file is part of GDB.
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.
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.
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/>. */
24 const unsigned char *breakpoint_data;
27 #define MAX_BREAKPOINT_LEN 8
29 /* GDB will never try to install multiple breakpoints at the same
30 address. But, we need to keep track of internal breakpoints too,
31 and so we do need to be able to install multiple breakpoints at the
32 same address transparently. We keep track of two different, and
33 closely related structures. A raw breakpoint, which manages the
34 low level, close to the metal aspect of a breakpoint. It holds the
35 breakpoint address, and a buffer holding a copy of the instructions
36 that would be in memory had not been a breakpoint there (we call
37 that the shadow memory of the breakpoint). We occasionally need to
38 temporarilly uninsert a breakpoint without the client knowing about
39 it (e.g., to step over an internal breakpoint), so we keep an
40 `inserted' state associated with this low level breakpoint
41 structure. There can only be one such object for a given address.
42 Then, we have (a bit higher level) breakpoints. This structure
43 holds a callback to be called whenever a breakpoint is hit, a
44 high-level type, and a link to a low level raw breakpoint. There
45 can be many high-level breakpoints at the same address, and all of
46 them will point to the same raw breakpoint, which is reference
49 /* The low level, physical, raw breakpoint. */
52 struct raw_breakpoint *next;
54 /* A reference count. Each high level breakpoint referencing this
55 raw breakpoint accounts for one reference. */
58 /* The breakpoint's insertion address. There can only be one raw
59 breakpoint for a given PC. */
62 /* The breakpoint's shadow memory. */
63 unsigned char old_data[MAX_BREAKPOINT_LEN];
65 /* Non-zero if this breakpoint is currently inserted in the
69 /* Non-zero if this breakpoint is currently disabled because we no
70 longer detect it as inserted. */
74 /* The type of a breakpoint. */
77 /* A GDB breakpoint, requested with a Z0 packet. */
80 /* A basic-software-single-step breakpoint. */
83 /* Any other breakpoint type that doesn't require specific
84 treatment goes here. E.g., an event breakpoint. */
88 /* A high level (in gdbserver's perspective) breakpoint. */
91 struct breakpoint *next;
93 /* The breakpoint's type. */
96 /* Link to this breakpoint's raw breakpoint. This is always
98 struct raw_breakpoint *raw;
100 /* Function to call when we hit this breakpoint. If it returns 1,
101 the breakpoint shall be deleted; 0 or if this callback is NULL,
102 it will be left inserted. */
103 int (*handler) (CORE_ADDR);
106 static struct raw_breakpoint *
107 find_raw_breakpoint_at (CORE_ADDR where)
109 struct process_info *proc = current_process ();
110 struct raw_breakpoint *bp;
112 for (bp = proc->raw_breakpoints; bp != NULL; bp = bp->next)
119 static struct raw_breakpoint *
120 set_raw_breakpoint_at (CORE_ADDR where)
122 struct process_info *proc = current_process ();
123 struct raw_breakpoint *bp;
125 unsigned char buf[MAX_BREAKPOINT_LEN];
127 if (breakpoint_data == NULL)
128 error ("Target does not support breakpoints.");
130 bp = find_raw_breakpoint_at (where);
137 bp = xcalloc (1, sizeof (*bp));
141 /* Note that there can be fast tracepoint jumps installed in the
142 same memory range, so to get at the original memory, we need to
143 use read_inferior_memory, which masks those out. */
144 err = read_inferior_memory (where, buf, breakpoint_len);
149 "Failed to read shadow memory of"
150 " breakpoint at 0x%s (%s).\n",
151 paddress (where), strerror (err));
155 memcpy (bp->old_data, buf, breakpoint_len);
157 err = (*the_target->write_memory) (where, breakpoint_data,
163 "Failed to insert breakpoint at 0x%s (%s).\n",
164 paddress (where), strerror (err));
169 /* Link the breakpoint in. */
171 bp->next = proc->raw_breakpoints;
172 proc->raw_breakpoints = bp;
176 /* Notice that breakpoint traps are always installed on top of fast
177 tracepoint jumps. This is even if the fast tracepoint is installed
178 at a later time compared to when the breakpoint was installed.
179 This means that a stopping breakpoint or tracepoint has higher
180 "priority". In turn, this allows having fast and slow tracepoints
181 (and breakpoints) at the same address behave correctly. */
184 /* A fast tracepoint jump. */
186 struct fast_tracepoint_jump
188 struct fast_tracepoint_jump *next;
190 /* A reference count. GDB can install more than one fast tracepoint
191 at the same address (each with its own action list, for
195 /* The fast tracepoint's insertion address. There can only be one
196 of these for a given PC. */
199 /* Non-zero if this fast tracepoint jump is currently inserted in
203 /* The length of the jump instruction. */
206 /* A poor-man's flexible array member, holding both the jump
207 instruction to insert, and a copy of the instruction that would
208 be in memory had not been a jump there (the shadow memory of the
210 unsigned char insn_and_shadow[0];
213 /* Fast tracepoint FP's jump instruction to insert. */
214 #define fast_tracepoint_jump_insn(fp) \
215 ((fp)->insn_and_shadow + 0)
217 /* The shadow memory of fast tracepoint jump FP. */
218 #define fast_tracepoint_jump_shadow(fp) \
219 ((fp)->insn_and_shadow + (fp)->length)
222 /* Return the fast tracepoint jump set at WHERE. */
224 static struct fast_tracepoint_jump *
225 find_fast_tracepoint_jump_at (CORE_ADDR where)
227 struct process_info *proc = current_process ();
228 struct fast_tracepoint_jump *jp;
230 for (jp = proc->fast_tracepoint_jumps; jp != NULL; jp = jp->next)
238 fast_tracepoint_jump_here (CORE_ADDR where)
240 struct fast_tracepoint_jump *jp = find_fast_tracepoint_jump_at (where);
246 delete_fast_tracepoint_jump (struct fast_tracepoint_jump *todel)
248 struct fast_tracepoint_jump *bp, **bp_link;
250 struct process_info *proc = current_process ();
252 bp = proc->fast_tracepoint_jumps;
253 bp_link = &proc->fast_tracepoint_jumps;
259 if (--bp->refcount == 0)
261 struct fast_tracepoint_jump *prev_bp_link = *bp_link;
267 /* Since there can be breakpoints inserted in the same
268 address range, we use `write_inferior_memory', which
269 takes care of layering breakpoints on top of fast
270 tracepoints, and on top of the buffer we pass it.
271 This works because we've already unlinked the fast
272 tracepoint jump above. Also note that we need to
273 pass the current shadow contents, because
274 write_inferior_memory updates any shadow memory with
275 what we pass here, and we want that to be a nop. */
276 buf = alloca (bp->length);
277 memcpy (buf, fast_tracepoint_jump_shadow (bp), bp->length);
278 ret = write_inferior_memory (bp->pc, buf, bp->length);
281 /* Something went wrong, relink the jump. */
282 *bp_link = prev_bp_link;
286 "Failed to uninsert fast tracepoint jump "
287 "at 0x%s (%s) while deleting it.\n",
288 paddress (bp->pc), strerror (ret));
304 warning ("Could not find fast tracepoint jump in list.");
309 inc_ref_fast_tracepoint_jump (struct fast_tracepoint_jump *jp)
314 struct fast_tracepoint_jump *
315 set_fast_tracepoint_jump (CORE_ADDR where,
316 unsigned char *insn, ULONGEST length)
318 struct process_info *proc = current_process ();
319 struct fast_tracepoint_jump *jp;
323 /* We refcount fast tracepoint jumps. Check if we already know
324 about a jump at this address. */
325 jp = find_fast_tracepoint_jump_at (where);
332 /* We don't, so create a new object. Double the length, because the
333 flexible array member holds both the jump insn, and the
335 jp = xcalloc (1, sizeof (*jp) + (length * 2));
338 memcpy (fast_tracepoint_jump_insn (jp), insn, length);
340 buf = alloca (length);
342 /* Note that there can be trap breakpoints inserted in the same
343 address range. To access the original memory contents, we use
344 `read_inferior_memory', which masks out breakpoints. */
345 err = read_inferior_memory (where, buf, length);
350 "Failed to read shadow memory of"
351 " fast tracepoint at 0x%s (%s).\n",
352 paddress (where), strerror (err));
356 memcpy (fast_tracepoint_jump_shadow (jp), buf, length);
358 /* Link the jump in. */
360 jp->next = proc->fast_tracepoint_jumps;
361 proc->fast_tracepoint_jumps = jp;
363 /* Since there can be trap breakpoints inserted in the same address
364 range, we use use `write_inferior_memory', which takes care of
365 layering breakpoints on top of fast tracepoints, on top of the
366 buffer we pass it. This works because we've already linked in
367 the fast tracepoint jump above. Also note that we need to pass
368 the current shadow contents, because write_inferior_memory
369 updates any shadow memory with what we pass here, and we want
371 err = write_inferior_memory (where, buf, length);
376 "Failed to insert fast tracepoint jump at 0x%s (%s).\n",
377 paddress (where), strerror (err));
380 proc->fast_tracepoint_jumps = jp->next;
390 uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc)
392 struct fast_tracepoint_jump *jp;
395 jp = find_fast_tracepoint_jump_at (pc);
398 /* This can happen when we remove all breakpoints while handling
402 "Could not find fast tracepoint jump at 0x%s "
403 "in list (uninserting).\n",
414 /* Since there can be trap breakpoints inserted in the same
415 address range, we use use `write_inferior_memory', which
416 takes care of layering breakpoints on top of fast
417 tracepoints, and on top of the buffer we pass it. This works
418 because we've already marked the fast tracepoint fast
419 tracepoint jump uninserted above. Also note that we need to
420 pass the current shadow contents, because
421 write_inferior_memory updates any shadow memory with what we
422 pass here, and we want that to be a nop. */
423 buf = alloca (jp->length);
424 memcpy (buf, fast_tracepoint_jump_shadow (jp), jp->length);
425 err = write_inferior_memory (jp->pc, buf, jp->length);
432 "Failed to uninsert fast tracepoint jump at 0x%s (%s).\n",
433 paddress (pc), strerror (err));
439 reinsert_fast_tracepoint_jumps_at (CORE_ADDR where)
441 struct fast_tracepoint_jump *jp;
445 jp = find_fast_tracepoint_jump_at (where);
448 /* This can happen when we remove breakpoints when a tracepoint
449 hit causes a tracing stop, while handling a step-over. */
452 "Could not find fast tracepoint jump at 0x%s "
453 "in list (reinserting).\n",
459 error ("Jump already inserted at reinsert time.");
463 /* Since there can be trap breakpoints inserted in the same address
464 range, we use `write_inferior_memory', which takes care of
465 layering breakpoints on top of fast tracepoints, and on top of
466 the buffer we pass it. This works because we've already marked
467 the fast tracepoint jump inserted above. Also note that we need
468 to pass the current shadow contents, because
469 write_inferior_memory updates any shadow memory with what we pass
470 here, and we want that to be a nop. */
471 buf = alloca (jp->length);
472 memcpy (buf, fast_tracepoint_jump_shadow (jp), jp->length);
473 err = write_inferior_memory (where, buf, jp->length);
480 "Failed to reinsert fast tracepoint jump at 0x%s (%s).\n",
481 paddress (where), strerror (err));
486 set_breakpoint_at (CORE_ADDR where, int (*handler) (CORE_ADDR))
488 struct process_info *proc = current_process ();
489 struct breakpoint *bp;
490 struct raw_breakpoint *raw;
492 raw = set_raw_breakpoint_at (where);
500 bp = xcalloc (1, sizeof (struct breakpoint));
501 bp->type = other_breakpoint;
504 bp->handler = handler;
506 bp->next = proc->breakpoints;
507 proc->breakpoints = bp;
513 delete_raw_breakpoint (struct process_info *proc, struct raw_breakpoint *todel)
515 struct raw_breakpoint *bp, **bp_link;
518 bp = proc->raw_breakpoints;
519 bp_link = &proc->raw_breakpoints;
527 struct raw_breakpoint *prev_bp_link = *bp_link;
528 unsigned char buf[MAX_BREAKPOINT_LEN];
532 /* Since there can be trap breakpoints inserted in the
533 same address range, we use `write_inferior_memory',
534 which takes care of layering breakpoints on top of
535 fast tracepoints, and on top of the buffer we pass
536 it. This works because we've already unlinked the
537 fast tracepoint jump above. Also note that we need
538 to pass the current shadow contents, because
539 write_inferior_memory updates any shadow memory with
540 what we pass here, and we want that to be a nop. */
541 memcpy (buf, bp->old_data, breakpoint_len);
542 ret = write_inferior_memory (bp->pc, buf, breakpoint_len);
545 /* Something went wrong, relink the breakpoint. */
546 *bp_link = prev_bp_link;
550 "Failed to uninsert raw breakpoint "
551 "at 0x%s (%s) while deleting it.\n",
552 paddress (bp->pc), strerror (ret));
570 warning ("Could not find raw breakpoint in list.");
575 release_breakpoint (struct process_info *proc, struct breakpoint *bp)
580 newrefcount = bp->raw->refcount - 1;
581 if (newrefcount == 0)
583 ret = delete_raw_breakpoint (proc, bp->raw);
588 bp->raw->refcount = newrefcount;
596 delete_breakpoint_1 (struct process_info *proc, struct breakpoint *todel)
598 struct breakpoint *bp, **bp_link;
601 bp = proc->breakpoints;
602 bp_link = &proc->breakpoints;
610 err = release_breakpoint (proc, bp);
624 warning ("Could not find breakpoint in list.");
629 delete_breakpoint (struct breakpoint *todel)
631 struct process_info *proc = current_process ();
632 return delete_breakpoint_1 (proc, todel);
635 static struct breakpoint *
636 find_gdb_breakpoint_at (CORE_ADDR where)
638 struct process_info *proc = current_process ();
639 struct breakpoint *bp;
641 for (bp = proc->breakpoints; bp != NULL; bp = bp->next)
642 if (bp->type == gdb_breakpoint && bp->raw->pc == where)
649 set_gdb_breakpoint_at (CORE_ADDR where)
651 struct breakpoint *bp;
653 if (breakpoint_data == NULL)
656 /* If we see GDB inserting a second breakpoint at the same address,
657 then the first breakpoint must have disappeared due to a shared
658 library unload. On targets where the shared libraries are
659 handled by userspace, like SVR4, for example, GDBserver can't
660 tell if a library was loaded or unloaded. Since we refcount
661 breakpoints, if we didn't do this, we'd just increase the
662 refcount of the previous breakpoint at this address, but the trap
663 was not planted in the inferior anymore, thus the breakpoint
664 would never be hit. */
665 bp = find_gdb_breakpoint_at (where);
668 delete_gdb_breakpoint_at (where);
670 /* Might as well validate all other breakpoints. */
671 validate_breakpoints ();
674 bp = set_breakpoint_at (where, NULL);
678 bp->type = gdb_breakpoint;
683 delete_gdb_breakpoint_at (CORE_ADDR addr)
685 struct breakpoint *bp;
688 if (breakpoint_data == NULL)
691 bp = find_gdb_breakpoint_at (addr);
695 err = delete_breakpoint (bp);
703 gdb_breakpoint_here (CORE_ADDR where)
705 struct breakpoint *bp = find_gdb_breakpoint_at (where);
711 set_reinsert_breakpoint (CORE_ADDR stop_at)
713 struct breakpoint *bp;
715 bp = set_breakpoint_at (stop_at, NULL);
716 bp->type = reinsert_breakpoint;
720 delete_reinsert_breakpoints (void)
722 struct process_info *proc = current_process ();
723 struct breakpoint *bp, **bp_link;
725 bp = proc->breakpoints;
726 bp_link = &proc->breakpoints;
730 if (bp->type == reinsert_breakpoint)
733 release_breakpoint (proc, bp);
745 uninsert_raw_breakpoint (struct raw_breakpoint *bp)
750 unsigned char buf[MAX_BREAKPOINT_LEN];
753 /* Since there can be fast tracepoint jumps inserted in the same
754 address range, we use `write_inferior_memory', which takes
755 care of layering breakpoints on top of fast tracepoints, and
756 on top of the buffer we pass it. This works because we've
757 already unlinked the fast tracepoint jump above. Also note
758 that we need to pass the current shadow contents, because
759 write_inferior_memory updates any shadow memory with what we
760 pass here, and we want that to be a nop. */
761 memcpy (buf, bp->old_data, breakpoint_len);
762 err = write_inferior_memory (bp->pc, buf, breakpoint_len);
769 "Failed to uninsert raw breakpoint at 0x%s (%s).\n",
770 paddress (bp->pc), strerror (err));
776 uninsert_breakpoints_at (CORE_ADDR pc)
778 struct raw_breakpoint *bp;
780 bp = find_raw_breakpoint_at (pc);
783 /* This can happen when we remove all breakpoints while handling
787 "Could not find breakpoint at 0x%s "
788 "in list (uninserting).\n",
794 uninsert_raw_breakpoint (bp);
798 uninsert_all_breakpoints (void)
800 struct process_info *proc = current_process ();
801 struct raw_breakpoint *bp;
803 for (bp = proc->raw_breakpoints; bp != NULL; bp = bp->next)
805 uninsert_raw_breakpoint (bp);
809 reinsert_raw_breakpoint (struct raw_breakpoint *bp)
814 error ("Breakpoint already inserted at reinsert time.");
816 err = (*the_target->write_memory) (bp->pc, breakpoint_data,
820 else if (debug_threads)
822 "Failed to reinsert breakpoint at 0x%s (%s).\n",
823 paddress (bp->pc), strerror (err));
827 reinsert_breakpoints_at (CORE_ADDR pc)
829 struct raw_breakpoint *bp;
831 bp = find_raw_breakpoint_at (pc);
834 /* This can happen when we remove all breakpoints while handling
838 "Could not find raw breakpoint at 0x%s "
839 "in list (reinserting).\n",
844 reinsert_raw_breakpoint (bp);
848 reinsert_all_breakpoints (void)
850 struct process_info *proc = current_process ();
851 struct raw_breakpoint *bp;
853 for (bp = proc->raw_breakpoints; bp != NULL; bp = bp->next)
855 reinsert_raw_breakpoint (bp);
859 check_breakpoints (CORE_ADDR stop_pc)
861 struct process_info *proc = current_process ();
862 struct breakpoint *bp, **bp_link;
864 bp = proc->breakpoints;
865 bp_link = &proc->breakpoints;
869 if (bp->raw->pc == stop_pc)
871 if (!bp->raw->inserted)
873 warning ("Hit a removed breakpoint?");
877 if (bp->handler != NULL && (*bp->handler) (stop_pc))
881 release_breakpoint (proc, bp);
894 set_breakpoint_data (const unsigned char *bp_data, int bp_len)
896 breakpoint_data = bp_data;
897 breakpoint_len = bp_len;
901 breakpoint_here (CORE_ADDR addr)
903 return (find_raw_breakpoint_at (addr) != NULL);
907 breakpoint_inserted_here (CORE_ADDR addr)
909 struct raw_breakpoint *bp;
911 bp = find_raw_breakpoint_at (addr);
913 return (bp != NULL && bp->inserted);
917 validate_inserted_breakpoint (struct raw_breakpoint *bp)
922 gdb_assert (bp->inserted);
924 buf = alloca (breakpoint_len);
925 err = (*the_target->read_memory) (bp->pc, buf, breakpoint_len);
926 if (err || memcmp (buf, breakpoint_data, breakpoint_len) != 0)
928 /* Tag it as gone. */
930 bp->shlib_disabled = 1;
938 delete_disabled_breakpoints (void)
940 struct process_info *proc = current_process ();
941 struct breakpoint *bp, *next;
943 for (bp = proc->breakpoints; bp != NULL; bp = next)
946 if (bp->raw->shlib_disabled)
947 delete_breakpoint_1 (proc, bp);
951 /* Check if breakpoints we inserted still appear to be inserted. They
952 may disappear due to a shared library unload, and worse, a new
953 shared library may be reloaded at the same address as the
954 previously unloaded one. If that happens, we should make sure that
955 the shadow memory of the old breakpoints isn't used when reading or
959 validate_breakpoints (void)
961 struct process_info *proc = current_process ();
962 struct breakpoint *bp;
964 for (bp = proc->breakpoints; bp != NULL; bp = bp->next)
966 if (bp->raw->inserted)
967 validate_inserted_breakpoint (bp->raw);
970 delete_disabled_breakpoints ();
974 check_mem_read (CORE_ADDR mem_addr, unsigned char *buf, int mem_len)
976 struct process_info *proc = current_process ();
977 struct raw_breakpoint *bp = proc->raw_breakpoints;
978 struct fast_tracepoint_jump *jp = proc->fast_tracepoint_jumps;
979 CORE_ADDR mem_end = mem_addr + mem_len;
980 int disabled_one = 0;
982 for (; jp != NULL; jp = jp->next)
984 CORE_ADDR bp_end = jp->pc + jp->length;
985 CORE_ADDR start, end;
986 int copy_offset, copy_len, buf_offset;
988 gdb_assert (fast_tracepoint_jump_shadow (jp) >= buf + mem_len
989 || buf >= fast_tracepoint_jump_shadow (jp) + (jp)->length);
991 if (mem_addr >= bp_end)
993 if (jp->pc >= mem_end)
997 if (mem_addr > start)
1004 copy_len = end - start;
1005 copy_offset = start - jp->pc;
1006 buf_offset = start - mem_addr;
1009 memcpy (buf + buf_offset,
1010 fast_tracepoint_jump_shadow (jp) + copy_offset,
1014 for (; bp != NULL; bp = bp->next)
1016 CORE_ADDR bp_end = bp->pc + breakpoint_len;
1017 CORE_ADDR start, end;
1018 int copy_offset, copy_len, buf_offset;
1020 gdb_assert (bp->old_data >= buf + mem_len
1021 || buf >= &bp->old_data[sizeof (bp->old_data)]);
1023 if (mem_addr >= bp_end)
1025 if (bp->pc >= mem_end)
1029 if (mem_addr > start)
1036 copy_len = end - start;
1037 copy_offset = start - bp->pc;
1038 buf_offset = start - mem_addr;
1042 if (validate_inserted_breakpoint (bp))
1043 memcpy (buf + buf_offset, bp->old_data + copy_offset, copy_len);
1050 delete_disabled_breakpoints ();
1054 check_mem_write (CORE_ADDR mem_addr, unsigned char *buf,
1055 const unsigned char *myaddr, int mem_len)
1057 struct process_info *proc = current_process ();
1058 struct raw_breakpoint *bp = proc->raw_breakpoints;
1059 struct fast_tracepoint_jump *jp = proc->fast_tracepoint_jumps;
1060 CORE_ADDR mem_end = mem_addr + mem_len;
1061 int disabled_one = 0;
1063 /* First fast tracepoint jumps, then breakpoint traps on top. */
1065 for (; jp != NULL; jp = jp->next)
1067 CORE_ADDR jp_end = jp->pc + jp->length;
1068 CORE_ADDR start, end;
1069 int copy_offset, copy_len, buf_offset;
1071 gdb_assert (fast_tracepoint_jump_shadow (jp) >= myaddr + mem_len
1072 || myaddr >= fast_tracepoint_jump_shadow (jp) + (jp)->length);
1073 gdb_assert (fast_tracepoint_jump_insn (jp) >= buf + mem_len
1074 || buf >= fast_tracepoint_jump_insn (jp) + (jp)->length);
1076 if (mem_addr >= jp_end)
1078 if (jp->pc >= mem_end)
1082 if (mem_addr > start)
1089 copy_len = end - start;
1090 copy_offset = start - jp->pc;
1091 buf_offset = start - mem_addr;
1093 memcpy (fast_tracepoint_jump_shadow (jp) + copy_offset,
1094 myaddr + buf_offset, copy_len);
1096 memcpy (buf + buf_offset,
1097 fast_tracepoint_jump_insn (jp) + copy_offset, copy_len);
1100 for (; bp != NULL; bp = bp->next)
1102 CORE_ADDR bp_end = bp->pc + breakpoint_len;
1103 CORE_ADDR start, end;
1104 int copy_offset, copy_len, buf_offset;
1106 gdb_assert (bp->old_data >= myaddr + mem_len
1107 || myaddr >= &bp->old_data[sizeof (bp->old_data)]);
1109 if (mem_addr >= bp_end)
1111 if (bp->pc >= mem_end)
1115 if (mem_addr > start)
1122 copy_len = end - start;
1123 copy_offset = start - bp->pc;
1124 buf_offset = start - mem_addr;
1126 memcpy (bp->old_data + copy_offset, myaddr + buf_offset, copy_len);
1129 if (validate_inserted_breakpoint (bp))
1130 memcpy (buf + buf_offset, breakpoint_data + copy_offset, copy_len);
1137 delete_disabled_breakpoints ();
1140 /* Delete all breakpoints, and un-insert them from the inferior. */
1143 delete_all_breakpoints (void)
1145 struct process_info *proc = current_process ();
1147 while (proc->breakpoints)
1148 delete_breakpoint_1 (proc, proc->breakpoints);
1151 /* Clear the "inserted" flag in all breakpoints. */
1154 mark_breakpoints_out (struct process_info *proc)
1156 struct raw_breakpoint *raw_bp;
1158 for (raw_bp = proc->raw_breakpoints; raw_bp != NULL; raw_bp = raw_bp->next)
1159 raw_bp->inserted = 0;
1162 /* Release all breakpoints, but do not try to un-insert them from the
1166 free_all_breakpoints (struct process_info *proc)
1168 mark_breakpoints_out (proc);
1170 /* Note: use PROC explicitly instead of deferring to
1171 delete_all_breakpoints --- CURRENT_INFERIOR may already have been
1172 released when we get here. There should be no call to
1173 current_process from here on. */
1174 while (proc->breakpoints)
1175 delete_breakpoint_1 (proc, proc->breakpoints);