1 /* Memory breakpoint operations for the remote server for GDB.
2 Copyright (C) 2002-2003, 2005, 2007-2012 Free Software Foundation,
5 Contributed by MontaVista Software.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 const unsigned char *breakpoint_data
;
29 #define MAX_BREAKPOINT_LEN 8
31 /* GDB will never try to install multiple breakpoints at the same
32 address. But, we need to keep track of internal breakpoints too,
33 and so we do need to be able to install multiple breakpoints at the
34 same address transparently. We keep track of two different, and
35 closely related structures. A raw breakpoint, which manages the
36 low level, close to the metal aspect of a breakpoint. It holds the
37 breakpoint address, and a buffer holding a copy of the instructions
38 that would be in memory had not been a breakpoint there (we call
39 that the shadow memory of the breakpoint). We occasionally need to
40 temporarilly uninsert a breakpoint without the client knowing about
41 it (e.g., to step over an internal breakpoint), so we keep an
42 `inserted' state associated with this low level breakpoint
43 structure. There can only be one such object for a given address.
44 Then, we have (a bit higher level) breakpoints. This structure
45 holds a callback to be called whenever a breakpoint is hit, a
46 high-level type, and a link to a low level raw breakpoint. There
47 can be many high-level breakpoints at the same address, and all of
48 them will point to the same raw breakpoint, which is reference
51 /* The low level, physical, raw breakpoint. */
54 struct raw_breakpoint
*next
;
56 /* A reference count. Each high level breakpoint referencing this
57 raw breakpoint accounts for one reference. */
60 /* The breakpoint's insertion address. There can only be one raw
61 breakpoint for a given PC. */
64 /* The breakpoint's shadow memory. */
65 unsigned char old_data
[MAX_BREAKPOINT_LEN
];
67 /* Non-zero if this breakpoint is currently inserted in the
71 /* Non-zero if this breakpoint is currently disabled because we no
72 longer detect it as inserted. */
76 /* The type of a breakpoint. */
79 /* A GDB breakpoint, requested with a Z0 packet. */
82 /* A basic-software-single-step breakpoint. */
85 /* Any other breakpoint type that doesn't require specific
86 treatment goes here. E.g., an event breakpoint. */
90 struct point_cond_list
92 /* Pointer to the agent expression that is the breakpoint's
94 struct agent_expr
*cond
;
96 /* Pointer to the next condition. */
97 struct point_cond_list
*next
;
100 /* A high level (in gdbserver's perspective) breakpoint. */
103 struct breakpoint
*next
;
105 /* The breakpoint's type. */
108 /* Pointer to the condition list that should be evaluated on
109 the target or NULL if the breakpoint is unconditional or
110 if GDB doesn't want us to evaluate the conditionals on the
112 struct point_cond_list
*cond_list
;
114 /* Link to this breakpoint's raw breakpoint. This is always
116 struct raw_breakpoint
*raw
;
118 /* Function to call when we hit this breakpoint. If it returns 1,
119 the breakpoint shall be deleted; 0 or if this callback is NULL,
120 it will be left inserted. */
121 int (*handler
) (CORE_ADDR
);
124 static struct raw_breakpoint
*
125 find_raw_breakpoint_at (CORE_ADDR where
)
127 struct process_info
*proc
= current_process ();
128 struct raw_breakpoint
*bp
;
130 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
137 static struct raw_breakpoint
*
138 set_raw_breakpoint_at (CORE_ADDR where
)
140 struct process_info
*proc
= current_process ();
141 struct raw_breakpoint
*bp
;
143 unsigned char buf
[MAX_BREAKPOINT_LEN
];
145 if (breakpoint_data
== NULL
)
146 error ("Target does not support breakpoints.");
148 bp
= find_raw_breakpoint_at (where
);
155 bp
= xcalloc (1, sizeof (*bp
));
159 /* Note that there can be fast tracepoint jumps installed in the
160 same memory range, so to get at the original memory, we need to
161 use read_inferior_memory, which masks those out. */
162 err
= read_inferior_memory (where
, buf
, breakpoint_len
);
167 "Failed to read shadow memory of"
168 " breakpoint at 0x%s (%s).\n",
169 paddress (where
), strerror (err
));
173 memcpy (bp
->old_data
, buf
, breakpoint_len
);
175 err
= (*the_target
->write_memory
) (where
, breakpoint_data
,
181 "Failed to insert breakpoint at 0x%s (%s).\n",
182 paddress (where
), strerror (err
));
187 /* Link the breakpoint in. */
189 bp
->next
= proc
->raw_breakpoints
;
190 proc
->raw_breakpoints
= bp
;
194 /* Notice that breakpoint traps are always installed on top of fast
195 tracepoint jumps. This is even if the fast tracepoint is installed
196 at a later time compared to when the breakpoint was installed.
197 This means that a stopping breakpoint or tracepoint has higher
198 "priority". In turn, this allows having fast and slow tracepoints
199 (and breakpoints) at the same address behave correctly. */
202 /* A fast tracepoint jump. */
204 struct fast_tracepoint_jump
206 struct fast_tracepoint_jump
*next
;
208 /* A reference count. GDB can install more than one fast tracepoint
209 at the same address (each with its own action list, for
213 /* The fast tracepoint's insertion address. There can only be one
214 of these for a given PC. */
217 /* Non-zero if this fast tracepoint jump is currently inserted in
221 /* The length of the jump instruction. */
224 /* A poor-man's flexible array member, holding both the jump
225 instruction to insert, and a copy of the instruction that would
226 be in memory had not been a jump there (the shadow memory of the
228 unsigned char insn_and_shadow
[0];
231 /* Fast tracepoint FP's jump instruction to insert. */
232 #define fast_tracepoint_jump_insn(fp) \
233 ((fp)->insn_and_shadow + 0)
235 /* The shadow memory of fast tracepoint jump FP. */
236 #define fast_tracepoint_jump_shadow(fp) \
237 ((fp)->insn_and_shadow + (fp)->length)
240 /* Return the fast tracepoint jump set at WHERE. */
242 static struct fast_tracepoint_jump
*
243 find_fast_tracepoint_jump_at (CORE_ADDR where
)
245 struct process_info
*proc
= current_process ();
246 struct fast_tracepoint_jump
*jp
;
248 for (jp
= proc
->fast_tracepoint_jumps
; jp
!= NULL
; jp
= jp
->next
)
256 fast_tracepoint_jump_here (CORE_ADDR where
)
258 struct fast_tracepoint_jump
*jp
= find_fast_tracepoint_jump_at (where
);
264 delete_fast_tracepoint_jump (struct fast_tracepoint_jump
*todel
)
266 struct fast_tracepoint_jump
*bp
, **bp_link
;
268 struct process_info
*proc
= current_process ();
270 bp
= proc
->fast_tracepoint_jumps
;
271 bp_link
= &proc
->fast_tracepoint_jumps
;
277 if (--bp
->refcount
== 0)
279 struct fast_tracepoint_jump
*prev_bp_link
= *bp_link
;
285 /* Since there can be breakpoints inserted in the same
286 address range, we use `write_inferior_memory', which
287 takes care of layering breakpoints on top of fast
288 tracepoints, and on top of the buffer we pass it.
289 This works because we've already unlinked the fast
290 tracepoint jump above. Also note that we need to
291 pass the current shadow contents, because
292 write_inferior_memory updates any shadow memory with
293 what we pass here, and we want that to be a nop. */
294 buf
= alloca (bp
->length
);
295 memcpy (buf
, fast_tracepoint_jump_shadow (bp
), bp
->length
);
296 ret
= write_inferior_memory (bp
->pc
, buf
, bp
->length
);
299 /* Something went wrong, relink the jump. */
300 *bp_link
= prev_bp_link
;
304 "Failed to uninsert fast tracepoint jump "
305 "at 0x%s (%s) while deleting it.\n",
306 paddress (bp
->pc
), strerror (ret
));
322 warning ("Could not find fast tracepoint jump in list.");
327 inc_ref_fast_tracepoint_jump (struct fast_tracepoint_jump
*jp
)
332 struct fast_tracepoint_jump
*
333 set_fast_tracepoint_jump (CORE_ADDR where
,
334 unsigned char *insn
, ULONGEST length
)
336 struct process_info
*proc
= current_process ();
337 struct fast_tracepoint_jump
*jp
;
341 /* We refcount fast tracepoint jumps. Check if we already know
342 about a jump at this address. */
343 jp
= find_fast_tracepoint_jump_at (where
);
350 /* We don't, so create a new object. Double the length, because the
351 flexible array member holds both the jump insn, and the
353 jp
= xcalloc (1, sizeof (*jp
) + (length
* 2));
356 memcpy (fast_tracepoint_jump_insn (jp
), insn
, length
);
358 buf
= alloca (length
);
360 /* Note that there can be trap breakpoints inserted in the same
361 address range. To access the original memory contents, we use
362 `read_inferior_memory', which masks out breakpoints. */
363 err
= read_inferior_memory (where
, buf
, length
);
368 "Failed to read shadow memory of"
369 " fast tracepoint at 0x%s (%s).\n",
370 paddress (where
), strerror (err
));
374 memcpy (fast_tracepoint_jump_shadow (jp
), buf
, length
);
376 /* Link the jump in. */
378 jp
->next
= proc
->fast_tracepoint_jumps
;
379 proc
->fast_tracepoint_jumps
= jp
;
381 /* Since there can be trap breakpoints inserted in the same address
382 range, we use use `write_inferior_memory', which takes care of
383 layering breakpoints on top of fast tracepoints, on top of the
384 buffer we pass it. This works because we've already linked in
385 the fast tracepoint jump above. Also note that we need to pass
386 the current shadow contents, because write_inferior_memory
387 updates any shadow memory with what we pass here, and we want
389 err
= write_inferior_memory (where
, buf
, length
);
394 "Failed to insert fast tracepoint jump at 0x%s (%s).\n",
395 paddress (where
), strerror (err
));
398 proc
->fast_tracepoint_jumps
= jp
->next
;
408 uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc
)
410 struct fast_tracepoint_jump
*jp
;
413 jp
= find_fast_tracepoint_jump_at (pc
);
416 /* This can happen when we remove all breakpoints while handling
420 "Could not find fast tracepoint jump at 0x%s "
421 "in list (uninserting).\n",
432 /* Since there can be trap breakpoints inserted in the same
433 address range, we use use `write_inferior_memory', which
434 takes care of layering breakpoints on top of fast
435 tracepoints, and on top of the buffer we pass it. This works
436 because we've already marked the fast tracepoint fast
437 tracepoint jump uninserted above. Also note that we need to
438 pass the current shadow contents, because
439 write_inferior_memory updates any shadow memory with what we
440 pass here, and we want that to be a nop. */
441 buf
= alloca (jp
->length
);
442 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
443 err
= write_inferior_memory (jp
->pc
, buf
, jp
->length
);
450 "Failed to uninsert fast tracepoint jump at 0x%s (%s).\n",
451 paddress (pc
), strerror (err
));
457 reinsert_fast_tracepoint_jumps_at (CORE_ADDR where
)
459 struct fast_tracepoint_jump
*jp
;
463 jp
= find_fast_tracepoint_jump_at (where
);
466 /* This can happen when we remove breakpoints when a tracepoint
467 hit causes a tracing stop, while handling a step-over. */
470 "Could not find fast tracepoint jump at 0x%s "
471 "in list (reinserting).\n",
477 error ("Jump already inserted at reinsert time.");
481 /* Since there can be trap breakpoints inserted in the same address
482 range, we use `write_inferior_memory', which takes care of
483 layering breakpoints on top of fast tracepoints, and on top of
484 the buffer we pass it. This works because we've already marked
485 the fast tracepoint jump inserted above. Also note that we need
486 to pass the current shadow contents, because
487 write_inferior_memory updates any shadow memory with what we pass
488 here, and we want that to be a nop. */
489 buf
= alloca (jp
->length
);
490 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
491 err
= write_inferior_memory (where
, buf
, jp
->length
);
498 "Failed to reinsert fast tracepoint jump at 0x%s (%s).\n",
499 paddress (where
), strerror (err
));
504 set_breakpoint_at (CORE_ADDR where
, int (*handler
) (CORE_ADDR
))
506 struct process_info
*proc
= current_process ();
507 struct breakpoint
*bp
;
508 struct raw_breakpoint
*raw
;
510 raw
= set_raw_breakpoint_at (where
);
518 bp
= xcalloc (1, sizeof (struct breakpoint
));
519 bp
->type
= other_breakpoint
;
522 bp
->handler
= handler
;
524 bp
->next
= proc
->breakpoints
;
525 proc
->breakpoints
= bp
;
531 delete_raw_breakpoint (struct process_info
*proc
, struct raw_breakpoint
*todel
)
533 struct raw_breakpoint
*bp
, **bp_link
;
536 bp
= proc
->raw_breakpoints
;
537 bp_link
= &proc
->raw_breakpoints
;
545 struct raw_breakpoint
*prev_bp_link
= *bp_link
;
546 unsigned char buf
[MAX_BREAKPOINT_LEN
];
550 /* Since there can be trap breakpoints inserted in the
551 same address range, we use `write_inferior_memory',
552 which takes care of layering breakpoints on top of
553 fast tracepoints, and on top of the buffer we pass
554 it. This works because we've already unlinked the
555 fast tracepoint jump above. Also note that we need
556 to pass the current shadow contents, because
557 write_inferior_memory updates any shadow memory with
558 what we pass here, and we want that to be a nop. */
559 memcpy (buf
, bp
->old_data
, breakpoint_len
);
560 ret
= write_inferior_memory (bp
->pc
, buf
, breakpoint_len
);
563 /* Something went wrong, relink the breakpoint. */
564 *bp_link
= prev_bp_link
;
568 "Failed to uninsert raw breakpoint "
569 "at 0x%s (%s) while deleting it.\n",
570 paddress (bp
->pc
), strerror (ret
));
588 warning ("Could not find raw breakpoint in list.");
593 release_breakpoint (struct process_info
*proc
, struct breakpoint
*bp
)
598 newrefcount
= bp
->raw
->refcount
- 1;
599 if (newrefcount
== 0)
601 ret
= delete_raw_breakpoint (proc
, bp
->raw
);
606 bp
->raw
->refcount
= newrefcount
;
614 delete_breakpoint_1 (struct process_info
*proc
, struct breakpoint
*todel
)
616 struct breakpoint
*bp
, **bp_link
;
619 bp
= proc
->breakpoints
;
620 bp_link
= &proc
->breakpoints
;
628 err
= release_breakpoint (proc
, bp
);
642 warning ("Could not find breakpoint in list.");
647 delete_breakpoint (struct breakpoint
*todel
)
649 struct process_info
*proc
= current_process ();
650 return delete_breakpoint_1 (proc
, todel
);
654 find_gdb_breakpoint_at (CORE_ADDR where
)
656 struct process_info
*proc
= current_process ();
657 struct breakpoint
*bp
;
659 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
660 if (bp
->type
== gdb_breakpoint
&& bp
->raw
->pc
== where
)
667 set_gdb_breakpoint_at (CORE_ADDR where
)
669 struct breakpoint
*bp
;
671 if (breakpoint_data
== NULL
)
674 /* If we see GDB inserting a second breakpoint at the same address,
675 then the first breakpoint must have disappeared due to a shared
676 library unload. On targets where the shared libraries are
677 handled by userspace, like SVR4, for example, GDBserver can't
678 tell if a library was loaded or unloaded. Since we refcount
679 breakpoints, if we didn't do this, we'd just increase the
680 refcount of the previous breakpoint at this address, but the trap
681 was not planted in the inferior anymore, thus the breakpoint
682 would never be hit. */
683 bp
= find_gdb_breakpoint_at (where
);
686 delete_gdb_breakpoint_at (where
);
688 /* Might as well validate all other breakpoints. */
689 validate_breakpoints ();
692 bp
= set_breakpoint_at (where
, NULL
);
696 bp
->type
= gdb_breakpoint
;
701 delete_gdb_breakpoint_at (CORE_ADDR addr
)
703 struct breakpoint
*bp
;
706 if (breakpoint_data
== NULL
)
709 bp
= find_gdb_breakpoint_at (addr
);
713 /* Before deleting the breakpoint, make sure to free
714 its condition list. */
715 clear_gdb_breakpoint_conditions (addr
);
716 err
= delete_breakpoint (bp
);
723 /* Clear all conditions associated with this breakpoint address. */
726 clear_gdb_breakpoint_conditions (CORE_ADDR addr
)
728 struct breakpoint
*bp
= find_gdb_breakpoint_at (addr
);
729 struct point_cond_list
*cond
;
731 if (bp
== NULL
|| bp
->cond_list
== NULL
)
734 cond
= bp
->cond_list
;
738 struct point_cond_list
*cond_next
;
740 cond_next
= cond
->next
;
741 free (cond
->cond
->bytes
);
747 bp
->cond_list
= NULL
;
750 /* Add condition CONDITION to GDBserver's breakpoint BP. */
753 add_condition_to_breakpoint (struct breakpoint
*bp
,
754 struct agent_expr
*condition
)
756 struct point_cond_list
*new_cond
;
758 /* Create new condition. */
759 new_cond
= xcalloc (1, sizeof (*new_cond
));
760 new_cond
->cond
= condition
;
762 /* Add condition to the list. */
763 new_cond
->next
= bp
->cond_list
;
764 bp
->cond_list
= new_cond
;
767 /* Add a target-side condition CONDITION to the breakpoint at ADDR. */
770 add_breakpoint_condition (CORE_ADDR addr
, char **condition
)
772 struct breakpoint
*bp
= find_gdb_breakpoint_at (addr
);
773 char *actparm
= *condition
;
774 struct agent_expr
*cond
;
779 if (condition
== NULL
)
782 cond
= gdb_parse_agent_expr (&actparm
);
786 fprintf (stderr
, "Condition evaluation failed. "
787 "Assuming unconditional.\n");
791 add_condition_to_breakpoint (bp
, cond
);
793 *condition
= actparm
;
798 /* Evaluate condition (if any) at breakpoint BP. Return 1 if
799 true and 0 otherwise. */
802 gdb_condition_true_at_breakpoint (CORE_ADDR where
)
804 /* Fetch registers for the current inferior. */
805 struct breakpoint
*bp
= find_gdb_breakpoint_at (where
);
807 struct point_cond_list
*cl
;
810 struct regcache
*regcache
= get_thread_regcache (current_inferior
, 1);
815 /* Check if the breakpoint is unconditional. If it is,
816 the condition always evaluates to TRUE. */
817 if (bp
->cond_list
== NULL
)
820 /* Evaluate each condition in the breakpoint's list of conditions.
821 Return true if any of the conditions evaluates to TRUE.
823 If we failed to evaluate the expression, TRUE is returned. This
824 forces GDB to reevaluate the conditions. */
825 for (cl
= bp
->cond_list
;
826 cl
&& !value
&& !err
; cl
= cl
->next
)
828 /* Evaluate the condition. */
829 err
= gdb_eval_agent_expr (regcache
, NULL
, cl
->cond
, &value
);
838 /* Return 1 if there is a breakpoint inserted in address WHERE
839 and if its condition, if it exists, is true. */
842 gdb_breakpoint_here (CORE_ADDR where
)
844 return (find_gdb_breakpoint_at (where
) != NULL
);
848 set_reinsert_breakpoint (CORE_ADDR stop_at
)
850 struct breakpoint
*bp
;
852 bp
= set_breakpoint_at (stop_at
, NULL
);
853 bp
->type
= reinsert_breakpoint
;
857 delete_reinsert_breakpoints (void)
859 struct process_info
*proc
= current_process ();
860 struct breakpoint
*bp
, **bp_link
;
862 bp
= proc
->breakpoints
;
863 bp_link
= &proc
->breakpoints
;
867 if (bp
->type
== reinsert_breakpoint
)
870 release_breakpoint (proc
, bp
);
882 uninsert_raw_breakpoint (struct raw_breakpoint
*bp
)
887 unsigned char buf
[MAX_BREAKPOINT_LEN
];
890 /* Since there can be fast tracepoint jumps inserted in the same
891 address range, we use `write_inferior_memory', which takes
892 care of layering breakpoints on top of fast tracepoints, and
893 on top of the buffer we pass it. This works because we've
894 already unlinked the fast tracepoint jump above. Also note
895 that we need to pass the current shadow contents, because
896 write_inferior_memory updates any shadow memory with what we
897 pass here, and we want that to be a nop. */
898 memcpy (buf
, bp
->old_data
, breakpoint_len
);
899 err
= write_inferior_memory (bp
->pc
, buf
, breakpoint_len
);
906 "Failed to uninsert raw breakpoint at 0x%s (%s).\n",
907 paddress (bp
->pc
), strerror (err
));
913 uninsert_breakpoints_at (CORE_ADDR pc
)
915 struct raw_breakpoint
*bp
;
917 bp
= find_raw_breakpoint_at (pc
);
920 /* This can happen when we remove all breakpoints while handling
924 "Could not find breakpoint at 0x%s "
925 "in list (uninserting).\n",
931 uninsert_raw_breakpoint (bp
);
935 uninsert_all_breakpoints (void)
937 struct process_info
*proc
= current_process ();
938 struct raw_breakpoint
*bp
;
940 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
942 uninsert_raw_breakpoint (bp
);
946 reinsert_raw_breakpoint (struct raw_breakpoint
*bp
)
951 error ("Breakpoint already inserted at reinsert time.");
953 err
= (*the_target
->write_memory
) (bp
->pc
, breakpoint_data
,
957 else if (debug_threads
)
959 "Failed to reinsert breakpoint at 0x%s (%s).\n",
960 paddress (bp
->pc
), strerror (err
));
964 reinsert_breakpoints_at (CORE_ADDR pc
)
966 struct raw_breakpoint
*bp
;
968 bp
= find_raw_breakpoint_at (pc
);
971 /* This can happen when we remove all breakpoints while handling
975 "Could not find raw breakpoint at 0x%s "
976 "in list (reinserting).\n",
981 reinsert_raw_breakpoint (bp
);
985 reinsert_all_breakpoints (void)
987 struct process_info
*proc
= current_process ();
988 struct raw_breakpoint
*bp
;
990 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
992 reinsert_raw_breakpoint (bp
);
996 check_breakpoints (CORE_ADDR stop_pc
)
998 struct process_info
*proc
= current_process ();
999 struct breakpoint
*bp
, **bp_link
;
1001 bp
= proc
->breakpoints
;
1002 bp_link
= &proc
->breakpoints
;
1006 if (bp
->raw
->pc
== stop_pc
)
1008 if (!bp
->raw
->inserted
)
1010 warning ("Hit a removed breakpoint?");
1014 if (bp
->handler
!= NULL
&& (*bp
->handler
) (stop_pc
))
1016 *bp_link
= bp
->next
;
1018 release_breakpoint (proc
, bp
);
1025 bp_link
= &bp
->next
;
1031 set_breakpoint_data (const unsigned char *bp_data
, int bp_len
)
1033 breakpoint_data
= bp_data
;
1034 breakpoint_len
= bp_len
;
1038 breakpoint_here (CORE_ADDR addr
)
1040 return (find_raw_breakpoint_at (addr
) != NULL
);
1044 breakpoint_inserted_here (CORE_ADDR addr
)
1046 struct raw_breakpoint
*bp
;
1048 bp
= find_raw_breakpoint_at (addr
);
1050 return (bp
!= NULL
&& bp
->inserted
);
1054 validate_inserted_breakpoint (struct raw_breakpoint
*bp
)
1059 gdb_assert (bp
->inserted
);
1061 buf
= alloca (breakpoint_len
);
1062 err
= (*the_target
->read_memory
) (bp
->pc
, buf
, breakpoint_len
);
1063 if (err
|| memcmp (buf
, breakpoint_data
, breakpoint_len
) != 0)
1065 /* Tag it as gone. */
1067 bp
->shlib_disabled
= 1;
1075 delete_disabled_breakpoints (void)
1077 struct process_info
*proc
= current_process ();
1078 struct breakpoint
*bp
, *next
;
1080 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= next
)
1083 if (bp
->raw
->shlib_disabled
)
1084 delete_breakpoint_1 (proc
, bp
);
1088 /* Check if breakpoints we inserted still appear to be inserted. They
1089 may disappear due to a shared library unload, and worse, a new
1090 shared library may be reloaded at the same address as the
1091 previously unloaded one. If that happens, we should make sure that
1092 the shadow memory of the old breakpoints isn't used when reading or
1096 validate_breakpoints (void)
1098 struct process_info
*proc
= current_process ();
1099 struct breakpoint
*bp
;
1101 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1103 if (bp
->raw
->inserted
)
1104 validate_inserted_breakpoint (bp
->raw
);
1107 delete_disabled_breakpoints ();
1111 check_mem_read (CORE_ADDR mem_addr
, unsigned char *buf
, int mem_len
)
1113 struct process_info
*proc
= current_process ();
1114 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1115 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1116 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1117 int disabled_one
= 0;
1119 for (; jp
!= NULL
; jp
= jp
->next
)
1121 CORE_ADDR bp_end
= jp
->pc
+ jp
->length
;
1122 CORE_ADDR start
, end
;
1123 int copy_offset
, copy_len
, buf_offset
;
1125 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= buf
+ mem_len
1126 || buf
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1128 if (mem_addr
>= bp_end
)
1130 if (jp
->pc
>= mem_end
)
1134 if (mem_addr
> start
)
1141 copy_len
= end
- start
;
1142 copy_offset
= start
- jp
->pc
;
1143 buf_offset
= start
- mem_addr
;
1146 memcpy (buf
+ buf_offset
,
1147 fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1151 for (; bp
!= NULL
; bp
= bp
->next
)
1153 CORE_ADDR bp_end
= bp
->pc
+ breakpoint_len
;
1154 CORE_ADDR start
, end
;
1155 int copy_offset
, copy_len
, buf_offset
;
1157 gdb_assert (bp
->old_data
>= buf
+ mem_len
1158 || buf
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1160 if (mem_addr
>= bp_end
)
1162 if (bp
->pc
>= mem_end
)
1166 if (mem_addr
> start
)
1173 copy_len
= end
- start
;
1174 copy_offset
= start
- bp
->pc
;
1175 buf_offset
= start
- mem_addr
;
1179 if (validate_inserted_breakpoint (bp
))
1180 memcpy (buf
+ buf_offset
, bp
->old_data
+ copy_offset
, copy_len
);
1187 delete_disabled_breakpoints ();
1191 check_mem_write (CORE_ADDR mem_addr
, unsigned char *buf
,
1192 const unsigned char *myaddr
, int mem_len
)
1194 struct process_info
*proc
= current_process ();
1195 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1196 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1197 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1198 int disabled_one
= 0;
1200 /* First fast tracepoint jumps, then breakpoint traps on top. */
1202 for (; jp
!= NULL
; jp
= jp
->next
)
1204 CORE_ADDR jp_end
= jp
->pc
+ jp
->length
;
1205 CORE_ADDR start
, end
;
1206 int copy_offset
, copy_len
, buf_offset
;
1208 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= myaddr
+ mem_len
1209 || myaddr
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1210 gdb_assert (fast_tracepoint_jump_insn (jp
) >= buf
+ mem_len
1211 || buf
>= fast_tracepoint_jump_insn (jp
) + (jp
)->length
);
1213 if (mem_addr
>= jp_end
)
1215 if (jp
->pc
>= mem_end
)
1219 if (mem_addr
> start
)
1226 copy_len
= end
- start
;
1227 copy_offset
= start
- jp
->pc
;
1228 buf_offset
= start
- mem_addr
;
1230 memcpy (fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1231 myaddr
+ buf_offset
, copy_len
);
1233 memcpy (buf
+ buf_offset
,
1234 fast_tracepoint_jump_insn (jp
) + copy_offset
, copy_len
);
1237 for (; bp
!= NULL
; bp
= bp
->next
)
1239 CORE_ADDR bp_end
= bp
->pc
+ breakpoint_len
;
1240 CORE_ADDR start
, end
;
1241 int copy_offset
, copy_len
, buf_offset
;
1243 gdb_assert (bp
->old_data
>= myaddr
+ mem_len
1244 || myaddr
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1246 if (mem_addr
>= bp_end
)
1248 if (bp
->pc
>= mem_end
)
1252 if (mem_addr
> start
)
1259 copy_len
= end
- start
;
1260 copy_offset
= start
- bp
->pc
;
1261 buf_offset
= start
- mem_addr
;
1263 memcpy (bp
->old_data
+ copy_offset
, myaddr
+ buf_offset
, copy_len
);
1266 if (validate_inserted_breakpoint (bp
))
1267 memcpy (buf
+ buf_offset
, breakpoint_data
+ copy_offset
, copy_len
);
1274 delete_disabled_breakpoints ();
1277 /* Delete all breakpoints, and un-insert them from the inferior. */
1280 delete_all_breakpoints (void)
1282 struct process_info
*proc
= current_process ();
1284 while (proc
->breakpoints
)
1285 delete_breakpoint_1 (proc
, proc
->breakpoints
);
1288 /* Clear the "inserted" flag in all breakpoints. */
1291 mark_breakpoints_out (struct process_info
*proc
)
1293 struct raw_breakpoint
*raw_bp
;
1295 for (raw_bp
= proc
->raw_breakpoints
; raw_bp
!= NULL
; raw_bp
= raw_bp
->next
)
1296 raw_bp
->inserted
= 0;
1299 /* Release all breakpoints, but do not try to un-insert them from the
1303 free_all_breakpoints (struct process_info
*proc
)
1305 mark_breakpoints_out (proc
);
1307 /* Note: use PROC explicitly instead of deferring to
1308 delete_all_breakpoints --- CURRENT_INFERIOR may already have been
1309 released when we get here. There should be no call to
1310 current_process from here on. */
1311 while (proc
->breakpoints
)
1312 delete_breakpoint_1 (proc
, proc
->breakpoints
);
This page took 0.141699 seconds and 4 git commands to generate.