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/>. */
26 const unsigned char *breakpoint_data
;
29 #define MAX_BREAKPOINT_LEN 8
31 /* Helper macro used in loops that append multiple items to a singly-linked
32 list instead of inserting items at the head of the list, as, say, in the
33 breakpoint lists. LISTPP is a pointer to the pointer that is the head of
34 the new list. ITEMP is a pointer to the item to be added to the list.
35 TAILP must be defined to be the same type as ITEMP, and initialized to
38 #define APPEND_TO_LIST(listpp, itemp, tailp) \
41 if ((tailp) == NULL) \
42 *(listpp) = (itemp); \
44 (tailp)->next = (itemp); \
49 /* GDB will never try to install multiple breakpoints at the same
50 address. However, we can see GDB requesting to insert a breakpoint
51 at an address is had already inserted one previously in a few
54 - The RSP documentation on Z packets says that to avoid potential
55 problems with duplicate packets, the operations should be
56 implemented in an idempotent way.
58 - A breakpoint is set at ADDR, an address in a shared library.
59 Then the shared library is unloaded. And then another, unrelated,
60 breakpoint at ADDR is set. There is not breakpoint removal request
61 between the first and the second breakpoint.
63 - When GDB wants to update the target-side breakpoint conditions or
64 commands, it re-inserts the breakpoint, with updated
65 conditions/commands associated.
67 Also, we need to keep track of internal breakpoints too, so we do
68 need to be able to install multiple breakpoints at the same address
71 We keep track of two different, and closely related structures. A
72 raw breakpoint, which manages the low level, close to the metal
73 aspect of a breakpoint. It holds the breakpoint address, and for
74 software breakpoints, a buffer holding a copy of the instructions
75 that would be in memory had not been a breakpoint there (we call
76 that the shadow memory of the breakpoint). We occasionally need to
77 temporarilly uninsert a breakpoint without the client knowing about
78 it (e.g., to step over an internal breakpoint), so we keep an
79 `inserted' state associated with this low level breakpoint
80 structure. There can only be one such object for a given address.
81 Then, we have (a bit higher level) breakpoints. This structure
82 holds a callback to be called whenever a breakpoint is hit, a
83 high-level type, and a link to a low level raw breakpoint. There
84 can be many high-level breakpoints at the same address, and all of
85 them will point to the same raw breakpoint, which is reference
88 /* The low level, physical, raw breakpoint. */
91 struct raw_breakpoint
*next
;
93 /* The low level type of the breakpoint (software breakpoint,
95 enum raw_bkpt_type raw_type
;
97 /* A reference count. Each high level breakpoint referencing this
98 raw breakpoint accounts for one reference. */
101 /* The breakpoint's insertion address. There can only be one raw
102 breakpoint for a given PC. */
105 /* The breakpoint's size. */
108 /* The breakpoint's shadow memory. */
109 unsigned char old_data
[MAX_BREAKPOINT_LEN
];
111 /* Positive if this breakpoint is currently inserted in the
112 inferior. Negative if it was, but we've detected that it's now
113 gone. Zero if not inserted. */
117 /* The type of a breakpoint. */
120 /* A GDB breakpoint, requested with a Z0 packet. */
123 /* A GDB hardware breakpoint, requested with a Z1 packet. */
126 /* A GDB write watchpoint, requested with a Z2 packet. */
129 /* A GDB read watchpoint, requested with a Z3 packet. */
132 /* A GDB access watchpoint, requested with a Z4 packet. */
135 /* A basic-software-single-step breakpoint. */
138 /* Any other breakpoint type that doesn't require specific
139 treatment goes here. E.g., an event breakpoint. */
143 struct point_cond_list
145 /* Pointer to the agent expression that is the breakpoint's
147 struct agent_expr
*cond
;
149 /* Pointer to the next condition. */
150 struct point_cond_list
*next
;
153 struct point_command_list
155 /* Pointer to the agent expression that is the breakpoint's
157 struct agent_expr
*cmd
;
159 /* Flag that is true if this command should run even while GDB is
163 /* Pointer to the next command. */
164 struct point_command_list
*next
;
167 /* A high level (in gdbserver's perspective) breakpoint. */
170 struct breakpoint
*next
;
172 /* The breakpoint's type. */
175 /* Pointer to the condition list that should be evaluated on
176 the target or NULL if the breakpoint is unconditional or
177 if GDB doesn't want us to evaluate the conditionals on the
179 struct point_cond_list
*cond_list
;
181 /* Point to the list of commands to run when this is hit. */
182 struct point_command_list
*command_list
;
184 /* Link to this breakpoint's raw breakpoint. This is always
186 struct raw_breakpoint
*raw
;
188 /* Function to call when we hit this breakpoint. If it returns 1,
189 the breakpoint shall be deleted; 0 or if this callback is NULL,
190 it will be left inserted. */
191 int (*handler
) (CORE_ADDR
);
194 /* See mem-break.h. */
196 enum target_hw_bp_type
197 raw_bkpt_type_to_target_hw_bp_type (enum raw_bkpt_type raw_type
)
201 case raw_bkpt_type_hw
:
203 case raw_bkpt_type_write_wp
:
205 case raw_bkpt_type_read_wp
:
207 case raw_bkpt_type_access_wp
:
210 internal_error (__FILE__
, __LINE__
,
211 "bad raw breakpoint type %d", (int) raw_type
);
215 /* See mem-break.h. */
217 static enum bkpt_type
218 Z_packet_to_bkpt_type (char z_type
)
220 gdb_assert ('0' <= z_type
&& z_type
<= '4');
222 return gdb_breakpoint_Z0
+ (z_type
- '0');
225 /* See mem-break.h. */
228 Z_packet_to_raw_bkpt_type (char z_type
)
233 return raw_bkpt_type_sw
;
235 return raw_bkpt_type_hw
;
236 case Z_PACKET_WRITE_WP
:
237 return raw_bkpt_type_write_wp
;
238 case Z_PACKET_READ_WP
:
239 return raw_bkpt_type_read_wp
;
240 case Z_PACKET_ACCESS_WP
:
241 return raw_bkpt_type_access_wp
;
243 gdb_assert_not_reached ("unhandled Z packet type.");
248 any_persistent_commands ()
250 struct process_info
*proc
= current_process ();
251 struct breakpoint
*bp
;
252 struct point_command_list
*cl
;
254 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
256 for (cl
= bp
->command_list
; cl
!= NULL
; cl
= cl
->next
)
264 /* Find low-level breakpoint of type TYPE at address ADDR that is not
265 insert-disabled. Returns NULL if not found. */
267 static struct raw_breakpoint
*
268 find_enabled_raw_code_breakpoint_at (CORE_ADDR addr
, enum raw_bkpt_type type
)
270 struct process_info
*proc
= current_process ();
271 struct raw_breakpoint
*bp
;
273 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
275 && bp
->raw_type
== type
276 && bp
->inserted
>= 0)
282 /* Find low-level breakpoint of type TYPE at address ADDR. Returns
283 NULL if not found. */
285 static struct raw_breakpoint
*
286 find_raw_breakpoint_at (CORE_ADDR addr
, enum raw_bkpt_type type
, int size
)
288 struct process_info
*proc
= current_process ();
289 struct raw_breakpoint
*bp
;
291 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
292 if (bp
->pc
== addr
&& bp
->raw_type
== type
&& bp
->size
== size
)
298 /* See mem-break.h. */
301 insert_memory_breakpoint (struct raw_breakpoint
*bp
)
303 unsigned char buf
[MAX_BREAKPOINT_LEN
];
306 if (breakpoint_data
== NULL
)
309 /* If the architecture treats the size field of Z packets as a
310 'kind' field, then we'll need to be able to know which is the
311 breakpoint instruction too. */
312 if (bp
->size
!= breakpoint_len
)
315 debug_printf ("Don't know how to insert breakpoints of size %d.\n",
320 /* Note that there can be fast tracepoint jumps installed in the
321 same memory range, so to get at the original memory, we need to
322 use read_inferior_memory, which masks those out. */
323 err
= read_inferior_memory (bp
->pc
, buf
, breakpoint_len
);
327 debug_printf ("Failed to read shadow memory of"
328 " breakpoint at 0x%s (%s).\n",
329 paddress (bp
->pc
), strerror (err
));
333 memcpy (bp
->old_data
, buf
, breakpoint_len
);
335 err
= (*the_target
->write_memory
) (bp
->pc
, breakpoint_data
,
340 debug_printf ("Failed to insert breakpoint at 0x%s (%s).\n",
341 paddress (bp
->pc
), strerror (err
));
344 return err
!= 0 ? -1 : 0;
347 /* See mem-break.h */
350 remove_memory_breakpoint (struct raw_breakpoint
*bp
)
352 unsigned char buf
[MAX_BREAKPOINT_LEN
];
355 /* Since there can be trap breakpoints inserted in the same address
356 range, we use `write_inferior_memory', which takes care of
357 layering breakpoints on top of fast tracepoints, and on top of
358 the buffer we pass it. This works because the caller has already
359 either unlinked the breakpoint or marked it uninserted. Also
360 note that we need to pass the current shadow contents, because
361 write_inferior_memory updates any shadow memory with what we pass
362 here, and we want that to be a nop. */
363 memcpy (buf
, bp
->old_data
, breakpoint_len
);
364 err
= write_inferior_memory (bp
->pc
, buf
, breakpoint_len
);
368 debug_printf ("Failed to uninsert raw breakpoint "
369 "at 0x%s (%s) while deleting it.\n",
370 paddress (bp
->pc
), strerror (err
));
372 return err
!= 0 ? -1 : 0;
375 /* Set a RAW breakpoint of type TYPE and size SIZE at WHERE. On
376 success, a pointer to the new breakpoint is returned. On failure,
377 returns NULL and writes the error code to *ERR. */
379 static struct raw_breakpoint
*
380 set_raw_breakpoint_at (enum raw_bkpt_type type
, CORE_ADDR where
, int size
,
383 struct process_info
*proc
= current_process ();
384 struct raw_breakpoint
*bp
;
386 if (type
== raw_bkpt_type_sw
|| type
== raw_bkpt_type_hw
)
388 bp
= find_enabled_raw_code_breakpoint_at (where
, type
);
389 if (bp
!= NULL
&& bp
->size
!= size
)
391 /* A different size than previously seen. The previous
392 breakpoint must be gone then. */
394 debug_printf ("Inconsistent breakpoint size? Was %d, now %d.\n",
401 bp
= find_raw_breakpoint_at (where
, type
, size
);
409 bp
= xcalloc (1, sizeof (*bp
));
415 *err
= the_target
->insert_point (bp
->raw_type
, bp
->pc
, bp
->size
, bp
);
419 debug_printf ("Failed to insert breakpoint at 0x%s (%d).\n",
420 paddress (where
), *err
);
426 /* Link the breakpoint in. */
427 bp
->next
= proc
->raw_breakpoints
;
428 proc
->raw_breakpoints
= bp
;
432 /* Notice that breakpoint traps are always installed on top of fast
433 tracepoint jumps. This is even if the fast tracepoint is installed
434 at a later time compared to when the breakpoint was installed.
435 This means that a stopping breakpoint or tracepoint has higher
436 "priority". In turn, this allows having fast and slow tracepoints
437 (and breakpoints) at the same address behave correctly. */
440 /* A fast tracepoint jump. */
442 struct fast_tracepoint_jump
444 struct fast_tracepoint_jump
*next
;
446 /* A reference count. GDB can install more than one fast tracepoint
447 at the same address (each with its own action list, for
451 /* The fast tracepoint's insertion address. There can only be one
452 of these for a given PC. */
455 /* Non-zero if this fast tracepoint jump is currently inserted in
459 /* The length of the jump instruction. */
462 /* A poor-man's flexible array member, holding both the jump
463 instruction to insert, and a copy of the instruction that would
464 be in memory had not been a jump there (the shadow memory of the
466 unsigned char insn_and_shadow
[0];
469 /* Fast tracepoint FP's jump instruction to insert. */
470 #define fast_tracepoint_jump_insn(fp) \
471 ((fp)->insn_and_shadow + 0)
473 /* The shadow memory of fast tracepoint jump FP. */
474 #define fast_tracepoint_jump_shadow(fp) \
475 ((fp)->insn_and_shadow + (fp)->length)
478 /* Return the fast tracepoint jump set at WHERE. */
480 static struct fast_tracepoint_jump
*
481 find_fast_tracepoint_jump_at (CORE_ADDR where
)
483 struct process_info
*proc
= current_process ();
484 struct fast_tracepoint_jump
*jp
;
486 for (jp
= proc
->fast_tracepoint_jumps
; jp
!= NULL
; jp
= jp
->next
)
494 fast_tracepoint_jump_here (CORE_ADDR where
)
496 struct fast_tracepoint_jump
*jp
= find_fast_tracepoint_jump_at (where
);
502 delete_fast_tracepoint_jump (struct fast_tracepoint_jump
*todel
)
504 struct fast_tracepoint_jump
*bp
, **bp_link
;
506 struct process_info
*proc
= current_process ();
508 bp
= proc
->fast_tracepoint_jumps
;
509 bp_link
= &proc
->fast_tracepoint_jumps
;
515 if (--bp
->refcount
== 0)
517 struct fast_tracepoint_jump
*prev_bp_link
= *bp_link
;
523 /* Since there can be breakpoints inserted in the same
524 address range, we use `write_inferior_memory', which
525 takes care of layering breakpoints on top of fast
526 tracepoints, and on top of the buffer we pass it.
527 This works because we've already unlinked the fast
528 tracepoint jump above. Also note that we need to
529 pass the current shadow contents, because
530 write_inferior_memory updates any shadow memory with
531 what we pass here, and we want that to be a nop. */
532 buf
= alloca (bp
->length
);
533 memcpy (buf
, fast_tracepoint_jump_shadow (bp
), bp
->length
);
534 ret
= write_inferior_memory (bp
->pc
, buf
, bp
->length
);
537 /* Something went wrong, relink the jump. */
538 *bp_link
= prev_bp_link
;
541 debug_printf ("Failed to uninsert fast tracepoint jump "
542 "at 0x%s (%s) while deleting it.\n",
543 paddress (bp
->pc
), strerror (ret
));
559 warning ("Could not find fast tracepoint jump in list.");
564 inc_ref_fast_tracepoint_jump (struct fast_tracepoint_jump
*jp
)
569 struct fast_tracepoint_jump
*
570 set_fast_tracepoint_jump (CORE_ADDR where
,
571 unsigned char *insn
, ULONGEST length
)
573 struct process_info
*proc
= current_process ();
574 struct fast_tracepoint_jump
*jp
;
578 /* We refcount fast tracepoint jumps. Check if we already know
579 about a jump at this address. */
580 jp
= find_fast_tracepoint_jump_at (where
);
587 /* We don't, so create a new object. Double the length, because the
588 flexible array member holds both the jump insn, and the
590 jp
= xcalloc (1, sizeof (*jp
) + (length
* 2));
593 memcpy (fast_tracepoint_jump_insn (jp
), insn
, length
);
595 buf
= alloca (length
);
597 /* Note that there can be trap breakpoints inserted in the same
598 address range. To access the original memory contents, we use
599 `read_inferior_memory', which masks out breakpoints. */
600 err
= read_inferior_memory (where
, buf
, length
);
604 debug_printf ("Failed to read shadow memory of"
605 " fast tracepoint at 0x%s (%s).\n",
606 paddress (where
), strerror (err
));
610 memcpy (fast_tracepoint_jump_shadow (jp
), buf
, length
);
612 /* Link the jump in. */
614 jp
->next
= proc
->fast_tracepoint_jumps
;
615 proc
->fast_tracepoint_jumps
= jp
;
617 /* Since there can be trap breakpoints inserted in the same address
618 range, we use use `write_inferior_memory', which takes care of
619 layering breakpoints on top of fast tracepoints, on top of the
620 buffer we pass it. This works because we've already linked in
621 the fast tracepoint jump above. Also note that we need to pass
622 the current shadow contents, because write_inferior_memory
623 updates any shadow memory with what we pass here, and we want
625 err
= write_inferior_memory (where
, buf
, length
);
629 debug_printf ("Failed to insert fast tracepoint jump at 0x%s (%s).\n",
630 paddress (where
), strerror (err
));
633 proc
->fast_tracepoint_jumps
= jp
->next
;
643 uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc
)
645 struct fast_tracepoint_jump
*jp
;
648 jp
= find_fast_tracepoint_jump_at (pc
);
651 /* This can happen when we remove all breakpoints while handling
654 debug_printf ("Could not find fast tracepoint jump at 0x%s "
655 "in list (uninserting).\n",
666 /* Since there can be trap breakpoints inserted in the same
667 address range, we use use `write_inferior_memory', which
668 takes care of layering breakpoints on top of fast
669 tracepoints, and on top of the buffer we pass it. This works
670 because we've already marked the fast tracepoint fast
671 tracepoint jump uninserted above. Also note that we need to
672 pass the current shadow contents, because
673 write_inferior_memory updates any shadow memory with what we
674 pass here, and we want that to be a nop. */
675 buf
= alloca (jp
->length
);
676 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
677 err
= write_inferior_memory (jp
->pc
, buf
, jp
->length
);
683 debug_printf ("Failed to uninsert fast tracepoint jump at"
685 paddress (pc
), strerror (err
));
691 reinsert_fast_tracepoint_jumps_at (CORE_ADDR where
)
693 struct fast_tracepoint_jump
*jp
;
697 jp
= find_fast_tracepoint_jump_at (where
);
700 /* This can happen when we remove breakpoints when a tracepoint
701 hit causes a tracing stop, while handling a step-over. */
703 debug_printf ("Could not find fast tracepoint jump at 0x%s "
704 "in list (reinserting).\n",
710 error ("Jump already inserted at reinsert time.");
714 /* Since there can be trap breakpoints inserted in the same address
715 range, we use `write_inferior_memory', which takes care of
716 layering breakpoints on top of fast tracepoints, and on top of
717 the buffer we pass it. This works because we've already marked
718 the fast tracepoint jump inserted above. Also note that we need
719 to pass the current shadow contents, because
720 write_inferior_memory updates any shadow memory with what we pass
721 here, and we want that to be a nop. */
722 buf
= alloca (jp
->length
);
723 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
724 err
= write_inferior_memory (where
, buf
, jp
->length
);
730 debug_printf ("Failed to reinsert fast tracepoint jump at"
732 paddress (where
), strerror (err
));
736 /* Set a high-level breakpoint of type TYPE, with low level type
737 RAW_TYPE and size SIZE, at WHERE. On success, a pointer to the new
738 breakpoint is returned. On failure, returns NULL and writes the
739 error code to *ERR. HANDLER is called when the breakpoint is hit.
740 HANDLER should return 1 if the breakpoint should be deleted, 0
743 static struct breakpoint
*
744 set_breakpoint (enum bkpt_type type
, enum raw_bkpt_type raw_type
,
745 CORE_ADDR where
, int size
,
746 int (*handler
) (CORE_ADDR
), int *err
)
748 struct process_info
*proc
= current_process ();
749 struct breakpoint
*bp
;
750 struct raw_breakpoint
*raw
;
752 raw
= set_raw_breakpoint_at (raw_type
, where
, size
, err
);
760 bp
= xcalloc (1, sizeof (struct breakpoint
));
764 bp
->handler
= handler
;
766 bp
->next
= proc
->breakpoints
;
767 proc
->breakpoints
= bp
;
772 /* See mem-break.h */
775 set_breakpoint_at (CORE_ADDR where
, int (*handler
) (CORE_ADDR
))
779 return set_breakpoint (other_breakpoint
, raw_bkpt_type_sw
,
780 where
, breakpoint_len
, handler
,
786 delete_raw_breakpoint (struct process_info
*proc
, struct raw_breakpoint
*todel
)
788 struct raw_breakpoint
*bp
, **bp_link
;
791 bp
= proc
->raw_breakpoints
;
792 bp_link
= &proc
->raw_breakpoints
;
798 if (bp
->inserted
> 0)
800 struct raw_breakpoint
*prev_bp_link
= *bp_link
;
804 ret
= the_target
->remove_point (bp
->raw_type
, bp
->pc
, bp
->size
,
808 /* Something went wrong, relink the breakpoint. */
809 *bp_link
= prev_bp_link
;
812 debug_printf ("Failed to uninsert raw breakpoint "
813 "at 0x%s while deleting it.\n",
831 warning ("Could not find raw breakpoint in list.");
836 release_breakpoint (struct process_info
*proc
, struct breakpoint
*bp
)
841 newrefcount
= bp
->raw
->refcount
- 1;
842 if (newrefcount
== 0)
844 ret
= delete_raw_breakpoint (proc
, bp
->raw
);
849 bp
->raw
->refcount
= newrefcount
;
857 delete_breakpoint_1 (struct process_info
*proc
, struct breakpoint
*todel
)
859 struct breakpoint
*bp
, **bp_link
;
862 bp
= proc
->breakpoints
;
863 bp_link
= &proc
->breakpoints
;
871 err
= release_breakpoint (proc
, bp
);
885 warning ("Could not find breakpoint in list.");
890 delete_breakpoint (struct breakpoint
*todel
)
892 struct process_info
*proc
= current_process ();
893 return delete_breakpoint_1 (proc
, todel
);
896 /* Locate a GDB breakpoint of type Z_TYPE and size SIZE placed at
897 address ADDR and return a pointer to its structure. If SIZE is -1,
898 the breakpoints' sizes are ignored. */
900 static struct breakpoint
*
901 find_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int size
)
903 struct process_info
*proc
= current_process ();
904 struct breakpoint
*bp
;
905 enum bkpt_type type
= Z_packet_to_bkpt_type (z_type
);
907 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
908 if (bp
->type
== type
&& bp
->raw
->pc
== addr
909 && (size
== -1 || bp
->raw
->size
== size
))
916 z_type_supported (char z_type
)
918 return (z_type
>= '0' && z_type
<= '4'
919 && the_target
->supports_z_point_type
!= NULL
920 && the_target
->supports_z_point_type (z_type
));
923 /* Create a new GDB breakpoint of type Z_TYPE at ADDR with size SIZE.
924 Returns a pointer to the newly created breakpoint on success. On
925 failure returns NULL and sets *ERR to either -1 for error, or 1 if
926 Z_TYPE breakpoints are not supported on this target. */
928 static struct breakpoint
*
929 set_gdb_breakpoint_1 (char z_type
, CORE_ADDR addr
, int size
, int *err
)
931 struct breakpoint
*bp
;
933 enum raw_bkpt_type raw_type
;
935 /* If we see GDB inserting a second code breakpoint at the same
936 address, then either: GDB is updating the breakpoint's conditions
937 or commands; or, the first breakpoint must have disappeared due
938 to a shared library unload. On targets where the shared
939 libraries are handled by userspace, like SVR4, for example,
940 GDBserver can't tell if a library was loaded or unloaded. Since
941 we refcount raw breakpoints, we must be careful to make sure GDB
942 breakpoints never contribute more than one reference. if we
943 didn't do this, in case the previous breakpoint is gone due to a
944 shared library unload, we'd just increase the refcount of the
945 previous breakpoint at this address, but the trap was not planted
946 in the inferior anymore, thus the breakpoint would never be hit.
947 Note this must be careful to not create a window where
948 breakpoints are removed from the target, for non-stop, in case
949 the target can poke at memory while the program is running. */
950 if (z_type
== Z_PACKET_SW_BP
951 || z_type
== Z_PACKET_HW_BP
)
953 bp
= find_gdb_breakpoint (z_type
, addr
, -1);
957 if (bp
->raw
->size
!= size
)
959 /* A different size than previously seen. The previous
960 breakpoint must be gone then. */
961 bp
->raw
->inserted
= -1;
962 delete_breakpoint (bp
);
965 else if (z_type
== Z_PACKET_SW_BP
)
967 /* Check if the breakpoint is actually gone from the
968 target, due to an solib unload, for example. Might
969 as well validate _all_ breakpoints. */
970 validate_breakpoints ();
972 /* Breakpoints that don't pass validation are
974 bp
= find_gdb_breakpoint (z_type
, addr
, -1);
980 /* Data breakpoints for the same address but different size are
981 expected. GDB doesn't merge these. The backend gets to do
982 that if it wants/can. */
983 bp
= find_gdb_breakpoint (z_type
, addr
, size
);
988 /* We already know about this breakpoint, there's nothing else
989 to do - GDB's reference is already accounted for. Note that
990 whether the breakpoint inserted is left as is - we may be
991 stepping over it, for example, in which case we don't want to
992 force-reinsert it. */
996 raw_type
= Z_packet_to_raw_bkpt_type (z_type
);
997 type
= Z_packet_to_bkpt_type (z_type
);
998 return set_breakpoint (type
, raw_type
, addr
, size
, NULL
, err
);
1002 check_gdb_bp_preconditions (char z_type
, int *err
)
1004 /* As software/memory breakpoints work by poking at memory, we need
1005 to prepare to access memory. If that operation fails, we need to
1006 return error. Seeing an error, if this is the first breakpoint
1007 of that type that GDB tries to insert, GDB would then assume the
1008 breakpoint type is supported, but it may actually not be. So we
1009 need to check whether the type is supported at all before
1010 preparing to access memory. */
1011 if (!z_type_supported (z_type
))
1016 else if (current_thread
== NULL
)
1025 /* See mem-break.h. This is a wrapper for set_gdb_breakpoint_1 that
1026 knows to prepare to access memory for Z0 breakpoints. */
1029 set_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int size
, int *err
)
1031 struct breakpoint
*bp
;
1033 if (!check_gdb_bp_preconditions (z_type
, err
))
1036 /* If inserting a software/memory breakpoint, need to prepare to
1038 if (z_type
== Z_PACKET_SW_BP
)
1040 *err
= prepare_to_access_memory ();
1045 bp
= set_gdb_breakpoint_1 (z_type
, addr
, size
, err
);
1047 if (z_type
== Z_PACKET_SW_BP
)
1048 done_accessing_memory ();
1053 /* Delete a GDB breakpoint of type Z_TYPE and size SIZE previously
1054 inserted at ADDR with set_gdb_breakpoint_at. Returns 0 on success,
1055 -1 on error, and 1 if Z_TYPE breakpoints are not supported on this
1059 delete_gdb_breakpoint_1 (char z_type
, CORE_ADDR addr
, int size
)
1061 struct breakpoint
*bp
;
1064 bp
= find_gdb_breakpoint (z_type
, addr
, size
);
1068 /* Before deleting the breakpoint, make sure to free its condition
1069 and command lists. */
1070 clear_breakpoint_conditions_and_commands (bp
);
1071 err
= delete_breakpoint (bp
);
1078 /* See mem-break.h. This is a wrapper for delete_gdb_breakpoint that
1079 knows to prepare to access memory for Z0 breakpoints. */
1082 delete_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int size
)
1086 if (!check_gdb_bp_preconditions (z_type
, &ret
))
1089 /* If inserting a software/memory breakpoint, need to prepare to
1091 if (z_type
== Z_PACKET_SW_BP
)
1095 err
= prepare_to_access_memory ();
1100 ret
= delete_gdb_breakpoint_1 (z_type
, addr
, size
);
1102 if (z_type
== Z_PACKET_SW_BP
)
1103 done_accessing_memory ();
1108 /* Clear all conditions associated with a breakpoint. */
1111 clear_breakpoint_conditions (struct breakpoint
*bp
)
1113 struct point_cond_list
*cond
;
1115 if (bp
->cond_list
== NULL
)
1118 cond
= bp
->cond_list
;
1120 while (cond
!= NULL
)
1122 struct point_cond_list
*cond_next
;
1124 cond_next
= cond
->next
;
1125 gdb_free_agent_expr (cond
->cond
);
1130 bp
->cond_list
= NULL
;
1133 /* Clear all commands associated with a breakpoint. */
1136 clear_breakpoint_commands (struct breakpoint
*bp
)
1138 struct point_command_list
*cmd
;
1140 if (bp
->command_list
== NULL
)
1143 cmd
= bp
->command_list
;
1147 struct point_command_list
*cmd_next
;
1149 cmd_next
= cmd
->next
;
1150 gdb_free_agent_expr (cmd
->cmd
);
1155 bp
->command_list
= NULL
;
1159 clear_breakpoint_conditions_and_commands (struct breakpoint
*bp
)
1161 clear_breakpoint_conditions (bp
);
1162 clear_breakpoint_commands (bp
);
1165 /* Add condition CONDITION to GDBserver's breakpoint BP. */
1168 add_condition_to_breakpoint (struct breakpoint
*bp
,
1169 struct agent_expr
*condition
)
1171 struct point_cond_list
*new_cond
;
1173 /* Create new condition. */
1174 new_cond
= xcalloc (1, sizeof (*new_cond
));
1175 new_cond
->cond
= condition
;
1177 /* Add condition to the list. */
1178 new_cond
->next
= bp
->cond_list
;
1179 bp
->cond_list
= new_cond
;
1182 /* Add a target-side condition CONDITION to a breakpoint. */
1185 add_breakpoint_condition (struct breakpoint
*bp
, char **condition
)
1187 char *actparm
= *condition
;
1188 struct agent_expr
*cond
;
1190 if (condition
== NULL
)
1196 cond
= gdb_parse_agent_expr (&actparm
);
1200 fprintf (stderr
, "Condition evaluation failed. "
1201 "Assuming unconditional.\n");
1205 add_condition_to_breakpoint (bp
, cond
);
1207 *condition
= actparm
;
1212 /* Evaluate condition (if any) at breakpoint BP. Return 1 if
1213 true and 0 otherwise. */
1216 gdb_condition_true_at_breakpoint_z_type (char z_type
, CORE_ADDR addr
)
1218 /* Fetch registers for the current inferior. */
1219 struct breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1221 struct point_cond_list
*cl
;
1223 struct eval_agent_expr_context ctx
;
1228 /* Check if the breakpoint is unconditional. If it is,
1229 the condition always evaluates to TRUE. */
1230 if (bp
->cond_list
== NULL
)
1233 ctx
.regcache
= get_thread_regcache (current_thread
, 1);
1237 /* Evaluate each condition in the breakpoint's list of conditions.
1238 Return true if any of the conditions evaluates to TRUE.
1240 If we failed to evaluate the expression, TRUE is returned. This
1241 forces GDB to reevaluate the conditions. */
1242 for (cl
= bp
->cond_list
;
1243 cl
&& !value
&& !err
; cl
= cl
->next
)
1245 /* Evaluate the condition. */
1246 err
= gdb_eval_agent_expr (&ctx
, cl
->cond
, &value
);
1252 return (value
!= 0);
1256 gdb_condition_true_at_breakpoint (CORE_ADDR where
)
1258 /* Only check code (software or hardware) breakpoints. */
1259 return (gdb_condition_true_at_breakpoint_z_type (Z_PACKET_SW_BP
, where
)
1260 || gdb_condition_true_at_breakpoint_z_type (Z_PACKET_HW_BP
, where
));
1263 /* Add commands COMMANDS to GDBserver's breakpoint BP. */
1266 add_commands_to_breakpoint (struct breakpoint
*bp
,
1267 struct agent_expr
*commands
, int persist
)
1269 struct point_command_list
*new_cmd
;
1271 /* Create new command. */
1272 new_cmd
= xcalloc (1, sizeof (*new_cmd
));
1273 new_cmd
->cmd
= commands
;
1274 new_cmd
->persistence
= persist
;
1276 /* Add commands to the list. */
1277 new_cmd
->next
= bp
->command_list
;
1278 bp
->command_list
= new_cmd
;
1281 /* Add a target-side command COMMAND to the breakpoint at ADDR. */
1284 add_breakpoint_commands (struct breakpoint
*bp
, char **command
,
1287 char *actparm
= *command
;
1288 struct agent_expr
*cmd
;
1290 if (command
== NULL
)
1296 cmd
= gdb_parse_agent_expr (&actparm
);
1300 fprintf (stderr
, "Command evaluation failed. "
1305 add_commands_to_breakpoint (bp
, cmd
, persist
);
1312 /* Return true if there are no commands to run at this location,
1313 which likely means we want to report back to GDB. */
1316 gdb_no_commands_at_breakpoint_z_type (char z_type
, CORE_ADDR addr
)
1318 struct breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1324 debug_printf ("at 0x%s, type Z%c, bp command_list is 0x%s\n",
1325 paddress (addr
), z_type
,
1326 phex_nz ((uintptr_t) bp
->command_list
, 0));
1327 return (bp
->command_list
== NULL
);
1330 /* Return true if there are no commands to run at this location,
1331 which likely means we want to report back to GDB. */
1334 gdb_no_commands_at_breakpoint (CORE_ADDR where
)
1336 /* Only check code (software or hardware) breakpoints. */
1337 return (gdb_no_commands_at_breakpoint_z_type (Z_PACKET_SW_BP
, where
)
1338 && gdb_no_commands_at_breakpoint_z_type (Z_PACKET_HW_BP
, where
));
1341 /* Run a breakpoint's commands. Returns 0 if there was a problem
1342 running any command, 1 otherwise. */
1345 run_breakpoint_commands_z_type (char z_type
, CORE_ADDR addr
)
1347 /* Fetch registers for the current inferior. */
1348 struct breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1350 struct point_command_list
*cl
;
1352 struct eval_agent_expr_context ctx
;
1357 ctx
.regcache
= get_thread_regcache (current_thread
, 1);
1361 for (cl
= bp
->command_list
;
1362 cl
&& !value
&& !err
; cl
= cl
->next
)
1364 /* Run the command. */
1365 err
= gdb_eval_agent_expr (&ctx
, cl
->cmd
, &value
);
1367 /* If one command has a problem, stop digging the hole deeper. */
1376 run_breakpoint_commands (CORE_ADDR where
)
1378 /* Only check code (software or hardware) breakpoints. If one
1379 command has a problem, stop digging the hole deeper. */
1380 if (run_breakpoint_commands_z_type (Z_PACKET_SW_BP
, where
))
1381 run_breakpoint_commands_z_type (Z_PACKET_HW_BP
, where
);
1384 /* See mem-break.h. */
1387 gdb_breakpoint_here (CORE_ADDR where
)
1389 /* Only check code (software or hardware) breakpoints. */
1390 return (find_gdb_breakpoint (Z_PACKET_SW_BP
, where
, -1) != NULL
1391 || find_gdb_breakpoint (Z_PACKET_HW_BP
, where
, -1) != NULL
);
1395 set_reinsert_breakpoint (CORE_ADDR stop_at
)
1397 struct breakpoint
*bp
;
1399 bp
= set_breakpoint_at (stop_at
, NULL
);
1400 bp
->type
= reinsert_breakpoint
;
1404 delete_reinsert_breakpoints (void)
1406 struct process_info
*proc
= current_process ();
1407 struct breakpoint
*bp
, **bp_link
;
1409 bp
= proc
->breakpoints
;
1410 bp_link
= &proc
->breakpoints
;
1414 if (bp
->type
== reinsert_breakpoint
)
1416 *bp_link
= bp
->next
;
1417 release_breakpoint (proc
, bp
);
1422 bp_link
= &bp
->next
;
1429 uninsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1431 if (bp
->inserted
< 0)
1434 debug_printf ("Breakpoint at %s is marked insert-disabled.\n",
1437 else if (bp
->inserted
> 0)
1443 err
= the_target
->remove_point (bp
->raw_type
, bp
->pc
, bp
->size
, bp
);
1449 debug_printf ("Failed to uninsert raw breakpoint at 0x%s.\n",
1456 uninsert_breakpoints_at (CORE_ADDR pc
)
1458 struct process_info
*proc
= current_process ();
1459 struct raw_breakpoint
*bp
;
1462 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1463 if ((bp
->raw_type
== raw_bkpt_type_sw
1464 || bp
->raw_type
== raw_bkpt_type_hw
)
1470 uninsert_raw_breakpoint (bp
);
1475 /* This can happen when we remove all breakpoints while handling
1478 debug_printf ("Could not find breakpoint at 0x%s "
1479 "in list (uninserting).\n",
1485 uninsert_all_breakpoints (void)
1487 struct process_info
*proc
= current_process ();
1488 struct raw_breakpoint
*bp
;
1490 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1491 if ((bp
->raw_type
== raw_bkpt_type_sw
1492 || bp
->raw_type
== raw_bkpt_type_hw
)
1494 uninsert_raw_breakpoint (bp
);
1498 reinsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1503 error ("Breakpoint already inserted at reinsert time.");
1505 err
= the_target
->insert_point (bp
->raw_type
, bp
->pc
, bp
->size
, bp
);
1508 else if (debug_threads
)
1509 debug_printf ("Failed to reinsert breakpoint at 0x%s (%d).\n",
1510 paddress (bp
->pc
), err
);
1514 reinsert_breakpoints_at (CORE_ADDR pc
)
1516 struct process_info
*proc
= current_process ();
1517 struct raw_breakpoint
*bp
;
1520 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1521 if ((bp
->raw_type
== raw_bkpt_type_sw
1522 || bp
->raw_type
== raw_bkpt_type_hw
)
1527 reinsert_raw_breakpoint (bp
);
1532 /* This can happen when we remove all breakpoints while handling
1535 debug_printf ("Could not find raw breakpoint at 0x%s "
1536 "in list (reinserting).\n",
1542 reinsert_all_breakpoints (void)
1544 struct process_info
*proc
= current_process ();
1545 struct raw_breakpoint
*bp
;
1547 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1548 if ((bp
->raw_type
== raw_bkpt_type_sw
1549 || bp
->raw_type
== raw_bkpt_type_hw
)
1551 reinsert_raw_breakpoint (bp
);
1555 check_breakpoints (CORE_ADDR stop_pc
)
1557 struct process_info
*proc
= current_process ();
1558 struct breakpoint
*bp
, **bp_link
;
1560 bp
= proc
->breakpoints
;
1561 bp_link
= &proc
->breakpoints
;
1565 struct raw_breakpoint
*raw
= bp
->raw
;
1567 if ((raw
->raw_type
== raw_bkpt_type_sw
1568 || raw
->raw_type
== raw_bkpt_type_hw
)
1569 && raw
->pc
== stop_pc
)
1573 warning ("Hit a removed breakpoint?");
1577 if (bp
->handler
!= NULL
&& (*bp
->handler
) (stop_pc
))
1579 *bp_link
= bp
->next
;
1581 release_breakpoint (proc
, bp
);
1588 bp_link
= &bp
->next
;
1594 set_breakpoint_data (const unsigned char *bp_data
, int bp_len
)
1596 breakpoint_data
= bp_data
;
1597 breakpoint_len
= bp_len
;
1601 breakpoint_here (CORE_ADDR addr
)
1603 struct process_info
*proc
= current_process ();
1604 struct raw_breakpoint
*bp
;
1606 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1607 if ((bp
->raw_type
== raw_bkpt_type_sw
1608 || bp
->raw_type
== raw_bkpt_type_hw
)
1616 breakpoint_inserted_here (CORE_ADDR addr
)
1618 struct process_info
*proc
= current_process ();
1619 struct raw_breakpoint
*bp
;
1621 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1622 if ((bp
->raw_type
== raw_bkpt_type_sw
1623 || bp
->raw_type
== raw_bkpt_type_hw
)
1631 /* See mem-break.h. */
1634 software_breakpoint_inserted_here (CORE_ADDR addr
)
1636 struct process_info
*proc
= current_process ();
1637 struct raw_breakpoint
*bp
;
1639 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1640 if (bp
->raw_type
== raw_bkpt_type_sw
1648 /* See mem-break.h. */
1651 hardware_breakpoint_inserted_here (CORE_ADDR addr
)
1653 struct process_info
*proc
= current_process ();
1654 struct raw_breakpoint
*bp
;
1656 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1657 if (bp
->raw_type
== raw_bkpt_type_hw
1666 validate_inserted_breakpoint (struct raw_breakpoint
*bp
)
1671 gdb_assert (bp
->inserted
);
1672 gdb_assert (bp
->raw_type
== raw_bkpt_type_sw
);
1674 buf
= alloca (breakpoint_len
);
1675 err
= (*the_target
->read_memory
) (bp
->pc
, buf
, breakpoint_len
);
1676 if (err
|| memcmp (buf
, breakpoint_data
, breakpoint_len
) != 0)
1678 /* Tag it as gone. */
1687 delete_disabled_breakpoints (void)
1689 struct process_info
*proc
= current_process ();
1690 struct breakpoint
*bp
, *next
;
1692 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= next
)
1695 if (bp
->raw
->inserted
< 0)
1696 delete_breakpoint_1 (proc
, bp
);
1700 /* Check if breakpoints we inserted still appear to be inserted. They
1701 may disappear due to a shared library unload, and worse, a new
1702 shared library may be reloaded at the same address as the
1703 previously unloaded one. If that happens, we should make sure that
1704 the shadow memory of the old breakpoints isn't used when reading or
1708 validate_breakpoints (void)
1710 struct process_info
*proc
= current_process ();
1711 struct breakpoint
*bp
;
1713 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1715 struct raw_breakpoint
*raw
= bp
->raw
;
1717 if (raw
->raw_type
== raw_bkpt_type_sw
&& raw
->inserted
> 0)
1718 validate_inserted_breakpoint (raw
);
1721 delete_disabled_breakpoints ();
1725 check_mem_read (CORE_ADDR mem_addr
, unsigned char *buf
, int mem_len
)
1727 struct process_info
*proc
= current_process ();
1728 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1729 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1730 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1731 int disabled_one
= 0;
1733 for (; jp
!= NULL
; jp
= jp
->next
)
1735 CORE_ADDR bp_end
= jp
->pc
+ jp
->length
;
1736 CORE_ADDR start
, end
;
1737 int copy_offset
, copy_len
, buf_offset
;
1739 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= buf
+ mem_len
1740 || buf
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1742 if (mem_addr
>= bp_end
)
1744 if (jp
->pc
>= mem_end
)
1748 if (mem_addr
> start
)
1755 copy_len
= end
- start
;
1756 copy_offset
= start
- jp
->pc
;
1757 buf_offset
= start
- mem_addr
;
1760 memcpy (buf
+ buf_offset
,
1761 fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1765 for (; bp
!= NULL
; bp
= bp
->next
)
1767 CORE_ADDR bp_end
= bp
->pc
+ breakpoint_len
;
1768 CORE_ADDR start
, end
;
1769 int copy_offset
, copy_len
, buf_offset
;
1771 if (bp
->raw_type
!= raw_bkpt_type_sw
)
1774 gdb_assert (bp
->old_data
>= buf
+ mem_len
1775 || buf
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1777 if (mem_addr
>= bp_end
)
1779 if (bp
->pc
>= mem_end
)
1783 if (mem_addr
> start
)
1790 copy_len
= end
- start
;
1791 copy_offset
= start
- bp
->pc
;
1792 buf_offset
= start
- mem_addr
;
1794 if (bp
->inserted
> 0)
1796 if (validate_inserted_breakpoint (bp
))
1797 memcpy (buf
+ buf_offset
, bp
->old_data
+ copy_offset
, copy_len
);
1804 delete_disabled_breakpoints ();
1808 check_mem_write (CORE_ADDR mem_addr
, unsigned char *buf
,
1809 const unsigned char *myaddr
, int mem_len
)
1811 struct process_info
*proc
= current_process ();
1812 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1813 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1814 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1815 int disabled_one
= 0;
1817 /* First fast tracepoint jumps, then breakpoint traps on top. */
1819 for (; jp
!= NULL
; jp
= jp
->next
)
1821 CORE_ADDR jp_end
= jp
->pc
+ jp
->length
;
1822 CORE_ADDR start
, end
;
1823 int copy_offset
, copy_len
, buf_offset
;
1825 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= myaddr
+ mem_len
1826 || myaddr
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1827 gdb_assert (fast_tracepoint_jump_insn (jp
) >= buf
+ mem_len
1828 || buf
>= fast_tracepoint_jump_insn (jp
) + (jp
)->length
);
1830 if (mem_addr
>= jp_end
)
1832 if (jp
->pc
>= mem_end
)
1836 if (mem_addr
> start
)
1843 copy_len
= end
- start
;
1844 copy_offset
= start
- jp
->pc
;
1845 buf_offset
= start
- mem_addr
;
1847 memcpy (fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1848 myaddr
+ buf_offset
, copy_len
);
1850 memcpy (buf
+ buf_offset
,
1851 fast_tracepoint_jump_insn (jp
) + copy_offset
, copy_len
);
1854 for (; bp
!= NULL
; bp
= bp
->next
)
1856 CORE_ADDR bp_end
= bp
->pc
+ breakpoint_len
;
1857 CORE_ADDR start
, end
;
1858 int copy_offset
, copy_len
, buf_offset
;
1860 if (bp
->raw_type
!= raw_bkpt_type_sw
)
1863 gdb_assert (bp
->old_data
>= myaddr
+ mem_len
1864 || myaddr
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1866 if (mem_addr
>= bp_end
)
1868 if (bp
->pc
>= mem_end
)
1872 if (mem_addr
> start
)
1879 copy_len
= end
- start
;
1880 copy_offset
= start
- bp
->pc
;
1881 buf_offset
= start
- mem_addr
;
1883 memcpy (bp
->old_data
+ copy_offset
, myaddr
+ buf_offset
, copy_len
);
1884 if (bp
->inserted
> 0)
1886 if (validate_inserted_breakpoint (bp
))
1887 memcpy (buf
+ buf_offset
, breakpoint_data
+ copy_offset
, copy_len
);
1894 delete_disabled_breakpoints ();
1897 /* Delete all breakpoints, and un-insert them from the inferior. */
1900 delete_all_breakpoints (void)
1902 struct process_info
*proc
= current_process ();
1904 while (proc
->breakpoints
)
1905 delete_breakpoint_1 (proc
, proc
->breakpoints
);
1908 /* Clear the "inserted" flag in all breakpoints. */
1911 mark_breakpoints_out (struct process_info
*proc
)
1913 struct raw_breakpoint
*raw_bp
;
1915 for (raw_bp
= proc
->raw_breakpoints
; raw_bp
!= NULL
; raw_bp
= raw_bp
->next
)
1916 raw_bp
->inserted
= 0;
1919 /* Release all breakpoints, but do not try to un-insert them from the
1923 free_all_breakpoints (struct process_info
*proc
)
1925 mark_breakpoints_out (proc
);
1927 /* Note: use PROC explicitly instead of deferring to
1928 delete_all_breakpoints --- CURRENT_INFERIOR may already have been
1929 released when we get here. There should be no call to
1930 current_process from here on. */
1931 while (proc
->breakpoints
)
1932 delete_breakpoint_1 (proc
, proc
->breakpoints
);
1935 /* Clone an agent expression. */
1937 static struct agent_expr
*
1938 clone_agent_expr (const struct agent_expr
*src_ax
)
1940 struct agent_expr
*ax
;
1942 ax
= xcalloc (1, sizeof (*ax
));
1943 ax
->length
= src_ax
->length
;
1944 ax
->bytes
= xcalloc (ax
->length
, 1);
1945 memcpy (ax
->bytes
, src_ax
->bytes
, ax
->length
);
1949 /* Deep-copy the contents of one breakpoint to another. */
1951 static struct breakpoint
*
1952 clone_one_breakpoint (const struct breakpoint
*src
)
1954 struct breakpoint
*dest
;
1955 struct raw_breakpoint
*dest_raw
;
1956 struct point_cond_list
*current_cond
;
1957 struct point_cond_list
*new_cond
;
1958 struct point_cond_list
*cond_tail
= NULL
;
1959 struct point_command_list
*current_cmd
;
1960 struct point_command_list
*new_cmd
;
1961 struct point_command_list
*cmd_tail
= NULL
;
1963 /* Clone the raw breakpoint. */
1964 dest_raw
= xcalloc (1, sizeof (*dest_raw
));
1965 dest_raw
->raw_type
= src
->raw
->raw_type
;
1966 dest_raw
->refcount
= src
->raw
->refcount
;
1967 dest_raw
->pc
= src
->raw
->pc
;
1968 dest_raw
->size
= src
->raw
->size
;
1969 memcpy (dest_raw
->old_data
, src
->raw
->old_data
, MAX_BREAKPOINT_LEN
);
1970 dest_raw
->inserted
= src
->raw
->inserted
;
1972 /* Clone the high-level breakpoint. */
1973 dest
= xcalloc (1, sizeof (*dest
));
1974 dest
->type
= src
->type
;
1975 dest
->raw
= dest_raw
;
1976 dest
->handler
= src
->handler
;
1978 /* Clone the condition list. */
1979 for (current_cond
= src
->cond_list
; current_cond
!= NULL
;
1980 current_cond
= current_cond
->next
)
1982 new_cond
= xcalloc (1, sizeof (*new_cond
));
1983 new_cond
->cond
= clone_agent_expr (current_cond
->cond
);
1984 APPEND_TO_LIST (&dest
->cond_list
, new_cond
, cond_tail
);
1987 /* Clone the command list. */
1988 for (current_cmd
= src
->command_list
; current_cmd
!= NULL
;
1989 current_cmd
= current_cmd
->next
)
1991 new_cmd
= xcalloc (1, sizeof (*new_cmd
));
1992 new_cmd
->cmd
= clone_agent_expr (current_cmd
->cmd
);
1993 new_cmd
->persistence
= current_cmd
->persistence
;
1994 APPEND_TO_LIST (&dest
->command_list
, new_cmd
, cmd_tail
);
2000 /* Create a new breakpoint list NEW_LIST that is a copy of the
2001 list starting at SRC_LIST. Create the corresponding new
2002 raw_breakpoint list NEW_RAW_LIST as well. */
2005 clone_all_breakpoints (struct breakpoint
**new_list
,
2006 struct raw_breakpoint
**new_raw_list
,
2007 const struct breakpoint
*src_list
)
2009 const struct breakpoint
*bp
;
2010 struct breakpoint
*new_bkpt
;
2011 struct breakpoint
*bkpt_tail
= NULL
;
2012 struct raw_breakpoint
*raw_bkpt_tail
= NULL
;
2014 for (bp
= src_list
; bp
!= NULL
; bp
= bp
->next
)
2016 new_bkpt
= clone_one_breakpoint (bp
);
2017 APPEND_TO_LIST (new_list
, new_bkpt
, bkpt_tail
);
2018 APPEND_TO_LIST (new_raw_list
, new_bkpt
->raw
, raw_bkpt_tail
);