1 /* Memory breakpoint operations for the remote server for GDB.
2 Copyright (C) 2002-2016 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/>. */
25 #define MAX_BREAKPOINT_LEN 8
27 /* Helper macro used in loops that append multiple items to a singly-linked
28 list instead of inserting items at the head of the list, as, say, in the
29 breakpoint lists. LISTPP is a pointer to the pointer that is the head of
30 the new list. ITEMP is a pointer to the item to be added to the list.
31 TAILP must be defined to be the same type as ITEMP, and initialized to
34 #define APPEND_TO_LIST(listpp, itemp, tailp) \
37 if ((tailp) == NULL) \
38 *(listpp) = (itemp); \
40 (tailp)->next = (itemp); \
45 /* GDB will never try to install multiple breakpoints at the same
46 address. However, we can see GDB requesting to insert a breakpoint
47 at an address is had already inserted one previously in a few
50 - The RSP documentation on Z packets says that to avoid potential
51 problems with duplicate packets, the operations should be
52 implemented in an idempotent way.
54 - A breakpoint is set at ADDR, an address in a shared library.
55 Then the shared library is unloaded. And then another, unrelated,
56 breakpoint at ADDR is set. There is not breakpoint removal request
57 between the first and the second breakpoint.
59 - When GDB wants to update the target-side breakpoint conditions or
60 commands, it re-inserts the breakpoint, with updated
61 conditions/commands associated.
63 Also, we need to keep track of internal breakpoints too, so we do
64 need to be able to install multiple breakpoints at the same address
67 We keep track of two different, and closely related structures. A
68 raw breakpoint, which manages the low level, close to the metal
69 aspect of a breakpoint. It holds the breakpoint address, and for
70 software breakpoints, a buffer holding a copy of the instructions
71 that would be in memory had not been a breakpoint there (we call
72 that the shadow memory of the breakpoint). We occasionally need to
73 temporarilly uninsert a breakpoint without the client knowing about
74 it (e.g., to step over an internal breakpoint), so we keep an
75 `inserted' state associated with this low level breakpoint
76 structure. There can only be one such object for a given address.
77 Then, we have (a bit higher level) breakpoints. This structure
78 holds a callback to be called whenever a breakpoint is hit, a
79 high-level type, and a link to a low level raw breakpoint. There
80 can be many high-level breakpoints at the same address, and all of
81 them will point to the same raw breakpoint, which is reference
84 /* The low level, physical, raw breakpoint. */
87 struct raw_breakpoint
*next
;
89 /* The low level type of the breakpoint (software breakpoint,
91 enum raw_bkpt_type raw_type
;
93 /* A reference count. Each high level breakpoint referencing this
94 raw breakpoint accounts for one reference. */
97 /* The breakpoint's insertion address. There can only be one raw
98 breakpoint for a given PC. */
101 /* The breakpoint's kind. This is target specific. Most
102 architectures only use one specific instruction for breakpoints, while
103 others may use more than one. E.g., on ARM, we need to use different
104 breakpoint instructions on Thumb, Thumb-2, and ARM code. Likewise for
105 hardware breakpoints -- some architectures (including ARM) need to
106 setup debug registers differently depending on mode. */
109 /* The breakpoint's shadow memory. */
110 unsigned char old_data
[MAX_BREAKPOINT_LEN
];
112 /* Positive if this breakpoint is currently inserted in the
113 inferior. Negative if it was, but we've detected that it's now
114 gone. Zero if not inserted. */
118 /* The type of a breakpoint. */
121 /* A GDB breakpoint, requested with a Z0 packet. */
124 /* A GDB hardware breakpoint, requested with a Z1 packet. */
127 /* A GDB write watchpoint, requested with a Z2 packet. */
130 /* A GDB read watchpoint, requested with a Z3 packet. */
133 /* A GDB access watchpoint, requested with a Z4 packet. */
136 /* A basic-software-single-step breakpoint. */
139 /* Any other breakpoint type that doesn't require specific
140 treatment goes here. E.g., an event breakpoint. */
144 struct point_cond_list
146 /* Pointer to the agent expression that is the breakpoint's
148 struct agent_expr
*cond
;
150 /* Pointer to the next condition. */
151 struct point_cond_list
*next
;
154 struct point_command_list
156 /* Pointer to the agent expression that is the breakpoint's
158 struct agent_expr
*cmd
;
160 /* Flag that is true if this command should run even while GDB is
164 /* Pointer to the next command. */
165 struct point_command_list
*next
;
168 /* A high level (in gdbserver's perspective) breakpoint. */
171 struct breakpoint
*next
;
173 /* The breakpoint's type. */
176 /* Pointer to the condition list that should be evaluated on
177 the target or NULL if the breakpoint is unconditional or
178 if GDB doesn't want us to evaluate the conditionals on the
180 struct point_cond_list
*cond_list
;
182 /* Point to the list of commands to run when this is hit. */
183 struct point_command_list
*command_list
;
185 /* Link to this breakpoint's raw breakpoint. This is always
187 struct raw_breakpoint
*raw
;
189 /* Function to call when we hit this breakpoint. If it returns 1,
190 the breakpoint shall be deleted; 0 or if this callback is NULL,
191 it will be left inserted. */
192 int (*handler
) (CORE_ADDR
);
195 /* Return the breakpoint size from its kind. */
198 bp_size (struct raw_breakpoint
*bp
)
202 the_target
->sw_breakpoint_from_kind (bp
->kind
, &size
);
206 /* Return the breakpoint opcode from its kind. */
208 static const gdb_byte
*
209 bp_opcode (struct raw_breakpoint
*bp
)
213 return the_target
->sw_breakpoint_from_kind (bp
->kind
, &size
);
216 /* See mem-break.h. */
218 enum target_hw_bp_type
219 raw_bkpt_type_to_target_hw_bp_type (enum raw_bkpt_type raw_type
)
223 case raw_bkpt_type_hw
:
225 case raw_bkpt_type_write_wp
:
227 case raw_bkpt_type_read_wp
:
229 case raw_bkpt_type_access_wp
:
232 internal_error (__FILE__
, __LINE__
,
233 "bad raw breakpoint type %d", (int) raw_type
);
237 /* See mem-break.h. */
239 static enum bkpt_type
240 Z_packet_to_bkpt_type (char z_type
)
242 gdb_assert ('0' <= z_type
&& z_type
<= '4');
244 return (enum bkpt_type
) (gdb_breakpoint_Z0
+ (z_type
- '0'));
247 /* See mem-break.h. */
250 Z_packet_to_raw_bkpt_type (char z_type
)
255 return raw_bkpt_type_sw
;
257 return raw_bkpt_type_hw
;
258 case Z_PACKET_WRITE_WP
:
259 return raw_bkpt_type_write_wp
;
260 case Z_PACKET_READ_WP
:
261 return raw_bkpt_type_read_wp
;
262 case Z_PACKET_ACCESS_WP
:
263 return raw_bkpt_type_access_wp
;
265 gdb_assert_not_reached ("unhandled Z packet type.");
270 any_persistent_commands (void)
272 struct process_info
*proc
= current_process ();
273 struct breakpoint
*bp
;
274 struct point_command_list
*cl
;
276 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
278 for (cl
= bp
->command_list
; cl
!= NULL
; cl
= cl
->next
)
286 /* Find low-level breakpoint of type TYPE at address ADDR that is not
287 insert-disabled. Returns NULL if not found. */
289 static struct raw_breakpoint
*
290 find_enabled_raw_code_breakpoint_at (CORE_ADDR addr
, enum raw_bkpt_type type
)
292 struct process_info
*proc
= current_process ();
293 struct raw_breakpoint
*bp
;
295 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
297 && bp
->raw_type
== type
298 && bp
->inserted
>= 0)
304 /* Find low-level breakpoint of type TYPE at address ADDR. Returns
305 NULL if not found. */
307 static struct raw_breakpoint
*
308 find_raw_breakpoint_at (CORE_ADDR addr
, enum raw_bkpt_type type
, int kind
)
310 struct process_info
*proc
= current_process ();
311 struct raw_breakpoint
*bp
;
313 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
314 if (bp
->pc
== addr
&& bp
->raw_type
== type
&& bp
->kind
== kind
)
320 /* See mem-break.h. */
323 insert_memory_breakpoint (struct raw_breakpoint
*bp
)
325 unsigned char buf
[MAX_BREAKPOINT_LEN
];
328 /* Note that there can be fast tracepoint jumps installed in the
329 same memory range, so to get at the original memory, we need to
330 use read_inferior_memory, which masks those out. */
331 err
= read_inferior_memory (bp
->pc
, buf
, bp_size (bp
));
335 debug_printf ("Failed to read shadow memory of"
336 " breakpoint at 0x%s (%s).\n",
337 paddress (bp
->pc
), strerror (err
));
341 memcpy (bp
->old_data
, buf
, bp_size (bp
));
343 err
= (*the_target
->write_memory
) (bp
->pc
, bp_opcode (bp
),
348 debug_printf ("Failed to insert breakpoint at 0x%s (%s).\n",
349 paddress (bp
->pc
), strerror (err
));
352 return err
!= 0 ? -1 : 0;
355 /* See mem-break.h */
358 remove_memory_breakpoint (struct raw_breakpoint
*bp
)
360 unsigned char buf
[MAX_BREAKPOINT_LEN
];
363 /* Since there can be trap breakpoints inserted in the same address
364 range, we use `write_inferior_memory', which takes care of
365 layering breakpoints on top of fast tracepoints, and on top of
366 the buffer we pass it. This works because the caller has already
367 either unlinked the breakpoint or marked it uninserted. Also
368 note that we need to pass the current shadow contents, because
369 write_inferior_memory updates any shadow memory with what we pass
370 here, and we want that to be a nop. */
371 memcpy (buf
, bp
->old_data
, bp_size (bp
));
372 err
= write_inferior_memory (bp
->pc
, buf
, bp_size (bp
));
376 debug_printf ("Failed to uninsert raw breakpoint "
377 "at 0x%s (%s) while deleting it.\n",
378 paddress (bp
->pc
), strerror (err
));
380 return err
!= 0 ? -1 : 0;
383 /* Set a RAW breakpoint of type TYPE and kind KIND at WHERE. On
384 success, a pointer to the new breakpoint is returned. On failure,
385 returns NULL and writes the error code to *ERR. */
387 static struct raw_breakpoint
*
388 set_raw_breakpoint_at (enum raw_bkpt_type type
, CORE_ADDR where
, int kind
,
391 struct process_info
*proc
= current_process ();
392 struct raw_breakpoint
*bp
;
393 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
395 if (type
== raw_bkpt_type_sw
|| type
== raw_bkpt_type_hw
)
397 bp
= find_enabled_raw_code_breakpoint_at (where
, type
);
398 if (bp
!= NULL
&& bp
->kind
!= kind
)
400 /* A different kind than previously seen. The previous
401 breakpoint must be gone then. */
403 debug_printf ("Inconsistent breakpoint kind? Was %d, now %d.\n",
410 bp
= find_raw_breakpoint_at (where
, type
, kind
);
414 bp
= XCNEW (struct raw_breakpoint
);
418 make_cleanup (xfree
, bp
);
423 *err
= the_target
->insert_point (bp
->raw_type
, bp
->pc
, bp
->kind
, bp
);
427 debug_printf ("Failed to insert breakpoint at 0x%s (%d).\n",
428 paddress (where
), *err
);
430 do_cleanups (old_chain
);
437 discard_cleanups (old_chain
);
439 /* Link the breakpoint in, if this is the first reference. */
440 if (++bp
->refcount
== 1)
442 bp
->next
= proc
->raw_breakpoints
;
443 proc
->raw_breakpoints
= bp
;
448 /* Notice that breakpoint traps are always installed on top of fast
449 tracepoint jumps. This is even if the fast tracepoint is installed
450 at a later time compared to when the breakpoint was installed.
451 This means that a stopping breakpoint or tracepoint has higher
452 "priority". In turn, this allows having fast and slow tracepoints
453 (and breakpoints) at the same address behave correctly. */
456 /* A fast tracepoint jump. */
458 struct fast_tracepoint_jump
460 struct fast_tracepoint_jump
*next
;
462 /* A reference count. GDB can install more than one fast tracepoint
463 at the same address (each with its own action list, for
467 /* The fast tracepoint's insertion address. There can only be one
468 of these for a given PC. */
471 /* Non-zero if this fast tracepoint jump is currently inserted in
475 /* The length of the jump instruction. */
478 /* A poor-man's flexible array member, holding both the jump
479 instruction to insert, and a copy of the instruction that would
480 be in memory had not been a jump there (the shadow memory of the
482 unsigned char insn_and_shadow
[0];
485 /* Fast tracepoint FP's jump instruction to insert. */
486 #define fast_tracepoint_jump_insn(fp) \
487 ((fp)->insn_and_shadow + 0)
489 /* The shadow memory of fast tracepoint jump FP. */
490 #define fast_tracepoint_jump_shadow(fp) \
491 ((fp)->insn_and_shadow + (fp)->length)
494 /* Return the fast tracepoint jump set at WHERE. */
496 static struct fast_tracepoint_jump
*
497 find_fast_tracepoint_jump_at (CORE_ADDR where
)
499 struct process_info
*proc
= current_process ();
500 struct fast_tracepoint_jump
*jp
;
502 for (jp
= proc
->fast_tracepoint_jumps
; jp
!= NULL
; jp
= jp
->next
)
510 fast_tracepoint_jump_here (CORE_ADDR where
)
512 struct fast_tracepoint_jump
*jp
= find_fast_tracepoint_jump_at (where
);
518 delete_fast_tracepoint_jump (struct fast_tracepoint_jump
*todel
)
520 struct fast_tracepoint_jump
*bp
, **bp_link
;
522 struct process_info
*proc
= current_process ();
524 bp
= proc
->fast_tracepoint_jumps
;
525 bp_link
= &proc
->fast_tracepoint_jumps
;
531 if (--bp
->refcount
== 0)
533 struct fast_tracepoint_jump
*prev_bp_link
= *bp_link
;
539 /* Since there can be breakpoints inserted in the same
540 address range, we use `write_inferior_memory', which
541 takes care of layering breakpoints on top of fast
542 tracepoints, and on top of the buffer we pass it.
543 This works because we've already unlinked the fast
544 tracepoint jump above. Also note that we need to
545 pass the current shadow contents, because
546 write_inferior_memory updates any shadow memory with
547 what we pass here, and we want that to be a nop. */
548 buf
= (unsigned char *) alloca (bp
->length
);
549 memcpy (buf
, fast_tracepoint_jump_shadow (bp
), bp
->length
);
550 ret
= write_inferior_memory (bp
->pc
, buf
, bp
->length
);
553 /* Something went wrong, relink the jump. */
554 *bp_link
= prev_bp_link
;
557 debug_printf ("Failed to uninsert fast tracepoint jump "
558 "at 0x%s (%s) while deleting it.\n",
559 paddress (bp
->pc
), strerror (ret
));
575 warning ("Could not find fast tracepoint jump in list.");
580 inc_ref_fast_tracepoint_jump (struct fast_tracepoint_jump
*jp
)
585 struct fast_tracepoint_jump
*
586 set_fast_tracepoint_jump (CORE_ADDR where
,
587 unsigned char *insn
, ULONGEST length
)
589 struct process_info
*proc
= current_process ();
590 struct fast_tracepoint_jump
*jp
;
594 /* We refcount fast tracepoint jumps. Check if we already know
595 about a jump at this address. */
596 jp
= find_fast_tracepoint_jump_at (where
);
603 /* We don't, so create a new object. Double the length, because the
604 flexible array member holds both the jump insn, and the
606 jp
= (struct fast_tracepoint_jump
*) xcalloc (1, sizeof (*jp
) + (length
* 2));
609 memcpy (fast_tracepoint_jump_insn (jp
), insn
, length
);
611 buf
= (unsigned char *) alloca (length
);
613 /* Note that there can be trap breakpoints inserted in the same
614 address range. To access the original memory contents, we use
615 `read_inferior_memory', which masks out breakpoints. */
616 err
= read_inferior_memory (where
, buf
, length
);
620 debug_printf ("Failed to read shadow memory of"
621 " fast tracepoint at 0x%s (%s).\n",
622 paddress (where
), strerror (err
));
626 memcpy (fast_tracepoint_jump_shadow (jp
), buf
, length
);
628 /* Link the jump in. */
630 jp
->next
= proc
->fast_tracepoint_jumps
;
631 proc
->fast_tracepoint_jumps
= jp
;
633 /* Since there can be trap breakpoints inserted in the same address
634 range, we use use `write_inferior_memory', which takes care of
635 layering breakpoints on top of fast tracepoints, on top of the
636 buffer we pass it. This works because we've already linked in
637 the fast tracepoint jump above. Also note that we need to pass
638 the current shadow contents, because write_inferior_memory
639 updates any shadow memory with what we pass here, and we want
641 err
= write_inferior_memory (where
, buf
, length
);
645 debug_printf ("Failed to insert fast tracepoint jump at 0x%s (%s).\n",
646 paddress (where
), strerror (err
));
649 proc
->fast_tracepoint_jumps
= jp
->next
;
659 uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc
)
661 struct fast_tracepoint_jump
*jp
;
664 jp
= find_fast_tracepoint_jump_at (pc
);
667 /* This can happen when we remove all breakpoints while handling
670 debug_printf ("Could not find fast tracepoint jump at 0x%s "
671 "in list (uninserting).\n",
682 /* Since there can be trap breakpoints inserted in the same
683 address range, we use use `write_inferior_memory', which
684 takes care of layering breakpoints on top of fast
685 tracepoints, and on top of the buffer we pass it. This works
686 because we've already marked the fast tracepoint fast
687 tracepoint jump uninserted above. Also note that we need to
688 pass the current shadow contents, because
689 write_inferior_memory updates any shadow memory with what we
690 pass here, and we want that to be a nop. */
691 buf
= (unsigned char *) alloca (jp
->length
);
692 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
693 err
= write_inferior_memory (jp
->pc
, buf
, jp
->length
);
699 debug_printf ("Failed to uninsert fast tracepoint jump at"
701 paddress (pc
), strerror (err
));
707 reinsert_fast_tracepoint_jumps_at (CORE_ADDR where
)
709 struct fast_tracepoint_jump
*jp
;
713 jp
= find_fast_tracepoint_jump_at (where
);
716 /* This can happen when we remove breakpoints when a tracepoint
717 hit causes a tracing stop, while handling a step-over. */
719 debug_printf ("Could not find fast tracepoint jump at 0x%s "
720 "in list (reinserting).\n",
726 error ("Jump already inserted at reinsert time.");
730 /* Since there can be trap breakpoints inserted in the same address
731 range, we use `write_inferior_memory', which takes care of
732 layering breakpoints on top of fast tracepoints, and on top of
733 the buffer we pass it. This works because we've already marked
734 the fast tracepoint jump inserted above. Also note that we need
735 to pass the current shadow contents, because
736 write_inferior_memory updates any shadow memory with what we pass
737 here, and we want that to be a nop. */
738 buf
= (unsigned char *) alloca (jp
->length
);
739 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
740 err
= write_inferior_memory (where
, buf
, jp
->length
);
746 debug_printf ("Failed to reinsert fast tracepoint jump at"
748 paddress (where
), strerror (err
));
752 /* Set a high-level breakpoint of type TYPE, with low level type
753 RAW_TYPE and kind KIND, at WHERE. On success, a pointer to the new
754 breakpoint is returned. On failure, returns NULL and writes the
755 error code to *ERR. HANDLER is called when the breakpoint is hit.
756 HANDLER should return 1 if the breakpoint should be deleted, 0
759 static struct breakpoint
*
760 set_breakpoint (enum bkpt_type type
, enum raw_bkpt_type raw_type
,
761 CORE_ADDR where
, int kind
,
762 int (*handler
) (CORE_ADDR
), int *err
)
764 struct process_info
*proc
= current_process ();
765 struct breakpoint
*bp
;
766 struct raw_breakpoint
*raw
;
768 raw
= set_raw_breakpoint_at (raw_type
, where
, kind
, err
);
776 bp
= XCNEW (struct breakpoint
);
780 bp
->handler
= handler
;
782 bp
->next
= proc
->breakpoints
;
783 proc
->breakpoints
= bp
;
788 /* Set breakpoint of TYPE on address WHERE with handler HANDLER. */
790 static struct breakpoint
*
791 set_breakpoint_type_at (enum bkpt_type type
, CORE_ADDR where
,
792 int (*handler
) (CORE_ADDR
))
795 CORE_ADDR placed_address
= where
;
796 int breakpoint_kind
= target_breakpoint_kind_from_pc (&placed_address
);
798 return set_breakpoint (type
, raw_bkpt_type_sw
,
799 placed_address
, breakpoint_kind
, handler
,
803 /* See mem-break.h */
806 set_breakpoint_at (CORE_ADDR where
, int (*handler
) (CORE_ADDR
))
808 return set_breakpoint_type_at (other_breakpoint
, where
, handler
);
813 delete_raw_breakpoint (struct process_info
*proc
, struct raw_breakpoint
*todel
)
815 struct raw_breakpoint
*bp
, **bp_link
;
818 bp
= proc
->raw_breakpoints
;
819 bp_link
= &proc
->raw_breakpoints
;
825 if (bp
->inserted
> 0)
827 struct raw_breakpoint
*prev_bp_link
= *bp_link
;
831 ret
= the_target
->remove_point (bp
->raw_type
, bp
->pc
, bp
->kind
,
835 /* Something went wrong, relink the breakpoint. */
836 *bp_link
= prev_bp_link
;
839 debug_printf ("Failed to uninsert raw breakpoint "
840 "at 0x%s while deleting it.\n",
858 warning ("Could not find raw breakpoint in list.");
863 release_breakpoint (struct process_info
*proc
, struct breakpoint
*bp
)
868 newrefcount
= bp
->raw
->refcount
- 1;
869 if (newrefcount
== 0)
871 ret
= delete_raw_breakpoint (proc
, bp
->raw
);
876 bp
->raw
->refcount
= newrefcount
;
884 delete_breakpoint_1 (struct process_info
*proc
, struct breakpoint
*todel
)
886 struct breakpoint
*bp
, **bp_link
;
889 bp
= proc
->breakpoints
;
890 bp_link
= &proc
->breakpoints
;
898 err
= release_breakpoint (proc
, bp
);
912 warning ("Could not find breakpoint in list.");
917 delete_breakpoint (struct breakpoint
*todel
)
919 struct process_info
*proc
= current_process ();
920 return delete_breakpoint_1 (proc
, todel
);
923 /* Locate a GDB breakpoint of type Z_TYPE and kind KIND placed at
924 address ADDR and return a pointer to its structure. If KIND is -1,
925 the breakpoint's kind is ignored. */
927 static struct breakpoint
*
928 find_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int kind
)
930 struct process_info
*proc
= current_process ();
931 struct breakpoint
*bp
;
932 enum bkpt_type type
= Z_packet_to_bkpt_type (z_type
);
934 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
935 if (bp
->type
== type
&& bp
->raw
->pc
== addr
936 && (kind
== -1 || bp
->raw
->kind
== kind
))
943 z_type_supported (char z_type
)
945 return (z_type
>= '0' && z_type
<= '4'
946 && the_target
->supports_z_point_type
!= NULL
947 && the_target
->supports_z_point_type (z_type
));
950 /* Create a new GDB breakpoint of type Z_TYPE at ADDR with kind KIND.
951 Returns a pointer to the newly created breakpoint on success. On
952 failure returns NULL and sets *ERR to either -1 for error, or 1 if
953 Z_TYPE breakpoints are not supported on this target. */
955 static struct breakpoint
*
956 set_gdb_breakpoint_1 (char z_type
, CORE_ADDR addr
, int kind
, int *err
)
958 struct breakpoint
*bp
;
960 enum raw_bkpt_type raw_type
;
962 /* If we see GDB inserting a second code breakpoint at the same
963 address, then either: GDB is updating the breakpoint's conditions
964 or commands; or, the first breakpoint must have disappeared due
965 to a shared library unload. On targets where the shared
966 libraries are handled by userspace, like SVR4, for example,
967 GDBserver can't tell if a library was loaded or unloaded. Since
968 we refcount raw breakpoints, we must be careful to make sure GDB
969 breakpoints never contribute more than one reference. if we
970 didn't do this, in case the previous breakpoint is gone due to a
971 shared library unload, we'd just increase the refcount of the
972 previous breakpoint at this address, but the trap was not planted
973 in the inferior anymore, thus the breakpoint would never be hit.
974 Note this must be careful to not create a window where
975 breakpoints are removed from the target, for non-stop, in case
976 the target can poke at memory while the program is running. */
977 if (z_type
== Z_PACKET_SW_BP
978 || z_type
== Z_PACKET_HW_BP
)
980 bp
= find_gdb_breakpoint (z_type
, addr
, -1);
984 if (bp
->raw
->kind
!= kind
)
986 /* A different kind than previously seen. The previous
987 breakpoint must be gone then. */
988 bp
->raw
->inserted
= -1;
989 delete_breakpoint (bp
);
992 else if (z_type
== Z_PACKET_SW_BP
)
994 /* Check if the breakpoint is actually gone from the
995 target, due to an solib unload, for example. Might
996 as well validate _all_ breakpoints. */
997 validate_breakpoints ();
999 /* Breakpoints that don't pass validation are
1001 bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1007 /* Data breakpoints for the same address but different kind are
1008 expected. GDB doesn't merge these. The backend gets to do
1009 that if it wants/can. */
1010 bp
= find_gdb_breakpoint (z_type
, addr
, kind
);
1015 /* We already know about this breakpoint, there's nothing else
1016 to do - GDB's reference is already accounted for. Note that
1017 whether the breakpoint inserted is left as is - we may be
1018 stepping over it, for example, in which case we don't want to
1019 force-reinsert it. */
1023 raw_type
= Z_packet_to_raw_bkpt_type (z_type
);
1024 type
= Z_packet_to_bkpt_type (z_type
);
1025 return set_breakpoint (type
, raw_type
, addr
, kind
, NULL
, err
);
1029 check_gdb_bp_preconditions (char z_type
, int *err
)
1031 /* As software/memory breakpoints work by poking at memory, we need
1032 to prepare to access memory. If that operation fails, we need to
1033 return error. Seeing an error, if this is the first breakpoint
1034 of that type that GDB tries to insert, GDB would then assume the
1035 breakpoint type is supported, but it may actually not be. So we
1036 need to check whether the type is supported at all before
1037 preparing to access memory. */
1038 if (!z_type_supported (z_type
))
1047 /* See mem-break.h. This is a wrapper for set_gdb_breakpoint_1 that
1048 knows to prepare to access memory for Z0 breakpoints. */
1051 set_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int kind
, int *err
)
1053 struct breakpoint
*bp
;
1055 if (!check_gdb_bp_preconditions (z_type
, err
))
1058 /* If inserting a software/memory breakpoint, need to prepare to
1060 if (z_type
== Z_PACKET_SW_BP
)
1062 if (prepare_to_access_memory () != 0)
1069 bp
= set_gdb_breakpoint_1 (z_type
, addr
, kind
, err
);
1071 if (z_type
== Z_PACKET_SW_BP
)
1072 done_accessing_memory ();
1077 /* Delete a GDB breakpoint of type Z_TYPE and kind KIND previously
1078 inserted at ADDR with set_gdb_breakpoint_at. Returns 0 on success,
1079 -1 on error, and 1 if Z_TYPE breakpoints are not supported on this
1083 delete_gdb_breakpoint_1 (char z_type
, CORE_ADDR addr
, int kind
)
1085 struct breakpoint
*bp
;
1088 bp
= find_gdb_breakpoint (z_type
, addr
, kind
);
1092 /* Before deleting the breakpoint, make sure to free its condition
1093 and command lists. */
1094 clear_breakpoint_conditions_and_commands (bp
);
1095 err
= delete_breakpoint (bp
);
1102 /* See mem-break.h. This is a wrapper for delete_gdb_breakpoint that
1103 knows to prepare to access memory for Z0 breakpoints. */
1106 delete_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int kind
)
1110 if (!check_gdb_bp_preconditions (z_type
, &ret
))
1113 /* If inserting a software/memory breakpoint, need to prepare to
1115 if (z_type
== Z_PACKET_SW_BP
)
1119 err
= prepare_to_access_memory ();
1124 ret
= delete_gdb_breakpoint_1 (z_type
, addr
, kind
);
1126 if (z_type
== Z_PACKET_SW_BP
)
1127 done_accessing_memory ();
1132 /* Clear all conditions associated with a breakpoint. */
1135 clear_breakpoint_conditions (struct breakpoint
*bp
)
1137 struct point_cond_list
*cond
;
1139 if (bp
->cond_list
== NULL
)
1142 cond
= bp
->cond_list
;
1144 while (cond
!= NULL
)
1146 struct point_cond_list
*cond_next
;
1148 cond_next
= cond
->next
;
1149 gdb_free_agent_expr (cond
->cond
);
1154 bp
->cond_list
= NULL
;
1157 /* Clear all commands associated with a breakpoint. */
1160 clear_breakpoint_commands (struct breakpoint
*bp
)
1162 struct point_command_list
*cmd
;
1164 if (bp
->command_list
== NULL
)
1167 cmd
= bp
->command_list
;
1171 struct point_command_list
*cmd_next
;
1173 cmd_next
= cmd
->next
;
1174 gdb_free_agent_expr (cmd
->cmd
);
1179 bp
->command_list
= NULL
;
1183 clear_breakpoint_conditions_and_commands (struct breakpoint
*bp
)
1185 clear_breakpoint_conditions (bp
);
1186 clear_breakpoint_commands (bp
);
1189 /* Add condition CONDITION to GDBserver's breakpoint BP. */
1192 add_condition_to_breakpoint (struct breakpoint
*bp
,
1193 struct agent_expr
*condition
)
1195 struct point_cond_list
*new_cond
;
1197 /* Create new condition. */
1198 new_cond
= XCNEW (struct point_cond_list
);
1199 new_cond
->cond
= condition
;
1201 /* Add condition to the list. */
1202 new_cond
->next
= bp
->cond_list
;
1203 bp
->cond_list
= new_cond
;
1206 /* Add a target-side condition CONDITION to a breakpoint. */
1209 add_breakpoint_condition (struct breakpoint
*bp
, char **condition
)
1211 char *actparm
= *condition
;
1212 struct agent_expr
*cond
;
1214 if (condition
== NULL
)
1220 cond
= gdb_parse_agent_expr (&actparm
);
1224 fprintf (stderr
, "Condition evaluation failed. "
1225 "Assuming unconditional.\n");
1229 add_condition_to_breakpoint (bp
, cond
);
1231 *condition
= actparm
;
1236 /* Evaluate condition (if any) at breakpoint BP. Return 1 if
1237 true and 0 otherwise. */
1240 gdb_condition_true_at_breakpoint_z_type (char z_type
, CORE_ADDR addr
)
1242 /* Fetch registers for the current inferior. */
1243 struct breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1245 struct point_cond_list
*cl
;
1247 struct eval_agent_expr_context ctx
;
1252 /* Check if the breakpoint is unconditional. If it is,
1253 the condition always evaluates to TRUE. */
1254 if (bp
->cond_list
== NULL
)
1257 ctx
.regcache
= get_thread_regcache (current_thread
, 1);
1261 /* Evaluate each condition in the breakpoint's list of conditions.
1262 Return true if any of the conditions evaluates to TRUE.
1264 If we failed to evaluate the expression, TRUE is returned. This
1265 forces GDB to reevaluate the conditions. */
1266 for (cl
= bp
->cond_list
;
1267 cl
&& !value
&& !err
; cl
= cl
->next
)
1269 /* Evaluate the condition. */
1270 err
= gdb_eval_agent_expr (&ctx
, cl
->cond
, &value
);
1276 return (value
!= 0);
1280 gdb_condition_true_at_breakpoint (CORE_ADDR where
)
1282 /* Only check code (software or hardware) breakpoints. */
1283 return (gdb_condition_true_at_breakpoint_z_type (Z_PACKET_SW_BP
, where
)
1284 || gdb_condition_true_at_breakpoint_z_type (Z_PACKET_HW_BP
, where
));
1287 /* Add commands COMMANDS to GDBserver's breakpoint BP. */
1290 add_commands_to_breakpoint (struct breakpoint
*bp
,
1291 struct agent_expr
*commands
, int persist
)
1293 struct point_command_list
*new_cmd
;
1295 /* Create new command. */
1296 new_cmd
= XCNEW (struct point_command_list
);
1297 new_cmd
->cmd
= commands
;
1298 new_cmd
->persistence
= persist
;
1300 /* Add commands to the list. */
1301 new_cmd
->next
= bp
->command_list
;
1302 bp
->command_list
= new_cmd
;
1305 /* Add a target-side command COMMAND to the breakpoint at ADDR. */
1308 add_breakpoint_commands (struct breakpoint
*bp
, char **command
,
1311 char *actparm
= *command
;
1312 struct agent_expr
*cmd
;
1314 if (command
== NULL
)
1320 cmd
= gdb_parse_agent_expr (&actparm
);
1324 fprintf (stderr
, "Command evaluation failed. "
1329 add_commands_to_breakpoint (bp
, cmd
, persist
);
1336 /* Return true if there are no commands to run at this location,
1337 which likely means we want to report back to GDB. */
1340 gdb_no_commands_at_breakpoint_z_type (char z_type
, CORE_ADDR addr
)
1342 struct breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1348 debug_printf ("at 0x%s, type Z%c, bp command_list is 0x%s\n",
1349 paddress (addr
), z_type
,
1350 phex_nz ((uintptr_t) bp
->command_list
, 0));
1351 return (bp
->command_list
== NULL
);
1354 /* Return true if there are no commands to run at this location,
1355 which likely means we want to report back to GDB. */
1358 gdb_no_commands_at_breakpoint (CORE_ADDR where
)
1360 /* Only check code (software or hardware) breakpoints. */
1361 return (gdb_no_commands_at_breakpoint_z_type (Z_PACKET_SW_BP
, where
)
1362 && gdb_no_commands_at_breakpoint_z_type (Z_PACKET_HW_BP
, where
));
1365 /* Run a breakpoint's commands. Returns 0 if there was a problem
1366 running any command, 1 otherwise. */
1369 run_breakpoint_commands_z_type (char z_type
, CORE_ADDR addr
)
1371 /* Fetch registers for the current inferior. */
1372 struct breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1374 struct point_command_list
*cl
;
1376 struct eval_agent_expr_context ctx
;
1381 ctx
.regcache
= get_thread_regcache (current_thread
, 1);
1385 for (cl
= bp
->command_list
;
1386 cl
&& !value
&& !err
; cl
= cl
->next
)
1388 /* Run the command. */
1389 err
= gdb_eval_agent_expr (&ctx
, cl
->cmd
, &value
);
1391 /* If one command has a problem, stop digging the hole deeper. */
1400 run_breakpoint_commands (CORE_ADDR where
)
1402 /* Only check code (software or hardware) breakpoints. If one
1403 command has a problem, stop digging the hole deeper. */
1404 if (run_breakpoint_commands_z_type (Z_PACKET_SW_BP
, where
))
1405 run_breakpoint_commands_z_type (Z_PACKET_HW_BP
, where
);
1408 /* See mem-break.h. */
1411 gdb_breakpoint_here (CORE_ADDR where
)
1413 /* Only check code (software or hardware) breakpoints. */
1414 return (find_gdb_breakpoint (Z_PACKET_SW_BP
, where
, -1) != NULL
1415 || find_gdb_breakpoint (Z_PACKET_HW_BP
, where
, -1) != NULL
);
1419 set_reinsert_breakpoint (CORE_ADDR stop_at
)
1421 struct breakpoint
*bp
;
1423 bp
= set_breakpoint_type_at (reinsert_breakpoint
, stop_at
, NULL
);
1427 delete_reinsert_breakpoints (void)
1429 struct process_info
*proc
= current_process ();
1430 struct breakpoint
*bp
, **bp_link
;
1432 bp
= proc
->breakpoints
;
1433 bp_link
= &proc
->breakpoints
;
1437 if (bp
->type
== reinsert_breakpoint
)
1439 *bp_link
= bp
->next
;
1440 release_breakpoint (proc
, bp
);
1445 bp_link
= &bp
->next
;
1452 uninsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1454 if (bp
->inserted
< 0)
1457 debug_printf ("Breakpoint at %s is marked insert-disabled.\n",
1460 else if (bp
->inserted
> 0)
1466 err
= the_target
->remove_point (bp
->raw_type
, bp
->pc
, bp
->kind
, bp
);
1472 debug_printf ("Failed to uninsert raw breakpoint at 0x%s.\n",
1479 uninsert_breakpoints_at (CORE_ADDR pc
)
1481 struct process_info
*proc
= current_process ();
1482 struct raw_breakpoint
*bp
;
1485 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1486 if ((bp
->raw_type
== raw_bkpt_type_sw
1487 || bp
->raw_type
== raw_bkpt_type_hw
)
1493 uninsert_raw_breakpoint (bp
);
1498 /* This can happen when we remove all breakpoints while handling
1501 debug_printf ("Could not find breakpoint at 0x%s "
1502 "in list (uninserting).\n",
1508 uninsert_all_breakpoints (void)
1510 struct process_info
*proc
= current_process ();
1511 struct raw_breakpoint
*bp
;
1513 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1514 if ((bp
->raw_type
== raw_bkpt_type_sw
1515 || bp
->raw_type
== raw_bkpt_type_hw
)
1517 uninsert_raw_breakpoint (bp
);
1521 uninsert_reinsert_breakpoints (void)
1523 struct process_info
*proc
= current_process ();
1524 struct breakpoint
*bp
;
1526 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1528 if (bp
->type
== reinsert_breakpoint
)
1530 gdb_assert (bp
->raw
->inserted
> 0);
1532 /* Only uninsert the raw breakpoint if it only belongs to a
1533 reinsert breakpoint. */
1534 if (bp
->raw
->refcount
== 1)
1535 uninsert_raw_breakpoint (bp
->raw
);
1541 reinsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1548 err
= the_target
->insert_point (bp
->raw_type
, bp
->pc
, bp
->kind
, bp
);
1551 else if (debug_threads
)
1552 debug_printf ("Failed to reinsert breakpoint at 0x%s (%d).\n",
1553 paddress (bp
->pc
), err
);
1557 reinsert_breakpoints_at (CORE_ADDR pc
)
1559 struct process_info
*proc
= current_process ();
1560 struct raw_breakpoint
*bp
;
1563 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1564 if ((bp
->raw_type
== raw_bkpt_type_sw
1565 || bp
->raw_type
== raw_bkpt_type_hw
)
1570 reinsert_raw_breakpoint (bp
);
1575 /* This can happen when we remove all breakpoints while handling
1578 debug_printf ("Could not find raw breakpoint at 0x%s "
1579 "in list (reinserting).\n",
1585 has_reinsert_breakpoints (struct process_info
*proc
)
1587 struct breakpoint
*bp
, **bp_link
;
1589 bp
= proc
->breakpoints
;
1590 bp_link
= &proc
->breakpoints
;
1594 if (bp
->type
== reinsert_breakpoint
)
1598 bp_link
= &bp
->next
;
1607 reinsert_all_breakpoints (void)
1609 struct process_info
*proc
= current_process ();
1610 struct raw_breakpoint
*bp
;
1612 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1613 if ((bp
->raw_type
== raw_bkpt_type_sw
1614 || bp
->raw_type
== raw_bkpt_type_hw
)
1616 reinsert_raw_breakpoint (bp
);
1620 reinsert_reinsert_breakpoints (void)
1622 struct process_info
*proc
= current_process ();
1623 struct breakpoint
*bp
;
1625 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1627 if (bp
->type
== reinsert_breakpoint
)
1629 gdb_assert (bp
->raw
->inserted
> 0);
1631 if (bp
->raw
->refcount
== 1)
1632 reinsert_raw_breakpoint (bp
->raw
);
1638 check_breakpoints (CORE_ADDR stop_pc
)
1640 struct process_info
*proc
= current_process ();
1641 struct breakpoint
*bp
, **bp_link
;
1643 bp
= proc
->breakpoints
;
1644 bp_link
= &proc
->breakpoints
;
1648 struct raw_breakpoint
*raw
= bp
->raw
;
1650 if ((raw
->raw_type
== raw_bkpt_type_sw
1651 || raw
->raw_type
== raw_bkpt_type_hw
)
1652 && raw
->pc
== stop_pc
)
1656 warning ("Hit a removed breakpoint?");
1660 if (bp
->handler
!= NULL
&& (*bp
->handler
) (stop_pc
))
1662 *bp_link
= bp
->next
;
1664 release_breakpoint (proc
, bp
);
1671 bp_link
= &bp
->next
;
1677 breakpoint_here (CORE_ADDR addr
)
1679 struct process_info
*proc
= current_process ();
1680 struct raw_breakpoint
*bp
;
1682 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1683 if ((bp
->raw_type
== raw_bkpt_type_sw
1684 || bp
->raw_type
== raw_bkpt_type_hw
)
1692 breakpoint_inserted_here (CORE_ADDR addr
)
1694 struct process_info
*proc
= current_process ();
1695 struct raw_breakpoint
*bp
;
1697 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1698 if ((bp
->raw_type
== raw_bkpt_type_sw
1699 || bp
->raw_type
== raw_bkpt_type_hw
)
1707 /* See mem-break.h. */
1710 software_breakpoint_inserted_here (CORE_ADDR addr
)
1712 struct process_info
*proc
= current_process ();
1713 struct raw_breakpoint
*bp
;
1715 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1716 if (bp
->raw_type
== raw_bkpt_type_sw
1724 /* See mem-break.h. */
1727 hardware_breakpoint_inserted_here (CORE_ADDR addr
)
1729 struct process_info
*proc
= current_process ();
1730 struct raw_breakpoint
*bp
;
1732 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1733 if (bp
->raw_type
== raw_bkpt_type_hw
1741 /* See mem-break.h. */
1744 reinsert_breakpoint_inserted_here (CORE_ADDR addr
)
1746 struct process_info
*proc
= current_process ();
1747 struct breakpoint
*bp
;
1749 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1750 if (bp
->type
== reinsert_breakpoint
1751 && bp
->raw
->pc
== addr
1752 && bp
->raw
->inserted
)
1759 validate_inserted_breakpoint (struct raw_breakpoint
*bp
)
1764 gdb_assert (bp
->inserted
);
1765 gdb_assert (bp
->raw_type
== raw_bkpt_type_sw
);
1767 buf
= (unsigned char *) alloca (bp_size (bp
));
1768 err
= (*the_target
->read_memory
) (bp
->pc
, buf
, bp_size (bp
));
1769 if (err
|| memcmp (buf
, bp_opcode (bp
), bp_size (bp
)) != 0)
1771 /* Tag it as gone. */
1780 delete_disabled_breakpoints (void)
1782 struct process_info
*proc
= current_process ();
1783 struct breakpoint
*bp
, *next
;
1785 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= next
)
1788 if (bp
->raw
->inserted
< 0)
1790 /* If reinsert_breakpoints become disabled, that means the
1791 manipulations (insertion and removal) of them are wrong. */
1792 gdb_assert (bp
->type
!= reinsert_breakpoint
);
1793 delete_breakpoint_1 (proc
, bp
);
1798 /* Check if breakpoints we inserted still appear to be inserted. They
1799 may disappear due to a shared library unload, and worse, a new
1800 shared library may be reloaded at the same address as the
1801 previously unloaded one. If that happens, we should make sure that
1802 the shadow memory of the old breakpoints isn't used when reading or
1806 validate_breakpoints (void)
1808 struct process_info
*proc
= current_process ();
1809 struct breakpoint
*bp
;
1811 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1813 struct raw_breakpoint
*raw
= bp
->raw
;
1815 if (raw
->raw_type
== raw_bkpt_type_sw
&& raw
->inserted
> 0)
1816 validate_inserted_breakpoint (raw
);
1819 delete_disabled_breakpoints ();
1823 check_mem_read (CORE_ADDR mem_addr
, unsigned char *buf
, int mem_len
)
1825 struct process_info
*proc
= current_process ();
1826 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1827 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1828 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1829 int disabled_one
= 0;
1831 for (; jp
!= NULL
; jp
= jp
->next
)
1833 CORE_ADDR bp_end
= jp
->pc
+ jp
->length
;
1834 CORE_ADDR start
, end
;
1835 int copy_offset
, copy_len
, buf_offset
;
1837 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= buf
+ mem_len
1838 || buf
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1840 if (mem_addr
>= bp_end
)
1842 if (jp
->pc
>= mem_end
)
1846 if (mem_addr
> start
)
1853 copy_len
= end
- start
;
1854 copy_offset
= start
- jp
->pc
;
1855 buf_offset
= start
- mem_addr
;
1858 memcpy (buf
+ buf_offset
,
1859 fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1863 for (; bp
!= NULL
; bp
= bp
->next
)
1865 CORE_ADDR bp_end
= bp
->pc
+ bp_size (bp
);
1866 CORE_ADDR start
, end
;
1867 int copy_offset
, copy_len
, buf_offset
;
1869 if (bp
->raw_type
!= raw_bkpt_type_sw
)
1872 gdb_assert (bp
->old_data
>= buf
+ mem_len
1873 || buf
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1875 if (mem_addr
>= bp_end
)
1877 if (bp
->pc
>= mem_end
)
1881 if (mem_addr
> start
)
1888 copy_len
= end
- start
;
1889 copy_offset
= start
- bp
->pc
;
1890 buf_offset
= start
- mem_addr
;
1892 if (bp
->inserted
> 0)
1894 if (validate_inserted_breakpoint (bp
))
1895 memcpy (buf
+ buf_offset
, bp
->old_data
+ copy_offset
, copy_len
);
1902 delete_disabled_breakpoints ();
1906 check_mem_write (CORE_ADDR mem_addr
, unsigned char *buf
,
1907 const unsigned char *myaddr
, int mem_len
)
1909 struct process_info
*proc
= current_process ();
1910 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1911 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1912 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1913 int disabled_one
= 0;
1915 /* First fast tracepoint jumps, then breakpoint traps on top. */
1917 for (; jp
!= NULL
; jp
= jp
->next
)
1919 CORE_ADDR jp_end
= jp
->pc
+ jp
->length
;
1920 CORE_ADDR start
, end
;
1921 int copy_offset
, copy_len
, buf_offset
;
1923 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= myaddr
+ mem_len
1924 || myaddr
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1925 gdb_assert (fast_tracepoint_jump_insn (jp
) >= buf
+ mem_len
1926 || buf
>= fast_tracepoint_jump_insn (jp
) + (jp
)->length
);
1928 if (mem_addr
>= jp_end
)
1930 if (jp
->pc
>= mem_end
)
1934 if (mem_addr
> start
)
1941 copy_len
= end
- start
;
1942 copy_offset
= start
- jp
->pc
;
1943 buf_offset
= start
- mem_addr
;
1945 memcpy (fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1946 myaddr
+ buf_offset
, copy_len
);
1948 memcpy (buf
+ buf_offset
,
1949 fast_tracepoint_jump_insn (jp
) + copy_offset
, copy_len
);
1952 for (; bp
!= NULL
; bp
= bp
->next
)
1954 CORE_ADDR bp_end
= bp
->pc
+ bp_size (bp
);
1955 CORE_ADDR start
, end
;
1956 int copy_offset
, copy_len
, buf_offset
;
1958 if (bp
->raw_type
!= raw_bkpt_type_sw
)
1961 gdb_assert (bp
->old_data
>= myaddr
+ mem_len
1962 || myaddr
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1964 if (mem_addr
>= bp_end
)
1966 if (bp
->pc
>= mem_end
)
1970 if (mem_addr
> start
)
1977 copy_len
= end
- start
;
1978 copy_offset
= start
- bp
->pc
;
1979 buf_offset
= start
- mem_addr
;
1981 memcpy (bp
->old_data
+ copy_offset
, myaddr
+ buf_offset
, copy_len
);
1982 if (bp
->inserted
> 0)
1984 if (validate_inserted_breakpoint (bp
))
1985 memcpy (buf
+ buf_offset
, bp_opcode (bp
) + copy_offset
, copy_len
);
1992 delete_disabled_breakpoints ();
1995 /* Delete all breakpoints, and un-insert them from the inferior. */
1998 delete_all_breakpoints (void)
2000 struct process_info
*proc
= current_process ();
2002 while (proc
->breakpoints
)
2003 delete_breakpoint_1 (proc
, proc
->breakpoints
);
2006 /* Clear the "inserted" flag in all breakpoints. */
2009 mark_breakpoints_out (struct process_info
*proc
)
2011 struct raw_breakpoint
*raw_bp
;
2013 for (raw_bp
= proc
->raw_breakpoints
; raw_bp
!= NULL
; raw_bp
= raw_bp
->next
)
2014 raw_bp
->inserted
= 0;
2017 /* Release all breakpoints, but do not try to un-insert them from the
2021 free_all_breakpoints (struct process_info
*proc
)
2023 mark_breakpoints_out (proc
);
2025 /* Note: use PROC explicitly instead of deferring to
2026 delete_all_breakpoints --- CURRENT_INFERIOR may already have been
2027 released when we get here. There should be no call to
2028 current_process from here on. */
2029 while (proc
->breakpoints
)
2030 delete_breakpoint_1 (proc
, proc
->breakpoints
);
2033 /* Clone an agent expression. */
2035 static struct agent_expr
*
2036 clone_agent_expr (const struct agent_expr
*src_ax
)
2038 struct agent_expr
*ax
;
2040 ax
= XCNEW (struct agent_expr
);
2041 ax
->length
= src_ax
->length
;
2042 ax
->bytes
= (unsigned char *) xcalloc (ax
->length
, 1);
2043 memcpy (ax
->bytes
, src_ax
->bytes
, ax
->length
);
2047 /* Deep-copy the contents of one breakpoint to another. */
2049 static struct breakpoint
*
2050 clone_one_breakpoint (const struct breakpoint
*src
)
2052 struct breakpoint
*dest
;
2053 struct raw_breakpoint
*dest_raw
;
2054 struct point_cond_list
*current_cond
;
2055 struct point_cond_list
*new_cond
;
2056 struct point_cond_list
*cond_tail
= NULL
;
2057 struct point_command_list
*current_cmd
;
2058 struct point_command_list
*new_cmd
;
2059 struct point_command_list
*cmd_tail
= NULL
;
2061 /* Clone the raw breakpoint. */
2062 dest_raw
= XCNEW (struct raw_breakpoint
);
2063 dest_raw
->raw_type
= src
->raw
->raw_type
;
2064 dest_raw
->refcount
= src
->raw
->refcount
;
2065 dest_raw
->pc
= src
->raw
->pc
;
2066 dest_raw
->kind
= src
->raw
->kind
;
2067 memcpy (dest_raw
->old_data
, src
->raw
->old_data
, MAX_BREAKPOINT_LEN
);
2068 dest_raw
->inserted
= src
->raw
->inserted
;
2070 /* Clone the high-level breakpoint. */
2071 dest
= XCNEW (struct breakpoint
);
2072 dest
->type
= src
->type
;
2073 dest
->raw
= dest_raw
;
2074 dest
->handler
= src
->handler
;
2076 /* Clone the condition list. */
2077 for (current_cond
= src
->cond_list
; current_cond
!= NULL
;
2078 current_cond
= current_cond
->next
)
2080 new_cond
= XCNEW (struct point_cond_list
);
2081 new_cond
->cond
= clone_agent_expr (current_cond
->cond
);
2082 APPEND_TO_LIST (&dest
->cond_list
, new_cond
, cond_tail
);
2085 /* Clone the command list. */
2086 for (current_cmd
= src
->command_list
; current_cmd
!= NULL
;
2087 current_cmd
= current_cmd
->next
)
2089 new_cmd
= XCNEW (struct point_command_list
);
2090 new_cmd
->cmd
= clone_agent_expr (current_cmd
->cmd
);
2091 new_cmd
->persistence
= current_cmd
->persistence
;
2092 APPEND_TO_LIST (&dest
->command_list
, new_cmd
, cmd_tail
);
2098 /* Create a new breakpoint list NEW_LIST that is a copy of the
2099 list starting at SRC_LIST. Create the corresponding new
2100 raw_breakpoint list NEW_RAW_LIST as well. */
2103 clone_all_breakpoints (struct breakpoint
**new_list
,
2104 struct raw_breakpoint
**new_raw_list
,
2105 const struct breakpoint
*src_list
)
2107 const struct breakpoint
*bp
;
2108 struct breakpoint
*new_bkpt
;
2109 struct breakpoint
*bkpt_tail
= NULL
;
2110 struct raw_breakpoint
*raw_bkpt_tail
= NULL
;
2112 for (bp
= src_list
; bp
!= NULL
; bp
= bp
->next
)
2114 new_bkpt
= clone_one_breakpoint (bp
);
2115 APPEND_TO_LIST (new_list
, new_bkpt
, bkpt_tail
);
2116 APPEND_TO_LIST (new_raw_list
, new_bkpt
->raw
, raw_bkpt_tail
);