1 /* Memory breakpoint operations for the remote server for GDB.
2 Copyright (C) 2002-2015 Free Software Foundation, Inc.
4 Contributed by MontaVista Software.
6 This file is part of GDB.
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 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 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 /* Helper macro used in loops that append multiple items to a singly-linked
30 list instead of inserting items at the head of the list, as, say, in the
31 breakpoint lists. LISTPP is a pointer to the pointer that is the head of
32 the new list. ITEMP is a pointer to the item to be added to the list.
33 TAILP must be defined to be the same type as ITEMP, and initialized to
36 #define APPEND_TO_LIST(listpp, itemp, tailp) \
39 if ((tailp) == NULL) \
40 *(listpp) = (itemp); \
42 (tailp)->next = (itemp); \
47 /* GDB will never try to install multiple breakpoints at the same
48 address. However, we can see GDB requesting to insert a breakpoint
49 at an address is had already inserted one previously in a few
52 - The RSP documentation on Z packets says that to avoid potential
53 problems with duplicate packets, the operations should be
54 implemented in an idempotent way.
56 - A breakpoint is set at ADDR, an address in a shared library.
57 Then the shared library is unloaded. And then another, unrelated,
58 breakpoint at ADDR is set. There is not breakpoint removal request
59 between the first and the second breakpoint.
61 - When GDB wants to update the target-side breakpoint conditions or
62 commands, it re-inserts the breakpoint, with updated
63 conditions/commands associated.
65 Also, we need to keep track of internal breakpoints too, so we do
66 need to be able to install multiple breakpoints at the same address
69 We keep track of two different, and closely related structures. A
70 raw breakpoint, which manages the low level, close to the metal
71 aspect of a breakpoint. It holds the breakpoint address, and for
72 software breakpoints, a buffer holding a copy of the instructions
73 that would be in memory had not been a breakpoint there (we call
74 that the shadow memory of the breakpoint). We occasionally need to
75 temporarilly uninsert a breakpoint without the client knowing about
76 it (e.g., to step over an internal breakpoint), so we keep an
77 `inserted' state associated with this low level breakpoint
78 structure. There can only be one such object for a given address.
79 Then, we have (a bit higher level) breakpoints. This structure
80 holds a callback to be called whenever a breakpoint is hit, a
81 high-level type, and a link to a low level raw breakpoint. There
82 can be many high-level breakpoints at the same address, and all of
83 them will point to the same raw breakpoint, which is reference
86 /* The low level, physical, raw breakpoint. */
89 struct raw_breakpoint
*next
;
91 /* The low level type of the breakpoint (software breakpoint,
93 enum raw_bkpt_type raw_type
;
95 /* A reference count. Each high level breakpoint referencing this
96 raw breakpoint accounts for one reference. */
99 /* The breakpoint's insertion address. There can only be one raw
100 breakpoint for a given PC. */
103 /* The breakpoint's size. */
106 /* The breakpoint's shadow memory. */
107 unsigned char old_data
[MAX_BREAKPOINT_LEN
];
109 /* Positive if this breakpoint is currently inserted in the
110 inferior. Negative if it was, but we've detected that it's now
111 gone. Zero if not inserted. */
115 /* The type of a breakpoint. */
118 /* A GDB breakpoint, requested with a Z0 packet. */
121 /* A GDB hardware breakpoint, requested with a Z1 packet. */
124 /* A GDB write watchpoint, requested with a Z2 packet. */
127 /* A GDB read watchpoint, requested with a Z3 packet. */
130 /* A GDB access watchpoint, requested with a Z4 packet. */
133 /* A basic-software-single-step breakpoint. */
136 /* Any other breakpoint type that doesn't require specific
137 treatment goes here. E.g., an event breakpoint. */
141 struct point_cond_list
143 /* Pointer to the agent expression that is the breakpoint's
145 struct agent_expr
*cond
;
147 /* Pointer to the next condition. */
148 struct point_cond_list
*next
;
151 struct point_command_list
153 /* Pointer to the agent expression that is the breakpoint's
155 struct agent_expr
*cmd
;
157 /* Flag that is true if this command should run even while GDB is
161 /* Pointer to the next command. */
162 struct point_command_list
*next
;
165 /* A high level (in gdbserver's perspective) breakpoint. */
168 struct breakpoint
*next
;
170 /* The breakpoint's type. */
173 /* Pointer to the condition list that should be evaluated on
174 the target or NULL if the breakpoint is unconditional or
175 if GDB doesn't want us to evaluate the conditionals on the
177 struct point_cond_list
*cond_list
;
179 /* Point to the list of commands to run when this is hit. */
180 struct point_command_list
*command_list
;
182 /* Link to this breakpoint's raw breakpoint. This is always
184 struct raw_breakpoint
*raw
;
186 /* Function to call when we hit this breakpoint. If it returns 1,
187 the breakpoint shall be deleted; 0 or if this callback is NULL,
188 it will be left inserted. */
189 int (*handler
) (CORE_ADDR
);
192 /* See mem-break.h. */
194 enum target_hw_bp_type
195 raw_bkpt_type_to_target_hw_bp_type (enum raw_bkpt_type raw_type
)
199 case raw_bkpt_type_hw
:
201 case raw_bkpt_type_write_wp
:
203 case raw_bkpt_type_read_wp
:
205 case raw_bkpt_type_access_wp
:
208 internal_error (__FILE__
, __LINE__
,
209 "bad raw breakpoint type %d", (int) raw_type
);
213 /* See mem-break.h. */
215 static enum bkpt_type
216 Z_packet_to_bkpt_type (char z_type
)
218 gdb_assert ('0' <= z_type
&& z_type
<= '4');
220 return gdb_breakpoint_Z0
+ (z_type
- '0');
223 /* See mem-break.h. */
226 Z_packet_to_raw_bkpt_type (char z_type
)
231 return raw_bkpt_type_sw
;
233 return raw_bkpt_type_hw
;
234 case Z_PACKET_WRITE_WP
:
235 return raw_bkpt_type_write_wp
;
236 case Z_PACKET_READ_WP
:
237 return raw_bkpt_type_read_wp
;
238 case Z_PACKET_ACCESS_WP
:
239 return raw_bkpt_type_access_wp
;
241 gdb_assert_not_reached ("unhandled Z packet type.");
246 any_persistent_commands ()
248 struct process_info
*proc
= current_process ();
249 struct breakpoint
*bp
;
250 struct point_command_list
*cl
;
252 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
254 for (cl
= bp
->command_list
; cl
!= NULL
; cl
= cl
->next
)
262 /* Find low-level breakpoint of type TYPE at address ADDR that is not
263 insert-disabled. Returns NULL if not found. */
265 static struct raw_breakpoint
*
266 find_enabled_raw_code_breakpoint_at (CORE_ADDR addr
, enum raw_bkpt_type type
)
268 struct process_info
*proc
= current_process ();
269 struct raw_breakpoint
*bp
;
271 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
273 && bp
->raw_type
== type
274 && bp
->inserted
>= 0)
280 /* Find low-level breakpoint of type TYPE at address ADDR. Returns
281 NULL if not found. */
283 static struct raw_breakpoint
*
284 find_raw_breakpoint_at (CORE_ADDR addr
, enum raw_bkpt_type type
, int size
)
286 struct process_info
*proc
= current_process ();
287 struct raw_breakpoint
*bp
;
289 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
290 if (bp
->pc
== addr
&& bp
->raw_type
== type
&& bp
->size
== size
)
296 /* See mem-break.h. */
299 insert_memory_breakpoint (struct raw_breakpoint
*bp
)
301 unsigned char buf
[MAX_BREAKPOINT_LEN
];
304 if (breakpoint_data
== NULL
)
307 /* If the architecture treats the size field of Z packets as a
308 'kind' field, then we'll need to be able to know which is the
309 breakpoint instruction too. */
310 if (bp
->size
!= breakpoint_len
)
313 debug_printf ("Don't know how to insert breakpoints of size %d.\n",
318 /* Note that there can be fast tracepoint jumps installed in the
319 same memory range, so to get at the original memory, we need to
320 use read_inferior_memory, which masks those out. */
321 err
= read_inferior_memory (bp
->pc
, buf
, breakpoint_len
);
325 debug_printf ("Failed to read shadow memory of"
326 " breakpoint at 0x%s (%s).\n",
327 paddress (bp
->pc
), strerror (err
));
331 memcpy (bp
->old_data
, buf
, breakpoint_len
);
333 err
= (*the_target
->write_memory
) (bp
->pc
, breakpoint_data
,
338 debug_printf ("Failed to insert breakpoint at 0x%s (%s).\n",
339 paddress (bp
->pc
), strerror (err
));
342 return err
!= 0 ? -1 : 0;
345 /* See mem-break.h */
348 remove_memory_breakpoint (struct raw_breakpoint
*bp
)
350 unsigned char buf
[MAX_BREAKPOINT_LEN
];
353 /* Since there can be trap breakpoints inserted in the same address
354 range, we use `write_inferior_memory', which takes care of
355 layering breakpoints on top of fast tracepoints, and on top of
356 the buffer we pass it. This works because the caller has already
357 either unlinked the breakpoint or marked it uninserted. Also
358 note that we need to pass the current shadow contents, because
359 write_inferior_memory updates any shadow memory with what we pass
360 here, and we want that to be a nop. */
361 memcpy (buf
, bp
->old_data
, breakpoint_len
);
362 err
= write_inferior_memory (bp
->pc
, buf
, breakpoint_len
);
366 debug_printf ("Failed to uninsert raw breakpoint "
367 "at 0x%s (%s) while deleting it.\n",
368 paddress (bp
->pc
), strerror (err
));
370 return err
!= 0 ? -1 : 0;
373 /* Set a RAW breakpoint of type TYPE and size SIZE at WHERE. On
374 success, a pointer to the new breakpoint is returned. On failure,
375 returns NULL and writes the error code to *ERR. */
377 static struct raw_breakpoint
*
378 set_raw_breakpoint_at (enum raw_bkpt_type type
, CORE_ADDR where
, int size
,
381 struct process_info
*proc
= current_process ();
382 struct raw_breakpoint
*bp
;
384 if (type
== raw_bkpt_type_sw
|| type
== raw_bkpt_type_hw
)
386 bp
= find_enabled_raw_code_breakpoint_at (where
, type
);
387 if (bp
!= NULL
&& bp
->size
!= size
)
389 /* A different size than previously seen. The previous
390 breakpoint must be gone then. */
392 debug_printf ("Inconsistent breakpoint size? Was %d, now %d.\n",
399 bp
= find_raw_breakpoint_at (where
, type
, size
);
407 bp
= XCNEW (struct raw_breakpoint
);
413 *err
= the_target
->insert_point (bp
->raw_type
, bp
->pc
, bp
->size
, bp
);
417 debug_printf ("Failed to insert breakpoint at 0x%s (%d).\n",
418 paddress (where
), *err
);
424 /* Link the breakpoint in. */
425 bp
->next
= proc
->raw_breakpoints
;
426 proc
->raw_breakpoints
= bp
;
430 /* Notice that breakpoint traps are always installed on top of fast
431 tracepoint jumps. This is even if the fast tracepoint is installed
432 at a later time compared to when the breakpoint was installed.
433 This means that a stopping breakpoint or tracepoint has higher
434 "priority". In turn, this allows having fast and slow tracepoints
435 (and breakpoints) at the same address behave correctly. */
438 /* A fast tracepoint jump. */
440 struct fast_tracepoint_jump
442 struct fast_tracepoint_jump
*next
;
444 /* A reference count. GDB can install more than one fast tracepoint
445 at the same address (each with its own action list, for
449 /* The fast tracepoint's insertion address. There can only be one
450 of these for a given PC. */
453 /* Non-zero if this fast tracepoint jump is currently inserted in
457 /* The length of the jump instruction. */
460 /* A poor-man's flexible array member, holding both the jump
461 instruction to insert, and a copy of the instruction that would
462 be in memory had not been a jump there (the shadow memory of the
464 unsigned char insn_and_shadow
[0];
467 /* Fast tracepoint FP's jump instruction to insert. */
468 #define fast_tracepoint_jump_insn(fp) \
469 ((fp)->insn_and_shadow + 0)
471 /* The shadow memory of fast tracepoint jump FP. */
472 #define fast_tracepoint_jump_shadow(fp) \
473 ((fp)->insn_and_shadow + (fp)->length)
476 /* Return the fast tracepoint jump set at WHERE. */
478 static struct fast_tracepoint_jump
*
479 find_fast_tracepoint_jump_at (CORE_ADDR where
)
481 struct process_info
*proc
= current_process ();
482 struct fast_tracepoint_jump
*jp
;
484 for (jp
= proc
->fast_tracepoint_jumps
; jp
!= NULL
; jp
= jp
->next
)
492 fast_tracepoint_jump_here (CORE_ADDR where
)
494 struct fast_tracepoint_jump
*jp
= find_fast_tracepoint_jump_at (where
);
500 delete_fast_tracepoint_jump (struct fast_tracepoint_jump
*todel
)
502 struct fast_tracepoint_jump
*bp
, **bp_link
;
504 struct process_info
*proc
= current_process ();
506 bp
= proc
->fast_tracepoint_jumps
;
507 bp_link
= &proc
->fast_tracepoint_jumps
;
513 if (--bp
->refcount
== 0)
515 struct fast_tracepoint_jump
*prev_bp_link
= *bp_link
;
521 /* Since there can be breakpoints inserted in the same
522 address range, we use `write_inferior_memory', which
523 takes care of layering breakpoints on top of fast
524 tracepoints, and on top of the buffer we pass it.
525 This works because we've already unlinked the fast
526 tracepoint jump above. Also note that we need to
527 pass the current shadow contents, because
528 write_inferior_memory updates any shadow memory with
529 what we pass here, and we want that to be a nop. */
530 buf
= alloca (bp
->length
);
531 memcpy (buf
, fast_tracepoint_jump_shadow (bp
), bp
->length
);
532 ret
= write_inferior_memory (bp
->pc
, buf
, bp
->length
);
535 /* Something went wrong, relink the jump. */
536 *bp_link
= prev_bp_link
;
539 debug_printf ("Failed to uninsert fast tracepoint jump "
540 "at 0x%s (%s) while deleting it.\n",
541 paddress (bp
->pc
), strerror (ret
));
557 warning ("Could not find fast tracepoint jump in list.");
562 inc_ref_fast_tracepoint_jump (struct fast_tracepoint_jump
*jp
)
567 struct fast_tracepoint_jump
*
568 set_fast_tracepoint_jump (CORE_ADDR where
,
569 unsigned char *insn
, ULONGEST length
)
571 struct process_info
*proc
= current_process ();
572 struct fast_tracepoint_jump
*jp
;
576 /* We refcount fast tracepoint jumps. Check if we already know
577 about a jump at this address. */
578 jp
= find_fast_tracepoint_jump_at (where
);
585 /* We don't, so create a new object. Double the length, because the
586 flexible array member holds both the jump insn, and the
588 jp
= xcalloc (1, sizeof (*jp
) + (length
* 2));
591 memcpy (fast_tracepoint_jump_insn (jp
), insn
, length
);
593 buf
= alloca (length
);
595 /* Note that there can be trap breakpoints inserted in the same
596 address range. To access the original memory contents, we use
597 `read_inferior_memory', which masks out breakpoints. */
598 err
= read_inferior_memory (where
, buf
, length
);
602 debug_printf ("Failed to read shadow memory of"
603 " fast tracepoint at 0x%s (%s).\n",
604 paddress (where
), strerror (err
));
608 memcpy (fast_tracepoint_jump_shadow (jp
), buf
, length
);
610 /* Link the jump in. */
612 jp
->next
= proc
->fast_tracepoint_jumps
;
613 proc
->fast_tracepoint_jumps
= jp
;
615 /* Since there can be trap breakpoints inserted in the same address
616 range, we use use `write_inferior_memory', which takes care of
617 layering breakpoints on top of fast tracepoints, on top of the
618 buffer we pass it. This works because we've already linked in
619 the fast tracepoint jump above. Also note that we need to pass
620 the current shadow contents, because write_inferior_memory
621 updates any shadow memory with what we pass here, and we want
623 err
= write_inferior_memory (where
, buf
, length
);
627 debug_printf ("Failed to insert fast tracepoint jump at 0x%s (%s).\n",
628 paddress (where
), strerror (err
));
631 proc
->fast_tracepoint_jumps
= jp
->next
;
641 uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc
)
643 struct fast_tracepoint_jump
*jp
;
646 jp
= find_fast_tracepoint_jump_at (pc
);
649 /* This can happen when we remove all breakpoints while handling
652 debug_printf ("Could not find fast tracepoint jump at 0x%s "
653 "in list (uninserting).\n",
664 /* Since there can be trap breakpoints inserted in the same
665 address range, we use use `write_inferior_memory', which
666 takes care of layering breakpoints on top of fast
667 tracepoints, and on top of the buffer we pass it. This works
668 because we've already marked the fast tracepoint fast
669 tracepoint jump uninserted above. Also note that we need to
670 pass the current shadow contents, because
671 write_inferior_memory updates any shadow memory with what we
672 pass here, and we want that to be a nop. */
673 buf
= alloca (jp
->length
);
674 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
675 err
= write_inferior_memory (jp
->pc
, buf
, jp
->length
);
681 debug_printf ("Failed to uninsert fast tracepoint jump at"
683 paddress (pc
), strerror (err
));
689 reinsert_fast_tracepoint_jumps_at (CORE_ADDR where
)
691 struct fast_tracepoint_jump
*jp
;
695 jp
= find_fast_tracepoint_jump_at (where
);
698 /* This can happen when we remove breakpoints when a tracepoint
699 hit causes a tracing stop, while handling a step-over. */
701 debug_printf ("Could not find fast tracepoint jump at 0x%s "
702 "in list (reinserting).\n",
708 error ("Jump already inserted at reinsert time.");
712 /* Since there can be trap breakpoints inserted in the same address
713 range, we use `write_inferior_memory', which takes care of
714 layering breakpoints on top of fast tracepoints, and on top of
715 the buffer we pass it. This works because we've already marked
716 the fast tracepoint jump inserted above. Also note that we need
717 to pass the current shadow contents, because
718 write_inferior_memory updates any shadow memory with what we pass
719 here, and we want that to be a nop. */
720 buf
= alloca (jp
->length
);
721 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
722 err
= write_inferior_memory (where
, buf
, jp
->length
);
728 debug_printf ("Failed to reinsert fast tracepoint jump at"
730 paddress (where
), strerror (err
));
734 /* Set a high-level breakpoint of type TYPE, with low level type
735 RAW_TYPE and size SIZE, at WHERE. On success, a pointer to the new
736 breakpoint is returned. On failure, returns NULL and writes the
737 error code to *ERR. HANDLER is called when the breakpoint is hit.
738 HANDLER should return 1 if the breakpoint should be deleted, 0
741 static struct breakpoint
*
742 set_breakpoint (enum bkpt_type type
, enum raw_bkpt_type raw_type
,
743 CORE_ADDR where
, int size
,
744 int (*handler
) (CORE_ADDR
), int *err
)
746 struct process_info
*proc
= current_process ();
747 struct breakpoint
*bp
;
748 struct raw_breakpoint
*raw
;
750 raw
= set_raw_breakpoint_at (raw_type
, where
, size
, err
);
758 bp
= XCNEW (struct breakpoint
);
762 bp
->handler
= handler
;
764 bp
->next
= proc
->breakpoints
;
765 proc
->breakpoints
= bp
;
770 /* See mem-break.h */
773 set_breakpoint_at (CORE_ADDR where
, int (*handler
) (CORE_ADDR
))
777 return set_breakpoint (other_breakpoint
, raw_bkpt_type_sw
,
778 where
, breakpoint_len
, handler
,
784 delete_raw_breakpoint (struct process_info
*proc
, struct raw_breakpoint
*todel
)
786 struct raw_breakpoint
*bp
, **bp_link
;
789 bp
= proc
->raw_breakpoints
;
790 bp_link
= &proc
->raw_breakpoints
;
796 if (bp
->inserted
> 0)
798 struct raw_breakpoint
*prev_bp_link
= *bp_link
;
802 ret
= the_target
->remove_point (bp
->raw_type
, bp
->pc
, bp
->size
,
806 /* Something went wrong, relink the breakpoint. */
807 *bp_link
= prev_bp_link
;
810 debug_printf ("Failed to uninsert raw breakpoint "
811 "at 0x%s while deleting it.\n",
829 warning ("Could not find raw breakpoint in list.");
834 release_breakpoint (struct process_info
*proc
, struct breakpoint
*bp
)
839 newrefcount
= bp
->raw
->refcount
- 1;
840 if (newrefcount
== 0)
842 ret
= delete_raw_breakpoint (proc
, bp
->raw
);
847 bp
->raw
->refcount
= newrefcount
;
855 delete_breakpoint_1 (struct process_info
*proc
, struct breakpoint
*todel
)
857 struct breakpoint
*bp
, **bp_link
;
860 bp
= proc
->breakpoints
;
861 bp_link
= &proc
->breakpoints
;
869 err
= release_breakpoint (proc
, bp
);
883 warning ("Could not find breakpoint in list.");
888 delete_breakpoint (struct breakpoint
*todel
)
890 struct process_info
*proc
= current_process ();
891 return delete_breakpoint_1 (proc
, todel
);
894 /* Locate a GDB breakpoint of type Z_TYPE and size SIZE placed at
895 address ADDR and return a pointer to its structure. If SIZE is -1,
896 the breakpoints' sizes are ignored. */
898 static struct breakpoint
*
899 find_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int size
)
901 struct process_info
*proc
= current_process ();
902 struct breakpoint
*bp
;
903 enum bkpt_type type
= Z_packet_to_bkpt_type (z_type
);
905 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
906 if (bp
->type
== type
&& bp
->raw
->pc
== addr
907 && (size
== -1 || bp
->raw
->size
== size
))
914 z_type_supported (char z_type
)
916 return (z_type
>= '0' && z_type
<= '4'
917 && the_target
->supports_z_point_type
!= NULL
918 && the_target
->supports_z_point_type (z_type
));
921 /* Create a new GDB breakpoint of type Z_TYPE at ADDR with size SIZE.
922 Returns a pointer to the newly created breakpoint on success. On
923 failure returns NULL and sets *ERR to either -1 for error, or 1 if
924 Z_TYPE breakpoints are not supported on this target. */
926 static struct breakpoint
*
927 set_gdb_breakpoint_1 (char z_type
, CORE_ADDR addr
, int size
, int *err
)
929 struct breakpoint
*bp
;
931 enum raw_bkpt_type raw_type
;
933 /* If we see GDB inserting a second code breakpoint at the same
934 address, then either: GDB is updating the breakpoint's conditions
935 or commands; or, the first breakpoint must have disappeared due
936 to a shared library unload. On targets where the shared
937 libraries are handled by userspace, like SVR4, for example,
938 GDBserver can't tell if a library was loaded or unloaded. Since
939 we refcount raw breakpoints, we must be careful to make sure GDB
940 breakpoints never contribute more than one reference. if we
941 didn't do this, in case the previous breakpoint is gone due to a
942 shared library unload, we'd just increase the refcount of the
943 previous breakpoint at this address, but the trap was not planted
944 in the inferior anymore, thus the breakpoint would never be hit.
945 Note this must be careful to not create a window where
946 breakpoints are removed from the target, for non-stop, in case
947 the target can poke at memory while the program is running. */
948 if (z_type
== Z_PACKET_SW_BP
949 || z_type
== Z_PACKET_HW_BP
)
951 bp
= find_gdb_breakpoint (z_type
, addr
, -1);
955 if (bp
->raw
->size
!= size
)
957 /* A different size than previously seen. The previous
958 breakpoint must be gone then. */
959 bp
->raw
->inserted
= -1;
960 delete_breakpoint (bp
);
963 else if (z_type
== Z_PACKET_SW_BP
)
965 /* Check if the breakpoint is actually gone from the
966 target, due to an solib unload, for example. Might
967 as well validate _all_ breakpoints. */
968 validate_breakpoints ();
970 /* Breakpoints that don't pass validation are
972 bp
= find_gdb_breakpoint (z_type
, addr
, -1);
978 /* Data breakpoints for the same address but different size are
979 expected. GDB doesn't merge these. The backend gets to do
980 that if it wants/can. */
981 bp
= find_gdb_breakpoint (z_type
, addr
, size
);
986 /* We already know about this breakpoint, there's nothing else
987 to do - GDB's reference is already accounted for. Note that
988 whether the breakpoint inserted is left as is - we may be
989 stepping over it, for example, in which case we don't want to
990 force-reinsert it. */
994 raw_type
= Z_packet_to_raw_bkpt_type (z_type
);
995 type
= Z_packet_to_bkpt_type (z_type
);
996 return set_breakpoint (type
, raw_type
, addr
, size
, NULL
, err
);
1000 check_gdb_bp_preconditions (char z_type
, int *err
)
1002 /* As software/memory breakpoints work by poking at memory, we need
1003 to prepare to access memory. If that operation fails, we need to
1004 return error. Seeing an error, if this is the first breakpoint
1005 of that type that GDB tries to insert, GDB would then assume the
1006 breakpoint type is supported, but it may actually not be. So we
1007 need to check whether the type is supported at all before
1008 preparing to access memory. */
1009 if (!z_type_supported (z_type
))
1014 else if (current_thread
== NULL
)
1023 /* See mem-break.h. This is a wrapper for set_gdb_breakpoint_1 that
1024 knows to prepare to access memory for Z0 breakpoints. */
1027 set_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int size
, int *err
)
1029 struct breakpoint
*bp
;
1031 if (!check_gdb_bp_preconditions (z_type
, err
))
1034 /* If inserting a software/memory breakpoint, need to prepare to
1036 if (z_type
== Z_PACKET_SW_BP
)
1038 *err
= prepare_to_access_memory ();
1043 bp
= set_gdb_breakpoint_1 (z_type
, addr
, size
, err
);
1045 if (z_type
== Z_PACKET_SW_BP
)
1046 done_accessing_memory ();
1051 /* Delete a GDB breakpoint of type Z_TYPE and size SIZE previously
1052 inserted at ADDR with set_gdb_breakpoint_at. Returns 0 on success,
1053 -1 on error, and 1 if Z_TYPE breakpoints are not supported on this
1057 delete_gdb_breakpoint_1 (char z_type
, CORE_ADDR addr
, int size
)
1059 struct breakpoint
*bp
;
1062 bp
= find_gdb_breakpoint (z_type
, addr
, size
);
1066 /* Before deleting the breakpoint, make sure to free its condition
1067 and command lists. */
1068 clear_breakpoint_conditions_and_commands (bp
);
1069 err
= delete_breakpoint (bp
);
1076 /* See mem-break.h. This is a wrapper for delete_gdb_breakpoint that
1077 knows to prepare to access memory for Z0 breakpoints. */
1080 delete_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int size
)
1084 if (!check_gdb_bp_preconditions (z_type
, &ret
))
1087 /* If inserting a software/memory breakpoint, need to prepare to
1089 if (z_type
== Z_PACKET_SW_BP
)
1093 err
= prepare_to_access_memory ();
1098 ret
= delete_gdb_breakpoint_1 (z_type
, addr
, size
);
1100 if (z_type
== Z_PACKET_SW_BP
)
1101 done_accessing_memory ();
1106 /* Clear all conditions associated with a breakpoint. */
1109 clear_breakpoint_conditions (struct breakpoint
*bp
)
1111 struct point_cond_list
*cond
;
1113 if (bp
->cond_list
== NULL
)
1116 cond
= bp
->cond_list
;
1118 while (cond
!= NULL
)
1120 struct point_cond_list
*cond_next
;
1122 cond_next
= cond
->next
;
1123 gdb_free_agent_expr (cond
->cond
);
1128 bp
->cond_list
= NULL
;
1131 /* Clear all commands associated with a breakpoint. */
1134 clear_breakpoint_commands (struct breakpoint
*bp
)
1136 struct point_command_list
*cmd
;
1138 if (bp
->command_list
== NULL
)
1141 cmd
= bp
->command_list
;
1145 struct point_command_list
*cmd_next
;
1147 cmd_next
= cmd
->next
;
1148 gdb_free_agent_expr (cmd
->cmd
);
1153 bp
->command_list
= NULL
;
1157 clear_breakpoint_conditions_and_commands (struct breakpoint
*bp
)
1159 clear_breakpoint_conditions (bp
);
1160 clear_breakpoint_commands (bp
);
1163 /* Add condition CONDITION to GDBserver's breakpoint BP. */
1166 add_condition_to_breakpoint (struct breakpoint
*bp
,
1167 struct agent_expr
*condition
)
1169 struct point_cond_list
*new_cond
;
1171 /* Create new condition. */
1172 new_cond
= XCNEW (struct point_cond_list
);
1173 new_cond
->cond
= condition
;
1175 /* Add condition to the list. */
1176 new_cond
->next
= bp
->cond_list
;
1177 bp
->cond_list
= new_cond
;
1180 /* Add a target-side condition CONDITION to a breakpoint. */
1183 add_breakpoint_condition (struct breakpoint
*bp
, char **condition
)
1185 char *actparm
= *condition
;
1186 struct agent_expr
*cond
;
1188 if (condition
== NULL
)
1194 cond
= gdb_parse_agent_expr (&actparm
);
1198 fprintf (stderr
, "Condition evaluation failed. "
1199 "Assuming unconditional.\n");
1203 add_condition_to_breakpoint (bp
, cond
);
1205 *condition
= actparm
;
1210 /* Evaluate condition (if any) at breakpoint BP. Return 1 if
1211 true and 0 otherwise. */
1214 gdb_condition_true_at_breakpoint_z_type (char z_type
, CORE_ADDR addr
)
1216 /* Fetch registers for the current inferior. */
1217 struct breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1219 struct point_cond_list
*cl
;
1221 struct eval_agent_expr_context ctx
;
1226 /* Check if the breakpoint is unconditional. If it is,
1227 the condition always evaluates to TRUE. */
1228 if (bp
->cond_list
== NULL
)
1231 ctx
.regcache
= get_thread_regcache (current_thread
, 1);
1235 /* Evaluate each condition in the breakpoint's list of conditions.
1236 Return true if any of the conditions evaluates to TRUE.
1238 If we failed to evaluate the expression, TRUE is returned. This
1239 forces GDB to reevaluate the conditions. */
1240 for (cl
= bp
->cond_list
;
1241 cl
&& !value
&& !err
; cl
= cl
->next
)
1243 /* Evaluate the condition. */
1244 err
= gdb_eval_agent_expr (&ctx
, cl
->cond
, &value
);
1250 return (value
!= 0);
1254 gdb_condition_true_at_breakpoint (CORE_ADDR where
)
1256 /* Only check code (software or hardware) breakpoints. */
1257 return (gdb_condition_true_at_breakpoint_z_type (Z_PACKET_SW_BP
, where
)
1258 || gdb_condition_true_at_breakpoint_z_type (Z_PACKET_HW_BP
, where
));
1261 /* Add commands COMMANDS to GDBserver's breakpoint BP. */
1264 add_commands_to_breakpoint (struct breakpoint
*bp
,
1265 struct agent_expr
*commands
, int persist
)
1267 struct point_command_list
*new_cmd
;
1269 /* Create new command. */
1270 new_cmd
= XCNEW (struct point_command_list
);
1271 new_cmd
->cmd
= commands
;
1272 new_cmd
->persistence
= persist
;
1274 /* Add commands to the list. */
1275 new_cmd
->next
= bp
->command_list
;
1276 bp
->command_list
= new_cmd
;
1279 /* Add a target-side command COMMAND to the breakpoint at ADDR. */
1282 add_breakpoint_commands (struct breakpoint
*bp
, char **command
,
1285 char *actparm
= *command
;
1286 struct agent_expr
*cmd
;
1288 if (command
== NULL
)
1294 cmd
= gdb_parse_agent_expr (&actparm
);
1298 fprintf (stderr
, "Command evaluation failed. "
1303 add_commands_to_breakpoint (bp
, cmd
, persist
);
1310 /* Return true if there are no commands to run at this location,
1311 which likely means we want to report back to GDB. */
1314 gdb_no_commands_at_breakpoint_z_type (char z_type
, CORE_ADDR addr
)
1316 struct breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1322 debug_printf ("at 0x%s, type Z%c, bp command_list is 0x%s\n",
1323 paddress (addr
), z_type
,
1324 phex_nz ((uintptr_t) bp
->command_list
, 0));
1325 return (bp
->command_list
== NULL
);
1328 /* Return true if there are no commands to run at this location,
1329 which likely means we want to report back to GDB. */
1332 gdb_no_commands_at_breakpoint (CORE_ADDR where
)
1334 /* Only check code (software or hardware) breakpoints. */
1335 return (gdb_no_commands_at_breakpoint_z_type (Z_PACKET_SW_BP
, where
)
1336 && gdb_no_commands_at_breakpoint_z_type (Z_PACKET_HW_BP
, where
));
1339 /* Run a breakpoint's commands. Returns 0 if there was a problem
1340 running any command, 1 otherwise. */
1343 run_breakpoint_commands_z_type (char z_type
, CORE_ADDR addr
)
1345 /* Fetch registers for the current inferior. */
1346 struct breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1348 struct point_command_list
*cl
;
1350 struct eval_agent_expr_context ctx
;
1355 ctx
.regcache
= get_thread_regcache (current_thread
, 1);
1359 for (cl
= bp
->command_list
;
1360 cl
&& !value
&& !err
; cl
= cl
->next
)
1362 /* Run the command. */
1363 err
= gdb_eval_agent_expr (&ctx
, cl
->cmd
, &value
);
1365 /* If one command has a problem, stop digging the hole deeper. */
1374 run_breakpoint_commands (CORE_ADDR where
)
1376 /* Only check code (software or hardware) breakpoints. If one
1377 command has a problem, stop digging the hole deeper. */
1378 if (run_breakpoint_commands_z_type (Z_PACKET_SW_BP
, where
))
1379 run_breakpoint_commands_z_type (Z_PACKET_HW_BP
, where
);
1382 /* See mem-break.h. */
1385 gdb_breakpoint_here (CORE_ADDR where
)
1387 /* Only check code (software or hardware) breakpoints. */
1388 return (find_gdb_breakpoint (Z_PACKET_SW_BP
, where
, -1) != NULL
1389 || find_gdb_breakpoint (Z_PACKET_HW_BP
, where
, -1) != NULL
);
1393 set_reinsert_breakpoint (CORE_ADDR stop_at
)
1395 struct breakpoint
*bp
;
1397 bp
= set_breakpoint_at (stop_at
, NULL
);
1398 bp
->type
= reinsert_breakpoint
;
1402 delete_reinsert_breakpoints (void)
1404 struct process_info
*proc
= current_process ();
1405 struct breakpoint
*bp
, **bp_link
;
1407 bp
= proc
->breakpoints
;
1408 bp_link
= &proc
->breakpoints
;
1412 if (bp
->type
== reinsert_breakpoint
)
1414 *bp_link
= bp
->next
;
1415 release_breakpoint (proc
, bp
);
1420 bp_link
= &bp
->next
;
1427 uninsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1429 if (bp
->inserted
< 0)
1432 debug_printf ("Breakpoint at %s is marked insert-disabled.\n",
1435 else if (bp
->inserted
> 0)
1441 err
= the_target
->remove_point (bp
->raw_type
, bp
->pc
, bp
->size
, bp
);
1447 debug_printf ("Failed to uninsert raw breakpoint at 0x%s.\n",
1454 uninsert_breakpoints_at (CORE_ADDR pc
)
1456 struct process_info
*proc
= current_process ();
1457 struct raw_breakpoint
*bp
;
1460 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1461 if ((bp
->raw_type
== raw_bkpt_type_sw
1462 || bp
->raw_type
== raw_bkpt_type_hw
)
1468 uninsert_raw_breakpoint (bp
);
1473 /* This can happen when we remove all breakpoints while handling
1476 debug_printf ("Could not find breakpoint at 0x%s "
1477 "in list (uninserting).\n",
1483 uninsert_all_breakpoints (void)
1485 struct process_info
*proc
= current_process ();
1486 struct raw_breakpoint
*bp
;
1488 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1489 if ((bp
->raw_type
== raw_bkpt_type_sw
1490 || bp
->raw_type
== raw_bkpt_type_hw
)
1492 uninsert_raw_breakpoint (bp
);
1496 reinsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1501 error ("Breakpoint already inserted at reinsert time.");
1503 err
= the_target
->insert_point (bp
->raw_type
, bp
->pc
, bp
->size
, bp
);
1506 else if (debug_threads
)
1507 debug_printf ("Failed to reinsert breakpoint at 0x%s (%d).\n",
1508 paddress (bp
->pc
), err
);
1512 reinsert_breakpoints_at (CORE_ADDR pc
)
1514 struct process_info
*proc
= current_process ();
1515 struct raw_breakpoint
*bp
;
1518 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1519 if ((bp
->raw_type
== raw_bkpt_type_sw
1520 || bp
->raw_type
== raw_bkpt_type_hw
)
1525 reinsert_raw_breakpoint (bp
);
1530 /* This can happen when we remove all breakpoints while handling
1533 debug_printf ("Could not find raw breakpoint at 0x%s "
1534 "in list (reinserting).\n",
1540 reinsert_all_breakpoints (void)
1542 struct process_info
*proc
= current_process ();
1543 struct raw_breakpoint
*bp
;
1545 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1546 if ((bp
->raw_type
== raw_bkpt_type_sw
1547 || bp
->raw_type
== raw_bkpt_type_hw
)
1549 reinsert_raw_breakpoint (bp
);
1553 check_breakpoints (CORE_ADDR stop_pc
)
1555 struct process_info
*proc
= current_process ();
1556 struct breakpoint
*bp
, **bp_link
;
1558 bp
= proc
->breakpoints
;
1559 bp_link
= &proc
->breakpoints
;
1563 struct raw_breakpoint
*raw
= bp
->raw
;
1565 if ((raw
->raw_type
== raw_bkpt_type_sw
1566 || raw
->raw_type
== raw_bkpt_type_hw
)
1567 && raw
->pc
== stop_pc
)
1571 warning ("Hit a removed breakpoint?");
1575 if (bp
->handler
!= NULL
&& (*bp
->handler
) (stop_pc
))
1577 *bp_link
= bp
->next
;
1579 release_breakpoint (proc
, bp
);
1586 bp_link
= &bp
->next
;
1592 set_breakpoint_data (const unsigned char *bp_data
, int bp_len
)
1594 breakpoint_data
= bp_data
;
1595 breakpoint_len
= bp_len
;
1599 breakpoint_here (CORE_ADDR addr
)
1601 struct process_info
*proc
= current_process ();
1602 struct raw_breakpoint
*bp
;
1604 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1605 if ((bp
->raw_type
== raw_bkpt_type_sw
1606 || bp
->raw_type
== raw_bkpt_type_hw
)
1614 breakpoint_inserted_here (CORE_ADDR addr
)
1616 struct process_info
*proc
= current_process ();
1617 struct raw_breakpoint
*bp
;
1619 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1620 if ((bp
->raw_type
== raw_bkpt_type_sw
1621 || bp
->raw_type
== raw_bkpt_type_hw
)
1629 /* See mem-break.h. */
1632 software_breakpoint_inserted_here (CORE_ADDR addr
)
1634 struct process_info
*proc
= current_process ();
1635 struct raw_breakpoint
*bp
;
1637 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1638 if (bp
->raw_type
== raw_bkpt_type_sw
1646 /* See mem-break.h. */
1649 hardware_breakpoint_inserted_here (CORE_ADDR addr
)
1651 struct process_info
*proc
= current_process ();
1652 struct raw_breakpoint
*bp
;
1654 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1655 if (bp
->raw_type
== raw_bkpt_type_hw
1664 validate_inserted_breakpoint (struct raw_breakpoint
*bp
)
1669 gdb_assert (bp
->inserted
);
1670 gdb_assert (bp
->raw_type
== raw_bkpt_type_sw
);
1672 buf
= alloca (breakpoint_len
);
1673 err
= (*the_target
->read_memory
) (bp
->pc
, buf
, breakpoint_len
);
1674 if (err
|| memcmp (buf
, breakpoint_data
, breakpoint_len
) != 0)
1676 /* Tag it as gone. */
1685 delete_disabled_breakpoints (void)
1687 struct process_info
*proc
= current_process ();
1688 struct breakpoint
*bp
, *next
;
1690 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= next
)
1693 if (bp
->raw
->inserted
< 0)
1694 delete_breakpoint_1 (proc
, bp
);
1698 /* Check if breakpoints we inserted still appear to be inserted. They
1699 may disappear due to a shared library unload, and worse, a new
1700 shared library may be reloaded at the same address as the
1701 previously unloaded one. If that happens, we should make sure that
1702 the shadow memory of the old breakpoints isn't used when reading or
1706 validate_breakpoints (void)
1708 struct process_info
*proc
= current_process ();
1709 struct breakpoint
*bp
;
1711 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1713 struct raw_breakpoint
*raw
= bp
->raw
;
1715 if (raw
->raw_type
== raw_bkpt_type_sw
&& raw
->inserted
> 0)
1716 validate_inserted_breakpoint (raw
);
1719 delete_disabled_breakpoints ();
1723 check_mem_read (CORE_ADDR mem_addr
, unsigned char *buf
, int mem_len
)
1725 struct process_info
*proc
= current_process ();
1726 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1727 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1728 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1729 int disabled_one
= 0;
1731 for (; jp
!= NULL
; jp
= jp
->next
)
1733 CORE_ADDR bp_end
= jp
->pc
+ jp
->length
;
1734 CORE_ADDR start
, end
;
1735 int copy_offset
, copy_len
, buf_offset
;
1737 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= buf
+ mem_len
1738 || buf
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1740 if (mem_addr
>= bp_end
)
1742 if (jp
->pc
>= mem_end
)
1746 if (mem_addr
> start
)
1753 copy_len
= end
- start
;
1754 copy_offset
= start
- jp
->pc
;
1755 buf_offset
= start
- mem_addr
;
1758 memcpy (buf
+ buf_offset
,
1759 fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1763 for (; bp
!= NULL
; bp
= bp
->next
)
1765 CORE_ADDR bp_end
= bp
->pc
+ breakpoint_len
;
1766 CORE_ADDR start
, end
;
1767 int copy_offset
, copy_len
, buf_offset
;
1769 if (bp
->raw_type
!= raw_bkpt_type_sw
)
1772 gdb_assert (bp
->old_data
>= buf
+ mem_len
1773 || buf
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1775 if (mem_addr
>= bp_end
)
1777 if (bp
->pc
>= mem_end
)
1781 if (mem_addr
> start
)
1788 copy_len
= end
- start
;
1789 copy_offset
= start
- bp
->pc
;
1790 buf_offset
= start
- mem_addr
;
1792 if (bp
->inserted
> 0)
1794 if (validate_inserted_breakpoint (bp
))
1795 memcpy (buf
+ buf_offset
, bp
->old_data
+ copy_offset
, copy_len
);
1802 delete_disabled_breakpoints ();
1806 check_mem_write (CORE_ADDR mem_addr
, unsigned char *buf
,
1807 const unsigned char *myaddr
, int mem_len
)
1809 struct process_info
*proc
= current_process ();
1810 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1811 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1812 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1813 int disabled_one
= 0;
1815 /* First fast tracepoint jumps, then breakpoint traps on top. */
1817 for (; jp
!= NULL
; jp
= jp
->next
)
1819 CORE_ADDR jp_end
= jp
->pc
+ jp
->length
;
1820 CORE_ADDR start
, end
;
1821 int copy_offset
, copy_len
, buf_offset
;
1823 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= myaddr
+ mem_len
1824 || myaddr
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1825 gdb_assert (fast_tracepoint_jump_insn (jp
) >= buf
+ mem_len
1826 || buf
>= fast_tracepoint_jump_insn (jp
) + (jp
)->length
);
1828 if (mem_addr
>= jp_end
)
1830 if (jp
->pc
>= mem_end
)
1834 if (mem_addr
> start
)
1841 copy_len
= end
- start
;
1842 copy_offset
= start
- jp
->pc
;
1843 buf_offset
= start
- mem_addr
;
1845 memcpy (fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1846 myaddr
+ buf_offset
, copy_len
);
1848 memcpy (buf
+ buf_offset
,
1849 fast_tracepoint_jump_insn (jp
) + copy_offset
, copy_len
);
1852 for (; bp
!= NULL
; bp
= bp
->next
)
1854 CORE_ADDR bp_end
= bp
->pc
+ breakpoint_len
;
1855 CORE_ADDR start
, end
;
1856 int copy_offset
, copy_len
, buf_offset
;
1858 if (bp
->raw_type
!= raw_bkpt_type_sw
)
1861 gdb_assert (bp
->old_data
>= myaddr
+ mem_len
1862 || myaddr
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1864 if (mem_addr
>= bp_end
)
1866 if (bp
->pc
>= mem_end
)
1870 if (mem_addr
> start
)
1877 copy_len
= end
- start
;
1878 copy_offset
= start
- bp
->pc
;
1879 buf_offset
= start
- mem_addr
;
1881 memcpy (bp
->old_data
+ copy_offset
, myaddr
+ buf_offset
, copy_len
);
1882 if (bp
->inserted
> 0)
1884 if (validate_inserted_breakpoint (bp
))
1885 memcpy (buf
+ buf_offset
, breakpoint_data
+ copy_offset
, copy_len
);
1892 delete_disabled_breakpoints ();
1895 /* Delete all breakpoints, and un-insert them from the inferior. */
1898 delete_all_breakpoints (void)
1900 struct process_info
*proc
= current_process ();
1902 while (proc
->breakpoints
)
1903 delete_breakpoint_1 (proc
, proc
->breakpoints
);
1906 /* Clear the "inserted" flag in all breakpoints. */
1909 mark_breakpoints_out (struct process_info
*proc
)
1911 struct raw_breakpoint
*raw_bp
;
1913 for (raw_bp
= proc
->raw_breakpoints
; raw_bp
!= NULL
; raw_bp
= raw_bp
->next
)
1914 raw_bp
->inserted
= 0;
1917 /* Release all breakpoints, but do not try to un-insert them from the
1921 free_all_breakpoints (struct process_info
*proc
)
1923 mark_breakpoints_out (proc
);
1925 /* Note: use PROC explicitly instead of deferring to
1926 delete_all_breakpoints --- CURRENT_INFERIOR may already have been
1927 released when we get here. There should be no call to
1928 current_process from here on. */
1929 while (proc
->breakpoints
)
1930 delete_breakpoint_1 (proc
, proc
->breakpoints
);
1933 /* Clone an agent expression. */
1935 static struct agent_expr
*
1936 clone_agent_expr (const struct agent_expr
*src_ax
)
1938 struct agent_expr
*ax
;
1940 ax
= XCNEW (struct agent_expr
);
1941 ax
->length
= src_ax
->length
;
1942 ax
->bytes
= xcalloc (ax
->length
, 1);
1943 memcpy (ax
->bytes
, src_ax
->bytes
, ax
->length
);
1947 /* Deep-copy the contents of one breakpoint to another. */
1949 static struct breakpoint
*
1950 clone_one_breakpoint (const struct breakpoint
*src
)
1952 struct breakpoint
*dest
;
1953 struct raw_breakpoint
*dest_raw
;
1954 struct point_cond_list
*current_cond
;
1955 struct point_cond_list
*new_cond
;
1956 struct point_cond_list
*cond_tail
= NULL
;
1957 struct point_command_list
*current_cmd
;
1958 struct point_command_list
*new_cmd
;
1959 struct point_command_list
*cmd_tail
= NULL
;
1961 /* Clone the raw breakpoint. */
1962 dest_raw
= XCNEW (struct raw_breakpoint
);
1963 dest_raw
->raw_type
= src
->raw
->raw_type
;
1964 dest_raw
->refcount
= src
->raw
->refcount
;
1965 dest_raw
->pc
= src
->raw
->pc
;
1966 dest_raw
->size
= src
->raw
->size
;
1967 memcpy (dest_raw
->old_data
, src
->raw
->old_data
, MAX_BREAKPOINT_LEN
);
1968 dest_raw
->inserted
= src
->raw
->inserted
;
1970 /* Clone the high-level breakpoint. */
1971 dest
= XCNEW (struct breakpoint
);
1972 dest
->type
= src
->type
;
1973 dest
->raw
= dest_raw
;
1974 dest
->handler
= src
->handler
;
1976 /* Clone the condition list. */
1977 for (current_cond
= src
->cond_list
; current_cond
!= NULL
;
1978 current_cond
= current_cond
->next
)
1980 new_cond
= XCNEW (struct point_cond_list
);
1981 new_cond
->cond
= clone_agent_expr (current_cond
->cond
);
1982 APPEND_TO_LIST (&dest
->cond_list
, new_cond
, cond_tail
);
1985 /* Clone the command list. */
1986 for (current_cmd
= src
->command_list
; current_cmd
!= NULL
;
1987 current_cmd
= current_cmd
->next
)
1989 new_cmd
= XCNEW (struct point_command_list
);
1990 new_cmd
->cmd
= clone_agent_expr (current_cmd
->cmd
);
1991 new_cmd
->persistence
= current_cmd
->persistence
;
1992 APPEND_TO_LIST (&dest
->command_list
, new_cmd
, cmd_tail
);
1998 /* Create a new breakpoint list NEW_LIST that is a copy of the
1999 list starting at SRC_LIST. Create the corresponding new
2000 raw_breakpoint list NEW_RAW_LIST as well. */
2003 clone_all_breakpoints (struct breakpoint
**new_list
,
2004 struct raw_breakpoint
**new_raw_list
,
2005 const struct breakpoint
*src_list
)
2007 const struct breakpoint
*bp
;
2008 struct breakpoint
*new_bkpt
;
2009 struct breakpoint
*bkpt_tail
= NULL
;
2010 struct raw_breakpoint
*raw_bkpt_tail
= NULL
;
2012 for (bp
= src_list
; bp
!= NULL
; bp
= bp
->next
)
2014 new_bkpt
= clone_one_breakpoint (bp
);
2015 APPEND_TO_LIST (new_list
, new_bkpt
, bkpt_tail
);
2016 APPEND_TO_LIST (new_raw_list
, new_bkpt
->raw
, raw_bkpt_tail
);