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 /* Link to this breakpoint's raw breakpoint. This is always
178 struct raw_breakpoint
*raw
;
181 /* Breakpoint requested by GDB. */
183 struct gdb_breakpoint
185 struct breakpoint base
;
187 /* Pointer to the condition list that should be evaluated on
188 the target or NULL if the breakpoint is unconditional or
189 if GDB doesn't want us to evaluate the conditionals on the
191 struct point_cond_list
*cond_list
;
193 /* Point to the list of commands to run when this is hit. */
194 struct point_command_list
*command_list
;
197 /* Breakpoint used by GDBserver. */
199 struct other_breakpoint
201 struct breakpoint base
;
203 /* Function to call when we hit this breakpoint. If it returns 1,
204 the breakpoint shall be deleted; 0 or if this callback is NULL,
205 it will be left inserted. */
206 int (*handler
) (CORE_ADDR
);
209 /* Reinsert breakpoint. */
211 struct reinsert_breakpoint
213 struct breakpoint base
;
216 /* Return the breakpoint size from its kind. */
219 bp_size (struct raw_breakpoint
*bp
)
223 the_target
->sw_breakpoint_from_kind (bp
->kind
, &size
);
227 /* Return the breakpoint opcode from its kind. */
229 static const gdb_byte
*
230 bp_opcode (struct raw_breakpoint
*bp
)
234 return the_target
->sw_breakpoint_from_kind (bp
->kind
, &size
);
237 /* See mem-break.h. */
239 enum target_hw_bp_type
240 raw_bkpt_type_to_target_hw_bp_type (enum raw_bkpt_type raw_type
)
244 case raw_bkpt_type_hw
:
246 case raw_bkpt_type_write_wp
:
248 case raw_bkpt_type_read_wp
:
250 case raw_bkpt_type_access_wp
:
253 internal_error (__FILE__
, __LINE__
,
254 "bad raw breakpoint type %d", (int) raw_type
);
258 /* See mem-break.h. */
260 static enum bkpt_type
261 Z_packet_to_bkpt_type (char z_type
)
263 gdb_assert ('0' <= z_type
&& z_type
<= '4');
265 return (enum bkpt_type
) (gdb_breakpoint_Z0
+ (z_type
- '0'));
268 /* See mem-break.h. */
271 Z_packet_to_raw_bkpt_type (char z_type
)
276 return raw_bkpt_type_sw
;
278 return raw_bkpt_type_hw
;
279 case Z_PACKET_WRITE_WP
:
280 return raw_bkpt_type_write_wp
;
281 case Z_PACKET_READ_WP
:
282 return raw_bkpt_type_read_wp
;
283 case Z_PACKET_ACCESS_WP
:
284 return raw_bkpt_type_access_wp
;
286 gdb_assert_not_reached ("unhandled Z packet type.");
290 /* Return true if breakpoint TYPE is a GDB breakpoint. */
293 is_gdb_breakpoint (enum bkpt_type type
)
295 return (type
== gdb_breakpoint_Z0
296 || type
== gdb_breakpoint_Z1
297 || type
== gdb_breakpoint_Z2
298 || type
== gdb_breakpoint_Z3
299 || type
== gdb_breakpoint_Z4
);
303 any_persistent_commands (void)
305 struct process_info
*proc
= current_process ();
306 struct breakpoint
*bp
;
307 struct point_command_list
*cl
;
309 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
311 if (is_gdb_breakpoint (bp
->type
))
313 struct gdb_breakpoint
*gdb_bp
= (struct gdb_breakpoint
*) bp
;
315 for (cl
= gdb_bp
->command_list
; cl
!= NULL
; cl
= cl
->next
)
324 /* Find low-level breakpoint of type TYPE at address ADDR that is not
325 insert-disabled. Returns NULL if not found. */
327 static struct raw_breakpoint
*
328 find_enabled_raw_code_breakpoint_at (CORE_ADDR addr
, enum raw_bkpt_type type
)
330 struct process_info
*proc
= current_process ();
331 struct raw_breakpoint
*bp
;
333 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
335 && bp
->raw_type
== type
336 && bp
->inserted
>= 0)
342 /* Find low-level breakpoint of type TYPE at address ADDR. Returns
343 NULL if not found. */
345 static struct raw_breakpoint
*
346 find_raw_breakpoint_at (CORE_ADDR addr
, enum raw_bkpt_type type
, int kind
)
348 struct process_info
*proc
= current_process ();
349 struct raw_breakpoint
*bp
;
351 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
352 if (bp
->pc
== addr
&& bp
->raw_type
== type
&& bp
->kind
== kind
)
358 /* See mem-break.h. */
361 insert_memory_breakpoint (struct raw_breakpoint
*bp
)
363 unsigned char buf
[MAX_BREAKPOINT_LEN
];
366 /* Note that there can be fast tracepoint jumps installed in the
367 same memory range, so to get at the original memory, we need to
368 use read_inferior_memory, which masks those out. */
369 err
= read_inferior_memory (bp
->pc
, buf
, bp_size (bp
));
373 debug_printf ("Failed to read shadow memory of"
374 " breakpoint at 0x%s (%s).\n",
375 paddress (bp
->pc
), strerror (err
));
379 memcpy (bp
->old_data
, buf
, bp_size (bp
));
381 err
= (*the_target
->write_memory
) (bp
->pc
, bp_opcode (bp
),
386 debug_printf ("Failed to insert breakpoint at 0x%s (%s).\n",
387 paddress (bp
->pc
), strerror (err
));
390 return err
!= 0 ? -1 : 0;
393 /* See mem-break.h */
396 remove_memory_breakpoint (struct raw_breakpoint
*bp
)
398 unsigned char buf
[MAX_BREAKPOINT_LEN
];
401 /* Since there can be trap breakpoints inserted in the same address
402 range, we use `write_inferior_memory', which takes care of
403 layering breakpoints on top of fast tracepoints, and on top of
404 the buffer we pass it. This works because the caller has already
405 either unlinked the breakpoint or marked it uninserted. Also
406 note that we need to pass the current shadow contents, because
407 write_inferior_memory updates any shadow memory with what we pass
408 here, and we want that to be a nop. */
409 memcpy (buf
, bp
->old_data
, bp_size (bp
));
410 err
= write_inferior_memory (bp
->pc
, buf
, bp_size (bp
));
414 debug_printf ("Failed to uninsert raw breakpoint "
415 "at 0x%s (%s) while deleting it.\n",
416 paddress (bp
->pc
), strerror (err
));
418 return err
!= 0 ? -1 : 0;
421 /* Set a RAW breakpoint of type TYPE and kind KIND at WHERE. On
422 success, a pointer to the new breakpoint is returned. On failure,
423 returns NULL and writes the error code to *ERR. */
425 static struct raw_breakpoint
*
426 set_raw_breakpoint_at (enum raw_bkpt_type type
, CORE_ADDR where
, int kind
,
429 struct process_info
*proc
= current_process ();
430 struct raw_breakpoint
*bp
;
431 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
433 if (type
== raw_bkpt_type_sw
|| type
== raw_bkpt_type_hw
)
435 bp
= find_enabled_raw_code_breakpoint_at (where
, type
);
436 if (bp
!= NULL
&& bp
->kind
!= kind
)
438 /* A different kind than previously seen. The previous
439 breakpoint must be gone then. */
441 debug_printf ("Inconsistent breakpoint kind? Was %d, now %d.\n",
448 bp
= find_raw_breakpoint_at (where
, type
, kind
);
452 bp
= XCNEW (struct raw_breakpoint
);
456 make_cleanup (xfree
, bp
);
461 *err
= the_target
->insert_point (bp
->raw_type
, bp
->pc
, bp
->kind
, bp
);
465 debug_printf ("Failed to insert breakpoint at 0x%s (%d).\n",
466 paddress (where
), *err
);
468 do_cleanups (old_chain
);
475 discard_cleanups (old_chain
);
477 /* Link the breakpoint in, if this is the first reference. */
478 if (++bp
->refcount
== 1)
480 bp
->next
= proc
->raw_breakpoints
;
481 proc
->raw_breakpoints
= bp
;
486 /* Notice that breakpoint traps are always installed on top of fast
487 tracepoint jumps. This is even if the fast tracepoint is installed
488 at a later time compared to when the breakpoint was installed.
489 This means that a stopping breakpoint or tracepoint has higher
490 "priority". In turn, this allows having fast and slow tracepoints
491 (and breakpoints) at the same address behave correctly. */
494 /* A fast tracepoint jump. */
496 struct fast_tracepoint_jump
498 struct fast_tracepoint_jump
*next
;
500 /* A reference count. GDB can install more than one fast tracepoint
501 at the same address (each with its own action list, for
505 /* The fast tracepoint's insertion address. There can only be one
506 of these for a given PC. */
509 /* Non-zero if this fast tracepoint jump is currently inserted in
513 /* The length of the jump instruction. */
516 /* A poor-man's flexible array member, holding both the jump
517 instruction to insert, and a copy of the instruction that would
518 be in memory had not been a jump there (the shadow memory of the
520 unsigned char insn_and_shadow
[0];
523 /* Fast tracepoint FP's jump instruction to insert. */
524 #define fast_tracepoint_jump_insn(fp) \
525 ((fp)->insn_and_shadow + 0)
527 /* The shadow memory of fast tracepoint jump FP. */
528 #define fast_tracepoint_jump_shadow(fp) \
529 ((fp)->insn_and_shadow + (fp)->length)
532 /* Return the fast tracepoint jump set at WHERE. */
534 static struct fast_tracepoint_jump
*
535 find_fast_tracepoint_jump_at (CORE_ADDR where
)
537 struct process_info
*proc
= current_process ();
538 struct fast_tracepoint_jump
*jp
;
540 for (jp
= proc
->fast_tracepoint_jumps
; jp
!= NULL
; jp
= jp
->next
)
548 fast_tracepoint_jump_here (CORE_ADDR where
)
550 struct fast_tracepoint_jump
*jp
= find_fast_tracepoint_jump_at (where
);
556 delete_fast_tracepoint_jump (struct fast_tracepoint_jump
*todel
)
558 struct fast_tracepoint_jump
*bp
, **bp_link
;
560 struct process_info
*proc
= current_process ();
562 bp
= proc
->fast_tracepoint_jumps
;
563 bp_link
= &proc
->fast_tracepoint_jumps
;
569 if (--bp
->refcount
== 0)
571 struct fast_tracepoint_jump
*prev_bp_link
= *bp_link
;
577 /* Since there can be breakpoints inserted in the same
578 address range, we use `write_inferior_memory', which
579 takes care of layering breakpoints on top of fast
580 tracepoints, and on top of the buffer we pass it.
581 This works because we've already unlinked the fast
582 tracepoint jump above. Also note that we need to
583 pass the current shadow contents, because
584 write_inferior_memory updates any shadow memory with
585 what we pass here, and we want that to be a nop. */
586 buf
= (unsigned char *) alloca (bp
->length
);
587 memcpy (buf
, fast_tracepoint_jump_shadow (bp
), bp
->length
);
588 ret
= write_inferior_memory (bp
->pc
, buf
, bp
->length
);
591 /* Something went wrong, relink the jump. */
592 *bp_link
= prev_bp_link
;
595 debug_printf ("Failed to uninsert fast tracepoint jump "
596 "at 0x%s (%s) while deleting it.\n",
597 paddress (bp
->pc
), strerror (ret
));
613 warning ("Could not find fast tracepoint jump in list.");
618 inc_ref_fast_tracepoint_jump (struct fast_tracepoint_jump
*jp
)
623 struct fast_tracepoint_jump
*
624 set_fast_tracepoint_jump (CORE_ADDR where
,
625 unsigned char *insn
, ULONGEST length
)
627 struct process_info
*proc
= current_process ();
628 struct fast_tracepoint_jump
*jp
;
632 /* We refcount fast tracepoint jumps. Check if we already know
633 about a jump at this address. */
634 jp
= find_fast_tracepoint_jump_at (where
);
641 /* We don't, so create a new object. Double the length, because the
642 flexible array member holds both the jump insn, and the
644 jp
= (struct fast_tracepoint_jump
*) xcalloc (1, sizeof (*jp
) + (length
* 2));
647 memcpy (fast_tracepoint_jump_insn (jp
), insn
, length
);
649 buf
= (unsigned char *) alloca (length
);
651 /* Note that there can be trap breakpoints inserted in the same
652 address range. To access the original memory contents, we use
653 `read_inferior_memory', which masks out breakpoints. */
654 err
= read_inferior_memory (where
, buf
, length
);
658 debug_printf ("Failed to read shadow memory of"
659 " fast tracepoint at 0x%s (%s).\n",
660 paddress (where
), strerror (err
));
664 memcpy (fast_tracepoint_jump_shadow (jp
), buf
, length
);
666 /* Link the jump in. */
668 jp
->next
= proc
->fast_tracepoint_jumps
;
669 proc
->fast_tracepoint_jumps
= jp
;
671 /* Since there can be trap breakpoints inserted in the same address
672 range, we use use `write_inferior_memory', which takes care of
673 layering breakpoints on top of fast tracepoints, on top of the
674 buffer we pass it. This works because we've already linked in
675 the fast tracepoint jump above. Also note that we need to pass
676 the current shadow contents, because write_inferior_memory
677 updates any shadow memory with what we pass here, and we want
679 err
= write_inferior_memory (where
, buf
, length
);
683 debug_printf ("Failed to insert fast tracepoint jump at 0x%s (%s).\n",
684 paddress (where
), strerror (err
));
687 proc
->fast_tracepoint_jumps
= jp
->next
;
697 uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc
)
699 struct fast_tracepoint_jump
*jp
;
702 jp
= find_fast_tracepoint_jump_at (pc
);
705 /* This can happen when we remove all breakpoints while handling
708 debug_printf ("Could not find fast tracepoint jump at 0x%s "
709 "in list (uninserting).\n",
720 /* Since there can be trap breakpoints inserted in the same
721 address range, we use use `write_inferior_memory', which
722 takes care of layering breakpoints on top of fast
723 tracepoints, and on top of the buffer we pass it. This works
724 because we've already marked the fast tracepoint fast
725 tracepoint jump uninserted above. Also note that we need to
726 pass the current shadow contents, because
727 write_inferior_memory updates any shadow memory with what we
728 pass here, and we want that to be a nop. */
729 buf
= (unsigned char *) alloca (jp
->length
);
730 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
731 err
= write_inferior_memory (jp
->pc
, buf
, jp
->length
);
737 debug_printf ("Failed to uninsert fast tracepoint jump at"
739 paddress (pc
), strerror (err
));
745 reinsert_fast_tracepoint_jumps_at (CORE_ADDR where
)
747 struct fast_tracepoint_jump
*jp
;
751 jp
= find_fast_tracepoint_jump_at (where
);
754 /* This can happen when we remove breakpoints when a tracepoint
755 hit causes a tracing stop, while handling a step-over. */
757 debug_printf ("Could not find fast tracepoint jump at 0x%s "
758 "in list (reinserting).\n",
764 error ("Jump already inserted at reinsert time.");
768 /* Since there can be trap breakpoints inserted in the same address
769 range, we use `write_inferior_memory', which takes care of
770 layering breakpoints on top of fast tracepoints, and on top of
771 the buffer we pass it. This works because we've already marked
772 the fast tracepoint jump inserted above. Also note that we need
773 to pass the current shadow contents, because
774 write_inferior_memory updates any shadow memory with what we pass
775 here, and we want that to be a nop. */
776 buf
= (unsigned char *) alloca (jp
->length
);
777 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
778 err
= write_inferior_memory (where
, buf
, jp
->length
);
784 debug_printf ("Failed to reinsert fast tracepoint jump at"
786 paddress (where
), strerror (err
));
790 /* Set a high-level breakpoint of type TYPE, with low level type
791 RAW_TYPE and kind KIND, at WHERE. On success, a pointer to the new
792 breakpoint is returned. On failure, returns NULL and writes the
793 error code to *ERR. HANDLER is called when the breakpoint is hit.
794 HANDLER should return 1 if the breakpoint should be deleted, 0
797 static struct breakpoint
*
798 set_breakpoint (enum bkpt_type type
, enum raw_bkpt_type raw_type
,
799 CORE_ADDR where
, int kind
,
800 int (*handler
) (CORE_ADDR
), int *err
)
802 struct process_info
*proc
= current_process ();
803 struct breakpoint
*bp
;
804 struct raw_breakpoint
*raw
;
806 raw
= set_raw_breakpoint_at (raw_type
, where
, kind
, err
);
814 if (is_gdb_breakpoint (type
))
816 struct gdb_breakpoint
*gdb_bp
= XCNEW (struct gdb_breakpoint
);
818 bp
= (struct breakpoint
*) gdb_bp
;
819 gdb_assert (handler
== NULL
);
821 else if (type
== other_breakpoint
)
823 struct other_breakpoint
*other_bp
= XCNEW (struct other_breakpoint
);
825 other_bp
->handler
= handler
;
826 bp
= (struct breakpoint
*) other_bp
;
828 else if (type
== reinsert_breakpoint
)
830 struct reinsert_breakpoint
*reinsert_bp
831 = XCNEW (struct reinsert_breakpoint
);
833 bp
= (struct breakpoint
*) reinsert_bp
;
836 gdb_assert_not_reached ("unhandled breakpoint type");
841 bp
->next
= proc
->breakpoints
;
842 proc
->breakpoints
= bp
;
847 /* Set breakpoint of TYPE on address WHERE with handler HANDLER. */
849 static struct breakpoint
*
850 set_breakpoint_type_at (enum bkpt_type type
, CORE_ADDR where
,
851 int (*handler
) (CORE_ADDR
))
854 CORE_ADDR placed_address
= where
;
855 int breakpoint_kind
= target_breakpoint_kind_from_pc (&placed_address
);
857 return set_breakpoint (type
, raw_bkpt_type_sw
,
858 placed_address
, breakpoint_kind
, handler
,
862 /* See mem-break.h */
865 set_breakpoint_at (CORE_ADDR where
, int (*handler
) (CORE_ADDR
))
867 return set_breakpoint_type_at (other_breakpoint
, where
, handler
);
872 delete_raw_breakpoint (struct process_info
*proc
, struct raw_breakpoint
*todel
)
874 struct raw_breakpoint
*bp
, **bp_link
;
877 bp
= proc
->raw_breakpoints
;
878 bp_link
= &proc
->raw_breakpoints
;
884 if (bp
->inserted
> 0)
886 struct raw_breakpoint
*prev_bp_link
= *bp_link
;
890 ret
= the_target
->remove_point (bp
->raw_type
, bp
->pc
, bp
->kind
,
894 /* Something went wrong, relink the breakpoint. */
895 *bp_link
= prev_bp_link
;
898 debug_printf ("Failed to uninsert raw breakpoint "
899 "at 0x%s while deleting it.\n",
917 warning ("Could not find raw breakpoint in list.");
922 release_breakpoint (struct process_info
*proc
, struct breakpoint
*bp
)
927 newrefcount
= bp
->raw
->refcount
- 1;
928 if (newrefcount
== 0)
930 ret
= delete_raw_breakpoint (proc
, bp
->raw
);
935 bp
->raw
->refcount
= newrefcount
;
943 delete_breakpoint_1 (struct process_info
*proc
, struct breakpoint
*todel
)
945 struct breakpoint
*bp
, **bp_link
;
948 bp
= proc
->breakpoints
;
949 bp_link
= &proc
->breakpoints
;
957 err
= release_breakpoint (proc
, bp
);
971 warning ("Could not find breakpoint in list.");
976 delete_breakpoint (struct breakpoint
*todel
)
978 struct process_info
*proc
= current_process ();
979 return delete_breakpoint_1 (proc
, todel
);
982 /* Locate a GDB breakpoint of type Z_TYPE and kind KIND placed at
983 address ADDR and return a pointer to its structure. If KIND is -1,
984 the breakpoint's kind is ignored. */
986 static struct gdb_breakpoint
*
987 find_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int kind
)
989 struct process_info
*proc
= current_process ();
990 struct breakpoint
*bp
;
991 enum bkpt_type type
= Z_packet_to_bkpt_type (z_type
);
993 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
994 if (bp
->type
== type
&& bp
->raw
->pc
== addr
995 && (kind
== -1 || bp
->raw
->kind
== kind
))
996 return (gdb_breakpoint
*) bp
;
1002 z_type_supported (char z_type
)
1004 return (z_type
>= '0' && z_type
<= '4'
1005 && the_target
->supports_z_point_type
!= NULL
1006 && the_target
->supports_z_point_type (z_type
));
1009 /* Create a new GDB breakpoint of type Z_TYPE at ADDR with kind KIND.
1010 Returns a pointer to the newly created breakpoint on success. On
1011 failure returns NULL and sets *ERR to either -1 for error, or 1 if
1012 Z_TYPE breakpoints are not supported on this target. */
1014 static struct gdb_breakpoint
*
1015 set_gdb_breakpoint_1 (char z_type
, CORE_ADDR addr
, int kind
, int *err
)
1017 struct gdb_breakpoint
*bp
;
1018 enum bkpt_type type
;
1019 enum raw_bkpt_type raw_type
;
1021 /* If we see GDB inserting a second code breakpoint at the same
1022 address, then either: GDB is updating the breakpoint's conditions
1023 or commands; or, the first breakpoint must have disappeared due
1024 to a shared library unload. On targets where the shared
1025 libraries are handled by userspace, like SVR4, for example,
1026 GDBserver can't tell if a library was loaded or unloaded. Since
1027 we refcount raw breakpoints, we must be careful to make sure GDB
1028 breakpoints never contribute more than one reference. if we
1029 didn't do this, in case the previous breakpoint is gone due to a
1030 shared library unload, we'd just increase the refcount of the
1031 previous breakpoint at this address, but the trap was not planted
1032 in the inferior anymore, thus the breakpoint would never be hit.
1033 Note this must be careful to not create a window where
1034 breakpoints are removed from the target, for non-stop, in case
1035 the target can poke at memory while the program is running. */
1036 if (z_type
== Z_PACKET_SW_BP
1037 || z_type
== Z_PACKET_HW_BP
)
1039 bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1043 if (bp
->base
.raw
->kind
!= kind
)
1045 /* A different kind than previously seen. The previous
1046 breakpoint must be gone then. */
1047 bp
->base
.raw
->inserted
= -1;
1048 delete_breakpoint ((struct breakpoint
*) bp
);
1051 else if (z_type
== Z_PACKET_SW_BP
)
1053 /* Check if the breakpoint is actually gone from the
1054 target, due to an solib unload, for example. Might
1055 as well validate _all_ breakpoints. */
1056 validate_breakpoints ();
1058 /* Breakpoints that don't pass validation are
1060 bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1066 /* Data breakpoints for the same address but different kind are
1067 expected. GDB doesn't merge these. The backend gets to do
1068 that if it wants/can. */
1069 bp
= find_gdb_breakpoint (z_type
, addr
, kind
);
1074 /* We already know about this breakpoint, there's nothing else
1075 to do - GDB's reference is already accounted for. Note that
1076 whether the breakpoint inserted is left as is - we may be
1077 stepping over it, for example, in which case we don't want to
1078 force-reinsert it. */
1082 raw_type
= Z_packet_to_raw_bkpt_type (z_type
);
1083 type
= Z_packet_to_bkpt_type (z_type
);
1084 return (struct gdb_breakpoint
*) set_breakpoint (type
, raw_type
, addr
,
1089 check_gdb_bp_preconditions (char z_type
, int *err
)
1091 /* As software/memory breakpoints work by poking at memory, we need
1092 to prepare to access memory. If that operation fails, we need to
1093 return error. Seeing an error, if this is the first breakpoint
1094 of that type that GDB tries to insert, GDB would then assume the
1095 breakpoint type is supported, but it may actually not be. So we
1096 need to check whether the type is supported at all before
1097 preparing to access memory. */
1098 if (!z_type_supported (z_type
))
1107 /* See mem-break.h. This is a wrapper for set_gdb_breakpoint_1 that
1108 knows to prepare to access memory for Z0 breakpoints. */
1110 struct gdb_breakpoint
*
1111 set_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int kind
, int *err
)
1113 struct gdb_breakpoint
*bp
;
1115 if (!check_gdb_bp_preconditions (z_type
, err
))
1118 /* If inserting a software/memory breakpoint, need to prepare to
1120 if (z_type
== Z_PACKET_SW_BP
)
1122 if (prepare_to_access_memory () != 0)
1129 bp
= set_gdb_breakpoint_1 (z_type
, addr
, kind
, err
);
1131 if (z_type
== Z_PACKET_SW_BP
)
1132 done_accessing_memory ();
1137 /* Delete a GDB breakpoint of type Z_TYPE and kind KIND previously
1138 inserted at ADDR with set_gdb_breakpoint_at. Returns 0 on success,
1139 -1 on error, and 1 if Z_TYPE breakpoints are not supported on this
1143 delete_gdb_breakpoint_1 (char z_type
, CORE_ADDR addr
, int kind
)
1145 struct gdb_breakpoint
*bp
;
1148 bp
= find_gdb_breakpoint (z_type
, addr
, kind
);
1152 /* Before deleting the breakpoint, make sure to free its condition
1153 and command lists. */
1154 clear_breakpoint_conditions_and_commands (bp
);
1155 err
= delete_breakpoint ((struct breakpoint
*) bp
);
1162 /* See mem-break.h. This is a wrapper for delete_gdb_breakpoint that
1163 knows to prepare to access memory for Z0 breakpoints. */
1166 delete_gdb_breakpoint (char z_type
, CORE_ADDR addr
, int kind
)
1170 if (!check_gdb_bp_preconditions (z_type
, &ret
))
1173 /* If inserting a software/memory breakpoint, need to prepare to
1175 if (z_type
== Z_PACKET_SW_BP
)
1179 err
= prepare_to_access_memory ();
1184 ret
= delete_gdb_breakpoint_1 (z_type
, addr
, kind
);
1186 if (z_type
== Z_PACKET_SW_BP
)
1187 done_accessing_memory ();
1192 /* Clear all conditions associated with a breakpoint. */
1195 clear_breakpoint_conditions (struct gdb_breakpoint
*bp
)
1197 struct point_cond_list
*cond
;
1199 if (bp
->cond_list
== NULL
)
1202 cond
= bp
->cond_list
;
1204 while (cond
!= NULL
)
1206 struct point_cond_list
*cond_next
;
1208 cond_next
= cond
->next
;
1209 gdb_free_agent_expr (cond
->cond
);
1214 bp
->cond_list
= NULL
;
1217 /* Clear all commands associated with a breakpoint. */
1220 clear_breakpoint_commands (struct gdb_breakpoint
*bp
)
1222 struct point_command_list
*cmd
;
1224 if (bp
->command_list
== NULL
)
1227 cmd
= bp
->command_list
;
1231 struct point_command_list
*cmd_next
;
1233 cmd_next
= cmd
->next
;
1234 gdb_free_agent_expr (cmd
->cmd
);
1239 bp
->command_list
= NULL
;
1243 clear_breakpoint_conditions_and_commands (struct gdb_breakpoint
*bp
)
1245 clear_breakpoint_conditions (bp
);
1246 clear_breakpoint_commands (bp
);
1249 /* Add condition CONDITION to GDBserver's breakpoint BP. */
1252 add_condition_to_breakpoint (struct gdb_breakpoint
*bp
,
1253 struct agent_expr
*condition
)
1255 struct point_cond_list
*new_cond
;
1257 /* Create new condition. */
1258 new_cond
= XCNEW (struct point_cond_list
);
1259 new_cond
->cond
= condition
;
1261 /* Add condition to the list. */
1262 new_cond
->next
= bp
->cond_list
;
1263 bp
->cond_list
= new_cond
;
1266 /* Add a target-side condition CONDITION to a breakpoint. */
1269 add_breakpoint_condition (struct gdb_breakpoint
*bp
, char **condition
)
1271 char *actparm
= *condition
;
1272 struct agent_expr
*cond
;
1274 if (condition
== NULL
)
1280 cond
= gdb_parse_agent_expr (&actparm
);
1284 fprintf (stderr
, "Condition evaluation failed. "
1285 "Assuming unconditional.\n");
1289 add_condition_to_breakpoint (bp
, cond
);
1291 *condition
= actparm
;
1296 /* Evaluate condition (if any) at breakpoint BP. Return 1 if
1297 true and 0 otherwise. */
1300 gdb_condition_true_at_breakpoint_z_type (char z_type
, CORE_ADDR addr
)
1302 /* Fetch registers for the current inferior. */
1303 struct gdb_breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1305 struct point_cond_list
*cl
;
1307 struct eval_agent_expr_context ctx
;
1312 /* Check if the breakpoint is unconditional. If it is,
1313 the condition always evaluates to TRUE. */
1314 if (bp
->cond_list
== NULL
)
1317 ctx
.regcache
= get_thread_regcache (current_thread
, 1);
1321 /* Evaluate each condition in the breakpoint's list of conditions.
1322 Return true if any of the conditions evaluates to TRUE.
1324 If we failed to evaluate the expression, TRUE is returned. This
1325 forces GDB to reevaluate the conditions. */
1326 for (cl
= bp
->cond_list
;
1327 cl
&& !value
&& !err
; cl
= cl
->next
)
1329 /* Evaluate the condition. */
1330 err
= gdb_eval_agent_expr (&ctx
, cl
->cond
, &value
);
1336 return (value
!= 0);
1340 gdb_condition_true_at_breakpoint (CORE_ADDR where
)
1342 /* Only check code (software or hardware) breakpoints. */
1343 return (gdb_condition_true_at_breakpoint_z_type (Z_PACKET_SW_BP
, where
)
1344 || gdb_condition_true_at_breakpoint_z_type (Z_PACKET_HW_BP
, where
));
1347 /* Add commands COMMANDS to GDBserver's breakpoint BP. */
1350 add_commands_to_breakpoint (struct gdb_breakpoint
*bp
,
1351 struct agent_expr
*commands
, int persist
)
1353 struct point_command_list
*new_cmd
;
1355 /* Create new command. */
1356 new_cmd
= XCNEW (struct point_command_list
);
1357 new_cmd
->cmd
= commands
;
1358 new_cmd
->persistence
= persist
;
1360 /* Add commands to the list. */
1361 new_cmd
->next
= bp
->command_list
;
1362 bp
->command_list
= new_cmd
;
1365 /* Add a target-side command COMMAND to the breakpoint at ADDR. */
1368 add_breakpoint_commands (struct gdb_breakpoint
*bp
, char **command
,
1371 char *actparm
= *command
;
1372 struct agent_expr
*cmd
;
1374 if (command
== NULL
)
1380 cmd
= gdb_parse_agent_expr (&actparm
);
1384 fprintf (stderr
, "Command evaluation failed. "
1389 add_commands_to_breakpoint (bp
, cmd
, persist
);
1396 /* Return true if there are no commands to run at this location,
1397 which likely means we want to report back to GDB. */
1400 gdb_no_commands_at_breakpoint_z_type (char z_type
, CORE_ADDR addr
)
1402 struct gdb_breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1408 debug_printf ("at 0x%s, type Z%c, bp command_list is 0x%s\n",
1409 paddress (addr
), z_type
,
1410 phex_nz ((uintptr_t) bp
->command_list
, 0));
1411 return (bp
->command_list
== NULL
);
1414 /* Return true if there are no commands to run at this location,
1415 which likely means we want to report back to GDB. */
1418 gdb_no_commands_at_breakpoint (CORE_ADDR where
)
1420 /* Only check code (software or hardware) breakpoints. */
1421 return (gdb_no_commands_at_breakpoint_z_type (Z_PACKET_SW_BP
, where
)
1422 && gdb_no_commands_at_breakpoint_z_type (Z_PACKET_HW_BP
, where
));
1425 /* Run a breakpoint's commands. Returns 0 if there was a problem
1426 running any command, 1 otherwise. */
1429 run_breakpoint_commands_z_type (char z_type
, CORE_ADDR addr
)
1431 /* Fetch registers for the current inferior. */
1432 struct gdb_breakpoint
*bp
= find_gdb_breakpoint (z_type
, addr
, -1);
1434 struct point_command_list
*cl
;
1436 struct eval_agent_expr_context ctx
;
1441 ctx
.regcache
= get_thread_regcache (current_thread
, 1);
1445 for (cl
= bp
->command_list
;
1446 cl
&& !value
&& !err
; cl
= cl
->next
)
1448 /* Run the command. */
1449 err
= gdb_eval_agent_expr (&ctx
, cl
->cmd
, &value
);
1451 /* If one command has a problem, stop digging the hole deeper. */
1460 run_breakpoint_commands (CORE_ADDR where
)
1462 /* Only check code (software or hardware) breakpoints. If one
1463 command has a problem, stop digging the hole deeper. */
1464 if (run_breakpoint_commands_z_type (Z_PACKET_SW_BP
, where
))
1465 run_breakpoint_commands_z_type (Z_PACKET_HW_BP
, where
);
1468 /* See mem-break.h. */
1471 gdb_breakpoint_here (CORE_ADDR where
)
1473 /* Only check code (software or hardware) breakpoints. */
1474 return (find_gdb_breakpoint (Z_PACKET_SW_BP
, where
, -1) != NULL
1475 || find_gdb_breakpoint (Z_PACKET_HW_BP
, where
, -1) != NULL
);
1479 set_reinsert_breakpoint (CORE_ADDR stop_at
)
1481 struct breakpoint
*bp
;
1483 bp
= set_breakpoint_type_at (reinsert_breakpoint
, stop_at
, NULL
);
1487 delete_reinsert_breakpoints (void)
1489 struct process_info
*proc
= current_process ();
1490 struct breakpoint
*bp
, **bp_link
;
1492 bp
= proc
->breakpoints
;
1493 bp_link
= &proc
->breakpoints
;
1497 if (bp
->type
== reinsert_breakpoint
)
1499 *bp_link
= bp
->next
;
1500 release_breakpoint (proc
, bp
);
1505 bp_link
= &bp
->next
;
1512 uninsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1514 if (bp
->inserted
< 0)
1517 debug_printf ("Breakpoint at %s is marked insert-disabled.\n",
1520 else if (bp
->inserted
> 0)
1526 err
= the_target
->remove_point (bp
->raw_type
, bp
->pc
, bp
->kind
, bp
);
1532 debug_printf ("Failed to uninsert raw breakpoint at 0x%s.\n",
1539 uninsert_breakpoints_at (CORE_ADDR pc
)
1541 struct process_info
*proc
= current_process ();
1542 struct raw_breakpoint
*bp
;
1545 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1546 if ((bp
->raw_type
== raw_bkpt_type_sw
1547 || bp
->raw_type
== raw_bkpt_type_hw
)
1553 uninsert_raw_breakpoint (bp
);
1558 /* This can happen when we remove all breakpoints while handling
1561 debug_printf ("Could not find breakpoint at 0x%s "
1562 "in list (uninserting).\n",
1568 uninsert_all_breakpoints (void)
1570 struct process_info
*proc
= current_process ();
1571 struct raw_breakpoint
*bp
;
1573 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1574 if ((bp
->raw_type
== raw_bkpt_type_sw
1575 || bp
->raw_type
== raw_bkpt_type_hw
)
1577 uninsert_raw_breakpoint (bp
);
1581 uninsert_reinsert_breakpoints (void)
1583 struct process_info
*proc
= current_process ();
1584 struct breakpoint
*bp
;
1586 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1588 if (bp
->type
== reinsert_breakpoint
)
1590 gdb_assert (bp
->raw
->inserted
> 0);
1592 /* Only uninsert the raw breakpoint if it only belongs to a
1593 reinsert breakpoint. */
1594 if (bp
->raw
->refcount
== 1)
1595 uninsert_raw_breakpoint (bp
->raw
);
1601 reinsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1608 err
= the_target
->insert_point (bp
->raw_type
, bp
->pc
, bp
->kind
, bp
);
1611 else if (debug_threads
)
1612 debug_printf ("Failed to reinsert breakpoint at 0x%s (%d).\n",
1613 paddress (bp
->pc
), err
);
1617 reinsert_breakpoints_at (CORE_ADDR pc
)
1619 struct process_info
*proc
= current_process ();
1620 struct raw_breakpoint
*bp
;
1623 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1624 if ((bp
->raw_type
== raw_bkpt_type_sw
1625 || bp
->raw_type
== raw_bkpt_type_hw
)
1630 reinsert_raw_breakpoint (bp
);
1635 /* This can happen when we remove all breakpoints while handling
1638 debug_printf ("Could not find raw breakpoint at 0x%s "
1639 "in list (reinserting).\n",
1645 has_reinsert_breakpoints (struct process_info
*proc
)
1647 struct breakpoint
*bp
, **bp_link
;
1649 bp
= proc
->breakpoints
;
1650 bp_link
= &proc
->breakpoints
;
1654 if (bp
->type
== reinsert_breakpoint
)
1658 bp_link
= &bp
->next
;
1667 reinsert_all_breakpoints (void)
1669 struct process_info
*proc
= current_process ();
1670 struct raw_breakpoint
*bp
;
1672 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1673 if ((bp
->raw_type
== raw_bkpt_type_sw
1674 || bp
->raw_type
== raw_bkpt_type_hw
)
1676 reinsert_raw_breakpoint (bp
);
1680 reinsert_reinsert_breakpoints (void)
1682 struct process_info
*proc
= current_process ();
1683 struct breakpoint
*bp
;
1685 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1687 if (bp
->type
== reinsert_breakpoint
)
1689 gdb_assert (bp
->raw
->inserted
> 0);
1691 if (bp
->raw
->refcount
== 1)
1692 reinsert_raw_breakpoint (bp
->raw
);
1698 check_breakpoints (CORE_ADDR stop_pc
)
1700 struct process_info
*proc
= current_process ();
1701 struct breakpoint
*bp
, **bp_link
;
1703 bp
= proc
->breakpoints
;
1704 bp_link
= &proc
->breakpoints
;
1708 struct raw_breakpoint
*raw
= bp
->raw
;
1710 if ((raw
->raw_type
== raw_bkpt_type_sw
1711 || raw
->raw_type
== raw_bkpt_type_hw
)
1712 && raw
->pc
== stop_pc
)
1716 warning ("Hit a removed breakpoint?");
1720 if (bp
->type
== other_breakpoint
)
1722 struct other_breakpoint
*other_bp
1723 = (struct other_breakpoint
*) bp
;
1725 if (other_bp
->handler
!= NULL
&& (*other_bp
->handler
) (stop_pc
))
1727 *bp_link
= bp
->next
;
1729 release_breakpoint (proc
, bp
);
1737 bp_link
= &bp
->next
;
1743 breakpoint_here (CORE_ADDR addr
)
1745 struct process_info
*proc
= current_process ();
1746 struct raw_breakpoint
*bp
;
1748 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1749 if ((bp
->raw_type
== raw_bkpt_type_sw
1750 || bp
->raw_type
== raw_bkpt_type_hw
)
1758 breakpoint_inserted_here (CORE_ADDR addr
)
1760 struct process_info
*proc
= current_process ();
1761 struct raw_breakpoint
*bp
;
1763 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1764 if ((bp
->raw_type
== raw_bkpt_type_sw
1765 || bp
->raw_type
== raw_bkpt_type_hw
)
1773 /* See mem-break.h. */
1776 software_breakpoint_inserted_here (CORE_ADDR addr
)
1778 struct process_info
*proc
= current_process ();
1779 struct raw_breakpoint
*bp
;
1781 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1782 if (bp
->raw_type
== raw_bkpt_type_sw
1790 /* See mem-break.h. */
1793 hardware_breakpoint_inserted_here (CORE_ADDR addr
)
1795 struct process_info
*proc
= current_process ();
1796 struct raw_breakpoint
*bp
;
1798 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1799 if (bp
->raw_type
== raw_bkpt_type_hw
1807 /* See mem-break.h. */
1810 reinsert_breakpoint_inserted_here (CORE_ADDR addr
)
1812 struct process_info
*proc
= current_process ();
1813 struct breakpoint
*bp
;
1815 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1816 if (bp
->type
== reinsert_breakpoint
1817 && bp
->raw
->pc
== addr
1818 && bp
->raw
->inserted
)
1825 validate_inserted_breakpoint (struct raw_breakpoint
*bp
)
1830 gdb_assert (bp
->inserted
);
1831 gdb_assert (bp
->raw_type
== raw_bkpt_type_sw
);
1833 buf
= (unsigned char *) alloca (bp_size (bp
));
1834 err
= (*the_target
->read_memory
) (bp
->pc
, buf
, bp_size (bp
));
1835 if (err
|| memcmp (buf
, bp_opcode (bp
), bp_size (bp
)) != 0)
1837 /* Tag it as gone. */
1846 delete_disabled_breakpoints (void)
1848 struct process_info
*proc
= current_process ();
1849 struct breakpoint
*bp
, *next
;
1851 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= next
)
1854 if (bp
->raw
->inserted
< 0)
1856 /* If reinsert_breakpoints become disabled, that means the
1857 manipulations (insertion and removal) of them are wrong. */
1858 gdb_assert (bp
->type
!= reinsert_breakpoint
);
1859 delete_breakpoint_1 (proc
, bp
);
1864 /* Check if breakpoints we inserted still appear to be inserted. They
1865 may disappear due to a shared library unload, and worse, a new
1866 shared library may be reloaded at the same address as the
1867 previously unloaded one. If that happens, we should make sure that
1868 the shadow memory of the old breakpoints isn't used when reading or
1872 validate_breakpoints (void)
1874 struct process_info
*proc
= current_process ();
1875 struct breakpoint
*bp
;
1877 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1879 struct raw_breakpoint
*raw
= bp
->raw
;
1881 if (raw
->raw_type
== raw_bkpt_type_sw
&& raw
->inserted
> 0)
1882 validate_inserted_breakpoint (raw
);
1885 delete_disabled_breakpoints ();
1889 check_mem_read (CORE_ADDR mem_addr
, unsigned char *buf
, int mem_len
)
1891 struct process_info
*proc
= current_process ();
1892 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1893 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1894 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1895 int disabled_one
= 0;
1897 for (; jp
!= NULL
; jp
= jp
->next
)
1899 CORE_ADDR bp_end
= jp
->pc
+ jp
->length
;
1900 CORE_ADDR start
, end
;
1901 int copy_offset
, copy_len
, buf_offset
;
1903 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= buf
+ mem_len
1904 || buf
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1906 if (mem_addr
>= bp_end
)
1908 if (jp
->pc
>= mem_end
)
1912 if (mem_addr
> start
)
1919 copy_len
= end
- start
;
1920 copy_offset
= start
- jp
->pc
;
1921 buf_offset
= start
- mem_addr
;
1924 memcpy (buf
+ buf_offset
,
1925 fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1929 for (; bp
!= NULL
; bp
= bp
->next
)
1931 CORE_ADDR bp_end
= bp
->pc
+ bp_size (bp
);
1932 CORE_ADDR start
, end
;
1933 int copy_offset
, copy_len
, buf_offset
;
1935 if (bp
->raw_type
!= raw_bkpt_type_sw
)
1938 gdb_assert (bp
->old_data
>= buf
+ mem_len
1939 || buf
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1941 if (mem_addr
>= bp_end
)
1943 if (bp
->pc
>= mem_end
)
1947 if (mem_addr
> start
)
1954 copy_len
= end
- start
;
1955 copy_offset
= start
- bp
->pc
;
1956 buf_offset
= start
- mem_addr
;
1958 if (bp
->inserted
> 0)
1960 if (validate_inserted_breakpoint (bp
))
1961 memcpy (buf
+ buf_offset
, bp
->old_data
+ copy_offset
, copy_len
);
1968 delete_disabled_breakpoints ();
1972 check_mem_write (CORE_ADDR mem_addr
, unsigned char *buf
,
1973 const unsigned char *myaddr
, int mem_len
)
1975 struct process_info
*proc
= current_process ();
1976 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1977 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1978 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1979 int disabled_one
= 0;
1981 /* First fast tracepoint jumps, then breakpoint traps on top. */
1983 for (; jp
!= NULL
; jp
= jp
->next
)
1985 CORE_ADDR jp_end
= jp
->pc
+ jp
->length
;
1986 CORE_ADDR start
, end
;
1987 int copy_offset
, copy_len
, buf_offset
;
1989 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= myaddr
+ mem_len
1990 || myaddr
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1991 gdb_assert (fast_tracepoint_jump_insn (jp
) >= buf
+ mem_len
1992 || buf
>= fast_tracepoint_jump_insn (jp
) + (jp
)->length
);
1994 if (mem_addr
>= jp_end
)
1996 if (jp
->pc
>= mem_end
)
2000 if (mem_addr
> start
)
2007 copy_len
= end
- start
;
2008 copy_offset
= start
- jp
->pc
;
2009 buf_offset
= start
- mem_addr
;
2011 memcpy (fast_tracepoint_jump_shadow (jp
) + copy_offset
,
2012 myaddr
+ buf_offset
, copy_len
);
2014 memcpy (buf
+ buf_offset
,
2015 fast_tracepoint_jump_insn (jp
) + copy_offset
, copy_len
);
2018 for (; bp
!= NULL
; bp
= bp
->next
)
2020 CORE_ADDR bp_end
= bp
->pc
+ bp_size (bp
);
2021 CORE_ADDR start
, end
;
2022 int copy_offset
, copy_len
, buf_offset
;
2024 if (bp
->raw_type
!= raw_bkpt_type_sw
)
2027 gdb_assert (bp
->old_data
>= myaddr
+ mem_len
2028 || myaddr
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
2030 if (mem_addr
>= bp_end
)
2032 if (bp
->pc
>= mem_end
)
2036 if (mem_addr
> start
)
2043 copy_len
= end
- start
;
2044 copy_offset
= start
- bp
->pc
;
2045 buf_offset
= start
- mem_addr
;
2047 memcpy (bp
->old_data
+ copy_offset
, myaddr
+ buf_offset
, copy_len
);
2048 if (bp
->inserted
> 0)
2050 if (validate_inserted_breakpoint (bp
))
2051 memcpy (buf
+ buf_offset
, bp_opcode (bp
) + copy_offset
, copy_len
);
2058 delete_disabled_breakpoints ();
2061 /* Delete all breakpoints, and un-insert them from the inferior. */
2064 delete_all_breakpoints (void)
2066 struct process_info
*proc
= current_process ();
2068 while (proc
->breakpoints
)
2069 delete_breakpoint_1 (proc
, proc
->breakpoints
);
2072 /* Clear the "inserted" flag in all breakpoints. */
2075 mark_breakpoints_out (struct process_info
*proc
)
2077 struct raw_breakpoint
*raw_bp
;
2079 for (raw_bp
= proc
->raw_breakpoints
; raw_bp
!= NULL
; raw_bp
= raw_bp
->next
)
2080 raw_bp
->inserted
= 0;
2083 /* Release all breakpoints, but do not try to un-insert them from the
2087 free_all_breakpoints (struct process_info
*proc
)
2089 mark_breakpoints_out (proc
);
2091 /* Note: use PROC explicitly instead of deferring to
2092 delete_all_breakpoints --- CURRENT_INFERIOR may already have been
2093 released when we get here. There should be no call to
2094 current_process from here on. */
2095 while (proc
->breakpoints
)
2096 delete_breakpoint_1 (proc
, proc
->breakpoints
);
2099 /* Clone an agent expression. */
2101 static struct agent_expr
*
2102 clone_agent_expr (const struct agent_expr
*src_ax
)
2104 struct agent_expr
*ax
;
2106 ax
= XCNEW (struct agent_expr
);
2107 ax
->length
= src_ax
->length
;
2108 ax
->bytes
= (unsigned char *) xcalloc (ax
->length
, 1);
2109 memcpy (ax
->bytes
, src_ax
->bytes
, ax
->length
);
2113 /* Deep-copy the contents of one breakpoint to another. */
2115 static struct breakpoint
*
2116 clone_one_breakpoint (const struct breakpoint
*src
)
2118 struct breakpoint
*dest
;
2119 struct raw_breakpoint
*dest_raw
;
2121 /* Clone the raw breakpoint. */
2122 dest_raw
= XCNEW (struct raw_breakpoint
);
2123 dest_raw
->raw_type
= src
->raw
->raw_type
;
2124 dest_raw
->refcount
= src
->raw
->refcount
;
2125 dest_raw
->pc
= src
->raw
->pc
;
2126 dest_raw
->kind
= src
->raw
->kind
;
2127 memcpy (dest_raw
->old_data
, src
->raw
->old_data
, MAX_BREAKPOINT_LEN
);
2128 dest_raw
->inserted
= src
->raw
->inserted
;
2130 /* Clone the high-level breakpoint. */
2131 if (is_gdb_breakpoint (src
->type
))
2133 struct gdb_breakpoint
*gdb_dest
= XCNEW (struct gdb_breakpoint
);
2134 struct point_cond_list
*current_cond
;
2135 struct point_cond_list
*new_cond
;
2136 struct point_cond_list
*cond_tail
= NULL
;
2137 struct point_command_list
*current_cmd
;
2138 struct point_command_list
*new_cmd
;
2139 struct point_command_list
*cmd_tail
= NULL
;
2141 /* Clone the condition list. */
2142 for (current_cond
= ((struct gdb_breakpoint
*) src
)->cond_list
;
2143 current_cond
!= NULL
;
2144 current_cond
= current_cond
->next
)
2146 new_cond
= XCNEW (struct point_cond_list
);
2147 new_cond
->cond
= clone_agent_expr (current_cond
->cond
);
2148 APPEND_TO_LIST (&gdb_dest
->cond_list
, new_cond
, cond_tail
);
2151 /* Clone the command list. */
2152 for (current_cmd
= ((struct gdb_breakpoint
*) src
)->command_list
;
2153 current_cmd
!= NULL
;
2154 current_cmd
= current_cmd
->next
)
2156 new_cmd
= XCNEW (struct point_command_list
);
2157 new_cmd
->cmd
= clone_agent_expr (current_cmd
->cmd
);
2158 new_cmd
->persistence
= current_cmd
->persistence
;
2159 APPEND_TO_LIST (&gdb_dest
->command_list
, new_cmd
, cmd_tail
);
2162 dest
= (struct breakpoint
*) gdb_dest
;
2164 else if (src
->type
== other_breakpoint
)
2166 struct other_breakpoint
*other_dest
= XCNEW (struct other_breakpoint
);
2168 other_dest
->handler
= ((struct other_breakpoint
*) src
)->handler
;
2169 dest
= (struct breakpoint
*) other_dest
;
2171 else if (src
->type
== reinsert_breakpoint
)
2173 struct reinsert_breakpoint
*reinsert_dest
2174 = XCNEW (struct reinsert_breakpoint
);
2176 dest
= (struct breakpoint
*) reinsert_dest
;
2179 gdb_assert_not_reached ("unhandled breakpoint type");
2181 dest
->type
= src
->type
;
2182 dest
->raw
= dest_raw
;
2187 /* See mem-break.h. */
2190 clone_all_breakpoints (struct thread_info
*child_thread
,
2191 const struct thread_info
*parent_thread
)
2193 const struct breakpoint
*bp
;
2194 struct breakpoint
*new_bkpt
;
2195 struct breakpoint
*bkpt_tail
= NULL
;
2196 struct raw_breakpoint
*raw_bkpt_tail
= NULL
;
2197 struct process_info
*child_proc
= get_thread_process (child_thread
);
2198 struct process_info
*parent_proc
= get_thread_process (parent_thread
);
2199 struct breakpoint
**new_list
= &child_proc
->breakpoints
;
2200 struct raw_breakpoint
**new_raw_list
= &child_proc
->raw_breakpoints
;
2202 for (bp
= parent_proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
2204 new_bkpt
= clone_one_breakpoint (bp
);
2205 APPEND_TO_LIST (new_list
, new_bkpt
, bkpt_tail
);
2206 APPEND_TO_LIST (new_raw_list
, new_bkpt
->raw
, raw_bkpt_tail
);