1 /* Branch trace support for GDB, the GNU debugger.
3 Copyright (C) 2013-2015 Free Software Foundation, Inc.
5 Contributed by Intel Corp. <markus.t.metzger@intel.com>
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/>. */
24 #include "gdbthread.h"
29 #include "cli/cli-utils.h"
33 #include "filenames.h"
35 #include "frame-unwind.h"
38 #include "event-loop.h"
42 /* The target_ops of record-btrace. */
43 static struct target_ops record_btrace_ops
;
45 /* A new thread observer enabling branch tracing for the new thread. */
46 static struct observer
*record_btrace_thread_observer
;
48 /* Memory access types used in set/show record btrace replay-memory-access. */
49 static const char replay_memory_access_read_only
[] = "read-only";
50 static const char replay_memory_access_read_write
[] = "read-write";
51 static const char *const replay_memory_access_types
[] =
53 replay_memory_access_read_only
,
54 replay_memory_access_read_write
,
58 /* The currently allowed replay memory access type. */
59 static const char *replay_memory_access
= replay_memory_access_read_only
;
61 /* Command lists for "set/show record btrace". */
62 static struct cmd_list_element
*set_record_btrace_cmdlist
;
63 static struct cmd_list_element
*show_record_btrace_cmdlist
;
65 /* The execution direction of the last resume we got. See record-full.c. */
66 static enum exec_direction_kind record_btrace_resume_exec_dir
= EXEC_FORWARD
;
68 /* The async event handler for reverse/replay execution. */
69 static struct async_event_handler
*record_btrace_async_inferior_event_handler
;
71 /* A flag indicating that we are currently generating a core file. */
72 static int record_btrace_generating_corefile
;
74 /* The current branch trace configuration. */
75 static struct btrace_config record_btrace_conf
;
77 /* Command list for "record btrace". */
78 static struct cmd_list_element
*record_btrace_cmdlist
;
80 /* Command lists for "set/show record btrace bts". */
81 static struct cmd_list_element
*set_record_btrace_bts_cmdlist
;
82 static struct cmd_list_element
*show_record_btrace_bts_cmdlist
;
84 /* Command lists for "set/show record btrace pt". */
85 static struct cmd_list_element
*set_record_btrace_pt_cmdlist
;
86 static struct cmd_list_element
*show_record_btrace_pt_cmdlist
;
88 /* Print a record-btrace debug message. Use do ... while (0) to avoid
89 ambiguities when used in if statements. */
91 #define DEBUG(msg, args...) \
94 if (record_debug != 0) \
95 fprintf_unfiltered (gdb_stdlog, \
96 "[record-btrace] " msg "\n", ##args); \
101 /* Update the branch trace for the current thread and return a pointer to its
104 Throws an error if there is no thread or no trace. This function never
107 static struct thread_info
*
108 require_btrace_thread (void)
110 struct thread_info
*tp
;
114 tp
= find_thread_ptid (inferior_ptid
);
116 error (_("No thread."));
120 if (btrace_is_empty (tp
))
121 error (_("No trace."));
126 /* Update the branch trace for the current thread and return a pointer to its
127 branch trace information struct.
129 Throws an error if there is no thread or no trace. This function never
132 static struct btrace_thread_info
*
133 require_btrace (void)
135 struct thread_info
*tp
;
137 tp
= require_btrace_thread ();
142 /* Enable branch tracing for one thread. Warn on errors. */
145 record_btrace_enable_warn (struct thread_info
*tp
)
149 btrace_enable (tp
, &record_btrace_conf
);
151 CATCH (error
, RETURN_MASK_ERROR
)
153 warning ("%s", error
.message
);
158 /* Callback function to disable branch tracing for one thread. */
161 record_btrace_disable_callback (void *arg
)
163 struct thread_info
*tp
;
170 /* Enable automatic tracing of new threads. */
173 record_btrace_auto_enable (void)
175 DEBUG ("attach thread observer");
177 record_btrace_thread_observer
178 = observer_attach_new_thread (record_btrace_enable_warn
);
181 /* Disable automatic tracing of new threads. */
184 record_btrace_auto_disable (void)
186 /* The observer may have been detached, already. */
187 if (record_btrace_thread_observer
== NULL
)
190 DEBUG ("detach thread observer");
192 observer_detach_new_thread (record_btrace_thread_observer
);
193 record_btrace_thread_observer
= NULL
;
196 /* The record-btrace async event handler function. */
199 record_btrace_handle_async_inferior_event (gdb_client_data data
)
201 inferior_event_handler (INF_REG_EVENT
, NULL
);
204 /* The to_open method of target record-btrace. */
207 record_btrace_open (const char *args
, int from_tty
)
209 struct cleanup
*disable_chain
;
210 struct thread_info
*tp
;
216 if (!target_has_execution
)
217 error (_("The program is not being run."));
219 gdb_assert (record_btrace_thread_observer
== NULL
);
221 disable_chain
= make_cleanup (null_cleanup
, NULL
);
222 ALL_NON_EXITED_THREADS (tp
)
223 if (args
== NULL
|| *args
== 0 || number_is_in_list (args
, tp
->num
))
225 btrace_enable (tp
, &record_btrace_conf
);
227 make_cleanup (record_btrace_disable_callback
, tp
);
230 record_btrace_auto_enable ();
232 push_target (&record_btrace_ops
);
234 record_btrace_async_inferior_event_handler
235 = create_async_event_handler (record_btrace_handle_async_inferior_event
,
237 record_btrace_generating_corefile
= 0;
239 observer_notify_record_changed (current_inferior (), 1);
241 discard_cleanups (disable_chain
);
244 /* The to_stop_recording method of target record-btrace. */
247 record_btrace_stop_recording (struct target_ops
*self
)
249 struct thread_info
*tp
;
251 DEBUG ("stop recording");
253 record_btrace_auto_disable ();
255 ALL_NON_EXITED_THREADS (tp
)
256 if (tp
->btrace
.target
!= NULL
)
260 /* The to_close method of target record-btrace. */
263 record_btrace_close (struct target_ops
*self
)
265 struct thread_info
*tp
;
267 if (record_btrace_async_inferior_event_handler
!= NULL
)
268 delete_async_event_handler (&record_btrace_async_inferior_event_handler
);
270 /* Make sure automatic recording gets disabled even if we did not stop
271 recording before closing the record-btrace target. */
272 record_btrace_auto_disable ();
274 /* We should have already stopped recording.
275 Tear down btrace in case we have not. */
276 ALL_NON_EXITED_THREADS (tp
)
277 btrace_teardown (tp
);
280 /* The to_async method of target record-btrace. */
283 record_btrace_async (struct target_ops
*ops
, int enable
)
286 mark_async_event_handler (record_btrace_async_inferior_event_handler
);
288 clear_async_event_handler (record_btrace_async_inferior_event_handler
);
290 ops
->beneath
->to_async (ops
->beneath
, enable
);
293 /* Adjusts the size and returns a human readable size suffix. */
296 record_btrace_adjust_size (unsigned int *size
)
302 if ((sz
& ((1u << 30) - 1)) == 0)
307 else if ((sz
& ((1u << 20) - 1)) == 0)
312 else if ((sz
& ((1u << 10) - 1)) == 0)
321 /* Print a BTS configuration. */
324 record_btrace_print_bts_conf (const struct btrace_config_bts
*conf
)
332 suffix
= record_btrace_adjust_size (&size
);
333 printf_unfiltered (_("Buffer size: %u%s.\n"), size
, suffix
);
337 /* Print an Intel(R) Processor Trace configuration. */
340 record_btrace_print_pt_conf (const struct btrace_config_pt
*conf
)
348 suffix
= record_btrace_adjust_size (&size
);
349 printf_unfiltered (_("Buffer size: %u%s.\n"), size
, suffix
);
353 /* Print a branch tracing configuration. */
356 record_btrace_print_conf (const struct btrace_config
*conf
)
358 printf_unfiltered (_("Recording format: %s.\n"),
359 btrace_format_string (conf
->format
));
361 switch (conf
->format
)
363 case BTRACE_FORMAT_NONE
:
366 case BTRACE_FORMAT_BTS
:
367 record_btrace_print_bts_conf (&conf
->bts
);
370 case BTRACE_FORMAT_PT
:
371 record_btrace_print_pt_conf (&conf
->pt
);
375 internal_error (__FILE__
, __LINE__
, _("Unkown branch trace format."));
378 /* The to_info_record method of target record-btrace. */
381 record_btrace_info (struct target_ops
*self
)
383 struct btrace_thread_info
*btinfo
;
384 const struct btrace_config
*conf
;
385 struct thread_info
*tp
;
386 unsigned int insns
, calls
, gaps
;
390 tp
= find_thread_ptid (inferior_ptid
);
392 error (_("No thread."));
394 btinfo
= &tp
->btrace
;
396 conf
= btrace_conf (btinfo
);
398 record_btrace_print_conf (conf
);
406 if (!btrace_is_empty (tp
))
408 struct btrace_call_iterator call
;
409 struct btrace_insn_iterator insn
;
411 btrace_call_end (&call
, btinfo
);
412 btrace_call_prev (&call
, 1);
413 calls
= btrace_call_number (&call
);
415 btrace_insn_end (&insn
, btinfo
);
417 insns
= btrace_insn_number (&insn
);
420 /* The last instruction does not really belong to the trace. */
427 /* Skip gaps at the end. */
430 steps
= btrace_insn_prev (&insn
, 1);
434 insns
= btrace_insn_number (&insn
);
439 gaps
= btinfo
->ngaps
;
442 printf_unfiltered (_("Recorded %u instructions in %u functions (%u gaps) "
443 "for thread %d (%s).\n"), insns
, calls
, gaps
,
444 tp
->num
, target_pid_to_str (tp
->ptid
));
446 if (btrace_is_replaying (tp
))
447 printf_unfiltered (_("Replay in progress. At instruction %u.\n"),
448 btrace_insn_number (btinfo
->replay
));
451 /* Print a decode error. */
454 btrace_ui_out_decode_error (struct ui_out
*uiout
, int errcode
,
455 enum btrace_format format
)
460 errstr
= _("unknown");
468 case BTRACE_FORMAT_BTS
:
474 case BDE_BTS_OVERFLOW
:
475 errstr
= _("instruction overflow");
478 case BDE_BTS_INSN_SIZE
:
479 errstr
= _("unknown instruction");
484 #if defined (HAVE_LIBIPT)
485 case BTRACE_FORMAT_PT
:
488 case BDE_PT_USER_QUIT
:
490 errstr
= _("trace decode cancelled");
493 case BDE_PT_DISABLED
:
495 errstr
= _("disabled");
498 case BDE_PT_OVERFLOW
:
500 errstr
= _("overflow");
505 errstr
= pt_errstr (pt_errcode (errcode
));
509 #endif /* defined (HAVE_LIBIPT) */
512 ui_out_text (uiout
, _("["));
515 ui_out_text (uiout
, _("decode error ("));
516 ui_out_field_int (uiout
, "errcode", errcode
);
517 ui_out_text (uiout
, _("): "));
519 ui_out_text (uiout
, errstr
);
520 ui_out_text (uiout
, _("]\n"));
523 /* Print an unsigned int. */
526 ui_out_field_uint (struct ui_out
*uiout
, const char *fld
, unsigned int val
)
528 ui_out_field_fmt (uiout
, fld
, "%u", val
);
531 /* Disassemble a section of the recorded instruction trace. */
534 btrace_insn_history (struct ui_out
*uiout
,
535 const struct btrace_thread_info
*btinfo
,
536 const struct btrace_insn_iterator
*begin
,
537 const struct btrace_insn_iterator
*end
, int flags
)
539 struct gdbarch
*gdbarch
;
540 struct btrace_insn_iterator it
;
542 DEBUG ("itrace (0x%x): [%u; %u)", flags
, btrace_insn_number (begin
),
543 btrace_insn_number (end
));
545 gdbarch
= target_gdbarch ();
547 for (it
= *begin
; btrace_insn_cmp (&it
, end
) != 0; btrace_insn_next (&it
, 1))
549 const struct btrace_insn
*insn
;
551 insn
= btrace_insn_get (&it
);
553 /* A NULL instruction indicates a gap in the trace. */
556 const struct btrace_config
*conf
;
558 conf
= btrace_conf (btinfo
);
560 /* We have trace so we must have a configuration. */
561 gdb_assert (conf
!= NULL
);
563 btrace_ui_out_decode_error (uiout
, it
.function
->errcode
,
570 /* We may add a speculation prefix later. We use the same space
571 that is used for the pc prefix. */
572 if ((flags
& DISASSEMBLY_OMIT_PC
) == 0)
573 strncpy (prefix
, pc_prefix (insn
->pc
), 3);
582 /* Print the instruction index. */
583 ui_out_field_uint (uiout
, "index", btrace_insn_number (&it
));
584 ui_out_text (uiout
, "\t");
586 /* Indicate speculative execution by a leading '?'. */
587 if ((insn
->flags
& BTRACE_INSN_FLAG_SPECULATIVE
) != 0)
590 /* Print the prefix; we tell gdb_disassembly below to omit it. */
591 ui_out_field_fmt (uiout
, "prefix", "%s", prefix
);
593 /* Disassembly with '/m' flag may not produce the expected result.
595 gdb_disassembly (gdbarch
, uiout
, NULL
, flags
| DISASSEMBLY_OMIT_PC
,
596 1, insn
->pc
, insn
->pc
+ 1);
601 /* The to_insn_history method of target record-btrace. */
604 record_btrace_insn_history (struct target_ops
*self
, int size
, int flags
)
606 struct btrace_thread_info
*btinfo
;
607 struct btrace_insn_history
*history
;
608 struct btrace_insn_iterator begin
, end
;
609 struct cleanup
*uiout_cleanup
;
610 struct ui_out
*uiout
;
611 unsigned int context
, covered
;
613 uiout
= current_uiout
;
614 uiout_cleanup
= make_cleanup_ui_out_tuple_begin_end (uiout
,
616 context
= abs (size
);
618 error (_("Bad record instruction-history-size."));
620 btinfo
= require_btrace ();
621 history
= btinfo
->insn_history
;
624 struct btrace_insn_iterator
*replay
;
626 DEBUG ("insn-history (0x%x): %d", flags
, size
);
628 /* If we're replaying, we start at the replay position. Otherwise, we
629 start at the tail of the trace. */
630 replay
= btinfo
->replay
;
634 btrace_insn_end (&begin
, btinfo
);
636 /* We start from here and expand in the requested direction. Then we
637 expand in the other direction, as well, to fill up any remaining
642 /* We want the current position covered, as well. */
643 covered
= btrace_insn_next (&end
, 1);
644 covered
+= btrace_insn_prev (&begin
, context
- covered
);
645 covered
+= btrace_insn_next (&end
, context
- covered
);
649 covered
= btrace_insn_next (&end
, context
);
650 covered
+= btrace_insn_prev (&begin
, context
- covered
);
655 begin
= history
->begin
;
658 DEBUG ("insn-history (0x%x): %d, prev: [%u; %u)", flags
, size
,
659 btrace_insn_number (&begin
), btrace_insn_number (&end
));
664 covered
= btrace_insn_prev (&begin
, context
);
669 covered
= btrace_insn_next (&end
, context
);
674 btrace_insn_history (uiout
, btinfo
, &begin
, &end
, flags
);
678 printf_unfiltered (_("At the start of the branch trace record.\n"));
680 printf_unfiltered (_("At the end of the branch trace record.\n"));
683 btrace_set_insn_history (btinfo
, &begin
, &end
);
684 do_cleanups (uiout_cleanup
);
687 /* The to_insn_history_range method of target record-btrace. */
690 record_btrace_insn_history_range (struct target_ops
*self
,
691 ULONGEST from
, ULONGEST to
, int flags
)
693 struct btrace_thread_info
*btinfo
;
694 struct btrace_insn_history
*history
;
695 struct btrace_insn_iterator begin
, end
;
696 struct cleanup
*uiout_cleanup
;
697 struct ui_out
*uiout
;
698 unsigned int low
, high
;
701 uiout
= current_uiout
;
702 uiout_cleanup
= make_cleanup_ui_out_tuple_begin_end (uiout
,
707 DEBUG ("insn-history (0x%x): [%u; %u)", flags
, low
, high
);
709 /* Check for wrap-arounds. */
710 if (low
!= from
|| high
!= to
)
711 error (_("Bad range."));
714 error (_("Bad range."));
716 btinfo
= require_btrace ();
718 found
= btrace_find_insn_by_number (&begin
, btinfo
, low
);
720 error (_("Range out of bounds."));
722 found
= btrace_find_insn_by_number (&end
, btinfo
, high
);
725 /* Silently truncate the range. */
726 btrace_insn_end (&end
, btinfo
);
730 /* We want both begin and end to be inclusive. */
731 btrace_insn_next (&end
, 1);
734 btrace_insn_history (uiout
, btinfo
, &begin
, &end
, flags
);
735 btrace_set_insn_history (btinfo
, &begin
, &end
);
737 do_cleanups (uiout_cleanup
);
740 /* The to_insn_history_from method of target record-btrace. */
743 record_btrace_insn_history_from (struct target_ops
*self
,
744 ULONGEST from
, int size
, int flags
)
746 ULONGEST begin
, end
, context
;
748 context
= abs (size
);
750 error (_("Bad record instruction-history-size."));
759 begin
= from
- context
+ 1;
764 end
= from
+ context
- 1;
766 /* Check for wrap-around. */
771 record_btrace_insn_history_range (self
, begin
, end
, flags
);
774 /* Print the instruction number range for a function call history line. */
777 btrace_call_history_insn_range (struct ui_out
*uiout
,
778 const struct btrace_function
*bfun
)
780 unsigned int begin
, end
, size
;
782 size
= VEC_length (btrace_insn_s
, bfun
->insn
);
783 gdb_assert (size
> 0);
785 begin
= bfun
->insn_offset
;
786 end
= begin
+ size
- 1;
788 ui_out_field_uint (uiout
, "insn begin", begin
);
789 ui_out_text (uiout
, ",");
790 ui_out_field_uint (uiout
, "insn end", end
);
793 /* Compute the lowest and highest source line for the instructions in BFUN
794 and return them in PBEGIN and PEND.
795 Ignore instructions that can't be mapped to BFUN, e.g. instructions that
796 result from inlining or macro expansion. */
799 btrace_compute_src_line_range (const struct btrace_function
*bfun
,
800 int *pbegin
, int *pend
)
802 struct btrace_insn
*insn
;
803 struct symtab
*symtab
;
815 symtab
= symbol_symtab (sym
);
817 for (idx
= 0; VEC_iterate (btrace_insn_s
, bfun
->insn
, idx
, insn
); ++idx
)
819 struct symtab_and_line sal
;
821 sal
= find_pc_line (insn
->pc
, 0);
822 if (sal
.symtab
!= symtab
|| sal
.line
== 0)
825 begin
= min (begin
, sal
.line
);
826 end
= max (end
, sal
.line
);
834 /* Print the source line information for a function call history line. */
837 btrace_call_history_src_line (struct ui_out
*uiout
,
838 const struct btrace_function
*bfun
)
847 ui_out_field_string (uiout
, "file",
848 symtab_to_filename_for_display (symbol_symtab (sym
)));
850 btrace_compute_src_line_range (bfun
, &begin
, &end
);
854 ui_out_text (uiout
, ":");
855 ui_out_field_int (uiout
, "min line", begin
);
860 ui_out_text (uiout
, ",");
861 ui_out_field_int (uiout
, "max line", end
);
864 /* Get the name of a branch trace function. */
867 btrace_get_bfun_name (const struct btrace_function
*bfun
)
869 struct minimal_symbol
*msym
;
879 return SYMBOL_PRINT_NAME (sym
);
880 else if (msym
!= NULL
)
881 return MSYMBOL_PRINT_NAME (msym
);
886 /* Disassemble a section of the recorded function trace. */
889 btrace_call_history (struct ui_out
*uiout
,
890 const struct btrace_thread_info
*btinfo
,
891 const struct btrace_call_iterator
*begin
,
892 const struct btrace_call_iterator
*end
,
893 enum record_print_flag flags
)
895 struct btrace_call_iterator it
;
897 DEBUG ("ftrace (0x%x): [%u; %u)", flags
, btrace_call_number (begin
),
898 btrace_call_number (end
));
900 for (it
= *begin
; btrace_call_cmp (&it
, end
) < 0; btrace_call_next (&it
, 1))
902 const struct btrace_function
*bfun
;
903 struct minimal_symbol
*msym
;
906 bfun
= btrace_call_get (&it
);
910 /* Print the function index. */
911 ui_out_field_uint (uiout
, "index", bfun
->number
);
912 ui_out_text (uiout
, "\t");
914 /* Indicate gaps in the trace. */
915 if (bfun
->errcode
!= 0)
917 const struct btrace_config
*conf
;
919 conf
= btrace_conf (btinfo
);
921 /* We have trace so we must have a configuration. */
922 gdb_assert (conf
!= NULL
);
924 btrace_ui_out_decode_error (uiout
, bfun
->errcode
, conf
->format
);
929 if ((flags
& RECORD_PRINT_INDENT_CALLS
) != 0)
931 int level
= bfun
->level
+ btinfo
->level
, i
;
933 for (i
= 0; i
< level
; ++i
)
934 ui_out_text (uiout
, " ");
938 ui_out_field_string (uiout
, "function", SYMBOL_PRINT_NAME (sym
));
939 else if (msym
!= NULL
)
940 ui_out_field_string (uiout
, "function", MSYMBOL_PRINT_NAME (msym
));
941 else if (!ui_out_is_mi_like_p (uiout
))
942 ui_out_field_string (uiout
, "function", "??");
944 if ((flags
& RECORD_PRINT_INSN_RANGE
) != 0)
946 ui_out_text (uiout
, _("\tinst "));
947 btrace_call_history_insn_range (uiout
, bfun
);
950 if ((flags
& RECORD_PRINT_SRC_LINE
) != 0)
952 ui_out_text (uiout
, _("\tat "));
953 btrace_call_history_src_line (uiout
, bfun
);
956 ui_out_text (uiout
, "\n");
960 /* The to_call_history method of target record-btrace. */
963 record_btrace_call_history (struct target_ops
*self
, int size
, int flags
)
965 struct btrace_thread_info
*btinfo
;
966 struct btrace_call_history
*history
;
967 struct btrace_call_iterator begin
, end
;
968 struct cleanup
*uiout_cleanup
;
969 struct ui_out
*uiout
;
970 unsigned int context
, covered
;
972 uiout
= current_uiout
;
973 uiout_cleanup
= make_cleanup_ui_out_tuple_begin_end (uiout
,
975 context
= abs (size
);
977 error (_("Bad record function-call-history-size."));
979 btinfo
= require_btrace ();
980 history
= btinfo
->call_history
;
983 struct btrace_insn_iterator
*replay
;
985 DEBUG ("call-history (0x%x): %d", flags
, size
);
987 /* If we're replaying, we start at the replay position. Otherwise, we
988 start at the tail of the trace. */
989 replay
= btinfo
->replay
;
992 begin
.function
= replay
->function
;
993 begin
.btinfo
= btinfo
;
996 btrace_call_end (&begin
, btinfo
);
998 /* We start from here and expand in the requested direction. Then we
999 expand in the other direction, as well, to fill up any remaining
1004 /* We want the current position covered, as well. */
1005 covered
= btrace_call_next (&end
, 1);
1006 covered
+= btrace_call_prev (&begin
, context
- covered
);
1007 covered
+= btrace_call_next (&end
, context
- covered
);
1011 covered
= btrace_call_next (&end
, context
);
1012 covered
+= btrace_call_prev (&begin
, context
- covered
);
1017 begin
= history
->begin
;
1020 DEBUG ("call-history (0x%x): %d, prev: [%u; %u)", flags
, size
,
1021 btrace_call_number (&begin
), btrace_call_number (&end
));
1026 covered
= btrace_call_prev (&begin
, context
);
1031 covered
= btrace_call_next (&end
, context
);
1036 btrace_call_history (uiout
, btinfo
, &begin
, &end
, flags
);
1040 printf_unfiltered (_("At the start of the branch trace record.\n"));
1042 printf_unfiltered (_("At the end of the branch trace record.\n"));
1045 btrace_set_call_history (btinfo
, &begin
, &end
);
1046 do_cleanups (uiout_cleanup
);
1049 /* The to_call_history_range method of target record-btrace. */
1052 record_btrace_call_history_range (struct target_ops
*self
,
1053 ULONGEST from
, ULONGEST to
, int flags
)
1055 struct btrace_thread_info
*btinfo
;
1056 struct btrace_call_history
*history
;
1057 struct btrace_call_iterator begin
, end
;
1058 struct cleanup
*uiout_cleanup
;
1059 struct ui_out
*uiout
;
1060 unsigned int low
, high
;
1063 uiout
= current_uiout
;
1064 uiout_cleanup
= make_cleanup_ui_out_tuple_begin_end (uiout
,
1069 DEBUG ("call-history (0x%x): [%u; %u)", flags
, low
, high
);
1071 /* Check for wrap-arounds. */
1072 if (low
!= from
|| high
!= to
)
1073 error (_("Bad range."));
1076 error (_("Bad range."));
1078 btinfo
= require_btrace ();
1080 found
= btrace_find_call_by_number (&begin
, btinfo
, low
);
1082 error (_("Range out of bounds."));
1084 found
= btrace_find_call_by_number (&end
, btinfo
, high
);
1087 /* Silently truncate the range. */
1088 btrace_call_end (&end
, btinfo
);
1092 /* We want both begin and end to be inclusive. */
1093 btrace_call_next (&end
, 1);
1096 btrace_call_history (uiout
, btinfo
, &begin
, &end
, flags
);
1097 btrace_set_call_history (btinfo
, &begin
, &end
);
1099 do_cleanups (uiout_cleanup
);
1102 /* The to_call_history_from method of target record-btrace. */
1105 record_btrace_call_history_from (struct target_ops
*self
,
1106 ULONGEST from
, int size
, int flags
)
1108 ULONGEST begin
, end
, context
;
1110 context
= abs (size
);
1112 error (_("Bad record function-call-history-size."));
1121 begin
= from
- context
+ 1;
1126 end
= from
+ context
- 1;
1128 /* Check for wrap-around. */
1133 record_btrace_call_history_range (self
, begin
, end
, flags
);
1136 /* The to_record_is_replaying method of target record-btrace. */
1139 record_btrace_is_replaying (struct target_ops
*self
, ptid_t ptid
)
1141 struct thread_info
*tp
;
1143 ALL_NON_EXITED_THREADS (tp
)
1144 if (ptid_match (tp
->ptid
, ptid
) && btrace_is_replaying (tp
))
1150 /* The to_xfer_partial method of target record-btrace. */
1152 static enum target_xfer_status
1153 record_btrace_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1154 const char *annex
, gdb_byte
*readbuf
,
1155 const gdb_byte
*writebuf
, ULONGEST offset
,
1156 ULONGEST len
, ULONGEST
*xfered_len
)
1158 struct target_ops
*t
;
1160 /* Filter out requests that don't make sense during replay. */
1161 if (replay_memory_access
== replay_memory_access_read_only
1162 && !record_btrace_generating_corefile
1163 && record_btrace_is_replaying (ops
, inferior_ptid
))
1167 case TARGET_OBJECT_MEMORY
:
1169 struct target_section
*section
;
1171 /* We do not allow writing memory in general. */
1172 if (writebuf
!= NULL
)
1175 return TARGET_XFER_UNAVAILABLE
;
1178 /* We allow reading readonly memory. */
1179 section
= target_section_by_addr (ops
, offset
);
1180 if (section
!= NULL
)
1182 /* Check if the section we found is readonly. */
1183 if ((bfd_get_section_flags (section
->the_bfd_section
->owner
,
1184 section
->the_bfd_section
)
1185 & SEC_READONLY
) != 0)
1187 /* Truncate the request to fit into this section. */
1188 len
= min (len
, section
->endaddr
- offset
);
1194 return TARGET_XFER_UNAVAILABLE
;
1199 /* Forward the request. */
1201 return ops
->to_xfer_partial (ops
, object
, annex
, readbuf
, writebuf
,
1202 offset
, len
, xfered_len
);
1205 /* The to_insert_breakpoint method of target record-btrace. */
1208 record_btrace_insert_breakpoint (struct target_ops
*ops
,
1209 struct gdbarch
*gdbarch
,
1210 struct bp_target_info
*bp_tgt
)
1215 /* Inserting breakpoints requires accessing memory. Allow it for the
1216 duration of this function. */
1217 old
= replay_memory_access
;
1218 replay_memory_access
= replay_memory_access_read_write
;
1223 ret
= ops
->beneath
->to_insert_breakpoint (ops
->beneath
, gdbarch
, bp_tgt
);
1225 CATCH (except
, RETURN_MASK_ALL
)
1227 replay_memory_access
= old
;
1228 throw_exception (except
);
1231 replay_memory_access
= old
;
1236 /* The to_remove_breakpoint method of target record-btrace. */
1239 record_btrace_remove_breakpoint (struct target_ops
*ops
,
1240 struct gdbarch
*gdbarch
,
1241 struct bp_target_info
*bp_tgt
)
1246 /* Removing breakpoints requires accessing memory. Allow it for the
1247 duration of this function. */
1248 old
= replay_memory_access
;
1249 replay_memory_access
= replay_memory_access_read_write
;
1254 ret
= ops
->beneath
->to_remove_breakpoint (ops
->beneath
, gdbarch
, bp_tgt
);
1256 CATCH (except
, RETURN_MASK_ALL
)
1258 replay_memory_access
= old
;
1259 throw_exception (except
);
1262 replay_memory_access
= old
;
1267 /* The to_fetch_registers method of target record-btrace. */
1270 record_btrace_fetch_registers (struct target_ops
*ops
,
1271 struct regcache
*regcache
, int regno
)
1273 struct btrace_insn_iterator
*replay
;
1274 struct thread_info
*tp
;
1276 tp
= find_thread_ptid (inferior_ptid
);
1277 gdb_assert (tp
!= NULL
);
1279 replay
= tp
->btrace
.replay
;
1280 if (replay
!= NULL
&& !record_btrace_generating_corefile
)
1282 const struct btrace_insn
*insn
;
1283 struct gdbarch
*gdbarch
;
1286 gdbarch
= get_regcache_arch (regcache
);
1287 pcreg
= gdbarch_pc_regnum (gdbarch
);
1291 /* We can only provide the PC register. */
1292 if (regno
>= 0 && regno
!= pcreg
)
1295 insn
= btrace_insn_get (replay
);
1296 gdb_assert (insn
!= NULL
);
1298 regcache_raw_supply (regcache
, regno
, &insn
->pc
);
1302 struct target_ops
*t
= ops
->beneath
;
1304 t
->to_fetch_registers (t
, regcache
, regno
);
1308 /* The to_store_registers method of target record-btrace. */
1311 record_btrace_store_registers (struct target_ops
*ops
,
1312 struct regcache
*regcache
, int regno
)
1314 struct target_ops
*t
;
1316 if (!record_btrace_generating_corefile
1317 && record_btrace_is_replaying (ops
, inferior_ptid
))
1318 error (_("Cannot write registers while replaying."));
1320 gdb_assert (may_write_registers
!= 0);
1323 t
->to_store_registers (t
, regcache
, regno
);
1326 /* The to_prepare_to_store method of target record-btrace. */
1329 record_btrace_prepare_to_store (struct target_ops
*ops
,
1330 struct regcache
*regcache
)
1332 struct target_ops
*t
;
1334 if (!record_btrace_generating_corefile
1335 && record_btrace_is_replaying (ops
, inferior_ptid
))
1339 t
->to_prepare_to_store (t
, regcache
);
1342 /* The branch trace frame cache. */
1344 struct btrace_frame_cache
1347 struct thread_info
*tp
;
1349 /* The frame info. */
1350 struct frame_info
*frame
;
1352 /* The branch trace function segment. */
1353 const struct btrace_function
*bfun
;
1356 /* A struct btrace_frame_cache hash table indexed by NEXT. */
1358 static htab_t bfcache
;
1360 /* hash_f for htab_create_alloc of bfcache. */
1363 bfcache_hash (const void *arg
)
1365 const struct btrace_frame_cache
*cache
= arg
;
1367 return htab_hash_pointer (cache
->frame
);
1370 /* eq_f for htab_create_alloc of bfcache. */
1373 bfcache_eq (const void *arg1
, const void *arg2
)
1375 const struct btrace_frame_cache
*cache1
= arg1
;
1376 const struct btrace_frame_cache
*cache2
= arg2
;
1378 return cache1
->frame
== cache2
->frame
;
1381 /* Create a new btrace frame cache. */
1383 static struct btrace_frame_cache
*
1384 bfcache_new (struct frame_info
*frame
)
1386 struct btrace_frame_cache
*cache
;
1389 cache
= FRAME_OBSTACK_ZALLOC (struct btrace_frame_cache
);
1390 cache
->frame
= frame
;
1392 slot
= htab_find_slot (bfcache
, cache
, INSERT
);
1393 gdb_assert (*slot
== NULL
);
1399 /* Extract the branch trace function from a branch trace frame. */
1401 static const struct btrace_function
*
1402 btrace_get_frame_function (struct frame_info
*frame
)
1404 const struct btrace_frame_cache
*cache
;
1405 const struct btrace_function
*bfun
;
1406 struct btrace_frame_cache pattern
;
1409 pattern
.frame
= frame
;
1411 slot
= htab_find_slot (bfcache
, &pattern
, NO_INSERT
);
1419 /* Implement stop_reason method for record_btrace_frame_unwind. */
1421 static enum unwind_stop_reason
1422 record_btrace_frame_unwind_stop_reason (struct frame_info
*this_frame
,
1425 const struct btrace_frame_cache
*cache
;
1426 const struct btrace_function
*bfun
;
1428 cache
= *this_cache
;
1430 gdb_assert (bfun
!= NULL
);
1432 if (bfun
->up
== NULL
)
1433 return UNWIND_UNAVAILABLE
;
1435 return UNWIND_NO_REASON
;
1438 /* Implement this_id method for record_btrace_frame_unwind. */
1441 record_btrace_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
1442 struct frame_id
*this_id
)
1444 const struct btrace_frame_cache
*cache
;
1445 const struct btrace_function
*bfun
;
1446 CORE_ADDR code
, special
;
1448 cache
= *this_cache
;
1451 gdb_assert (bfun
!= NULL
);
1453 while (bfun
->segment
.prev
!= NULL
)
1454 bfun
= bfun
->segment
.prev
;
1456 code
= get_frame_func (this_frame
);
1457 special
= bfun
->number
;
1459 *this_id
= frame_id_build_unavailable_stack_special (code
, special
);
1461 DEBUG ("[frame] %s id: (!stack, pc=%s, special=%s)",
1462 btrace_get_bfun_name (cache
->bfun
),
1463 core_addr_to_string_nz (this_id
->code_addr
),
1464 core_addr_to_string_nz (this_id
->special_addr
));
1467 /* Implement prev_register method for record_btrace_frame_unwind. */
1469 static struct value
*
1470 record_btrace_frame_prev_register (struct frame_info
*this_frame
,
1474 const struct btrace_frame_cache
*cache
;
1475 const struct btrace_function
*bfun
, *caller
;
1476 const struct btrace_insn
*insn
;
1477 struct gdbarch
*gdbarch
;
1481 gdbarch
= get_frame_arch (this_frame
);
1482 pcreg
= gdbarch_pc_regnum (gdbarch
);
1483 if (pcreg
< 0 || regnum
!= pcreg
)
1484 throw_error (NOT_AVAILABLE_ERROR
,
1485 _("Registers are not available in btrace record history"));
1487 cache
= *this_cache
;
1489 gdb_assert (bfun
!= NULL
);
1493 throw_error (NOT_AVAILABLE_ERROR
,
1494 _("No caller in btrace record history"));
1496 if ((bfun
->flags
& BFUN_UP_LINKS_TO_RET
) != 0)
1498 insn
= VEC_index (btrace_insn_s
, caller
->insn
, 0);
1503 insn
= VEC_last (btrace_insn_s
, caller
->insn
);
1506 pc
+= gdb_insn_length (gdbarch
, pc
);
1509 DEBUG ("[frame] unwound PC in %s on level %d: %s",
1510 btrace_get_bfun_name (bfun
), bfun
->level
,
1511 core_addr_to_string_nz (pc
));
1513 return frame_unwind_got_address (this_frame
, regnum
, pc
);
1516 /* Implement sniffer method for record_btrace_frame_unwind. */
1519 record_btrace_frame_sniffer (const struct frame_unwind
*self
,
1520 struct frame_info
*this_frame
,
1523 const struct btrace_function
*bfun
;
1524 struct btrace_frame_cache
*cache
;
1525 struct thread_info
*tp
;
1526 struct frame_info
*next
;
1528 /* THIS_FRAME does not contain a reference to its thread. */
1529 tp
= find_thread_ptid (inferior_ptid
);
1530 gdb_assert (tp
!= NULL
);
1533 next
= get_next_frame (this_frame
);
1536 const struct btrace_insn_iterator
*replay
;
1538 replay
= tp
->btrace
.replay
;
1540 bfun
= replay
->function
;
1544 const struct btrace_function
*callee
;
1546 callee
= btrace_get_frame_function (next
);
1547 if (callee
!= NULL
&& (callee
->flags
& BFUN_UP_LINKS_TO_TAILCALL
) == 0)
1554 DEBUG ("[frame] sniffed frame for %s on level %d",
1555 btrace_get_bfun_name (bfun
), bfun
->level
);
1557 /* This is our frame. Initialize the frame cache. */
1558 cache
= bfcache_new (this_frame
);
1562 *this_cache
= cache
;
1566 /* Implement sniffer method for record_btrace_tailcall_frame_unwind. */
1569 record_btrace_tailcall_frame_sniffer (const struct frame_unwind
*self
,
1570 struct frame_info
*this_frame
,
1573 const struct btrace_function
*bfun
, *callee
;
1574 struct btrace_frame_cache
*cache
;
1575 struct frame_info
*next
;
1577 next
= get_next_frame (this_frame
);
1581 callee
= btrace_get_frame_function (next
);
1585 if ((callee
->flags
& BFUN_UP_LINKS_TO_TAILCALL
) == 0)
1592 DEBUG ("[frame] sniffed tailcall frame for %s on level %d",
1593 btrace_get_bfun_name (bfun
), bfun
->level
);
1595 /* This is our frame. Initialize the frame cache. */
1596 cache
= bfcache_new (this_frame
);
1597 cache
->tp
= find_thread_ptid (inferior_ptid
);
1600 *this_cache
= cache
;
1605 record_btrace_frame_dealloc_cache (struct frame_info
*self
, void *this_cache
)
1607 struct btrace_frame_cache
*cache
;
1612 slot
= htab_find_slot (bfcache
, cache
, NO_INSERT
);
1613 gdb_assert (slot
!= NULL
);
1615 htab_remove_elt (bfcache
, cache
);
1618 /* btrace recording does not store previous memory content, neither the stack
1619 frames content. Any unwinding would return errorneous results as the stack
1620 contents no longer matches the changed PC value restored from history.
1621 Therefore this unwinder reports any possibly unwound registers as
1624 const struct frame_unwind record_btrace_frame_unwind
=
1627 record_btrace_frame_unwind_stop_reason
,
1628 record_btrace_frame_this_id
,
1629 record_btrace_frame_prev_register
,
1631 record_btrace_frame_sniffer
,
1632 record_btrace_frame_dealloc_cache
1635 const struct frame_unwind record_btrace_tailcall_frame_unwind
=
1638 record_btrace_frame_unwind_stop_reason
,
1639 record_btrace_frame_this_id
,
1640 record_btrace_frame_prev_register
,
1642 record_btrace_tailcall_frame_sniffer
,
1643 record_btrace_frame_dealloc_cache
1646 /* Implement the to_get_unwinder method. */
1648 static const struct frame_unwind
*
1649 record_btrace_to_get_unwinder (struct target_ops
*self
)
1651 return &record_btrace_frame_unwind
;
1654 /* Implement the to_get_tailcall_unwinder method. */
1656 static const struct frame_unwind
*
1657 record_btrace_to_get_tailcall_unwinder (struct target_ops
*self
)
1659 return &record_btrace_tailcall_frame_unwind
;
1662 /* Return a human-readable string for FLAG. */
1665 btrace_thread_flag_to_str (enum btrace_thread_flag flag
)
1673 return "reverse-step";
1679 return "reverse-cont";
1688 /* Indicate that TP should be resumed according to FLAG. */
1691 record_btrace_resume_thread (struct thread_info
*tp
,
1692 enum btrace_thread_flag flag
)
1694 struct btrace_thread_info
*btinfo
;
1696 DEBUG ("resuming thread %d (%s): %x (%s)", tp
->num
,
1697 target_pid_to_str (tp
->ptid
), flag
, btrace_thread_flag_to_str (flag
));
1699 btinfo
= &tp
->btrace
;
1701 /* Fetch the latest branch trace. */
1704 /* A resume request overwrites a preceding resume or stop request. */
1705 btinfo
->flags
&= ~(BTHR_MOVE
| BTHR_STOP
);
1706 btinfo
->flags
|= flag
;
1709 /* Get the current frame for TP. */
1711 static struct frame_info
*
1712 get_thread_current_frame (struct thread_info
*tp
)
1714 struct frame_info
*frame
;
1715 ptid_t old_inferior_ptid
;
1718 /* Set INFERIOR_PTID, which is implicitly used by get_current_frame. */
1719 old_inferior_ptid
= inferior_ptid
;
1720 inferior_ptid
= tp
->ptid
;
1722 /* Clear the executing flag to allow changes to the current frame.
1723 We are not actually running, yet. We just started a reverse execution
1724 command or a record goto command.
1725 For the latter, EXECUTING is false and this has no effect.
1726 For the former, EXECUTING is true and we're in to_wait, about to
1727 move the thread. Since we need to recompute the stack, we temporarily
1728 set EXECUTING to flase. */
1729 executing
= is_executing (inferior_ptid
);
1730 set_executing (inferior_ptid
, 0);
1735 frame
= get_current_frame ();
1737 CATCH (except
, RETURN_MASK_ALL
)
1739 /* Restore the previous execution state. */
1740 set_executing (inferior_ptid
, executing
);
1742 /* Restore the previous inferior_ptid. */
1743 inferior_ptid
= old_inferior_ptid
;
1745 throw_exception (except
);
1749 /* Restore the previous execution state. */
1750 set_executing (inferior_ptid
, executing
);
1752 /* Restore the previous inferior_ptid. */
1753 inferior_ptid
= old_inferior_ptid
;
1758 /* Start replaying a thread. */
1760 static struct btrace_insn_iterator
*
1761 record_btrace_start_replaying (struct thread_info
*tp
)
1763 struct btrace_insn_iterator
*replay
;
1764 struct btrace_thread_info
*btinfo
;
1766 btinfo
= &tp
->btrace
;
1769 /* We can't start replaying without trace. */
1770 if (btinfo
->begin
== NULL
)
1773 /* GDB stores the current frame_id when stepping in order to detects steps
1775 Since frames are computed differently when we're replaying, we need to
1776 recompute those stored frames and fix them up so we can still detect
1777 subroutines after we started replaying. */
1780 struct frame_info
*frame
;
1781 struct frame_id frame_id
;
1782 int upd_step_frame_id
, upd_step_stack_frame_id
;
1784 /* The current frame without replaying - computed via normal unwind. */
1785 frame
= get_thread_current_frame (tp
);
1786 frame_id
= get_frame_id (frame
);
1788 /* Check if we need to update any stepping-related frame id's. */
1789 upd_step_frame_id
= frame_id_eq (frame_id
,
1790 tp
->control
.step_frame_id
);
1791 upd_step_stack_frame_id
= frame_id_eq (frame_id
,
1792 tp
->control
.step_stack_frame_id
);
1794 /* We start replaying at the end of the branch trace. This corresponds
1795 to the current instruction. */
1796 replay
= XNEW (struct btrace_insn_iterator
);
1797 btrace_insn_end (replay
, btinfo
);
1799 /* Skip gaps at the end of the trace. */
1800 while (btrace_insn_get (replay
) == NULL
)
1804 steps
= btrace_insn_prev (replay
, 1);
1806 error (_("No trace."));
1809 /* We're not replaying, yet. */
1810 gdb_assert (btinfo
->replay
== NULL
);
1811 btinfo
->replay
= replay
;
1813 /* Make sure we're not using any stale registers. */
1814 registers_changed_ptid (tp
->ptid
);
1816 /* The current frame with replaying - computed via btrace unwind. */
1817 frame
= get_thread_current_frame (tp
);
1818 frame_id
= get_frame_id (frame
);
1820 /* Replace stepping related frames where necessary. */
1821 if (upd_step_frame_id
)
1822 tp
->control
.step_frame_id
= frame_id
;
1823 if (upd_step_stack_frame_id
)
1824 tp
->control
.step_stack_frame_id
= frame_id
;
1826 CATCH (except
, RETURN_MASK_ALL
)
1828 xfree (btinfo
->replay
);
1829 btinfo
->replay
= NULL
;
1831 registers_changed_ptid (tp
->ptid
);
1833 throw_exception (except
);
1840 /* Stop replaying a thread. */
1843 record_btrace_stop_replaying (struct thread_info
*tp
)
1845 struct btrace_thread_info
*btinfo
;
1847 btinfo
= &tp
->btrace
;
1849 xfree (btinfo
->replay
);
1850 btinfo
->replay
= NULL
;
1852 /* Make sure we're not leaving any stale registers. */
1853 registers_changed_ptid (tp
->ptid
);
1856 /* Stop replaying TP if it is at the end of its execution history. */
1859 record_btrace_stop_replaying_at_end (struct thread_info
*tp
)
1861 struct btrace_insn_iterator
*replay
, end
;
1862 struct btrace_thread_info
*btinfo
;
1864 btinfo
= &tp
->btrace
;
1865 replay
= btinfo
->replay
;
1870 btrace_insn_end (&end
, btinfo
);
1872 if (btrace_insn_cmp (replay
, &end
) == 0)
1873 record_btrace_stop_replaying (tp
);
1876 /* The to_resume method of target record-btrace. */
1879 record_btrace_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
1880 enum gdb_signal signal
)
1882 struct thread_info
*tp
;
1883 enum btrace_thread_flag flag
;
1886 DEBUG ("resume %s: %s%s", target_pid_to_str (ptid
),
1887 execution_direction
== EXEC_REVERSE
? "reverse-" : "",
1888 step
? "step" : "cont");
1892 /* Store the execution direction of the last resume.
1894 If there is more than one to_resume call, we have to rely on infrun
1895 to not change the execution direction in-between. */
1896 record_btrace_resume_exec_dir
= execution_direction
;
1898 /* For all-stop targets... */
1899 if (!target_is_non_stop_p ())
1901 /* ...we pick the current thread when asked to resume an entire process
1903 if (ptid_equal (minus_one_ptid
, ptid
) || ptid_is_pid (ptid
))
1904 ptid
= inferior_ptid
;
1906 tp
= find_thread_ptid (ptid
);
1908 error (_("Cannot find thread to resume."));
1910 /* ...and we stop replaying other threads if the thread to resume is not
1912 if (!btrace_is_replaying (tp
) && execution_direction
!= EXEC_REVERSE
)
1913 target_record_stop_replaying ();
1916 /* As long as we're not replaying, just forward the request.
1918 For non-stop targets this means that no thread is replaying. In order to
1919 make progress, we may need to explicitly move replaying threads to the end
1920 of their execution history. */
1921 if ((execution_direction
!= EXEC_REVERSE
)
1922 && !record_btrace_is_replaying (ops
, minus_one_ptid
))
1925 return ops
->to_resume (ops
, orig_ptid
, step
, signal
);
1928 /* Compute the btrace thread flag for the requested move. */
1930 flag
= execution_direction
== EXEC_REVERSE
? BTHR_RCONT
: BTHR_CONT
;
1932 flag
= execution_direction
== EXEC_REVERSE
? BTHR_RSTEP
: BTHR_STEP
;
1934 /* We just indicate the resume intent here. The actual stepping happens in
1935 record_btrace_wait below. */
1936 ALL_NON_EXITED_THREADS (tp
)
1937 if (ptid_match (tp
->ptid
, ptid
))
1938 record_btrace_resume_thread (tp
, flag
);
1940 /* Async support. */
1941 if (target_can_async_p ())
1944 mark_async_event_handler (record_btrace_async_inferior_event_handler
);
1948 /* Cancel resuming TP. */
1951 record_btrace_cancel_resume (struct thread_info
*tp
)
1953 enum btrace_thread_flag flags
;
1955 flags
= tp
->btrace
.flags
& (BTHR_MOVE
| BTHR_STOP
);
1959 DEBUG ("cancel resume thread %d (%s): %x (%s)", tp
->num
,
1960 target_pid_to_str (tp
->ptid
), flags
,
1961 btrace_thread_flag_to_str (flags
));
1963 tp
->btrace
.flags
&= ~(BTHR_MOVE
| BTHR_STOP
);
1964 record_btrace_stop_replaying_at_end (tp
);
1967 /* Return a target_waitstatus indicating that we ran out of history. */
1969 static struct target_waitstatus
1970 btrace_step_no_history (void)
1972 struct target_waitstatus status
;
1974 status
.kind
= TARGET_WAITKIND_NO_HISTORY
;
1979 /* Return a target_waitstatus indicating that a step finished. */
1981 static struct target_waitstatus
1982 btrace_step_stopped (void)
1984 struct target_waitstatus status
;
1986 status
.kind
= TARGET_WAITKIND_STOPPED
;
1987 status
.value
.sig
= GDB_SIGNAL_TRAP
;
1992 /* Return a target_waitstatus indicating that a thread was stopped as
1995 static struct target_waitstatus
1996 btrace_step_stopped_on_request (void)
1998 struct target_waitstatus status
;
2000 status
.kind
= TARGET_WAITKIND_STOPPED
;
2001 status
.value
.sig
= GDB_SIGNAL_0
;
2006 /* Return a target_waitstatus indicating a spurious stop. */
2008 static struct target_waitstatus
2009 btrace_step_spurious (void)
2011 struct target_waitstatus status
;
2013 status
.kind
= TARGET_WAITKIND_SPURIOUS
;
2018 /* Return a target_waitstatus indicating that the thread was not resumed. */
2020 static struct target_waitstatus
2021 btrace_step_no_resumed (void)
2023 struct target_waitstatus status
;
2025 status
.kind
= TARGET_WAITKIND_NO_RESUMED
;
2030 /* Return a target_waitstatus indicating that we should wait again. */
2032 static struct target_waitstatus
2033 btrace_step_again (void)
2035 struct target_waitstatus status
;
2037 status
.kind
= TARGET_WAITKIND_IGNORE
;
2042 /* Clear the record histories. */
2045 record_btrace_clear_histories (struct btrace_thread_info
*btinfo
)
2047 xfree (btinfo
->insn_history
);
2048 xfree (btinfo
->call_history
);
2050 btinfo
->insn_history
= NULL
;
2051 btinfo
->call_history
= NULL
;
2054 /* Check whether TP's current replay position is at a breakpoint. */
2057 record_btrace_replay_at_breakpoint (struct thread_info
*tp
)
2059 struct btrace_insn_iterator
*replay
;
2060 struct btrace_thread_info
*btinfo
;
2061 const struct btrace_insn
*insn
;
2062 struct inferior
*inf
;
2064 btinfo
= &tp
->btrace
;
2065 replay
= btinfo
->replay
;
2070 insn
= btrace_insn_get (replay
);
2074 inf
= find_inferior_ptid (tp
->ptid
);
2078 return record_check_stopped_by_breakpoint (inf
->aspace
, insn
->pc
,
2079 &btinfo
->stop_reason
);
2082 /* Step one instruction in forward direction. */
2084 static struct target_waitstatus
2085 record_btrace_single_step_forward (struct thread_info
*tp
)
2087 struct btrace_insn_iterator
*replay
, end
;
2088 struct btrace_thread_info
*btinfo
;
2090 btinfo
= &tp
->btrace
;
2091 replay
= btinfo
->replay
;
2093 /* We're done if we're not replaying. */
2095 return btrace_step_no_history ();
2097 /* Check if we're stepping a breakpoint. */
2098 if (record_btrace_replay_at_breakpoint (tp
))
2099 return btrace_step_stopped ();
2101 /* Skip gaps during replay. */
2106 /* We will bail out here if we continue stepping after reaching the end
2107 of the execution history. */
2108 steps
= btrace_insn_next (replay
, 1);
2110 return btrace_step_no_history ();
2112 while (btrace_insn_get (replay
) == NULL
);
2114 /* Determine the end of the instruction trace. */
2115 btrace_insn_end (&end
, btinfo
);
2117 /* The execution trace contains (and ends with) the current instruction.
2118 This instruction has not been executed, yet, so the trace really ends
2119 one instruction earlier. */
2120 if (btrace_insn_cmp (replay
, &end
) == 0)
2121 return btrace_step_no_history ();
2123 return btrace_step_spurious ();
2126 /* Step one instruction in backward direction. */
2128 static struct target_waitstatus
2129 record_btrace_single_step_backward (struct thread_info
*tp
)
2131 struct btrace_insn_iterator
*replay
;
2132 struct btrace_thread_info
*btinfo
;
2134 btinfo
= &tp
->btrace
;
2135 replay
= btinfo
->replay
;
2137 /* Start replaying if we're not already doing so. */
2139 replay
= record_btrace_start_replaying (tp
);
2141 /* If we can't step any further, we reached the end of the history.
2142 Skip gaps during replay. */
2147 steps
= btrace_insn_prev (replay
, 1);
2149 return btrace_step_no_history ();
2151 while (btrace_insn_get (replay
) == NULL
);
2153 /* Check if we're stepping a breakpoint.
2155 For reverse-stepping, this check is after the step. There is logic in
2156 infrun.c that handles reverse-stepping separately. See, for example,
2157 proceed and adjust_pc_after_break.
2159 This code assumes that for reverse-stepping, PC points to the last
2160 de-executed instruction, whereas for forward-stepping PC points to the
2161 next to-be-executed instruction. */
2162 if (record_btrace_replay_at_breakpoint (tp
))
2163 return btrace_step_stopped ();
2165 return btrace_step_spurious ();
2168 /* Step a single thread. */
2170 static struct target_waitstatus
2171 record_btrace_step_thread (struct thread_info
*tp
)
2173 struct btrace_thread_info
*btinfo
;
2174 struct target_waitstatus status
;
2175 enum btrace_thread_flag flags
;
2177 btinfo
= &tp
->btrace
;
2179 flags
= btinfo
->flags
& (BTHR_MOVE
| BTHR_STOP
);
2180 btinfo
->flags
&= ~(BTHR_MOVE
| BTHR_STOP
);
2182 DEBUG ("stepping thread %d (%s): %x (%s)", tp
->num
,
2183 target_pid_to_str (tp
->ptid
), flags
,
2184 btrace_thread_flag_to_str (flags
));
2186 /* We can't step without an execution history. */
2187 if ((flags
& BTHR_MOVE
) != 0 && btrace_is_empty (tp
))
2188 return btrace_step_no_history ();
2193 internal_error (__FILE__
, __LINE__
, _("invalid stepping type."));
2196 return btrace_step_stopped_on_request ();
2199 status
= record_btrace_single_step_forward (tp
);
2200 if (status
.kind
!= TARGET_WAITKIND_SPURIOUS
)
2203 return btrace_step_stopped ();
2206 status
= record_btrace_single_step_backward (tp
);
2207 if (status
.kind
!= TARGET_WAITKIND_SPURIOUS
)
2210 return btrace_step_stopped ();
2213 status
= record_btrace_single_step_forward (tp
);
2214 if (status
.kind
!= TARGET_WAITKIND_SPURIOUS
)
2217 btinfo
->flags
|= flags
;
2218 return btrace_step_again ();
2221 status
= record_btrace_single_step_backward (tp
);
2222 if (status
.kind
!= TARGET_WAITKIND_SPURIOUS
)
2225 btinfo
->flags
|= flags
;
2226 return btrace_step_again ();
2229 /* We keep threads moving at the end of their execution history. The to_wait
2230 method will stop the thread for whom the event is reported. */
2231 if (status
.kind
== TARGET_WAITKIND_NO_HISTORY
)
2232 btinfo
->flags
|= flags
;
2237 /* A vector of threads. */
2239 typedef struct thread_info
* tp_t
;
2242 /* Announce further events if necessary. */
2245 record_btrace_maybe_mark_async_event (const VEC (tp_t
) *moving
,
2246 const VEC (tp_t
) *no_history
)
2248 int more_moving
, more_no_history
;
2250 more_moving
= !VEC_empty (tp_t
, moving
);
2251 more_no_history
= !VEC_empty (tp_t
, no_history
);
2253 if (!more_moving
&& !more_no_history
)
2257 DEBUG ("movers pending");
2259 if (more_no_history
)
2260 DEBUG ("no-history pending");
2262 mark_async_event_handler (record_btrace_async_inferior_event_handler
);
2265 /* The to_wait method of target record-btrace. */
2268 record_btrace_wait (struct target_ops
*ops
, ptid_t ptid
,
2269 struct target_waitstatus
*status
, int options
)
2271 VEC (tp_t
) *moving
, *no_history
;
2272 struct thread_info
*tp
, *eventing
;
2273 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
2275 DEBUG ("wait %s (0x%x)", target_pid_to_str (ptid
), options
);
2277 /* As long as we're not replaying, just forward the request. */
2278 if ((execution_direction
!= EXEC_REVERSE
)
2279 && !record_btrace_is_replaying (ops
, minus_one_ptid
))
2282 return ops
->to_wait (ops
, ptid
, status
, options
);
2288 make_cleanup (VEC_cleanup (tp_t
), &moving
);
2289 make_cleanup (VEC_cleanup (tp_t
), &no_history
);
2291 /* Keep a work list of moving threads. */
2292 ALL_NON_EXITED_THREADS (tp
)
2293 if (ptid_match (tp
->ptid
, ptid
)
2294 && ((tp
->btrace
.flags
& (BTHR_MOVE
| BTHR_STOP
)) != 0))
2295 VEC_safe_push (tp_t
, moving
, tp
);
2297 if (VEC_empty (tp_t
, moving
))
2299 *status
= btrace_step_no_resumed ();
2301 DEBUG ("wait ended by %s: %s", target_pid_to_str (null_ptid
),
2302 target_waitstatus_to_string (status
));
2304 do_cleanups (cleanups
);
2308 /* Step moving threads one by one, one step each, until either one thread
2309 reports an event or we run out of threads to step.
2311 When stepping more than one thread, chances are that some threads reach
2312 the end of their execution history earlier than others. If we reported
2313 this immediately, all-stop on top of non-stop would stop all threads and
2314 resume the same threads next time. And we would report the same thread
2315 having reached the end of its execution history again.
2317 In the worst case, this would starve the other threads. But even if other
2318 threads would be allowed to make progress, this would result in far too
2319 many intermediate stops.
2321 We therefore delay the reporting of "no execution history" until we have
2322 nothing else to report. By this time, all threads should have moved to
2323 either the beginning or the end of their execution history. There will
2324 be a single user-visible stop. */
2326 while ((eventing
== NULL
) && !VEC_empty (tp_t
, moving
))
2331 while ((eventing
== NULL
) && VEC_iterate (tp_t
, moving
, ix
, tp
))
2333 *status
= record_btrace_step_thread (tp
);
2335 switch (status
->kind
)
2337 case TARGET_WAITKIND_IGNORE
:
2341 case TARGET_WAITKIND_NO_HISTORY
:
2342 VEC_safe_push (tp_t
, no_history
,
2343 VEC_ordered_remove (tp_t
, moving
, ix
));
2347 eventing
= VEC_unordered_remove (tp_t
, moving
, ix
);
2353 if (eventing
== NULL
)
2355 /* We started with at least one moving thread. This thread must have
2356 either stopped or reached the end of its execution history.
2358 In the former case, EVENTING must not be NULL.
2359 In the latter case, NO_HISTORY must not be empty. */
2360 gdb_assert (!VEC_empty (tp_t
, no_history
));
2362 /* We kept threads moving at the end of their execution history. Stop
2363 EVENTING now that we are going to report its stop. */
2364 eventing
= VEC_unordered_remove (tp_t
, no_history
, 0);
2365 eventing
->btrace
.flags
&= ~BTHR_MOVE
;
2367 *status
= btrace_step_no_history ();
2370 gdb_assert (eventing
!= NULL
);
2372 /* We kept threads replaying at the end of their execution history. Stop
2373 replaying EVENTING now that we are going to report its stop. */
2374 record_btrace_stop_replaying_at_end (eventing
);
2376 /* Stop all other threads. */
2377 if (!target_is_non_stop_p ())
2378 ALL_NON_EXITED_THREADS (tp
)
2379 record_btrace_cancel_resume (tp
);
2381 /* In async mode, we need to announce further events. */
2382 if (target_is_async_p ())
2383 record_btrace_maybe_mark_async_event (moving
, no_history
);
2385 /* Start record histories anew from the current position. */
2386 record_btrace_clear_histories (&eventing
->btrace
);
2388 /* We moved the replay position but did not update registers. */
2389 registers_changed_ptid (eventing
->ptid
);
2391 DEBUG ("wait ended by thread %d (%s): %s", eventing
->num
,
2392 target_pid_to_str (eventing
->ptid
),
2393 target_waitstatus_to_string (status
));
2395 do_cleanups (cleanups
);
2396 return eventing
->ptid
;
2399 /* The to_stop method of target record-btrace. */
2402 record_btrace_stop (struct target_ops
*ops
, ptid_t ptid
)
2404 DEBUG ("stop %s", target_pid_to_str (ptid
));
2406 /* As long as we're not replaying, just forward the request. */
2407 if ((execution_direction
!= EXEC_REVERSE
)
2408 && !record_btrace_is_replaying (ops
, minus_one_ptid
))
2411 ops
->to_stop (ops
, ptid
);
2415 struct thread_info
*tp
;
2417 ALL_NON_EXITED_THREADS (tp
)
2418 if (ptid_match (tp
->ptid
, ptid
))
2420 tp
->btrace
.flags
&= ~BTHR_MOVE
;
2421 tp
->btrace
.flags
|= BTHR_STOP
;
2426 /* The to_can_execute_reverse method of target record-btrace. */
2429 record_btrace_can_execute_reverse (struct target_ops
*self
)
2434 /* The to_stopped_by_sw_breakpoint method of target record-btrace. */
2437 record_btrace_stopped_by_sw_breakpoint (struct target_ops
*ops
)
2439 if (record_btrace_is_replaying (ops
, minus_one_ptid
))
2441 struct thread_info
*tp
= inferior_thread ();
2443 return tp
->btrace
.stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
2446 return ops
->beneath
->to_stopped_by_sw_breakpoint (ops
->beneath
);
2449 /* The to_supports_stopped_by_sw_breakpoint method of target
2453 record_btrace_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
2455 if (record_btrace_is_replaying (ops
, minus_one_ptid
))
2458 return ops
->beneath
->to_supports_stopped_by_sw_breakpoint (ops
->beneath
);
2461 /* The to_stopped_by_sw_breakpoint method of target record-btrace. */
2464 record_btrace_stopped_by_hw_breakpoint (struct target_ops
*ops
)
2466 if (record_btrace_is_replaying (ops
, minus_one_ptid
))
2468 struct thread_info
*tp
= inferior_thread ();
2470 return tp
->btrace
.stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
2473 return ops
->beneath
->to_stopped_by_hw_breakpoint (ops
->beneath
);
2476 /* The to_supports_stopped_by_hw_breakpoint method of target
2480 record_btrace_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
2482 if (record_btrace_is_replaying (ops
, minus_one_ptid
))
2485 return ops
->beneath
->to_supports_stopped_by_hw_breakpoint (ops
->beneath
);
2488 /* The to_update_thread_list method of target record-btrace. */
2491 record_btrace_update_thread_list (struct target_ops
*ops
)
2493 /* We don't add or remove threads during replay. */
2494 if (record_btrace_is_replaying (ops
, minus_one_ptid
))
2497 /* Forward the request. */
2499 ops
->to_update_thread_list (ops
);
2502 /* The to_thread_alive method of target record-btrace. */
2505 record_btrace_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2507 /* We don't add or remove threads during replay. */
2508 if (record_btrace_is_replaying (ops
, minus_one_ptid
))
2509 return find_thread_ptid (ptid
) != NULL
;
2511 /* Forward the request. */
2513 return ops
->to_thread_alive (ops
, ptid
);
2516 /* Set the replay branch trace instruction iterator. If IT is NULL, replay
2520 record_btrace_set_replay (struct thread_info
*tp
,
2521 const struct btrace_insn_iterator
*it
)
2523 struct btrace_thread_info
*btinfo
;
2525 btinfo
= &tp
->btrace
;
2527 if (it
== NULL
|| it
->function
== NULL
)
2528 record_btrace_stop_replaying (tp
);
2531 if (btinfo
->replay
== NULL
)
2532 record_btrace_start_replaying (tp
);
2533 else if (btrace_insn_cmp (btinfo
->replay
, it
) == 0)
2536 *btinfo
->replay
= *it
;
2537 registers_changed_ptid (tp
->ptid
);
2540 /* Start anew from the new replay position. */
2541 record_btrace_clear_histories (btinfo
);
2543 stop_pc
= regcache_read_pc (get_current_regcache ());
2544 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2547 /* The to_goto_record_begin method of target record-btrace. */
2550 record_btrace_goto_begin (struct target_ops
*self
)
2552 struct thread_info
*tp
;
2553 struct btrace_insn_iterator begin
;
2555 tp
= require_btrace_thread ();
2557 btrace_insn_begin (&begin
, &tp
->btrace
);
2558 record_btrace_set_replay (tp
, &begin
);
2561 /* The to_goto_record_end method of target record-btrace. */
2564 record_btrace_goto_end (struct target_ops
*ops
)
2566 struct thread_info
*tp
;
2568 tp
= require_btrace_thread ();
2570 record_btrace_set_replay (tp
, NULL
);
2573 /* The to_goto_record method of target record-btrace. */
2576 record_btrace_goto (struct target_ops
*self
, ULONGEST insn
)
2578 struct thread_info
*tp
;
2579 struct btrace_insn_iterator it
;
2580 unsigned int number
;
2585 /* Check for wrap-arounds. */
2587 error (_("Instruction number out of range."));
2589 tp
= require_btrace_thread ();
2591 found
= btrace_find_insn_by_number (&it
, &tp
->btrace
, number
);
2593 error (_("No such instruction."));
2595 record_btrace_set_replay (tp
, &it
);
2598 /* The to_record_stop_replaying method of target record-btrace. */
2601 record_btrace_stop_replaying_all (struct target_ops
*self
)
2603 struct thread_info
*tp
;
2605 ALL_NON_EXITED_THREADS (tp
)
2606 record_btrace_stop_replaying (tp
);
2609 /* The to_execution_direction target method. */
2611 static enum exec_direction_kind
2612 record_btrace_execution_direction (struct target_ops
*self
)
2614 return record_btrace_resume_exec_dir
;
2617 /* The to_prepare_to_generate_core target method. */
2620 record_btrace_prepare_to_generate_core (struct target_ops
*self
)
2622 record_btrace_generating_corefile
= 1;
2625 /* The to_done_generating_core target method. */
2628 record_btrace_done_generating_core (struct target_ops
*self
)
2630 record_btrace_generating_corefile
= 0;
2633 /* Initialize the record-btrace target ops. */
2636 init_record_btrace_ops (void)
2638 struct target_ops
*ops
;
2640 ops
= &record_btrace_ops
;
2641 ops
->to_shortname
= "record-btrace";
2642 ops
->to_longname
= "Branch tracing target";
2643 ops
->to_doc
= "Collect control-flow trace and provide the execution history.";
2644 ops
->to_open
= record_btrace_open
;
2645 ops
->to_close
= record_btrace_close
;
2646 ops
->to_async
= record_btrace_async
;
2647 ops
->to_detach
= record_detach
;
2648 ops
->to_disconnect
= record_disconnect
;
2649 ops
->to_mourn_inferior
= record_mourn_inferior
;
2650 ops
->to_kill
= record_kill
;
2651 ops
->to_stop_recording
= record_btrace_stop_recording
;
2652 ops
->to_info_record
= record_btrace_info
;
2653 ops
->to_insn_history
= record_btrace_insn_history
;
2654 ops
->to_insn_history_from
= record_btrace_insn_history_from
;
2655 ops
->to_insn_history_range
= record_btrace_insn_history_range
;
2656 ops
->to_call_history
= record_btrace_call_history
;
2657 ops
->to_call_history_from
= record_btrace_call_history_from
;
2658 ops
->to_call_history_range
= record_btrace_call_history_range
;
2659 ops
->to_record_is_replaying
= record_btrace_is_replaying
;
2660 ops
->to_record_stop_replaying
= record_btrace_stop_replaying_all
;
2661 ops
->to_xfer_partial
= record_btrace_xfer_partial
;
2662 ops
->to_remove_breakpoint
= record_btrace_remove_breakpoint
;
2663 ops
->to_insert_breakpoint
= record_btrace_insert_breakpoint
;
2664 ops
->to_fetch_registers
= record_btrace_fetch_registers
;
2665 ops
->to_store_registers
= record_btrace_store_registers
;
2666 ops
->to_prepare_to_store
= record_btrace_prepare_to_store
;
2667 ops
->to_get_unwinder
= &record_btrace_to_get_unwinder
;
2668 ops
->to_get_tailcall_unwinder
= &record_btrace_to_get_tailcall_unwinder
;
2669 ops
->to_resume
= record_btrace_resume
;
2670 ops
->to_wait
= record_btrace_wait
;
2671 ops
->to_stop
= record_btrace_stop
;
2672 ops
->to_update_thread_list
= record_btrace_update_thread_list
;
2673 ops
->to_thread_alive
= record_btrace_thread_alive
;
2674 ops
->to_goto_record_begin
= record_btrace_goto_begin
;
2675 ops
->to_goto_record_end
= record_btrace_goto_end
;
2676 ops
->to_goto_record
= record_btrace_goto
;
2677 ops
->to_can_execute_reverse
= record_btrace_can_execute_reverse
;
2678 ops
->to_stopped_by_sw_breakpoint
= record_btrace_stopped_by_sw_breakpoint
;
2679 ops
->to_supports_stopped_by_sw_breakpoint
2680 = record_btrace_supports_stopped_by_sw_breakpoint
;
2681 ops
->to_stopped_by_hw_breakpoint
= record_btrace_stopped_by_hw_breakpoint
;
2682 ops
->to_supports_stopped_by_hw_breakpoint
2683 = record_btrace_supports_stopped_by_hw_breakpoint
;
2684 ops
->to_execution_direction
= record_btrace_execution_direction
;
2685 ops
->to_prepare_to_generate_core
= record_btrace_prepare_to_generate_core
;
2686 ops
->to_done_generating_core
= record_btrace_done_generating_core
;
2687 ops
->to_stratum
= record_stratum
;
2688 ops
->to_magic
= OPS_MAGIC
;
2691 /* Start recording in BTS format. */
2694 cmd_record_btrace_bts_start (char *args
, int from_tty
)
2696 if (args
!= NULL
&& *args
!= 0)
2697 error (_("Invalid argument."));
2699 record_btrace_conf
.format
= BTRACE_FORMAT_BTS
;
2703 execute_command ("target record-btrace", from_tty
);
2705 CATCH (exception
, RETURN_MASK_ALL
)
2707 record_btrace_conf
.format
= BTRACE_FORMAT_NONE
;
2708 throw_exception (exception
);
2713 /* Start recording Intel(R) Processor Trace. */
2716 cmd_record_btrace_pt_start (char *args
, int from_tty
)
2718 if (args
!= NULL
&& *args
!= 0)
2719 error (_("Invalid argument."));
2721 record_btrace_conf
.format
= BTRACE_FORMAT_PT
;
2725 execute_command ("target record-btrace", from_tty
);
2727 CATCH (exception
, RETURN_MASK_ALL
)
2729 record_btrace_conf
.format
= BTRACE_FORMAT_NONE
;
2730 throw_exception (exception
);
2735 /* Alias for "target record". */
2738 cmd_record_btrace_start (char *args
, int from_tty
)
2740 if (args
!= NULL
&& *args
!= 0)
2741 error (_("Invalid argument."));
2743 record_btrace_conf
.format
= BTRACE_FORMAT_PT
;
2747 execute_command ("target record-btrace", from_tty
);
2749 CATCH (exception
, RETURN_MASK_ALL
)
2751 record_btrace_conf
.format
= BTRACE_FORMAT_BTS
;
2755 execute_command ("target record-btrace", from_tty
);
2757 CATCH (exception
, RETURN_MASK_ALL
)
2759 record_btrace_conf
.format
= BTRACE_FORMAT_NONE
;
2760 throw_exception (exception
);
2767 /* The "set record btrace" command. */
2770 cmd_set_record_btrace (char *args
, int from_tty
)
2772 cmd_show_list (set_record_btrace_cmdlist
, from_tty
, "");
2775 /* The "show record btrace" command. */
2778 cmd_show_record_btrace (char *args
, int from_tty
)
2780 cmd_show_list (show_record_btrace_cmdlist
, from_tty
, "");
2783 /* The "show record btrace replay-memory-access" command. */
2786 cmd_show_replay_memory_access (struct ui_file
*file
, int from_tty
,
2787 struct cmd_list_element
*c
, const char *value
)
2789 fprintf_filtered (gdb_stdout
, _("Replay memory access is %s.\n"),
2790 replay_memory_access
);
2793 /* The "set record btrace bts" command. */
2796 cmd_set_record_btrace_bts (char *args
, int from_tty
)
2798 printf_unfiltered (_("\"set record btrace bts\" must be followed "
2799 "by an appropriate subcommand.\n"));
2800 help_list (set_record_btrace_bts_cmdlist
, "set record btrace bts ",
2801 all_commands
, gdb_stdout
);
2804 /* The "show record btrace bts" command. */
2807 cmd_show_record_btrace_bts (char *args
, int from_tty
)
2809 cmd_show_list (show_record_btrace_bts_cmdlist
, from_tty
, "");
2812 /* The "set record btrace pt" command. */
2815 cmd_set_record_btrace_pt (char *args
, int from_tty
)
2817 printf_unfiltered (_("\"set record btrace pt\" must be followed "
2818 "by an appropriate subcommand.\n"));
2819 help_list (set_record_btrace_pt_cmdlist
, "set record btrace pt ",
2820 all_commands
, gdb_stdout
);
2823 /* The "show record btrace pt" command. */
2826 cmd_show_record_btrace_pt (char *args
, int from_tty
)
2828 cmd_show_list (show_record_btrace_pt_cmdlist
, from_tty
, "");
2831 /* The "record bts buffer-size" show value function. */
2834 show_record_bts_buffer_size_value (struct ui_file
*file
, int from_tty
,
2835 struct cmd_list_element
*c
,
2838 fprintf_filtered (file
, _("The record/replay bts buffer size is %s.\n"),
2842 /* The "record pt buffer-size" show value function. */
2845 show_record_pt_buffer_size_value (struct ui_file
*file
, int from_tty
,
2846 struct cmd_list_element
*c
,
2849 fprintf_filtered (file
, _("The record/replay pt buffer size is %s.\n"),
2853 void _initialize_record_btrace (void);
2855 /* Initialize btrace commands. */
2858 _initialize_record_btrace (void)
2860 add_prefix_cmd ("btrace", class_obscure
, cmd_record_btrace_start
,
2861 _("Start branch trace recording."), &record_btrace_cmdlist
,
2862 "record btrace ", 0, &record_cmdlist
);
2863 add_alias_cmd ("b", "btrace", class_obscure
, 1, &record_cmdlist
);
2865 add_cmd ("bts", class_obscure
, cmd_record_btrace_bts_start
,
2867 Start branch trace recording in Branch Trace Store (BTS) format.\n\n\
2868 The processor stores a from/to record for each branch into a cyclic buffer.\n\
2869 This format may not be available on all processors."),
2870 &record_btrace_cmdlist
);
2871 add_alias_cmd ("bts", "btrace bts", class_obscure
, 1, &record_cmdlist
);
2873 add_cmd ("pt", class_obscure
, cmd_record_btrace_pt_start
,
2875 Start branch trace recording in Intel(R) Processor Trace format.\n\n\
2876 This format may not be available on all processors."),
2877 &record_btrace_cmdlist
);
2878 add_alias_cmd ("pt", "btrace pt", class_obscure
, 1, &record_cmdlist
);
2880 add_prefix_cmd ("btrace", class_support
, cmd_set_record_btrace
,
2881 _("Set record options"), &set_record_btrace_cmdlist
,
2882 "set record btrace ", 0, &set_record_cmdlist
);
2884 add_prefix_cmd ("btrace", class_support
, cmd_show_record_btrace
,
2885 _("Show record options"), &show_record_btrace_cmdlist
,
2886 "show record btrace ", 0, &show_record_cmdlist
);
2888 add_setshow_enum_cmd ("replay-memory-access", no_class
,
2889 replay_memory_access_types
, &replay_memory_access
, _("\
2890 Set what memory accesses are allowed during replay."), _("\
2891 Show what memory accesses are allowed during replay."),
2892 _("Default is READ-ONLY.\n\n\
2893 The btrace record target does not trace data.\n\
2894 The memory therefore corresponds to the live target and not \
2895 to the current replay position.\n\n\
2896 When READ-ONLY, allow accesses to read-only memory during replay.\n\
2897 When READ-WRITE, allow accesses to read-only and read-write memory during \
2899 NULL
, cmd_show_replay_memory_access
,
2900 &set_record_btrace_cmdlist
,
2901 &show_record_btrace_cmdlist
);
2903 add_prefix_cmd ("bts", class_support
, cmd_set_record_btrace_bts
,
2904 _("Set record btrace bts options"),
2905 &set_record_btrace_bts_cmdlist
,
2906 "set record btrace bts ", 0, &set_record_btrace_cmdlist
);
2908 add_prefix_cmd ("bts", class_support
, cmd_show_record_btrace_bts
,
2909 _("Show record btrace bts options"),
2910 &show_record_btrace_bts_cmdlist
,
2911 "show record btrace bts ", 0, &show_record_btrace_cmdlist
);
2913 add_setshow_uinteger_cmd ("buffer-size", no_class
,
2914 &record_btrace_conf
.bts
.size
,
2915 _("Set the record/replay bts buffer size."),
2916 _("Show the record/replay bts buffer size."), _("\
2917 When starting recording request a trace buffer of this size. \
2918 The actual buffer size may differ from the requested size. \
2919 Use \"info record\" to see the actual buffer size.\n\n\
2920 Bigger buffers allow longer recording but also take more time to process \
2921 the recorded execution trace.\n\n\
2922 The trace buffer size may not be changed while recording."), NULL
,
2923 show_record_bts_buffer_size_value
,
2924 &set_record_btrace_bts_cmdlist
,
2925 &show_record_btrace_bts_cmdlist
);
2927 add_prefix_cmd ("pt", class_support
, cmd_set_record_btrace_pt
,
2928 _("Set record btrace pt options"),
2929 &set_record_btrace_pt_cmdlist
,
2930 "set record btrace pt ", 0, &set_record_btrace_cmdlist
);
2932 add_prefix_cmd ("pt", class_support
, cmd_show_record_btrace_pt
,
2933 _("Show record btrace pt options"),
2934 &show_record_btrace_pt_cmdlist
,
2935 "show record btrace pt ", 0, &show_record_btrace_cmdlist
);
2937 add_setshow_uinteger_cmd ("buffer-size", no_class
,
2938 &record_btrace_conf
.pt
.size
,
2939 _("Set the record/replay pt buffer size."),
2940 _("Show the record/replay pt buffer size."), _("\
2941 Bigger buffers allow longer recording but also take more time to process \
2942 the recorded execution.\n\
2943 The actual buffer size may differ from the requested size. Use \"info record\" \
2944 to see the actual buffer size."), NULL
, show_record_pt_buffer_size_value
,
2945 &set_record_btrace_pt_cmdlist
,
2946 &show_record_btrace_pt_cmdlist
);
2948 init_record_btrace_ops ();
2949 add_target (&record_btrace_ops
);
2951 bfcache
= htab_create_alloc (50, bfcache_hash
, bfcache_eq
, NULL
,
2954 record_btrace_conf
.bts
.size
= 64 * 1024;
2955 record_btrace_conf
.pt
.size
= 16 * 1024;