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/>. */
27 const unsigned char *breakpoint_data
;
30 #define MAX_BREAKPOINT_LEN 8
32 /* GDB will never try to install multiple breakpoints at the same
33 address. But, we need to keep track of internal breakpoints too,
34 and so we do need to be able to install multiple breakpoints at the
35 same address transparently. We keep track of two different, and
36 closely related structures. A raw breakpoint, which manages the
37 low level, close to the metal aspect of a breakpoint. It holds the
38 breakpoint address, and a buffer holding a copy of the instructions
39 that would be in memory had not been a breakpoint there (we call
40 that the shadow memory of the breakpoint). We occasionally need to
41 temporarilly uninsert a breakpoint without the client knowing about
42 it (e.g., to step over an internal breakpoint), so we keep an
43 `inserted' state associated with this low level breakpoint
44 structure. There can only be one such object for a given address.
45 Then, we have (a bit higher level) breakpoints. This structure
46 holds a callback to be called whenever a breakpoint is hit, a
47 high-level type, and a link to a low level raw breakpoint. There
48 can be many high-level breakpoints at the same address, and all of
49 them will point to the same raw breakpoint, which is reference
52 /* The low level, physical, raw breakpoint. */
55 struct raw_breakpoint
*next
;
57 /* A reference count. Each high level breakpoint referencing this
58 raw breakpoint accounts for one reference. */
61 /* The breakpoint's insertion address. There can only be one raw
62 breakpoint for a given PC. */
65 /* The breakpoint's shadow memory. */
66 unsigned char old_data
[MAX_BREAKPOINT_LEN
];
68 /* Non-zero if this breakpoint is currently inserted in the
72 /* Non-zero if this breakpoint is currently disabled because we no
73 longer detect it as inserted. */
77 /* The type of a breakpoint. */
80 /* A GDB breakpoint, requested with a Z0 packet. */
83 /* A basic-software-single-step breakpoint. */
86 /* Any other breakpoint type that doesn't require specific
87 treatment goes here. E.g., an event breakpoint. */
91 struct point_cond_list
93 /* Pointer to the agent expression that is the breakpoint's
95 struct agent_expr
*cond
;
97 /* Pointer to the next condition. */
98 struct point_cond_list
*next
;
101 struct point_command_list
103 /* Pointer to the agent expression that is the breakpoint's
105 struct agent_expr
*cmd
;
107 /* Flag that is true if this command should run even while GDB is
111 /* Pointer to the next command. */
112 struct point_command_list
*next
;
115 /* A high level (in gdbserver's perspective) breakpoint. */
118 struct breakpoint
*next
;
120 /* The breakpoint's type. */
123 /* Pointer to the condition list that should be evaluated on
124 the target or NULL if the breakpoint is unconditional or
125 if GDB doesn't want us to evaluate the conditionals on the
127 struct point_cond_list
*cond_list
;
129 /* Point to the list of commands to run when this is hit. */
130 struct point_command_list
*command_list
;
132 /* Link to this breakpoint's raw breakpoint. This is always
134 struct raw_breakpoint
*raw
;
136 /* Function to call when we hit this breakpoint. If it returns 1,
137 the breakpoint shall be deleted; 0 or if this callback is NULL,
138 it will be left inserted. */
139 int (*handler
) (CORE_ADDR
);
143 any_persistent_commands ()
145 struct process_info
*proc
= current_process ();
146 struct breakpoint
*bp
;
147 struct point_command_list
*cl
;
149 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
151 for (cl
= bp
->command_list
; cl
!= NULL
; cl
= cl
->next
)
159 static struct raw_breakpoint
*
160 find_raw_breakpoint_at (CORE_ADDR where
)
162 struct process_info
*proc
= current_process ();
163 struct raw_breakpoint
*bp
;
165 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
172 static struct raw_breakpoint
*
173 set_raw_breakpoint_at (CORE_ADDR where
)
175 struct process_info
*proc
= current_process ();
176 struct raw_breakpoint
*bp
;
178 unsigned char buf
[MAX_BREAKPOINT_LEN
];
180 if (breakpoint_data
== NULL
)
181 error ("Target does not support breakpoints.");
183 bp
= find_raw_breakpoint_at (where
);
190 bp
= xcalloc (1, sizeof (*bp
));
194 /* Note that there can be fast tracepoint jumps installed in the
195 same memory range, so to get at the original memory, we need to
196 use read_inferior_memory, which masks those out. */
197 err
= read_inferior_memory (where
, buf
, breakpoint_len
);
202 "Failed to read shadow memory of"
203 " breakpoint at 0x%s (%s).\n",
204 paddress (where
), strerror (err
));
208 memcpy (bp
->old_data
, buf
, breakpoint_len
);
210 err
= (*the_target
->write_memory
) (where
, breakpoint_data
,
216 "Failed to insert breakpoint at 0x%s (%s).\n",
217 paddress (where
), strerror (err
));
222 /* Link the breakpoint in. */
224 bp
->next
= proc
->raw_breakpoints
;
225 proc
->raw_breakpoints
= bp
;
229 /* Notice that breakpoint traps are always installed on top of fast
230 tracepoint jumps. This is even if the fast tracepoint is installed
231 at a later time compared to when the breakpoint was installed.
232 This means that a stopping breakpoint or tracepoint has higher
233 "priority". In turn, this allows having fast and slow tracepoints
234 (and breakpoints) at the same address behave correctly. */
237 /* A fast tracepoint jump. */
239 struct fast_tracepoint_jump
241 struct fast_tracepoint_jump
*next
;
243 /* A reference count. GDB can install more than one fast tracepoint
244 at the same address (each with its own action list, for
248 /* The fast tracepoint's insertion address. There can only be one
249 of these for a given PC. */
252 /* Non-zero if this fast tracepoint jump is currently inserted in
256 /* The length of the jump instruction. */
259 /* A poor-man's flexible array member, holding both the jump
260 instruction to insert, and a copy of the instruction that would
261 be in memory had not been a jump there (the shadow memory of the
263 unsigned char insn_and_shadow
[0];
266 /* Fast tracepoint FP's jump instruction to insert. */
267 #define fast_tracepoint_jump_insn(fp) \
268 ((fp)->insn_and_shadow + 0)
270 /* The shadow memory of fast tracepoint jump FP. */
271 #define fast_tracepoint_jump_shadow(fp) \
272 ((fp)->insn_and_shadow + (fp)->length)
275 /* Return the fast tracepoint jump set at WHERE. */
277 static struct fast_tracepoint_jump
*
278 find_fast_tracepoint_jump_at (CORE_ADDR where
)
280 struct process_info
*proc
= current_process ();
281 struct fast_tracepoint_jump
*jp
;
283 for (jp
= proc
->fast_tracepoint_jumps
; jp
!= NULL
; jp
= jp
->next
)
291 fast_tracepoint_jump_here (CORE_ADDR where
)
293 struct fast_tracepoint_jump
*jp
= find_fast_tracepoint_jump_at (where
);
299 delete_fast_tracepoint_jump (struct fast_tracepoint_jump
*todel
)
301 struct fast_tracepoint_jump
*bp
, **bp_link
;
303 struct process_info
*proc
= current_process ();
305 bp
= proc
->fast_tracepoint_jumps
;
306 bp_link
= &proc
->fast_tracepoint_jumps
;
312 if (--bp
->refcount
== 0)
314 struct fast_tracepoint_jump
*prev_bp_link
= *bp_link
;
320 /* Since there can be breakpoints inserted in the same
321 address range, we use `write_inferior_memory', which
322 takes care of layering breakpoints on top of fast
323 tracepoints, and on top of the buffer we pass it.
324 This works because we've already unlinked the fast
325 tracepoint jump above. Also note that we need to
326 pass the current shadow contents, because
327 write_inferior_memory updates any shadow memory with
328 what we pass here, and we want that to be a nop. */
329 buf
= alloca (bp
->length
);
330 memcpy (buf
, fast_tracepoint_jump_shadow (bp
), bp
->length
);
331 ret
= write_inferior_memory (bp
->pc
, buf
, bp
->length
);
334 /* Something went wrong, relink the jump. */
335 *bp_link
= prev_bp_link
;
339 "Failed to uninsert fast tracepoint jump "
340 "at 0x%s (%s) while deleting it.\n",
341 paddress (bp
->pc
), strerror (ret
));
357 warning ("Could not find fast tracepoint jump in list.");
362 inc_ref_fast_tracepoint_jump (struct fast_tracepoint_jump
*jp
)
367 struct fast_tracepoint_jump
*
368 set_fast_tracepoint_jump (CORE_ADDR where
,
369 unsigned char *insn
, ULONGEST length
)
371 struct process_info
*proc
= current_process ();
372 struct fast_tracepoint_jump
*jp
;
376 /* We refcount fast tracepoint jumps. Check if we already know
377 about a jump at this address. */
378 jp
= find_fast_tracepoint_jump_at (where
);
385 /* We don't, so create a new object. Double the length, because the
386 flexible array member holds both the jump insn, and the
388 jp
= xcalloc (1, sizeof (*jp
) + (length
* 2));
391 memcpy (fast_tracepoint_jump_insn (jp
), insn
, length
);
393 buf
= alloca (length
);
395 /* Note that there can be trap breakpoints inserted in the same
396 address range. To access the original memory contents, we use
397 `read_inferior_memory', which masks out breakpoints. */
398 err
= read_inferior_memory (where
, buf
, length
);
403 "Failed to read shadow memory of"
404 " fast tracepoint at 0x%s (%s).\n",
405 paddress (where
), strerror (err
));
409 memcpy (fast_tracepoint_jump_shadow (jp
), buf
, length
);
411 /* Link the jump in. */
413 jp
->next
= proc
->fast_tracepoint_jumps
;
414 proc
->fast_tracepoint_jumps
= jp
;
416 /* Since there can be trap breakpoints inserted in the same address
417 range, we use use `write_inferior_memory', which takes care of
418 layering breakpoints on top of fast tracepoints, on top of the
419 buffer we pass it. This works because we've already linked in
420 the fast tracepoint jump above. Also note that we need to pass
421 the current shadow contents, because write_inferior_memory
422 updates any shadow memory with what we pass here, and we want
424 err
= write_inferior_memory (where
, buf
, length
);
429 "Failed to insert fast tracepoint jump at 0x%s (%s).\n",
430 paddress (where
), strerror (err
));
433 proc
->fast_tracepoint_jumps
= jp
->next
;
443 uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc
)
445 struct fast_tracepoint_jump
*jp
;
448 jp
= find_fast_tracepoint_jump_at (pc
);
451 /* This can happen when we remove all breakpoints while handling
455 "Could not find fast tracepoint jump at 0x%s "
456 "in list (uninserting).\n",
467 /* Since there can be trap breakpoints inserted in the same
468 address range, we use use `write_inferior_memory', which
469 takes care of layering breakpoints on top of fast
470 tracepoints, and on top of the buffer we pass it. This works
471 because we've already marked the fast tracepoint fast
472 tracepoint jump uninserted above. Also note that we need to
473 pass the current shadow contents, because
474 write_inferior_memory updates any shadow memory with what we
475 pass here, and we want that to be a nop. */
476 buf
= alloca (jp
->length
);
477 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
478 err
= write_inferior_memory (jp
->pc
, buf
, jp
->length
);
485 "Failed to uninsert fast tracepoint jump at 0x%s (%s).\n",
486 paddress (pc
), strerror (err
));
492 reinsert_fast_tracepoint_jumps_at (CORE_ADDR where
)
494 struct fast_tracepoint_jump
*jp
;
498 jp
= find_fast_tracepoint_jump_at (where
);
501 /* This can happen when we remove breakpoints when a tracepoint
502 hit causes a tracing stop, while handling a step-over. */
505 "Could not find fast tracepoint jump at 0x%s "
506 "in list (reinserting).\n",
512 error ("Jump already inserted at reinsert time.");
516 /* Since there can be trap breakpoints inserted in the same address
517 range, we use `write_inferior_memory', which takes care of
518 layering breakpoints on top of fast tracepoints, and on top of
519 the buffer we pass it. This works because we've already marked
520 the fast tracepoint jump inserted above. Also note that we need
521 to pass the current shadow contents, because
522 write_inferior_memory updates any shadow memory with what we pass
523 here, and we want that to be a nop. */
524 buf
= alloca (jp
->length
);
525 memcpy (buf
, fast_tracepoint_jump_shadow (jp
), jp
->length
);
526 err
= write_inferior_memory (where
, buf
, jp
->length
);
533 "Failed to reinsert fast tracepoint jump at 0x%s (%s).\n",
534 paddress (where
), strerror (err
));
539 set_breakpoint_at (CORE_ADDR where
, int (*handler
) (CORE_ADDR
))
541 struct process_info
*proc
= current_process ();
542 struct breakpoint
*bp
;
543 struct raw_breakpoint
*raw
;
545 raw
= set_raw_breakpoint_at (where
);
553 bp
= xcalloc (1, sizeof (struct breakpoint
));
554 bp
->type
= other_breakpoint
;
557 bp
->handler
= handler
;
559 bp
->next
= proc
->breakpoints
;
560 proc
->breakpoints
= bp
;
566 delete_raw_breakpoint (struct process_info
*proc
, struct raw_breakpoint
*todel
)
568 struct raw_breakpoint
*bp
, **bp_link
;
571 bp
= proc
->raw_breakpoints
;
572 bp_link
= &proc
->raw_breakpoints
;
580 struct raw_breakpoint
*prev_bp_link
= *bp_link
;
581 unsigned char buf
[MAX_BREAKPOINT_LEN
];
585 /* Since there can be trap breakpoints inserted in the
586 same address range, we use `write_inferior_memory',
587 which takes care of layering breakpoints on top of
588 fast tracepoints, and on top of the buffer we pass
589 it. This works because we've already unlinked the
590 fast tracepoint jump above. Also note that we need
591 to pass the current shadow contents, because
592 write_inferior_memory updates any shadow memory with
593 what we pass here, and we want that to be a nop. */
594 memcpy (buf
, bp
->old_data
, breakpoint_len
);
595 ret
= write_inferior_memory (bp
->pc
, buf
, breakpoint_len
);
598 /* Something went wrong, relink the breakpoint. */
599 *bp_link
= prev_bp_link
;
603 "Failed to uninsert raw breakpoint "
604 "at 0x%s (%s) while deleting it.\n",
605 paddress (bp
->pc
), strerror (ret
));
623 warning ("Could not find raw breakpoint in list.");
628 release_breakpoint (struct process_info
*proc
, struct breakpoint
*bp
)
633 newrefcount
= bp
->raw
->refcount
- 1;
634 if (newrefcount
== 0)
636 ret
= delete_raw_breakpoint (proc
, bp
->raw
);
641 bp
->raw
->refcount
= newrefcount
;
649 delete_breakpoint_1 (struct process_info
*proc
, struct breakpoint
*todel
)
651 struct breakpoint
*bp
, **bp_link
;
654 bp
= proc
->breakpoints
;
655 bp_link
= &proc
->breakpoints
;
663 err
= release_breakpoint (proc
, bp
);
677 warning ("Could not find breakpoint in list.");
682 delete_breakpoint (struct breakpoint
*todel
)
684 struct process_info
*proc
= current_process ();
685 return delete_breakpoint_1 (proc
, todel
);
689 find_gdb_breakpoint_at (CORE_ADDR where
)
691 struct process_info
*proc
= current_process ();
692 struct breakpoint
*bp
;
694 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
695 if (bp
->type
== gdb_breakpoint
&& bp
->raw
->pc
== where
)
702 set_gdb_breakpoint_at (CORE_ADDR where
)
704 struct breakpoint
*bp
;
706 if (breakpoint_data
== NULL
)
709 /* If we see GDB inserting a second breakpoint at the same address,
710 then the first breakpoint must have disappeared due to a shared
711 library unload. On targets where the shared libraries are
712 handled by userspace, like SVR4, for example, GDBserver can't
713 tell if a library was loaded or unloaded. Since we refcount
714 breakpoints, if we didn't do this, we'd just increase the
715 refcount of the previous breakpoint at this address, but the trap
716 was not planted in the inferior anymore, thus the breakpoint
717 would never be hit. */
718 bp
= find_gdb_breakpoint_at (where
);
721 delete_gdb_breakpoint_at (where
);
723 /* Might as well validate all other breakpoints. */
724 validate_breakpoints ();
727 bp
= set_breakpoint_at (where
, NULL
);
731 bp
->type
= gdb_breakpoint
;
736 delete_gdb_breakpoint_at (CORE_ADDR addr
)
738 struct breakpoint
*bp
;
741 if (breakpoint_data
== NULL
)
744 bp
= find_gdb_breakpoint_at (addr
);
748 /* Before deleting the breakpoint, make sure to free
749 its condition list. */
750 clear_gdb_breakpoint_conditions (addr
);
751 err
= delete_breakpoint (bp
);
758 /* Clear all conditions associated with this breakpoint address. */
761 clear_gdb_breakpoint_conditions (CORE_ADDR addr
)
763 struct breakpoint
*bp
= find_gdb_breakpoint_at (addr
);
764 struct point_cond_list
*cond
;
766 if (bp
== NULL
|| bp
->cond_list
== NULL
)
769 cond
= bp
->cond_list
;
773 struct point_cond_list
*cond_next
;
775 cond_next
= cond
->next
;
776 free (cond
->cond
->bytes
);
782 bp
->cond_list
= NULL
;
785 /* Add condition CONDITION to GDBserver's breakpoint BP. */
788 add_condition_to_breakpoint (struct breakpoint
*bp
,
789 struct agent_expr
*condition
)
791 struct point_cond_list
*new_cond
;
793 /* Create new condition. */
794 new_cond
= xcalloc (1, sizeof (*new_cond
));
795 new_cond
->cond
= condition
;
797 /* Add condition to the list. */
798 new_cond
->next
= bp
->cond_list
;
799 bp
->cond_list
= new_cond
;
802 /* Add a target-side condition CONDITION to the breakpoint at ADDR. */
805 add_breakpoint_condition (CORE_ADDR addr
, char **condition
)
807 struct breakpoint
*bp
= find_gdb_breakpoint_at (addr
);
808 char *actparm
= *condition
;
809 struct agent_expr
*cond
;
814 if (condition
== NULL
)
817 cond
= gdb_parse_agent_expr (&actparm
);
821 fprintf (stderr
, "Condition evaluation failed. "
822 "Assuming unconditional.\n");
826 add_condition_to_breakpoint (bp
, cond
);
828 *condition
= actparm
;
833 /* Evaluate condition (if any) at breakpoint BP. Return 1 if
834 true and 0 otherwise. */
837 gdb_condition_true_at_breakpoint (CORE_ADDR where
)
839 /* Fetch registers for the current inferior. */
840 struct breakpoint
*bp
= find_gdb_breakpoint_at (where
);
842 struct point_cond_list
*cl
;
845 struct regcache
*regcache
= get_thread_regcache (current_inferior
, 1);
850 /* Check if the breakpoint is unconditional. If it is,
851 the condition always evaluates to TRUE. */
852 if (bp
->cond_list
== NULL
)
855 /* Evaluate each condition in the breakpoint's list of conditions.
856 Return true if any of the conditions evaluates to TRUE.
858 If we failed to evaluate the expression, TRUE is returned. This
859 forces GDB to reevaluate the conditions. */
860 for (cl
= bp
->cond_list
;
861 cl
&& !value
&& !err
; cl
= cl
->next
)
863 /* Evaluate the condition. */
864 err
= gdb_eval_agent_expr (regcache
, NULL
, cl
->cond
, &value
);
873 /* Add commands COMMANDS to GDBserver's breakpoint BP. */
876 add_commands_to_breakpoint (struct breakpoint
*bp
,
877 struct agent_expr
*commands
, int persist
)
879 struct point_command_list
*new_cmd
;
881 /* Create new command. */
882 new_cmd
= xcalloc (1, sizeof (*new_cmd
));
883 new_cmd
->cmd
= commands
;
884 new_cmd
->persistence
= persist
;
886 /* Add commands to the list. */
887 new_cmd
->next
= bp
->command_list
;
888 bp
->command_list
= new_cmd
;
891 /* Add a target-side command COMMAND to the breakpoint at ADDR. */
894 add_breakpoint_commands (CORE_ADDR addr
, char **command
, int persist
)
896 struct breakpoint
*bp
= find_gdb_breakpoint_at (addr
);
897 char *actparm
= *command
;
898 struct agent_expr
*cmd
;
906 cmd
= gdb_parse_agent_expr (&actparm
);
910 fprintf (stderr
, "Command evaluation failed. "
915 add_commands_to_breakpoint (bp
, cmd
, persist
);
922 /* Return true if there are no commands to run at this location,
923 which likely means we want to report back to GDB. */
925 gdb_no_commands_at_breakpoint (CORE_ADDR where
)
927 struct breakpoint
*bp
= find_gdb_breakpoint_at (where
);
933 fprintf (stderr
, "at 0x%s, bp command_list is 0x%s\n",
935 phex_nz ((uintptr_t) bp
->command_list
, 0));
936 return (bp
->command_list
== NULL
);
940 run_breakpoint_commands (CORE_ADDR where
)
942 /* Fetch registers for the current inferior. */
943 struct breakpoint
*bp
= find_gdb_breakpoint_at (where
);
945 struct point_command_list
*cl
;
948 struct regcache
*regcache
= get_thread_regcache (current_inferior
, 1);
953 for (cl
= bp
->command_list
;
954 cl
&& !value
&& !err
; cl
= cl
->next
)
956 /* Run the command. */
957 err
= gdb_eval_agent_expr (regcache
, NULL
, cl
->cmd
, &value
);
959 /* If one command has a problem, stop digging the hole deeper. */
965 /* Return 1 if there is a breakpoint inserted in address WHERE
966 and if its condition, if it exists, is true. */
969 gdb_breakpoint_here (CORE_ADDR where
)
971 return (find_gdb_breakpoint_at (where
) != NULL
);
975 set_reinsert_breakpoint (CORE_ADDR stop_at
)
977 struct breakpoint
*bp
;
979 bp
= set_breakpoint_at (stop_at
, NULL
);
980 bp
->type
= reinsert_breakpoint
;
984 delete_reinsert_breakpoints (void)
986 struct process_info
*proc
= current_process ();
987 struct breakpoint
*bp
, **bp_link
;
989 bp
= proc
->breakpoints
;
990 bp_link
= &proc
->breakpoints
;
994 if (bp
->type
== reinsert_breakpoint
)
997 release_breakpoint (proc
, bp
);
1002 bp_link
= &bp
->next
;
1009 uninsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1014 unsigned char buf
[MAX_BREAKPOINT_LEN
];
1017 /* Since there can be fast tracepoint jumps inserted in the same
1018 address range, we use `write_inferior_memory', which takes
1019 care of layering breakpoints on top of fast tracepoints, and
1020 on top of the buffer we pass it. This works because we've
1021 already unlinked the fast tracepoint jump above. Also note
1022 that we need to pass the current shadow contents, because
1023 write_inferior_memory updates any shadow memory with what we
1024 pass here, and we want that to be a nop. */
1025 memcpy (buf
, bp
->old_data
, breakpoint_len
);
1026 err
= write_inferior_memory (bp
->pc
, buf
, breakpoint_len
);
1033 "Failed to uninsert raw breakpoint at 0x%s (%s).\n",
1034 paddress (bp
->pc
), strerror (err
));
1040 uninsert_breakpoints_at (CORE_ADDR pc
)
1042 struct raw_breakpoint
*bp
;
1044 bp
= find_raw_breakpoint_at (pc
);
1047 /* This can happen when we remove all breakpoints while handling
1051 "Could not find breakpoint at 0x%s "
1052 "in list (uninserting).\n",
1058 uninsert_raw_breakpoint (bp
);
1062 uninsert_all_breakpoints (void)
1064 struct process_info
*proc
= current_process ();
1065 struct raw_breakpoint
*bp
;
1067 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1069 uninsert_raw_breakpoint (bp
);
1073 reinsert_raw_breakpoint (struct raw_breakpoint
*bp
)
1078 error ("Breakpoint already inserted at reinsert time.");
1080 err
= (*the_target
->write_memory
) (bp
->pc
, breakpoint_data
,
1084 else if (debug_threads
)
1086 "Failed to reinsert breakpoint at 0x%s (%s).\n",
1087 paddress (bp
->pc
), strerror (err
));
1091 reinsert_breakpoints_at (CORE_ADDR pc
)
1093 struct raw_breakpoint
*bp
;
1095 bp
= find_raw_breakpoint_at (pc
);
1098 /* This can happen when we remove all breakpoints while handling
1102 "Could not find raw breakpoint at 0x%s "
1103 "in list (reinserting).\n",
1108 reinsert_raw_breakpoint (bp
);
1112 reinsert_all_breakpoints (void)
1114 struct process_info
*proc
= current_process ();
1115 struct raw_breakpoint
*bp
;
1117 for (bp
= proc
->raw_breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1119 reinsert_raw_breakpoint (bp
);
1123 check_breakpoints (CORE_ADDR stop_pc
)
1125 struct process_info
*proc
= current_process ();
1126 struct breakpoint
*bp
, **bp_link
;
1128 bp
= proc
->breakpoints
;
1129 bp_link
= &proc
->breakpoints
;
1133 if (bp
->raw
->pc
== stop_pc
)
1135 if (!bp
->raw
->inserted
)
1137 warning ("Hit a removed breakpoint?");
1141 if (bp
->handler
!= NULL
&& (*bp
->handler
) (stop_pc
))
1143 *bp_link
= bp
->next
;
1145 release_breakpoint (proc
, bp
);
1152 bp_link
= &bp
->next
;
1158 set_breakpoint_data (const unsigned char *bp_data
, int bp_len
)
1160 breakpoint_data
= bp_data
;
1161 breakpoint_len
= bp_len
;
1165 breakpoint_here (CORE_ADDR addr
)
1167 return (find_raw_breakpoint_at (addr
) != NULL
);
1171 breakpoint_inserted_here (CORE_ADDR addr
)
1173 struct raw_breakpoint
*bp
;
1175 bp
= find_raw_breakpoint_at (addr
);
1177 return (bp
!= NULL
&& bp
->inserted
);
1181 validate_inserted_breakpoint (struct raw_breakpoint
*bp
)
1186 gdb_assert (bp
->inserted
);
1188 buf
= alloca (breakpoint_len
);
1189 err
= (*the_target
->read_memory
) (bp
->pc
, buf
, breakpoint_len
);
1190 if (err
|| memcmp (buf
, breakpoint_data
, breakpoint_len
) != 0)
1192 /* Tag it as gone. */
1194 bp
->shlib_disabled
= 1;
1202 delete_disabled_breakpoints (void)
1204 struct process_info
*proc
= current_process ();
1205 struct breakpoint
*bp
, *next
;
1207 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= next
)
1210 if (bp
->raw
->shlib_disabled
)
1211 delete_breakpoint_1 (proc
, bp
);
1215 /* Check if breakpoints we inserted still appear to be inserted. They
1216 may disappear due to a shared library unload, and worse, a new
1217 shared library may be reloaded at the same address as the
1218 previously unloaded one. If that happens, we should make sure that
1219 the shadow memory of the old breakpoints isn't used when reading or
1223 validate_breakpoints (void)
1225 struct process_info
*proc
= current_process ();
1226 struct breakpoint
*bp
;
1228 for (bp
= proc
->breakpoints
; bp
!= NULL
; bp
= bp
->next
)
1230 if (bp
->raw
->inserted
)
1231 validate_inserted_breakpoint (bp
->raw
);
1234 delete_disabled_breakpoints ();
1238 check_mem_read (CORE_ADDR mem_addr
, unsigned char *buf
, int mem_len
)
1240 struct process_info
*proc
= current_process ();
1241 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1242 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1243 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1244 int disabled_one
= 0;
1246 for (; jp
!= NULL
; jp
= jp
->next
)
1248 CORE_ADDR bp_end
= jp
->pc
+ jp
->length
;
1249 CORE_ADDR start
, end
;
1250 int copy_offset
, copy_len
, buf_offset
;
1252 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= buf
+ mem_len
1253 || buf
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1255 if (mem_addr
>= bp_end
)
1257 if (jp
->pc
>= mem_end
)
1261 if (mem_addr
> start
)
1268 copy_len
= end
- start
;
1269 copy_offset
= start
- jp
->pc
;
1270 buf_offset
= start
- mem_addr
;
1273 memcpy (buf
+ buf_offset
,
1274 fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1278 for (; bp
!= NULL
; bp
= bp
->next
)
1280 CORE_ADDR bp_end
= bp
->pc
+ breakpoint_len
;
1281 CORE_ADDR start
, end
;
1282 int copy_offset
, copy_len
, buf_offset
;
1284 gdb_assert (bp
->old_data
>= buf
+ mem_len
1285 || buf
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1287 if (mem_addr
>= bp_end
)
1289 if (bp
->pc
>= mem_end
)
1293 if (mem_addr
> start
)
1300 copy_len
= end
- start
;
1301 copy_offset
= start
- bp
->pc
;
1302 buf_offset
= start
- mem_addr
;
1306 if (validate_inserted_breakpoint (bp
))
1307 memcpy (buf
+ buf_offset
, bp
->old_data
+ copy_offset
, copy_len
);
1314 delete_disabled_breakpoints ();
1318 check_mem_write (CORE_ADDR mem_addr
, unsigned char *buf
,
1319 const unsigned char *myaddr
, int mem_len
)
1321 struct process_info
*proc
= current_process ();
1322 struct raw_breakpoint
*bp
= proc
->raw_breakpoints
;
1323 struct fast_tracepoint_jump
*jp
= proc
->fast_tracepoint_jumps
;
1324 CORE_ADDR mem_end
= mem_addr
+ mem_len
;
1325 int disabled_one
= 0;
1327 /* First fast tracepoint jumps, then breakpoint traps on top. */
1329 for (; jp
!= NULL
; jp
= jp
->next
)
1331 CORE_ADDR jp_end
= jp
->pc
+ jp
->length
;
1332 CORE_ADDR start
, end
;
1333 int copy_offset
, copy_len
, buf_offset
;
1335 gdb_assert (fast_tracepoint_jump_shadow (jp
) >= myaddr
+ mem_len
1336 || myaddr
>= fast_tracepoint_jump_shadow (jp
) + (jp
)->length
);
1337 gdb_assert (fast_tracepoint_jump_insn (jp
) >= buf
+ mem_len
1338 || buf
>= fast_tracepoint_jump_insn (jp
) + (jp
)->length
);
1340 if (mem_addr
>= jp_end
)
1342 if (jp
->pc
>= mem_end
)
1346 if (mem_addr
> start
)
1353 copy_len
= end
- start
;
1354 copy_offset
= start
- jp
->pc
;
1355 buf_offset
= start
- mem_addr
;
1357 memcpy (fast_tracepoint_jump_shadow (jp
) + copy_offset
,
1358 myaddr
+ buf_offset
, copy_len
);
1360 memcpy (buf
+ buf_offset
,
1361 fast_tracepoint_jump_insn (jp
) + copy_offset
, copy_len
);
1364 for (; bp
!= NULL
; bp
= bp
->next
)
1366 CORE_ADDR bp_end
= bp
->pc
+ breakpoint_len
;
1367 CORE_ADDR start
, end
;
1368 int copy_offset
, copy_len
, buf_offset
;
1370 gdb_assert (bp
->old_data
>= myaddr
+ mem_len
1371 || myaddr
>= &bp
->old_data
[sizeof (bp
->old_data
)]);
1373 if (mem_addr
>= bp_end
)
1375 if (bp
->pc
>= mem_end
)
1379 if (mem_addr
> start
)
1386 copy_len
= end
- start
;
1387 copy_offset
= start
- bp
->pc
;
1388 buf_offset
= start
- mem_addr
;
1390 memcpy (bp
->old_data
+ copy_offset
, myaddr
+ buf_offset
, copy_len
);
1393 if (validate_inserted_breakpoint (bp
))
1394 memcpy (buf
+ buf_offset
, breakpoint_data
+ copy_offset
, copy_len
);
1401 delete_disabled_breakpoints ();
1404 /* Delete all breakpoints, and un-insert them from the inferior. */
1407 delete_all_breakpoints (void)
1409 struct process_info
*proc
= current_process ();
1411 while (proc
->breakpoints
)
1412 delete_breakpoint_1 (proc
, proc
->breakpoints
);
1415 /* Clear the "inserted" flag in all breakpoints. */
1418 mark_breakpoints_out (struct process_info
*proc
)
1420 struct raw_breakpoint
*raw_bp
;
1422 for (raw_bp
= proc
->raw_breakpoints
; raw_bp
!= NULL
; raw_bp
= raw_bp
->next
)
1423 raw_bp
->inserted
= 0;
1426 /* Release all breakpoints, but do not try to un-insert them from the
1430 free_all_breakpoints (struct process_info
*proc
)
1432 mark_breakpoints_out (proc
);
1434 /* Note: use PROC explicitly instead of deferring to
1435 delete_all_breakpoints --- CURRENT_INFERIOR may already have been
1436 released when we get here. There should be no call to
1437 current_process from here on. */
1438 while (proc
->breakpoints
)
1439 delete_breakpoint_1 (proc
, proc
->breakpoints
);
This page took 0.059143 seconds and 4 git commands to generate.