record-btrace: supply register target methods
[external/binutils.git] / gdb / record-btrace.c
1 /* Branch trace support for GDB, the GNU debugger.
2
3    Copyright (C) 2013-2014 Free Software Foundation, Inc.
4
5    Contributed by Intel Corp. <markus.t.metzger@intel.com>
6
7    This file is part of GDB.
8
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.
13
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.
18
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/>.  */
21
22 #include "defs.h"
23 #include "record.h"
24 #include "gdbthread.h"
25 #include "target.h"
26 #include "gdbcmd.h"
27 #include "disasm.h"
28 #include "observer.h"
29 #include "exceptions.h"
30 #include "cli/cli-utils.h"
31 #include "source.h"
32 #include "ui-out.h"
33 #include "symtab.h"
34 #include "filenames.h"
35 #include "regcache.h"
36
37 /* The target_ops of record-btrace.  */
38 static struct target_ops record_btrace_ops;
39
40 /* A new thread observer enabling branch tracing for the new thread.  */
41 static struct observer *record_btrace_thread_observer;
42
43 /* Print a record-btrace debug message.  Use do ... while (0) to avoid
44    ambiguities when used in if statements.  */
45
46 #define DEBUG(msg, args...)                                             \
47   do                                                                    \
48     {                                                                   \
49       if (record_debug != 0)                                            \
50         fprintf_unfiltered (gdb_stdlog,                                 \
51                             "[record-btrace] " msg "\n", ##args);       \
52     }                                                                   \
53   while (0)
54
55
56 /* Update the branch trace for the current thread and return a pointer to its
57    branch trace information struct.
58
59    Throws an error if there is no thread or no trace.  This function never
60    returns NULL.  */
61
62 static struct btrace_thread_info *
63 require_btrace (void)
64 {
65   struct thread_info *tp;
66   struct btrace_thread_info *btinfo;
67
68   DEBUG ("require");
69
70   tp = find_thread_ptid (inferior_ptid);
71   if (tp == NULL)
72     error (_("No thread."));
73
74   btrace_fetch (tp);
75
76   btinfo = &tp->btrace;
77
78   if (btinfo->begin == NULL)
79     error (_("No trace."));
80
81   return btinfo;
82 }
83
84 /* Enable branch tracing for one thread.  Warn on errors.  */
85
86 static void
87 record_btrace_enable_warn (struct thread_info *tp)
88 {
89   volatile struct gdb_exception error;
90
91   TRY_CATCH (error, RETURN_MASK_ERROR)
92     btrace_enable (tp);
93
94   if (error.message != NULL)
95     warning ("%s", error.message);
96 }
97
98 /* Callback function to disable branch tracing for one thread.  */
99
100 static void
101 record_btrace_disable_callback (void *arg)
102 {
103   struct thread_info *tp;
104
105   tp = arg;
106
107   btrace_disable (tp);
108 }
109
110 /* Enable automatic tracing of new threads.  */
111
112 static void
113 record_btrace_auto_enable (void)
114 {
115   DEBUG ("attach thread observer");
116
117   record_btrace_thread_observer
118     = observer_attach_new_thread (record_btrace_enable_warn);
119 }
120
121 /* Disable automatic tracing of new threads.  */
122
123 static void
124 record_btrace_auto_disable (void)
125 {
126   /* The observer may have been detached, already.  */
127   if (record_btrace_thread_observer == NULL)
128     return;
129
130   DEBUG ("detach thread observer");
131
132   observer_detach_new_thread (record_btrace_thread_observer);
133   record_btrace_thread_observer = NULL;
134 }
135
136 /* The to_open method of target record-btrace.  */
137
138 static void
139 record_btrace_open (char *args, int from_tty)
140 {
141   struct cleanup *disable_chain;
142   struct thread_info *tp;
143
144   DEBUG ("open");
145
146   record_preopen ();
147
148   if (!target_has_execution)
149     error (_("The program is not being run."));
150
151   if (!target_supports_btrace ())
152     error (_("Target does not support branch tracing."));
153
154   gdb_assert (record_btrace_thread_observer == NULL);
155
156   disable_chain = make_cleanup (null_cleanup, NULL);
157   ALL_THREADS (tp)
158     if (args == NULL || *args == 0 || number_is_in_list (args, tp->num))
159       {
160         btrace_enable (tp);
161
162         make_cleanup (record_btrace_disable_callback, tp);
163       }
164
165   record_btrace_auto_enable ();
166
167   push_target (&record_btrace_ops);
168
169   observer_notify_record_changed (current_inferior (),  1);
170
171   discard_cleanups (disable_chain);
172 }
173
174 /* The to_stop_recording method of target record-btrace.  */
175
176 static void
177 record_btrace_stop_recording (void)
178 {
179   struct thread_info *tp;
180
181   DEBUG ("stop recording");
182
183   record_btrace_auto_disable ();
184
185   ALL_THREADS (tp)
186     if (tp->btrace.target != NULL)
187       btrace_disable (tp);
188 }
189
190 /* The to_close method of target record-btrace.  */
191
192 static void
193 record_btrace_close (void)
194 {
195   /* Make sure automatic recording gets disabled even if we did not stop
196      recording before closing the record-btrace target.  */
197   record_btrace_auto_disable ();
198
199   /* We already stopped recording.  */
200 }
201
202 /* The to_info_record method of target record-btrace.  */
203
204 static void
205 record_btrace_info (void)
206 {
207   struct btrace_thread_info *btinfo;
208   struct thread_info *tp;
209   unsigned int insns, calls;
210
211   DEBUG ("info");
212
213   tp = find_thread_ptid (inferior_ptid);
214   if (tp == NULL)
215     error (_("No thread."));
216
217   btrace_fetch (tp);
218
219   insns = 0;
220   calls = 0;
221
222   btinfo = &tp->btrace;
223   if (btinfo->begin != NULL)
224     {
225       struct btrace_call_iterator call;
226       struct btrace_insn_iterator insn;
227
228       btrace_call_end (&call, btinfo);
229       btrace_call_prev (&call, 1);
230       calls = btrace_call_number (&call);
231
232       btrace_insn_end (&insn, btinfo);
233       btrace_insn_prev (&insn, 1);
234       insns = btrace_insn_number (&insn);
235     }
236
237   printf_unfiltered (_("Recorded %u instructions in %u functions for thread "
238                        "%d (%s).\n"), insns, calls, tp->num,
239                      target_pid_to_str (tp->ptid));
240
241   if (btrace_is_replaying (tp))
242     printf_unfiltered (_("Replay in progress.  At instruction %u.\n"),
243                        btrace_insn_number (btinfo->replay));
244 }
245
246 /* Print an unsigned int.  */
247
248 static void
249 ui_out_field_uint (struct ui_out *uiout, const char *fld, unsigned int val)
250 {
251   ui_out_field_fmt (uiout, fld, "%u", val);
252 }
253
254 /* Disassemble a section of the recorded instruction trace.  */
255
256 static void
257 btrace_insn_history (struct ui_out *uiout,
258                      const struct btrace_insn_iterator *begin,
259                      const struct btrace_insn_iterator *end, int flags)
260 {
261   struct gdbarch *gdbarch;
262   struct btrace_insn_iterator it;
263
264   DEBUG ("itrace (0x%x): [%u; %u)", flags, btrace_insn_number (begin),
265          btrace_insn_number (end));
266
267   gdbarch = target_gdbarch ();
268
269   for (it = *begin; btrace_insn_cmp (&it, end) != 0; btrace_insn_next (&it, 1))
270     {
271       const struct btrace_insn *insn;
272
273       insn = btrace_insn_get (&it);
274
275       /* Print the instruction index.  */
276       ui_out_field_uint (uiout, "index", btrace_insn_number (&it));
277       ui_out_text (uiout, "\t");
278
279       /* Disassembly with '/m' flag may not produce the expected result.
280          See PR gdb/11833.  */
281       gdb_disassembly (gdbarch, uiout, NULL, flags, 1, insn->pc, insn->pc + 1);
282     }
283 }
284
285 /* The to_insn_history method of target record-btrace.  */
286
287 static void
288 record_btrace_insn_history (int size, int flags)
289 {
290   struct btrace_thread_info *btinfo;
291   struct btrace_insn_history *history;
292   struct btrace_insn_iterator begin, end;
293   struct cleanup *uiout_cleanup;
294   struct ui_out *uiout;
295   unsigned int context, covered;
296
297   uiout = current_uiout;
298   uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout,
299                                                        "insn history");
300   context = abs (size);
301   if (context == 0)
302     error (_("Bad record instruction-history-size."));
303
304   btinfo = require_btrace ();
305   history = btinfo->insn_history;
306   if (history == NULL)
307     {
308       struct btrace_insn_iterator *replay;
309
310       DEBUG ("insn-history (0x%x): %d", flags, size);
311
312       /* If we're replaying, we start at the replay position.  Otherwise, we
313          start at the tail of the trace.  */
314       replay = btinfo->replay;
315       if (replay != NULL)
316         begin = *replay;
317       else
318         btrace_insn_end (&begin, btinfo);
319
320       /* We start from here and expand in the requested direction.  Then we
321          expand in the other direction, as well, to fill up any remaining
322          context.  */
323       end = begin;
324       if (size < 0)
325         {
326           /* We want the current position covered, as well.  */
327           covered = btrace_insn_next (&end, 1);
328           covered += btrace_insn_prev (&begin, context - covered);
329           covered += btrace_insn_next (&end, context - covered);
330         }
331       else
332         {
333           covered = btrace_insn_next (&end, context);
334           covered += btrace_insn_prev (&begin, context - covered);
335         }
336     }
337   else
338     {
339       begin = history->begin;
340       end = history->end;
341
342       DEBUG ("insn-history (0x%x): %d, prev: [%u; %u)", flags, size,
343              btrace_insn_number (&begin), btrace_insn_number (&end));
344
345       if (size < 0)
346         {
347           end = begin;
348           covered = btrace_insn_prev (&begin, context);
349         }
350       else
351         {
352           begin = end;
353           covered = btrace_insn_next (&end, context);
354         }
355     }
356
357   if (covered > 0)
358     btrace_insn_history (uiout, &begin, &end, flags);
359   else
360     {
361       if (size < 0)
362         printf_unfiltered (_("At the start of the branch trace record.\n"));
363       else
364         printf_unfiltered (_("At the end of the branch trace record.\n"));
365     }
366
367   btrace_set_insn_history (btinfo, &begin, &end);
368   do_cleanups (uiout_cleanup);
369 }
370
371 /* The to_insn_history_range method of target record-btrace.  */
372
373 static void
374 record_btrace_insn_history_range (ULONGEST from, ULONGEST to, int flags)
375 {
376   struct btrace_thread_info *btinfo;
377   struct btrace_insn_history *history;
378   struct btrace_insn_iterator begin, end;
379   struct cleanup *uiout_cleanup;
380   struct ui_out *uiout;
381   unsigned int low, high;
382   int found;
383
384   uiout = current_uiout;
385   uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout,
386                                                        "insn history");
387   low = from;
388   high = to;
389
390   DEBUG ("insn-history (0x%x): [%u; %u)", flags, low, high);
391
392   /* Check for wrap-arounds.  */
393   if (low != from || high != to)
394     error (_("Bad range."));
395
396   if (high < low)
397     error (_("Bad range."));
398
399   btinfo = require_btrace ();
400
401   found = btrace_find_insn_by_number (&begin, btinfo, low);
402   if (found == 0)
403     error (_("Range out of bounds."));
404
405   found = btrace_find_insn_by_number (&end, btinfo, high);
406   if (found == 0)
407     {
408       /* Silently truncate the range.  */
409       btrace_insn_end (&end, btinfo);
410     }
411   else
412     {
413       /* We want both begin and end to be inclusive.  */
414       btrace_insn_next (&end, 1);
415     }
416
417   btrace_insn_history (uiout, &begin, &end, flags);
418   btrace_set_insn_history (btinfo, &begin, &end);
419
420   do_cleanups (uiout_cleanup);
421 }
422
423 /* The to_insn_history_from method of target record-btrace.  */
424
425 static void
426 record_btrace_insn_history_from (ULONGEST from, int size, int flags)
427 {
428   ULONGEST begin, end, context;
429
430   context = abs (size);
431   if (context == 0)
432     error (_("Bad record instruction-history-size."));
433
434   if (size < 0)
435     {
436       end = from;
437
438       if (from < context)
439         begin = 0;
440       else
441         begin = from - context + 1;
442     }
443   else
444     {
445       begin = from;
446       end = from + context - 1;
447
448       /* Check for wrap-around.  */
449       if (end < begin)
450         end = ULONGEST_MAX;
451     }
452
453   record_btrace_insn_history_range (begin, end, flags);
454 }
455
456 /* Print the instruction number range for a function call history line.  */
457
458 static void
459 btrace_call_history_insn_range (struct ui_out *uiout,
460                                 const struct btrace_function *bfun)
461 {
462   unsigned int begin, end, size;
463
464   size = VEC_length (btrace_insn_s, bfun->insn);
465   gdb_assert (size > 0);
466
467   begin = bfun->insn_offset;
468   end = begin + size - 1;
469
470   ui_out_field_uint (uiout, "insn begin", begin);
471   ui_out_text (uiout, ",");
472   ui_out_field_uint (uiout, "insn end", end);
473 }
474
475 /* Print the source line information for a function call history line.  */
476
477 static void
478 btrace_call_history_src_line (struct ui_out *uiout,
479                               const struct btrace_function *bfun)
480 {
481   struct symbol *sym;
482   int begin, end;
483
484   sym = bfun->sym;
485   if (sym == NULL)
486     return;
487
488   ui_out_field_string (uiout, "file",
489                        symtab_to_filename_for_display (sym->symtab));
490
491   begin = bfun->lbegin;
492   end = bfun->lend;
493
494   if (end < begin)
495     return;
496
497   ui_out_text (uiout, ":");
498   ui_out_field_int (uiout, "min line", begin);
499
500   if (end == begin)
501     return;
502
503   ui_out_text (uiout, ",");
504   ui_out_field_int (uiout, "max line", end);
505 }
506
507 /* Disassemble a section of the recorded function trace.  */
508
509 static void
510 btrace_call_history (struct ui_out *uiout,
511                      const struct btrace_thread_info *btinfo,
512                      const struct btrace_call_iterator *begin,
513                      const struct btrace_call_iterator *end,
514                      enum record_print_flag flags)
515 {
516   struct btrace_call_iterator it;
517
518   DEBUG ("ftrace (0x%x): [%u; %u)", flags, btrace_call_number (begin),
519          btrace_call_number (end));
520
521   for (it = *begin; btrace_call_cmp (&it, end) < 0; btrace_call_next (&it, 1))
522     {
523       const struct btrace_function *bfun;
524       struct minimal_symbol *msym;
525       struct symbol *sym;
526
527       bfun = btrace_call_get (&it);
528       msym = bfun->msym;
529       sym = bfun->sym;
530
531       /* Print the function index.  */
532       ui_out_field_uint (uiout, "index", bfun->number);
533       ui_out_text (uiout, "\t");
534
535       if ((flags & RECORD_PRINT_INDENT_CALLS) != 0)
536         {
537           int level = bfun->level + btinfo->level, i;
538
539           for (i = 0; i < level; ++i)
540             ui_out_text (uiout, "  ");
541         }
542
543       if (sym != NULL)
544         ui_out_field_string (uiout, "function", SYMBOL_PRINT_NAME (sym));
545       else if (msym != NULL)
546         ui_out_field_string (uiout, "function", SYMBOL_PRINT_NAME (msym));
547       else if (!ui_out_is_mi_like_p (uiout))
548         ui_out_field_string (uiout, "function", "??");
549
550       if ((flags & RECORD_PRINT_INSN_RANGE) != 0)
551         {
552           ui_out_text (uiout, _("\tinst "));
553           btrace_call_history_insn_range (uiout, bfun);
554         }
555
556       if ((flags & RECORD_PRINT_SRC_LINE) != 0)
557         {
558           ui_out_text (uiout, _("\tat "));
559           btrace_call_history_src_line (uiout, bfun);
560         }
561
562       ui_out_text (uiout, "\n");
563     }
564 }
565
566 /* The to_call_history method of target record-btrace.  */
567
568 static void
569 record_btrace_call_history (int size, int flags)
570 {
571   struct btrace_thread_info *btinfo;
572   struct btrace_call_history *history;
573   struct btrace_call_iterator begin, end;
574   struct cleanup *uiout_cleanup;
575   struct ui_out *uiout;
576   unsigned int context, covered;
577
578   uiout = current_uiout;
579   uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout,
580                                                        "insn history");
581   context = abs (size);
582   if (context == 0)
583     error (_("Bad record function-call-history-size."));
584
585   btinfo = require_btrace ();
586   history = btinfo->call_history;
587   if (history == NULL)
588     {
589       struct btrace_insn_iterator *replay;
590
591       DEBUG ("call-history (0x%x): %d", flags, size);
592
593       /* If we're replaying, we start at the replay position.  Otherwise, we
594          start at the tail of the trace.  */
595       replay = btinfo->replay;
596       if (replay != NULL)
597         {
598           begin.function = replay->function;
599           begin.btinfo = btinfo;
600         }
601       else
602         btrace_call_end (&begin, btinfo);
603
604       /* We start from here and expand in the requested direction.  Then we
605          expand in the other direction, as well, to fill up any remaining
606          context.  */
607       end = begin;
608       if (size < 0)
609         {
610           /* We want the current position covered, as well.  */
611           covered = btrace_call_next (&end, 1);
612           covered += btrace_call_prev (&begin, context - covered);
613           covered += btrace_call_next (&end, context - covered);
614         }
615       else
616         {
617           covered = btrace_call_next (&end, context);
618           covered += btrace_call_prev (&begin, context- covered);
619         }
620     }
621   else
622     {
623       begin = history->begin;
624       end = history->end;
625
626       DEBUG ("call-history (0x%x): %d, prev: [%u; %u)", flags, size,
627              btrace_call_number (&begin), btrace_call_number (&end));
628
629       if (size < 0)
630         {
631           end = begin;
632           covered = btrace_call_prev (&begin, context);
633         }
634       else
635         {
636           begin = end;
637           covered = btrace_call_next (&end, context);
638         }
639     }
640
641   if (covered > 0)
642     btrace_call_history (uiout, btinfo, &begin, &end, flags);
643   else
644     {
645       if (size < 0)
646         printf_unfiltered (_("At the start of the branch trace record.\n"));
647       else
648         printf_unfiltered (_("At the end of the branch trace record.\n"));
649     }
650
651   btrace_set_call_history (btinfo, &begin, &end);
652   do_cleanups (uiout_cleanup);
653 }
654
655 /* The to_call_history_range method of target record-btrace.  */
656
657 static void
658 record_btrace_call_history_range (ULONGEST from, ULONGEST to, int flags)
659 {
660   struct btrace_thread_info *btinfo;
661   struct btrace_call_history *history;
662   struct btrace_call_iterator begin, end;
663   struct cleanup *uiout_cleanup;
664   struct ui_out *uiout;
665   unsigned int low, high;
666   int found;
667
668   uiout = current_uiout;
669   uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout,
670                                                        "func history");
671   low = from;
672   high = to;
673
674   DEBUG ("call-history (0x%x): [%u; %u)", flags, low, high);
675
676   /* Check for wrap-arounds.  */
677   if (low != from || high != to)
678     error (_("Bad range."));
679
680   if (high < low)
681     error (_("Bad range."));
682
683   btinfo = require_btrace ();
684
685   found = btrace_find_call_by_number (&begin, btinfo, low);
686   if (found == 0)
687     error (_("Range out of bounds."));
688
689   found = btrace_find_call_by_number (&end, btinfo, high);
690   if (found == 0)
691     {
692       /* Silently truncate the range.  */
693       btrace_call_end (&end, btinfo);
694     }
695   else
696     {
697       /* We want both begin and end to be inclusive.  */
698       btrace_call_next (&end, 1);
699     }
700
701   btrace_call_history (uiout, btinfo, &begin, &end, flags);
702   btrace_set_call_history (btinfo, &begin, &end);
703
704   do_cleanups (uiout_cleanup);
705 }
706
707 /* The to_call_history_from method of target record-btrace.  */
708
709 static void
710 record_btrace_call_history_from (ULONGEST from, int size, int flags)
711 {
712   ULONGEST begin, end, context;
713
714   context = abs (size);
715   if (context == 0)
716     error (_("Bad record function-call-history-size."));
717
718   if (size < 0)
719     {
720       end = from;
721
722       if (from < context)
723         begin = 0;
724       else
725         begin = from - context + 1;
726     }
727   else
728     {
729       begin = from;
730       end = from + context - 1;
731
732       /* Check for wrap-around.  */
733       if (end < begin)
734         end = ULONGEST_MAX;
735     }
736
737   record_btrace_call_history_range (begin, end, flags);
738 }
739
740 /* The to_record_is_replaying method of target record-btrace.  */
741
742 static int
743 record_btrace_is_replaying (void)
744 {
745   struct thread_info *tp;
746
747   ALL_THREADS (tp)
748     if (btrace_is_replaying (tp))
749       return 1;
750
751   return 0;
752 }
753
754 /* The to_fetch_registers method of target record-btrace.  */
755
756 static void
757 record_btrace_fetch_registers (struct target_ops *ops,
758                                struct regcache *regcache, int regno)
759 {
760   struct btrace_insn_iterator *replay;
761   struct thread_info *tp;
762
763   tp = find_thread_ptid (inferior_ptid);
764   gdb_assert (tp != NULL);
765
766   replay = tp->btrace.replay;
767   if (replay != NULL)
768     {
769       const struct btrace_insn *insn;
770       struct gdbarch *gdbarch;
771       int pcreg;
772
773       gdbarch = get_regcache_arch (regcache);
774       pcreg = gdbarch_pc_regnum (gdbarch);
775       if (pcreg < 0)
776         return;
777
778       /* We can only provide the PC register.  */
779       if (regno >= 0 && regno != pcreg)
780         return;
781
782       insn = btrace_insn_get (replay);
783       gdb_assert (insn != NULL);
784
785       regcache_raw_supply (regcache, regno, &insn->pc);
786     }
787   else
788     {
789       struct target_ops *t;
790
791       for (t = ops->beneath; t != NULL; t = t->beneath)
792         if (t->to_fetch_registers != NULL)
793           {
794             t->to_fetch_registers (t, regcache, regno);
795             break;
796           }
797     }
798 }
799
800 /* The to_store_registers method of target record-btrace.  */
801
802 static void
803 record_btrace_store_registers (struct target_ops *ops,
804                                struct regcache *regcache, int regno)
805 {
806   struct target_ops *t;
807
808   if (record_btrace_is_replaying ())
809     error (_("This record target does not allow writing registers."));
810
811   gdb_assert (may_write_registers != 0);
812
813   for (t = ops->beneath; t != NULL; t = t->beneath)
814     if (t->to_store_registers != NULL)
815       {
816         t->to_store_registers (t, regcache, regno);
817         return;
818       }
819
820   noprocess ();
821 }
822
823 /* The to_prepare_to_store method of target record-btrace.  */
824
825 static void
826 record_btrace_prepare_to_store (struct target_ops *ops,
827                                 struct regcache *regcache)
828 {
829   struct target_ops *t;
830
831   if (record_btrace_is_replaying ())
832     return;
833
834   for (t = ops->beneath; t != NULL; t = t->beneath)
835     if (t->to_prepare_to_store != NULL)
836       {
837         t->to_prepare_to_store (t, regcache);
838         return;
839       }
840 }
841
842 /* Initialize the record-btrace target ops.  */
843
844 static void
845 init_record_btrace_ops (void)
846 {
847   struct target_ops *ops;
848
849   ops = &record_btrace_ops;
850   ops->to_shortname = "record-btrace";
851   ops->to_longname = "Branch tracing target";
852   ops->to_doc = "Collect control-flow trace and provide the execution history.";
853   ops->to_open = record_btrace_open;
854   ops->to_close = record_btrace_close;
855   ops->to_detach = record_detach;
856   ops->to_disconnect = record_disconnect;
857   ops->to_mourn_inferior = record_mourn_inferior;
858   ops->to_kill = record_kill;
859   ops->to_create_inferior = find_default_create_inferior;
860   ops->to_stop_recording = record_btrace_stop_recording;
861   ops->to_info_record = record_btrace_info;
862   ops->to_insn_history = record_btrace_insn_history;
863   ops->to_insn_history_from = record_btrace_insn_history_from;
864   ops->to_insn_history_range = record_btrace_insn_history_range;
865   ops->to_call_history = record_btrace_call_history;
866   ops->to_call_history_from = record_btrace_call_history_from;
867   ops->to_call_history_range = record_btrace_call_history_range;
868   ops->to_record_is_replaying = record_btrace_is_replaying;
869   ops->to_fetch_registers = record_btrace_fetch_registers;
870   ops->to_store_registers = record_btrace_store_registers;
871   ops->to_prepare_to_store = record_btrace_prepare_to_store;
872   ops->to_stratum = record_stratum;
873   ops->to_magic = OPS_MAGIC;
874 }
875
876 /* Alias for "target record".  */
877
878 static void
879 cmd_record_btrace_start (char *args, int from_tty)
880 {
881   if (args != NULL && *args != 0)
882     error (_("Invalid argument."));
883
884   execute_command ("target record-btrace", from_tty);
885 }
886
887 void _initialize_record_btrace (void);
888
889 /* Initialize btrace commands.  */
890
891 void
892 _initialize_record_btrace (void)
893 {
894   add_cmd ("btrace", class_obscure, cmd_record_btrace_start,
895            _("Start branch trace recording."),
896            &record_cmdlist);
897   add_alias_cmd ("b", "btrace", class_obscure, 1, &record_cmdlist);
898
899   init_record_btrace_ops ();
900   add_target (&record_btrace_ops);
901 }