1 /* Branch trace support for GDB, the GNU debugger.
3 Copyright (C) 2013-2016 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"
31 #include "filenames.h"
32 #include "xml-support.h"
36 #include "cli/cli-utils.h"
42 /* Command lists for btrace maintenance commands. */
43 static struct cmd_list_element *maint_btrace_cmdlist;
44 static struct cmd_list_element *maint_btrace_set_cmdlist;
45 static struct cmd_list_element *maint_btrace_show_cmdlist;
46 static struct cmd_list_element *maint_btrace_pt_set_cmdlist;
47 static struct cmd_list_element *maint_btrace_pt_show_cmdlist;
49 /* Control whether to skip PAD packets when computing the packet history. */
50 static int maint_btrace_pt_skip_pad = 1;
52 static void btrace_add_pc (struct thread_info *tp);
54 /* Print a record debug message. Use do ... while (0) to avoid ambiguities
55 when used in if statements. */
57 #define DEBUG(msg, args...) \
60 if (record_debug != 0) \
61 fprintf_unfiltered (gdb_stdlog, \
62 "[btrace] " msg "\n", ##args); \
66 #define DEBUG_FTRACE(msg, args...) DEBUG ("[ftrace] " msg, ##args)
68 /* Return the function name of a recorded function segment for printing.
69 This function never returns NULL. */
72 ftrace_print_function_name (const struct btrace_function *bfun)
74 struct minimal_symbol *msym;
81 return SYMBOL_PRINT_NAME (sym);
84 return MSYMBOL_PRINT_NAME (msym);
89 /* Return the file name of a recorded function segment for printing.
90 This function never returns NULL. */
93 ftrace_print_filename (const struct btrace_function *bfun)
101 filename = symtab_to_filename_for_display (symbol_symtab (sym));
103 filename = "<unknown>";
108 /* Return a string representation of the address of an instruction.
109 This function never returns NULL. */
112 ftrace_print_insn_addr (const struct btrace_insn *insn)
117 return core_addr_to_string_nz (insn->pc);
120 /* Print an ftrace debug status message. */
123 ftrace_debug (const struct btrace_function *bfun, const char *prefix)
125 const char *fun, *file;
126 unsigned int ibegin, iend;
129 fun = ftrace_print_function_name (bfun);
130 file = ftrace_print_filename (bfun);
133 ibegin = bfun->insn_offset;
134 iend = ibegin + VEC_length (btrace_insn_s, bfun->insn);
136 DEBUG_FTRACE ("%s: fun = %s, file = %s, level = %d, insn = [%u; %u)",
137 prefix, fun, file, level, ibegin, iend);
140 /* Return non-zero if BFUN does not match MFUN and FUN,
141 return zero otherwise. */
144 ftrace_function_switched (const struct btrace_function *bfun,
145 const struct minimal_symbol *mfun,
146 const struct symbol *fun)
148 struct minimal_symbol *msym;
154 /* If the minimal symbol changed, we certainly switched functions. */
155 if (mfun != NULL && msym != NULL
156 && strcmp (MSYMBOL_LINKAGE_NAME (mfun), MSYMBOL_LINKAGE_NAME (msym)) != 0)
159 /* If the symbol changed, we certainly switched functions. */
160 if (fun != NULL && sym != NULL)
162 const char *bfname, *fname;
164 /* Check the function name. */
165 if (strcmp (SYMBOL_LINKAGE_NAME (fun), SYMBOL_LINKAGE_NAME (sym)) != 0)
168 /* Check the location of those functions, as well. */
169 bfname = symtab_to_fullname (symbol_symtab (sym));
170 fname = symtab_to_fullname (symbol_symtab (fun));
171 if (filename_cmp (fname, bfname) != 0)
175 /* If we lost symbol information, we switched functions. */
176 if (!(msym == NULL && sym == NULL) && mfun == NULL && fun == NULL)
179 /* If we gained symbol information, we switched functions. */
180 if (msym == NULL && sym == NULL && !(mfun == NULL && fun == NULL))
186 /* Allocate and initialize a new branch trace function segment.
187 PREV is the chronologically preceding function segment.
188 MFUN and FUN are the symbol information we have for this function. */
190 static struct btrace_function *
191 ftrace_new_function (struct btrace_function *prev,
192 struct minimal_symbol *mfun,
195 struct btrace_function *bfun;
197 bfun = XCNEW (struct btrace_function);
201 bfun->flow.prev = prev;
205 /* Start counting at one. */
207 bfun->insn_offset = 1;
211 gdb_assert (prev->flow.next == NULL);
212 prev->flow.next = bfun;
214 bfun->number = prev->number + 1;
215 bfun->insn_offset = (prev->insn_offset
216 + VEC_length (btrace_insn_s, prev->insn));
217 bfun->level = prev->level;
223 /* Update the UP field of a function segment. */
226 ftrace_update_caller (struct btrace_function *bfun,
227 struct btrace_function *caller,
228 enum btrace_function_flag flags)
230 if (bfun->up != NULL)
231 ftrace_debug (bfun, "updating caller");
236 ftrace_debug (bfun, "set caller");
239 /* Fix up the caller for all segments of a function. */
242 ftrace_fixup_caller (struct btrace_function *bfun,
243 struct btrace_function *caller,
244 enum btrace_function_flag flags)
246 struct btrace_function *prev, *next;
248 ftrace_update_caller (bfun, caller, flags);
250 /* Update all function segments belonging to the same function. */
251 for (prev = bfun->segment.prev; prev != NULL; prev = prev->segment.prev)
252 ftrace_update_caller (prev, caller, flags);
254 for (next = bfun->segment.next; next != NULL; next = next->segment.next)
255 ftrace_update_caller (next, caller, flags);
258 /* Add a new function segment for a call.
259 CALLER is the chronologically preceding function segment.
260 MFUN and FUN are the symbol information we have for this function. */
262 static struct btrace_function *
263 ftrace_new_call (struct btrace_function *caller,
264 struct minimal_symbol *mfun,
267 struct btrace_function *bfun;
269 bfun = ftrace_new_function (caller, mfun, fun);
273 ftrace_debug (bfun, "new call");
278 /* Add a new function segment for a tail call.
279 CALLER is the chronologically preceding function segment.
280 MFUN and FUN are the symbol information we have for this function. */
282 static struct btrace_function *
283 ftrace_new_tailcall (struct btrace_function *caller,
284 struct minimal_symbol *mfun,
287 struct btrace_function *bfun;
289 bfun = ftrace_new_function (caller, mfun, fun);
292 bfun->flags |= BFUN_UP_LINKS_TO_TAILCALL;
294 ftrace_debug (bfun, "new tail call");
299 /* Find the innermost caller in the back trace of BFUN with MFUN/FUN
300 symbol information. */
302 static struct btrace_function *
303 ftrace_find_caller (struct btrace_function *bfun,
304 struct minimal_symbol *mfun,
307 for (; bfun != NULL; bfun = bfun->up)
309 /* Skip functions with incompatible symbol information. */
310 if (ftrace_function_switched (bfun, mfun, fun))
313 /* This is the function segment we're looking for. */
320 /* Find the innermost caller in the back trace of BFUN, skipping all
321 function segments that do not end with a call instruction (e.g.
322 tail calls ending with a jump). */
324 static struct btrace_function *
325 ftrace_find_call (struct btrace_function *bfun)
327 for (; bfun != NULL; bfun = bfun->up)
329 struct btrace_insn *last;
332 if (bfun->errcode != 0)
335 last = VEC_last (btrace_insn_s, bfun->insn);
337 if (last->iclass == BTRACE_INSN_CALL)
344 /* Add a continuation segment for a function into which we return.
345 PREV is the chronologically preceding function segment.
346 MFUN and FUN are the symbol information we have for this function. */
348 static struct btrace_function *
349 ftrace_new_return (struct btrace_function *prev,
350 struct minimal_symbol *mfun,
353 struct btrace_function *bfun, *caller;
355 bfun = ftrace_new_function (prev, mfun, fun);
357 /* It is important to start at PREV's caller. Otherwise, we might find
358 PREV itself, if PREV is a recursive function. */
359 caller = ftrace_find_caller (prev->up, mfun, fun);
362 /* The caller of PREV is the preceding btrace function segment in this
363 function instance. */
364 gdb_assert (caller->segment.next == NULL);
366 caller->segment.next = bfun;
367 bfun->segment.prev = caller;
369 /* Maintain the function level. */
370 bfun->level = caller->level;
372 /* Maintain the call stack. */
373 bfun->up = caller->up;
374 bfun->flags = caller->flags;
376 ftrace_debug (bfun, "new return");
380 /* We did not find a caller. This could mean that something went
381 wrong or that the call is simply not included in the trace. */
383 /* Let's search for some actual call. */
384 caller = ftrace_find_call (prev->up);
387 /* There is no call in PREV's back trace. We assume that the
388 branch trace did not include it. */
390 /* Let's find the topmost call function - this skips tail calls. */
391 while (prev->up != NULL)
394 /* We maintain levels for a series of returns for which we have
396 We start at the preceding function's level in case this has
397 already been a return for which we have not seen the call.
398 We start at level 0 otherwise, to handle tail calls correctly. */
399 bfun->level = std::min (0, prev->level) - 1;
401 /* Fix up the call stack for PREV. */
402 ftrace_fixup_caller (prev, bfun, BFUN_UP_LINKS_TO_RET);
404 ftrace_debug (bfun, "new return - no caller");
408 /* There is a call in PREV's back trace to which we should have
409 returned. Let's remain at this level. */
410 bfun->level = prev->level;
412 ftrace_debug (bfun, "new return - unknown caller");
419 /* Add a new function segment for a function switch.
420 PREV is the chronologically preceding function segment.
421 MFUN and FUN are the symbol information we have for this function. */
423 static struct btrace_function *
424 ftrace_new_switch (struct btrace_function *prev,
425 struct minimal_symbol *mfun,
428 struct btrace_function *bfun;
430 /* This is an unexplained function switch. The call stack will likely
431 be wrong at this point. */
432 bfun = ftrace_new_function (prev, mfun, fun);
434 ftrace_debug (bfun, "new switch");
439 /* Add a new function segment for a gap in the trace due to a decode error.
440 PREV is the chronologically preceding function segment.
441 ERRCODE is the format-specific error code. */
443 static struct btrace_function *
444 ftrace_new_gap (struct btrace_function *prev, int errcode)
446 struct btrace_function *bfun;
448 /* We hijack prev if it was empty. */
449 if (prev != NULL && prev->errcode == 0
450 && VEC_empty (btrace_insn_s, prev->insn))
453 bfun = ftrace_new_function (prev, NULL, NULL);
455 bfun->errcode = errcode;
457 ftrace_debug (bfun, "new gap");
462 /* Update BFUN with respect to the instruction at PC. This may create new
464 Return the chronologically latest function segment, never NULL. */
466 static struct btrace_function *
467 ftrace_update_function (struct btrace_function *bfun, CORE_ADDR pc)
469 struct bound_minimal_symbol bmfun;
470 struct minimal_symbol *mfun;
472 struct btrace_insn *last;
474 /* Try to determine the function we're in. We use both types of symbols
475 to avoid surprises when we sometimes get a full symbol and sometimes
476 only a minimal symbol. */
477 fun = find_pc_function (pc);
478 bmfun = lookup_minimal_symbol_by_pc (pc);
481 if (fun == NULL && mfun == NULL)
482 DEBUG_FTRACE ("no symbol at %s", core_addr_to_string_nz (pc));
484 /* If we didn't have a function or if we had a gap before, we create one. */
485 if (bfun == NULL || bfun->errcode != 0)
486 return ftrace_new_function (bfun, mfun, fun);
488 /* Check the last instruction, if we have one.
489 We do this check first, since it allows us to fill in the call stack
490 links in addition to the normal flow links. */
492 if (!VEC_empty (btrace_insn_s, bfun->insn))
493 last = VEC_last (btrace_insn_s, bfun->insn);
497 switch (last->iclass)
499 case BTRACE_INSN_RETURN:
503 /* On some systems, _dl_runtime_resolve returns to the resolved
504 function instead of jumping to it. From our perspective,
505 however, this is a tailcall.
506 If we treated it as return, we wouldn't be able to find the
507 resolved function in our stack back trace. Hence, we would
508 lose the current stack back trace and start anew with an empty
509 back trace. When the resolved function returns, we would then
510 create a stack back trace with the same function names but
511 different frame id's. This will confuse stepping. */
512 fname = ftrace_print_function_name (bfun);
513 if (strcmp (fname, "_dl_runtime_resolve") == 0)
514 return ftrace_new_tailcall (bfun, mfun, fun);
516 return ftrace_new_return (bfun, mfun, fun);
519 case BTRACE_INSN_CALL:
520 /* Ignore calls to the next instruction. They are used for PIC. */
521 if (last->pc + last->size == pc)
524 return ftrace_new_call (bfun, mfun, fun);
526 case BTRACE_INSN_JUMP:
530 start = get_pc_function_start (pc);
532 /* If we can't determine the function for PC, we treat a jump at
533 the end of the block as tail call. */
534 if (start == 0 || start == pc)
535 return ftrace_new_tailcall (bfun, mfun, fun);
540 /* Check if we're switching functions for some other reason. */
541 if (ftrace_function_switched (bfun, mfun, fun))
543 DEBUG_FTRACE ("switching from %s in %s at %s",
544 ftrace_print_insn_addr (last),
545 ftrace_print_function_name (bfun),
546 ftrace_print_filename (bfun));
548 return ftrace_new_switch (bfun, mfun, fun);
554 /* Add the instruction at PC to BFUN's instructions. */
557 ftrace_update_insns (struct btrace_function *bfun,
558 const struct btrace_insn *insn)
560 VEC_safe_push (btrace_insn_s, bfun->insn, insn);
562 if (record_debug > 1)
563 ftrace_debug (bfun, "update insn");
566 /* Classify the instruction at PC. */
568 static enum btrace_insn_class
569 ftrace_classify_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
571 enum btrace_insn_class iclass;
573 iclass = BTRACE_INSN_OTHER;
576 if (gdbarch_insn_is_call (gdbarch, pc))
577 iclass = BTRACE_INSN_CALL;
578 else if (gdbarch_insn_is_ret (gdbarch, pc))
579 iclass = BTRACE_INSN_RETURN;
580 else if (gdbarch_insn_is_jump (gdbarch, pc))
581 iclass = BTRACE_INSN_JUMP;
583 CATCH (error, RETURN_MASK_ERROR)
591 /* Compute the function branch trace from BTS trace. */
594 btrace_compute_ftrace_bts (struct thread_info *tp,
595 const struct btrace_data_bts *btrace)
597 struct btrace_thread_info *btinfo;
598 struct btrace_function *begin, *end;
599 struct gdbarch *gdbarch;
600 unsigned int blk, ngaps;
603 gdbarch = target_gdbarch ();
604 btinfo = &tp->btrace;
605 begin = btinfo->begin;
607 ngaps = btinfo->ngaps;
608 level = begin != NULL ? -btinfo->level : INT_MAX;
609 blk = VEC_length (btrace_block_s, btrace->blocks);
613 btrace_block_s *block;
618 block = VEC_index (btrace_block_s, btrace->blocks, blk);
623 struct btrace_insn insn;
626 /* We should hit the end of the block. Warn if we went too far. */
629 /* Indicate the gap in the trace - unless we're at the
633 end = ftrace_new_gap (end, BDE_BTS_OVERFLOW);
636 warning (_("Recorded trace may be corrupted at instruction "
637 "%u (pc = %s)."), end->insn_offset - 1,
638 core_addr_to_string_nz (pc));
643 end = ftrace_update_function (end, pc);
647 /* Maintain the function level offset.
648 For all but the last block, we do it here. */
650 level = std::min (level, end->level);
655 size = gdb_insn_length (gdbarch, pc);
657 CATCH (error, RETURN_MASK_ERROR)
664 insn.iclass = ftrace_classify_insn (gdbarch, pc);
667 ftrace_update_insns (end, &insn);
669 /* We're done once we pushed the instruction at the end. */
670 if (block->end == pc)
673 /* We can't continue if we fail to compute the size. */
676 /* Indicate the gap in the trace. We just added INSN so we're
677 not at the beginning. */
678 end = ftrace_new_gap (end, BDE_BTS_INSN_SIZE);
681 warning (_("Recorded trace may be incomplete at instruction %u "
682 "(pc = %s)."), end->insn_offset - 1,
683 core_addr_to_string_nz (pc));
690 /* Maintain the function level offset.
691 For the last block, we do it here to not consider the last
693 Since the last instruction corresponds to the current instruction
694 and is not really part of the execution history, it shouldn't
697 level = std::min (level, end->level);
701 btinfo->begin = begin;
703 btinfo->ngaps = ngaps;
705 /* LEVEL is the minimal function level of all btrace function segments.
706 Define the global level offset to -LEVEL so all function levels are
707 normalized to start at zero. */
708 btinfo->level = -level;
711 #if defined (HAVE_LIBIPT)
713 static enum btrace_insn_class
714 pt_reclassify_insn (enum pt_insn_class iclass)
719 return BTRACE_INSN_CALL;
722 return BTRACE_INSN_RETURN;
725 return BTRACE_INSN_JUMP;
728 return BTRACE_INSN_OTHER;
732 /* Return the btrace instruction flags for INSN. */
734 static btrace_insn_flags
735 pt_btrace_insn_flags (const struct pt_insn *insn)
737 btrace_insn_flags flags = 0;
739 if (insn->speculative)
740 flags |= BTRACE_INSN_FLAG_SPECULATIVE;
745 /* Add function branch trace using DECODER. */
748 ftrace_add_pt (struct pt_insn_decoder *decoder,
749 struct btrace_function **pbegin,
750 struct btrace_function **pend, int *plevel,
753 struct btrace_function *begin, *end, *upd;
761 struct btrace_insn btinsn;
764 errcode = pt_insn_sync_forward (decoder);
767 if (errcode != -pte_eos)
768 warning (_("Failed to synchronize onto the Intel Processor "
769 "Trace stream: %s."), pt_errstr (pt_errcode (errcode)));
773 memset (&btinsn, 0, sizeof (btinsn));
776 errcode = pt_insn_next (decoder, &insn, sizeof(insn));
780 /* Look for gaps in the trace - unless we're at the beginning. */
783 /* Tracing is disabled and re-enabled each time we enter the
784 kernel. Most times, we continue from the same instruction we
785 stopped before. This is indicated via the RESUMED instruction
786 flag. The ENABLED instruction flag means that we continued
787 from some other instruction. Indicate this as a trace gap. */
790 *pend = end = ftrace_new_gap (end, BDE_PT_DISABLED);
793 pt_insn_get_offset (decoder, &offset);
795 warning (_("Non-contiguous trace at instruction %u (offset "
796 "= 0x%" PRIx64 ", pc = 0x%" PRIx64 ")."),
797 end->insn_offset - 1, offset, insn.ip);
800 /* Indicate trace overflows. */
803 *pend = end = ftrace_new_gap (end, BDE_PT_OVERFLOW);
806 pt_insn_get_offset (decoder, &offset);
808 warning (_("Overflow at instruction %u (offset = 0x%" PRIx64
809 ", pc = 0x%" PRIx64 ")."), end->insn_offset - 1,
814 upd = ftrace_update_function (end, insn.ip);
820 *pbegin = begin = upd;
823 /* Maintain the function level offset. */
824 *plevel = std::min (*plevel, end->level);
826 btinsn.pc = (CORE_ADDR) insn.ip;
827 btinsn.size = (gdb_byte) insn.size;
828 btinsn.iclass = pt_reclassify_insn (insn.iclass);
829 btinsn.flags = pt_btrace_insn_flags (&insn);
831 ftrace_update_insns (end, &btinsn);
834 if (errcode == -pte_eos)
837 /* If the gap is at the very beginning, we ignore it - we will have
838 less trace, but we won't have any holes in the trace. */
842 /* Indicate the gap in the trace. */
843 *pend = end = ftrace_new_gap (end, errcode);
846 pt_insn_get_offset (decoder, &offset);
848 warning (_("Decode error (%d) at instruction %u (offset = 0x%" PRIx64
849 ", pc = 0x%" PRIx64 "): %s."), errcode, end->insn_offset - 1,
850 offset, insn.ip, pt_errstr (pt_errcode (errcode)));
854 /* A callback function to allow the trace decoder to read the inferior's
858 btrace_pt_readmem_callback (gdb_byte *buffer, size_t size,
859 const struct pt_asid *asid, uint64_t pc,
867 errcode = target_read_code ((CORE_ADDR) pc, buffer, size);
871 CATCH (error, RETURN_MASK_ERROR)
880 /* Translate the vendor from one enum to another. */
882 static enum pt_cpu_vendor
883 pt_translate_cpu_vendor (enum btrace_cpu_vendor vendor)
895 /* Finalize the function branch trace after decode. */
897 static void btrace_finalize_ftrace_pt (struct pt_insn_decoder *decoder,
898 struct thread_info *tp, int level)
900 pt_insn_free_decoder (decoder);
902 /* LEVEL is the minimal function level of all btrace function segments.
903 Define the global level offset to -LEVEL so all function levels are
904 normalized to start at zero. */
905 tp->btrace.level = -level;
907 /* Add a single last instruction entry for the current PC.
908 This allows us to compute the backtrace at the current PC using both
909 standard unwind and btrace unwind.
910 This extra entry is ignored by all record commands. */
914 /* Compute the function branch trace from Intel Processor Trace
918 btrace_compute_ftrace_pt (struct thread_info *tp,
919 const struct btrace_data_pt *btrace)
921 struct btrace_thread_info *btinfo;
922 struct pt_insn_decoder *decoder;
923 struct pt_config config;
926 if (btrace->size == 0)
929 btinfo = &tp->btrace;
930 level = btinfo->begin != NULL ? -btinfo->level : INT_MAX;
932 pt_config_init(&config);
933 config.begin = btrace->data;
934 config.end = btrace->data + btrace->size;
936 config.cpu.vendor = pt_translate_cpu_vendor (btrace->config.cpu.vendor);
937 config.cpu.family = btrace->config.cpu.family;
938 config.cpu.model = btrace->config.cpu.model;
939 config.cpu.stepping = btrace->config.cpu.stepping;
941 errcode = pt_cpu_errata (&config.errata, &config.cpu);
943 error (_("Failed to configure the Intel Processor Trace decoder: %s."),
944 pt_errstr (pt_errcode (errcode)));
946 decoder = pt_insn_alloc_decoder (&config);
948 error (_("Failed to allocate the Intel Processor Trace decoder."));
952 struct pt_image *image;
954 image = pt_insn_get_image(decoder);
956 error (_("Failed to configure the Intel Processor Trace decoder."));
958 errcode = pt_image_set_callback(image, btrace_pt_readmem_callback, NULL);
960 error (_("Failed to configure the Intel Processor Trace decoder: "
961 "%s."), pt_errstr (pt_errcode (errcode)));
963 ftrace_add_pt (decoder, &btinfo->begin, &btinfo->end, &level,
966 CATCH (error, RETURN_MASK_ALL)
968 /* Indicate a gap in the trace if we quit trace processing. */
969 if (error.reason == RETURN_QUIT && btinfo->end != NULL)
971 btinfo->end = ftrace_new_gap (btinfo->end, BDE_PT_USER_QUIT);
975 btrace_finalize_ftrace_pt (decoder, tp, level);
977 throw_exception (error);
981 btrace_finalize_ftrace_pt (decoder, tp, level);
984 #else /* defined (HAVE_LIBIPT) */
987 btrace_compute_ftrace_pt (struct thread_info *tp,
988 const struct btrace_data_pt *btrace)
990 internal_error (__FILE__, __LINE__, _("Unexpected branch trace format."));
993 #endif /* defined (HAVE_LIBIPT) */
995 /* Compute the function branch trace from a block branch trace BTRACE for
996 a thread given by BTINFO. */
999 btrace_compute_ftrace (struct thread_info *tp, struct btrace_data *btrace)
1001 DEBUG ("compute ftrace");
1003 switch (btrace->format)
1005 case BTRACE_FORMAT_NONE:
1008 case BTRACE_FORMAT_BTS:
1009 btrace_compute_ftrace_bts (tp, &btrace->variant.bts);
1012 case BTRACE_FORMAT_PT:
1013 btrace_compute_ftrace_pt (tp, &btrace->variant.pt);
1017 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
1020 /* Add an entry for the current PC. */
1023 btrace_add_pc (struct thread_info *tp)
1025 struct btrace_data btrace;
1026 struct btrace_block *block;
1027 struct regcache *regcache;
1028 struct cleanup *cleanup;
1031 regcache = get_thread_regcache (tp->ptid);
1032 pc = regcache_read_pc (regcache);
1034 btrace_data_init (&btrace);
1035 btrace.format = BTRACE_FORMAT_BTS;
1036 btrace.variant.bts.blocks = NULL;
1038 cleanup = make_cleanup_btrace_data (&btrace);
1040 block = VEC_safe_push (btrace_block_s, btrace.variant.bts.blocks, NULL);
1044 btrace_compute_ftrace (tp, &btrace);
1046 do_cleanups (cleanup);
1052 btrace_enable (struct thread_info *tp, const struct btrace_config *conf)
1054 if (tp->btrace.target != NULL)
1057 #if !defined (HAVE_LIBIPT)
1058 if (conf->format == BTRACE_FORMAT_PT)
1059 error (_("GDB does not support Intel Processor Trace."));
1060 #endif /* !defined (HAVE_LIBIPT) */
1062 if (!target_supports_btrace (conf->format))
1063 error (_("Target does not support branch tracing."));
1065 DEBUG ("enable thread %s (%s)", print_thread_id (tp),
1066 target_pid_to_str (tp->ptid));
1068 tp->btrace.target = target_enable_btrace (tp->ptid, conf);
1070 /* Add an entry for the current PC so we start tracing from where we
1072 if (tp->btrace.target != NULL)
1078 const struct btrace_config *
1079 btrace_conf (const struct btrace_thread_info *btinfo)
1081 if (btinfo->target == NULL)
1084 return target_btrace_conf (btinfo->target);
1090 btrace_disable (struct thread_info *tp)
1092 struct btrace_thread_info *btp = &tp->btrace;
1095 if (btp->target == NULL)
1098 DEBUG ("disable thread %s (%s)", print_thread_id (tp),
1099 target_pid_to_str (tp->ptid));
1101 target_disable_btrace (btp->target);
1110 btrace_teardown (struct thread_info *tp)
1112 struct btrace_thread_info *btp = &tp->btrace;
1115 if (btp->target == NULL)
1118 DEBUG ("teardown thread %s (%s)", print_thread_id (tp),
1119 target_pid_to_str (tp->ptid));
1121 target_teardown_btrace (btp->target);
1127 /* Stitch branch trace in BTS format. */
1130 btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
1132 struct btrace_thread_info *btinfo;
1133 struct btrace_function *last_bfun;
1134 struct btrace_insn *last_insn;
1135 btrace_block_s *first_new_block;
1137 btinfo = &tp->btrace;
1138 last_bfun = btinfo->end;
1139 gdb_assert (last_bfun != NULL);
1140 gdb_assert (!VEC_empty (btrace_block_s, btrace->blocks));
1142 /* If the existing trace ends with a gap, we just glue the traces
1143 together. We need to drop the last (i.e. chronologically first) block
1144 of the new trace, though, since we can't fill in the start address.*/
1145 if (VEC_empty (btrace_insn_s, last_bfun->insn))
1147 VEC_pop (btrace_block_s, btrace->blocks);
1151 /* Beware that block trace starts with the most recent block, so the
1152 chronologically first block in the new trace is the last block in
1153 the new trace's block vector. */
1154 first_new_block = VEC_last (btrace_block_s, btrace->blocks);
1155 last_insn = VEC_last (btrace_insn_s, last_bfun->insn);
1157 /* If the current PC at the end of the block is the same as in our current
1158 trace, there are two explanations:
1159 1. we executed the instruction and some branch brought us back.
1160 2. we have not made any progress.
1161 In the first case, the delta trace vector should contain at least two
1163 In the second case, the delta trace vector should contain exactly one
1164 entry for the partial block containing the current PC. Remove it. */
1165 if (first_new_block->end == last_insn->pc
1166 && VEC_length (btrace_block_s, btrace->blocks) == 1)
1168 VEC_pop (btrace_block_s, btrace->blocks);
1172 DEBUG ("stitching %s to %s", ftrace_print_insn_addr (last_insn),
1173 core_addr_to_string_nz (first_new_block->end));
1175 /* Do a simple sanity check to make sure we don't accidentally end up
1176 with a bad block. This should not occur in practice. */
1177 if (first_new_block->end < last_insn->pc)
1179 warning (_("Error while trying to read delta trace. Falling back to "
1184 /* We adjust the last block to start at the end of our current trace. */
1185 gdb_assert (first_new_block->begin == 0);
1186 first_new_block->begin = last_insn->pc;
1188 /* We simply pop the last insn so we can insert it again as part of
1189 the normal branch trace computation.
1190 Since instruction iterators are based on indices in the instructions
1191 vector, we don't leave any pointers dangling. */
1192 DEBUG ("pruning insn at %s for stitching",
1193 ftrace_print_insn_addr (last_insn));
1195 VEC_pop (btrace_insn_s, last_bfun->insn);
1197 /* The instructions vector may become empty temporarily if this has
1198 been the only instruction in this function segment.
1199 This violates the invariant but will be remedied shortly by
1200 btrace_compute_ftrace when we add the new trace. */
1202 /* The only case where this would hurt is if the entire trace consisted
1203 of just that one instruction. If we remove it, we might turn the now
1204 empty btrace function segment into a gap. But we don't want gaps at
1205 the beginning. To avoid this, we remove the entire old trace. */
1206 if (last_bfun == btinfo->begin && VEC_empty (btrace_insn_s, last_bfun->insn))
1212 /* Adjust the block trace in order to stitch old and new trace together.
1213 BTRACE is the new delta trace between the last and the current stop.
1214 TP is the traced thread.
1215 May modifx BTRACE as well as the existing trace in TP.
1216 Return 0 on success, -1 otherwise. */
1219 btrace_stitch_trace (struct btrace_data *btrace, struct thread_info *tp)
1221 /* If we don't have trace, there's nothing to do. */
1222 if (btrace_data_empty (btrace))
1225 switch (btrace->format)
1227 case BTRACE_FORMAT_NONE:
1230 case BTRACE_FORMAT_BTS:
1231 return btrace_stitch_bts (&btrace->variant.bts, tp);
1233 case BTRACE_FORMAT_PT:
1234 /* Delta reads are not supported. */
1238 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
1241 /* Clear the branch trace histories in BTINFO. */
1244 btrace_clear_history (struct btrace_thread_info *btinfo)
1246 xfree (btinfo->insn_history);
1247 xfree (btinfo->call_history);
1248 xfree (btinfo->replay);
1250 btinfo->insn_history = NULL;
1251 btinfo->call_history = NULL;
1252 btinfo->replay = NULL;
1255 /* Clear the branch trace maintenance histories in BTINFO. */
1258 btrace_maint_clear (struct btrace_thread_info *btinfo)
1260 switch (btinfo->data.format)
1265 case BTRACE_FORMAT_BTS:
1266 btinfo->maint.variant.bts.packet_history.begin = 0;
1267 btinfo->maint.variant.bts.packet_history.end = 0;
1270 #if defined (HAVE_LIBIPT)
1271 case BTRACE_FORMAT_PT:
1272 xfree (btinfo->maint.variant.pt.packets);
1274 btinfo->maint.variant.pt.packets = NULL;
1275 btinfo->maint.variant.pt.packet_history.begin = 0;
1276 btinfo->maint.variant.pt.packet_history.end = 0;
1278 #endif /* defined (HAVE_LIBIPT) */
1285 btrace_fetch (struct thread_info *tp)
1287 struct btrace_thread_info *btinfo;
1288 struct btrace_target_info *tinfo;
1289 struct btrace_data btrace;
1290 struct cleanup *cleanup;
1293 DEBUG ("fetch thread %s (%s)", print_thread_id (tp),
1294 target_pid_to_str (tp->ptid));
1296 btinfo = &tp->btrace;
1297 tinfo = btinfo->target;
1301 /* There's no way we could get new trace while replaying.
1302 On the other hand, delta trace would return a partial record with the
1303 current PC, which is the replay PC, not the last PC, as expected. */
1304 if (btinfo->replay != NULL)
1307 btrace_data_init (&btrace);
1308 cleanup = make_cleanup_btrace_data (&btrace);
1310 /* Let's first try to extend the trace we already have. */
1311 if (btinfo->end != NULL)
1313 errcode = target_read_btrace (&btrace, tinfo, BTRACE_READ_DELTA);
1316 /* Success. Let's try to stitch the traces together. */
1317 errcode = btrace_stitch_trace (&btrace, tp);
1321 /* We failed to read delta trace. Let's try to read new trace. */
1322 errcode = target_read_btrace (&btrace, tinfo, BTRACE_READ_NEW);
1324 /* If we got any new trace, discard what we have. */
1325 if (errcode == 0 && !btrace_data_empty (&btrace))
1329 /* If we were not able to read the trace, we start over. */
1333 errcode = target_read_btrace (&btrace, tinfo, BTRACE_READ_ALL);
1337 errcode = target_read_btrace (&btrace, tinfo, BTRACE_READ_ALL);
1339 /* If we were not able to read the branch trace, signal an error. */
1341 error (_("Failed to read branch trace."));
1343 /* Compute the trace, provided we have any. */
1344 if (!btrace_data_empty (&btrace))
1346 /* Store the raw trace data. The stored data will be cleared in
1347 btrace_clear, so we always append the new trace. */
1348 btrace_data_append (&btinfo->data, &btrace);
1349 btrace_maint_clear (btinfo);
1351 btrace_clear_history (btinfo);
1352 btrace_compute_ftrace (tp, &btrace);
1355 do_cleanups (cleanup);
1361 btrace_clear (struct thread_info *tp)
1363 struct btrace_thread_info *btinfo;
1364 struct btrace_function *it, *trash;
1366 DEBUG ("clear thread %s (%s)", print_thread_id (tp),
1367 target_pid_to_str (tp->ptid));
1369 /* Make sure btrace frames that may hold a pointer into the branch
1370 trace data are destroyed. */
1371 reinit_frame_cache ();
1373 btinfo = &tp->btrace;
1384 btinfo->begin = NULL;
1388 /* Must clear the maint data before - it depends on BTINFO->DATA. */
1389 btrace_maint_clear (btinfo);
1390 btrace_data_clear (&btinfo->data);
1391 btrace_clear_history (btinfo);
1397 btrace_free_objfile (struct objfile *objfile)
1399 struct thread_info *tp;
1401 DEBUG ("free objfile");
1403 ALL_NON_EXITED_THREADS (tp)
1407 #if defined (HAVE_LIBEXPAT)
1409 /* Check the btrace document version. */
1412 check_xml_btrace_version (struct gdb_xml_parser *parser,
1413 const struct gdb_xml_element *element,
1414 void *user_data, VEC (gdb_xml_value_s) *attributes)
1417 = (const char *) xml_find_attribute (attributes, "version")->value;
1419 if (strcmp (version, "1.0") != 0)
1420 gdb_xml_error (parser, _("Unsupported btrace version: \"%s\""), version);
1423 /* Parse a btrace "block" xml record. */
1426 parse_xml_btrace_block (struct gdb_xml_parser *parser,
1427 const struct gdb_xml_element *element,
1428 void *user_data, VEC (gdb_xml_value_s) *attributes)
1430 struct btrace_data *btrace;
1431 struct btrace_block *block;
1432 ULONGEST *begin, *end;
1434 btrace = (struct btrace_data *) user_data;
1436 switch (btrace->format)
1438 case BTRACE_FORMAT_BTS:
1441 case BTRACE_FORMAT_NONE:
1442 btrace->format = BTRACE_FORMAT_BTS;
1443 btrace->variant.bts.blocks = NULL;
1447 gdb_xml_error (parser, _("Btrace format error."));
1450 begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value;
1451 end = (ULONGEST *) xml_find_attribute (attributes, "end")->value;
1453 block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
1454 block->begin = *begin;
1458 /* Parse a "raw" xml record. */
1461 parse_xml_raw (struct gdb_xml_parser *parser, const char *body_text,
1462 gdb_byte **pdata, size_t *psize)
1464 struct cleanup *cleanup;
1465 gdb_byte *data, *bin;
1468 len = strlen (body_text);
1470 gdb_xml_error (parser, _("Bad raw data size."));
1474 bin = data = (gdb_byte *) xmalloc (size);
1475 cleanup = make_cleanup (xfree, data);
1477 /* We use hex encoding - see common/rsp-low.h. */
1485 if (hi == 0 || lo == 0)
1486 gdb_xml_error (parser, _("Bad hex encoding."));
1488 *bin++ = fromhex (hi) * 16 + fromhex (lo);
1492 discard_cleanups (cleanup);
1498 /* Parse a btrace pt-config "cpu" xml record. */
1501 parse_xml_btrace_pt_config_cpu (struct gdb_xml_parser *parser,
1502 const struct gdb_xml_element *element,
1504 VEC (gdb_xml_value_s) *attributes)
1506 struct btrace_data *btrace;
1508 ULONGEST *family, *model, *stepping;
1510 vendor = (const char *) xml_find_attribute (attributes, "vendor")->value;
1511 family = (ULONGEST *) xml_find_attribute (attributes, "family")->value;
1512 model = (ULONGEST *) xml_find_attribute (attributes, "model")->value;
1513 stepping = (ULONGEST *) xml_find_attribute (attributes, "stepping")->value;
1515 btrace = (struct btrace_data *) user_data;
1517 if (strcmp (vendor, "GenuineIntel") == 0)
1518 btrace->variant.pt.config.cpu.vendor = CV_INTEL;
1520 btrace->variant.pt.config.cpu.family = *family;
1521 btrace->variant.pt.config.cpu.model = *model;
1522 btrace->variant.pt.config.cpu.stepping = *stepping;
1525 /* Parse a btrace pt "raw" xml record. */
1528 parse_xml_btrace_pt_raw (struct gdb_xml_parser *parser,
1529 const struct gdb_xml_element *element,
1530 void *user_data, const char *body_text)
1532 struct btrace_data *btrace;
1534 btrace = (struct btrace_data *) user_data;
1535 parse_xml_raw (parser, body_text, &btrace->variant.pt.data,
1536 &btrace->variant.pt.size);
1539 /* Parse a btrace "pt" xml record. */
1542 parse_xml_btrace_pt (struct gdb_xml_parser *parser,
1543 const struct gdb_xml_element *element,
1544 void *user_data, VEC (gdb_xml_value_s) *attributes)
1546 struct btrace_data *btrace;
1548 btrace = (struct btrace_data *) user_data;
1549 btrace->format = BTRACE_FORMAT_PT;
1550 btrace->variant.pt.config.cpu.vendor = CV_UNKNOWN;
1551 btrace->variant.pt.data = NULL;
1552 btrace->variant.pt.size = 0;
1555 static const struct gdb_xml_attribute block_attributes[] = {
1556 { "begin", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1557 { "end", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1558 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1561 static const struct gdb_xml_attribute btrace_pt_config_cpu_attributes[] = {
1562 { "vendor", GDB_XML_AF_NONE, NULL, NULL },
1563 { "family", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1564 { "model", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1565 { "stepping", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1566 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1569 static const struct gdb_xml_element btrace_pt_config_children[] = {
1570 { "cpu", btrace_pt_config_cpu_attributes, NULL, GDB_XML_EF_OPTIONAL,
1571 parse_xml_btrace_pt_config_cpu, NULL },
1572 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1575 static const struct gdb_xml_element btrace_pt_children[] = {
1576 { "pt-config", NULL, btrace_pt_config_children, GDB_XML_EF_OPTIONAL, NULL,
1578 { "raw", NULL, NULL, GDB_XML_EF_OPTIONAL, NULL, parse_xml_btrace_pt_raw },
1579 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1582 static const struct gdb_xml_attribute btrace_attributes[] = {
1583 { "version", GDB_XML_AF_NONE, NULL, NULL },
1584 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1587 static const struct gdb_xml_element btrace_children[] = {
1588 { "block", block_attributes, NULL,
1589 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, parse_xml_btrace_block, NULL },
1590 { "pt", NULL, btrace_pt_children, GDB_XML_EF_OPTIONAL, parse_xml_btrace_pt,
1592 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1595 static const struct gdb_xml_element btrace_elements[] = {
1596 { "btrace", btrace_attributes, btrace_children, GDB_XML_EF_NONE,
1597 check_xml_btrace_version, NULL },
1598 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1601 #endif /* defined (HAVE_LIBEXPAT) */
1606 parse_xml_btrace (struct btrace_data *btrace, const char *buffer)
1608 struct cleanup *cleanup;
1611 #if defined (HAVE_LIBEXPAT)
1613 btrace->format = BTRACE_FORMAT_NONE;
1615 cleanup = make_cleanup_btrace_data (btrace);
1616 errcode = gdb_xml_parse_quick (_("btrace"), "btrace.dtd", btrace_elements,
1619 error (_("Error parsing branch trace."));
1621 /* Keep parse results. */
1622 discard_cleanups (cleanup);
1624 #else /* !defined (HAVE_LIBEXPAT) */
1626 error (_("Cannot process branch trace. XML parsing is not supported."));
1628 #endif /* !defined (HAVE_LIBEXPAT) */
1631 #if defined (HAVE_LIBEXPAT)
1633 /* Parse a btrace-conf "bts" xml record. */
1636 parse_xml_btrace_conf_bts (struct gdb_xml_parser *parser,
1637 const struct gdb_xml_element *element,
1638 void *user_data, VEC (gdb_xml_value_s) *attributes)
1640 struct btrace_config *conf;
1641 struct gdb_xml_value *size;
1643 conf = (struct btrace_config *) user_data;
1644 conf->format = BTRACE_FORMAT_BTS;
1647 size = xml_find_attribute (attributes, "size");
1649 conf->bts.size = (unsigned int) *(ULONGEST *) size->value;
1652 /* Parse a btrace-conf "pt" xml record. */
1655 parse_xml_btrace_conf_pt (struct gdb_xml_parser *parser,
1656 const struct gdb_xml_element *element,
1657 void *user_data, VEC (gdb_xml_value_s) *attributes)
1659 struct btrace_config *conf;
1660 struct gdb_xml_value *size;
1662 conf = (struct btrace_config *) user_data;
1663 conf->format = BTRACE_FORMAT_PT;
1666 size = xml_find_attribute (attributes, "size");
1668 conf->pt.size = (unsigned int) *(ULONGEST *) size->value;
1671 static const struct gdb_xml_attribute btrace_conf_pt_attributes[] = {
1672 { "size", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
1673 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1676 static const struct gdb_xml_attribute btrace_conf_bts_attributes[] = {
1677 { "size", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
1678 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1681 static const struct gdb_xml_element btrace_conf_children[] = {
1682 { "bts", btrace_conf_bts_attributes, NULL, GDB_XML_EF_OPTIONAL,
1683 parse_xml_btrace_conf_bts, NULL },
1684 { "pt", btrace_conf_pt_attributes, NULL, GDB_XML_EF_OPTIONAL,
1685 parse_xml_btrace_conf_pt, NULL },
1686 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1689 static const struct gdb_xml_attribute btrace_conf_attributes[] = {
1690 { "version", GDB_XML_AF_NONE, NULL, NULL },
1691 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1694 static const struct gdb_xml_element btrace_conf_elements[] = {
1695 { "btrace-conf", btrace_conf_attributes, btrace_conf_children,
1696 GDB_XML_EF_NONE, NULL, NULL },
1697 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1700 #endif /* defined (HAVE_LIBEXPAT) */
1705 parse_xml_btrace_conf (struct btrace_config *conf, const char *xml)
1709 #if defined (HAVE_LIBEXPAT)
1711 errcode = gdb_xml_parse_quick (_("btrace-conf"), "btrace-conf.dtd",
1712 btrace_conf_elements, xml, conf);
1714 error (_("Error parsing branch trace configuration."));
1716 #else /* !defined (HAVE_LIBEXPAT) */
1718 error (_("XML parsing is not supported."));
1720 #endif /* !defined (HAVE_LIBEXPAT) */
1725 const struct btrace_insn *
1726 btrace_insn_get (const struct btrace_insn_iterator *it)
1728 const struct btrace_function *bfun;
1729 unsigned int index, end;
1732 bfun = it->function;
1734 /* Check if the iterator points to a gap in the trace. */
1735 if (bfun->errcode != 0)
1738 /* The index is within the bounds of this function's instruction vector. */
1739 end = VEC_length (btrace_insn_s, bfun->insn);
1740 gdb_assert (0 < end);
1741 gdb_assert (index < end);
1743 return VEC_index (btrace_insn_s, bfun->insn, index);
1749 btrace_insn_number (const struct btrace_insn_iterator *it)
1751 const struct btrace_function *bfun;
1753 bfun = it->function;
1755 /* Return zero if the iterator points to a gap in the trace. */
1756 if (bfun->errcode != 0)
1759 return bfun->insn_offset + it->index;
1765 btrace_insn_begin (struct btrace_insn_iterator *it,
1766 const struct btrace_thread_info *btinfo)
1768 const struct btrace_function *bfun;
1770 bfun = btinfo->begin;
1772 error (_("No trace."));
1774 it->function = bfun;
1781 btrace_insn_end (struct btrace_insn_iterator *it,
1782 const struct btrace_thread_info *btinfo)
1784 const struct btrace_function *bfun;
1785 unsigned int length;
1789 error (_("No trace."));
1791 length = VEC_length (btrace_insn_s, bfun->insn);
1793 /* The last function may either be a gap or it contains the current
1794 instruction, which is one past the end of the execution trace; ignore
1799 it->function = bfun;
1806 btrace_insn_next (struct btrace_insn_iterator *it, unsigned int stride)
1808 const struct btrace_function *bfun;
1809 unsigned int index, steps;
1811 bfun = it->function;
1817 unsigned int end, space, adv;
1819 end = VEC_length (btrace_insn_s, bfun->insn);
1821 /* An empty function segment represents a gap in the trace. We count
1822 it as one instruction. */
1825 const struct btrace_function *next;
1827 next = bfun->flow.next;
1840 gdb_assert (0 < end);
1841 gdb_assert (index < end);
1843 /* Compute the number of instructions remaining in this segment. */
1844 space = end - index;
1846 /* Advance the iterator as far as possible within this segment. */
1847 adv = std::min (space, stride);
1852 /* Move to the next function if we're at the end of this one. */
1855 const struct btrace_function *next;
1857 next = bfun->flow.next;
1860 /* We stepped past the last function.
1862 Let's adjust the index to point to the last instruction in
1863 the previous function. */
1869 /* We now point to the first instruction in the new function. */
1874 /* We did make progress. */
1875 gdb_assert (adv > 0);
1878 /* Update the iterator. */
1879 it->function = bfun;
1888 btrace_insn_prev (struct btrace_insn_iterator *it, unsigned int stride)
1890 const struct btrace_function *bfun;
1891 unsigned int index, steps;
1893 bfun = it->function;
1901 /* Move to the previous function if we're at the start of this one. */
1904 const struct btrace_function *prev;
1906 prev = bfun->flow.prev;
1910 /* We point to one after the last instruction in the new function. */
1912 index = VEC_length (btrace_insn_s, bfun->insn);
1914 /* An empty function segment represents a gap in the trace. We count
1915 it as one instruction. */
1925 /* Advance the iterator as far as possible within this segment. */
1926 adv = std::min (index, stride);
1932 /* We did make progress. */
1933 gdb_assert (adv > 0);
1936 /* Update the iterator. */
1937 it->function = bfun;
1946 btrace_insn_cmp (const struct btrace_insn_iterator *lhs,
1947 const struct btrace_insn_iterator *rhs)
1949 unsigned int lnum, rnum;
1951 lnum = btrace_insn_number (lhs);
1952 rnum = btrace_insn_number (rhs);
1954 /* A gap has an instruction number of zero. Things are getting more
1955 complicated if gaps are involved.
1957 We take the instruction number offset from the iterator's function.
1958 This is the number of the first instruction after the gap.
1960 This is OK as long as both lhs and rhs point to gaps. If only one of
1961 them does, we need to adjust the number based on the other's regular
1962 instruction number. Otherwise, a gap might compare equal to an
1965 if (lnum == 0 && rnum == 0)
1967 lnum = lhs->function->insn_offset;
1968 rnum = rhs->function->insn_offset;
1972 lnum = lhs->function->insn_offset;
1979 rnum = rhs->function->insn_offset;
1985 return (int) (lnum - rnum);
1991 btrace_find_insn_by_number (struct btrace_insn_iterator *it,
1992 const struct btrace_thread_info *btinfo,
1993 unsigned int number)
1995 const struct btrace_function *bfun;
1996 unsigned int end, length;
1998 for (bfun = btinfo->end; bfun != NULL; bfun = bfun->flow.prev)
2001 if (bfun->errcode != 0)
2004 if (bfun->insn_offset <= number)
2011 length = VEC_length (btrace_insn_s, bfun->insn);
2012 gdb_assert (length > 0);
2014 end = bfun->insn_offset + length;
2018 it->function = bfun;
2019 it->index = number - bfun->insn_offset;
2026 const struct btrace_function *
2027 btrace_call_get (const struct btrace_call_iterator *it)
2029 return it->function;
2035 btrace_call_number (const struct btrace_call_iterator *it)
2037 const struct btrace_thread_info *btinfo;
2038 const struct btrace_function *bfun;
2041 btinfo = it->btinfo;
2042 bfun = it->function;
2044 return bfun->number;
2046 /* For the end iterator, i.e. bfun == NULL, we return one more than the
2047 number of the last function. */
2049 insns = VEC_length (btrace_insn_s, bfun->insn);
2051 /* If the function contains only a single instruction (i.e. the current
2052 instruction), it will be skipped and its number is already the number
2055 return bfun->number;
2057 /* Otherwise, return one more than the number of the last function. */
2058 return bfun->number + 1;
2064 btrace_call_begin (struct btrace_call_iterator *it,
2065 const struct btrace_thread_info *btinfo)
2067 const struct btrace_function *bfun;
2069 bfun = btinfo->begin;
2071 error (_("No trace."));
2073 it->btinfo = btinfo;
2074 it->function = bfun;
2080 btrace_call_end (struct btrace_call_iterator *it,
2081 const struct btrace_thread_info *btinfo)
2083 const struct btrace_function *bfun;
2087 error (_("No trace."));
2089 it->btinfo = btinfo;
2090 it->function = NULL;
2096 btrace_call_next (struct btrace_call_iterator *it, unsigned int stride)
2098 const struct btrace_function *bfun;
2101 bfun = it->function;
2103 while (bfun != NULL)
2105 const struct btrace_function *next;
2108 next = bfun->flow.next;
2111 /* Ignore the last function if it only contains a single
2112 (i.e. the current) instruction. */
2113 insns = VEC_length (btrace_insn_s, bfun->insn);
2118 if (stride == steps)
2125 it->function = bfun;
2132 btrace_call_prev (struct btrace_call_iterator *it, unsigned int stride)
2134 const struct btrace_thread_info *btinfo;
2135 const struct btrace_function *bfun;
2138 bfun = it->function;
2145 btinfo = it->btinfo;
2150 /* Ignore the last function if it only contains a single
2151 (i.e. the current) instruction. */
2152 insns = VEC_length (btrace_insn_s, bfun->insn);
2154 bfun = bfun->flow.prev;
2162 while (steps < stride)
2164 const struct btrace_function *prev;
2166 prev = bfun->flow.prev;
2174 it->function = bfun;
2181 btrace_call_cmp (const struct btrace_call_iterator *lhs,
2182 const struct btrace_call_iterator *rhs)
2184 unsigned int lnum, rnum;
2186 lnum = btrace_call_number (lhs);
2187 rnum = btrace_call_number (rhs);
2189 return (int) (lnum - rnum);
2195 btrace_find_call_by_number (struct btrace_call_iterator *it,
2196 const struct btrace_thread_info *btinfo,
2197 unsigned int number)
2199 const struct btrace_function *bfun;
2201 for (bfun = btinfo->end; bfun != NULL; bfun = bfun->flow.prev)
2205 bnum = bfun->number;
2208 it->btinfo = btinfo;
2209 it->function = bfun;
2213 /* Functions are ordered and numbered consecutively. We could bail out
2214 earlier. On the other hand, it is very unlikely that we search for
2215 a nonexistent function. */
2224 btrace_set_insn_history (struct btrace_thread_info *btinfo,
2225 const struct btrace_insn_iterator *begin,
2226 const struct btrace_insn_iterator *end)
2228 if (btinfo->insn_history == NULL)
2229 btinfo->insn_history = XCNEW (struct btrace_insn_history);
2231 btinfo->insn_history->begin = *begin;
2232 btinfo->insn_history->end = *end;
2238 btrace_set_call_history (struct btrace_thread_info *btinfo,
2239 const struct btrace_call_iterator *begin,
2240 const struct btrace_call_iterator *end)
2242 gdb_assert (begin->btinfo == end->btinfo);
2244 if (btinfo->call_history == NULL)
2245 btinfo->call_history = XCNEW (struct btrace_call_history);
2247 btinfo->call_history->begin = *begin;
2248 btinfo->call_history->end = *end;
2254 btrace_is_replaying (struct thread_info *tp)
2256 return tp->btrace.replay != NULL;
2262 btrace_is_empty (struct thread_info *tp)
2264 struct btrace_insn_iterator begin, end;
2265 struct btrace_thread_info *btinfo;
2267 btinfo = &tp->btrace;
2269 if (btinfo->begin == NULL)
2272 btrace_insn_begin (&begin, btinfo);
2273 btrace_insn_end (&end, btinfo);
2275 return btrace_insn_cmp (&begin, &end) == 0;
2278 /* Forward the cleanup request. */
2281 do_btrace_data_cleanup (void *arg)
2283 btrace_data_fini ((struct btrace_data *) arg);
2289 make_cleanup_btrace_data (struct btrace_data *data)
2291 return make_cleanup (do_btrace_data_cleanup, data);
2294 #if defined (HAVE_LIBIPT)
2296 /* Print a single packet. */
2299 pt_print_packet (const struct pt_packet *packet)
2301 switch (packet->type)
2304 printf_unfiltered (("[??: %x]"), packet->type);
2308 printf_unfiltered (("psb"));
2312 printf_unfiltered (("psbend"));
2316 printf_unfiltered (("pad"));
2320 printf_unfiltered (("tip %u: 0x%" PRIx64 ""),
2321 packet->payload.ip.ipc,
2322 packet->payload.ip.ip);
2326 printf_unfiltered (("tip.pge %u: 0x%" PRIx64 ""),
2327 packet->payload.ip.ipc,
2328 packet->payload.ip.ip);
2332 printf_unfiltered (("tip.pgd %u: 0x%" PRIx64 ""),
2333 packet->payload.ip.ipc,
2334 packet->payload.ip.ip);
2338 printf_unfiltered (("fup %u: 0x%" PRIx64 ""),
2339 packet->payload.ip.ipc,
2340 packet->payload.ip.ip);
2344 printf_unfiltered (("tnt-8 %u: 0x%" PRIx64 ""),
2345 packet->payload.tnt.bit_size,
2346 packet->payload.tnt.payload);
2350 printf_unfiltered (("tnt-64 %u: 0x%" PRIx64 ""),
2351 packet->payload.tnt.bit_size,
2352 packet->payload.tnt.payload);
2356 printf_unfiltered (("pip %" PRIx64 "%s"), packet->payload.pip.cr3,
2357 packet->payload.pip.nr ? (" nr") : (""));
2361 printf_unfiltered (("tsc %" PRIx64 ""), packet->payload.tsc.tsc);
2365 printf_unfiltered (("cbr %u"), packet->payload.cbr.ratio);
2369 switch (packet->payload.mode.leaf)
2372 printf_unfiltered (("mode %u"), packet->payload.mode.leaf);
2376 printf_unfiltered (("mode.exec%s%s"),
2377 packet->payload.mode.bits.exec.csl
2379 packet->payload.mode.bits.exec.csd
2380 ? (" cs.d") : (""));
2384 printf_unfiltered (("mode.tsx%s%s"),
2385 packet->payload.mode.bits.tsx.intx
2387 packet->payload.mode.bits.tsx.abrt
2388 ? (" abrt") : (""));
2394 printf_unfiltered (("ovf"));
2398 printf_unfiltered (("stop"));
2402 printf_unfiltered (("vmcs %" PRIx64 ""), packet->payload.vmcs.base);
2406 printf_unfiltered (("tma %x %x"), packet->payload.tma.ctc,
2407 packet->payload.tma.fc);
2411 printf_unfiltered (("mtc %x"), packet->payload.mtc.ctc);
2415 printf_unfiltered (("cyc %" PRIx64 ""), packet->payload.cyc.value);
2419 printf_unfiltered (("mnt %" PRIx64 ""), packet->payload.mnt.payload);
2424 /* Decode packets into MAINT using DECODER. */
2427 btrace_maint_decode_pt (struct btrace_maint_info *maint,
2428 struct pt_packet_decoder *decoder)
2434 struct btrace_pt_packet packet;
2436 errcode = pt_pkt_sync_forward (decoder);
2442 pt_pkt_get_offset (decoder, &packet.offset);
2444 errcode = pt_pkt_next (decoder, &packet.packet,
2445 sizeof(packet.packet));
2449 if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
2451 packet.errcode = pt_errcode (errcode);
2452 VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
2457 if (errcode == -pte_eos)
2460 packet.errcode = pt_errcode (errcode);
2461 VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
2464 warning (_("Error at trace offset 0x%" PRIx64 ": %s."),
2465 packet.offset, pt_errstr (packet.errcode));
2468 if (errcode != -pte_eos)
2469 warning (_("Failed to synchronize onto the Intel Processor Trace "
2470 "stream: %s."), pt_errstr (pt_errcode (errcode)));
2473 /* Update the packet history in BTINFO. */
2476 btrace_maint_update_pt_packets (struct btrace_thread_info *btinfo)
2478 volatile struct gdb_exception except;
2479 struct pt_packet_decoder *decoder;
2480 struct btrace_data_pt *pt;
2481 struct pt_config config;
2484 pt = &btinfo->data.variant.pt;
2486 /* Nothing to do if there is no trace. */
2490 memset (&config, 0, sizeof(config));
2492 config.size = sizeof (config);
2493 config.begin = pt->data;
2494 config.end = pt->data + pt->size;
2496 config.cpu.vendor = pt_translate_cpu_vendor (pt->config.cpu.vendor);
2497 config.cpu.family = pt->config.cpu.family;
2498 config.cpu.model = pt->config.cpu.model;
2499 config.cpu.stepping = pt->config.cpu.stepping;
2501 errcode = pt_cpu_errata (&config.errata, &config.cpu);
2503 error (_("Failed to configure the Intel Processor Trace decoder: %s."),
2504 pt_errstr (pt_errcode (errcode)));
2506 decoder = pt_pkt_alloc_decoder (&config);
2507 if (decoder == NULL)
2508 error (_("Failed to allocate the Intel Processor Trace decoder."));
2512 btrace_maint_decode_pt (&btinfo->maint, decoder);
2514 CATCH (except, RETURN_MASK_ALL)
2516 pt_pkt_free_decoder (decoder);
2518 if (except.reason < 0)
2519 throw_exception (except);
2523 pt_pkt_free_decoder (decoder);
2526 #endif /* !defined (HAVE_LIBIPT) */
2528 /* Update the packet maintenance information for BTINFO and store the
2529 low and high bounds into BEGIN and END, respectively.
2530 Store the current iterator state into FROM and TO. */
2533 btrace_maint_update_packets (struct btrace_thread_info *btinfo,
2534 unsigned int *begin, unsigned int *end,
2535 unsigned int *from, unsigned int *to)
2537 switch (btinfo->data.format)
2546 case BTRACE_FORMAT_BTS:
2547 /* Nothing to do - we operate directly on BTINFO->DATA. */
2549 *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
2550 *from = btinfo->maint.variant.bts.packet_history.begin;
2551 *to = btinfo->maint.variant.bts.packet_history.end;
2554 #if defined (HAVE_LIBIPT)
2555 case BTRACE_FORMAT_PT:
2556 if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets))
2557 btrace_maint_update_pt_packets (btinfo);
2560 *end = VEC_length (btrace_pt_packet_s, btinfo->maint.variant.pt.packets);
2561 *from = btinfo->maint.variant.pt.packet_history.begin;
2562 *to = btinfo->maint.variant.pt.packet_history.end;
2564 #endif /* defined (HAVE_LIBIPT) */
2568 /* Print packets in BTINFO from BEGIN (inclusive) until END (exclusive) and
2569 update the current iterator position. */
2572 btrace_maint_print_packets (struct btrace_thread_info *btinfo,
2573 unsigned int begin, unsigned int end)
2575 switch (btinfo->data.format)
2580 case BTRACE_FORMAT_BTS:
2582 VEC (btrace_block_s) *blocks;
2585 blocks = btinfo->data.variant.bts.blocks;
2586 for (blk = begin; blk < end; ++blk)
2588 const btrace_block_s *block;
2590 block = VEC_index (btrace_block_s, blocks, blk);
2592 printf_unfiltered ("%u\tbegin: %s, end: %s\n", blk,
2593 core_addr_to_string_nz (block->begin),
2594 core_addr_to_string_nz (block->end));
2597 btinfo->maint.variant.bts.packet_history.begin = begin;
2598 btinfo->maint.variant.bts.packet_history.end = end;
2602 #if defined (HAVE_LIBIPT)
2603 case BTRACE_FORMAT_PT:
2605 VEC (btrace_pt_packet_s) *packets;
2608 packets = btinfo->maint.variant.pt.packets;
2609 for (pkt = begin; pkt < end; ++pkt)
2611 const struct btrace_pt_packet *packet;
2613 packet = VEC_index (btrace_pt_packet_s, packets, pkt);
2615 printf_unfiltered ("%u\t", pkt);
2616 printf_unfiltered ("0x%" PRIx64 "\t", packet->offset);
2618 if (packet->errcode == pte_ok)
2619 pt_print_packet (&packet->packet);
2621 printf_unfiltered ("[error: %s]", pt_errstr (packet->errcode));
2623 printf_unfiltered ("\n");
2626 btinfo->maint.variant.pt.packet_history.begin = begin;
2627 btinfo->maint.variant.pt.packet_history.end = end;
2630 #endif /* defined (HAVE_LIBIPT) */
2634 /* Read a number from an argument string. */
2637 get_uint (char **arg)
2639 char *begin, *end, *pos;
2640 unsigned long number;
2643 pos = skip_spaces (begin);
2645 if (!isdigit (*pos))
2646 error (_("Expected positive number, got: %s."), pos);
2648 number = strtoul (pos, &end, 10);
2649 if (number > UINT_MAX)
2650 error (_("Number too big."));
2652 *arg += (end - begin);
2654 return (unsigned int) number;
2657 /* Read a context size from an argument string. */
2660 get_context_size (char **arg)
2665 pos = skip_spaces (*arg);
2667 if (!isdigit (*pos))
2668 error (_("Expected positive number, got: %s."), pos);
2670 return strtol (pos, arg, 10);
2673 /* Complain about junk at the end of an argument string. */
2676 no_chunk (char *arg)
2679 error (_("Junk after argument: %s."), arg);
2682 /* The "maintenance btrace packet-history" command. */
2685 maint_btrace_packet_history_cmd (char *arg, int from_tty)
2687 struct btrace_thread_info *btinfo;
2688 struct thread_info *tp;
2689 unsigned int size, begin, end, from, to;
2691 tp = find_thread_ptid (inferior_ptid);
2693 error (_("No thread."));
2696 btinfo = &tp->btrace;
2698 btrace_maint_update_packets (btinfo, &begin, &end, &from, &to);
2701 printf_unfiltered (_("No trace.\n"));
2705 if (arg == NULL || *arg == 0 || strcmp (arg, "+") == 0)
2709 if (end - from < size)
2713 else if (strcmp (arg, "-") == 0)
2717 if (to - begin < size)
2723 from = get_uint (&arg);
2725 error (_("'%u' is out of range."), from);
2727 arg = skip_spaces (arg);
2730 arg = skip_spaces (++arg);
2735 size = get_context_size (&arg);
2739 if (end - from < size)
2743 else if (*arg == '-')
2746 size = get_context_size (&arg);
2750 /* Include the packet given as first argument. */
2754 if (to - begin < size)
2760 to = get_uint (&arg);
2762 /* Include the packet at the second argument and silently
2763 truncate the range. */
2776 if (end - from < size)
2784 btrace_maint_print_packets (btinfo, from, to);
2787 /* The "maintenance btrace clear-packet-history" command. */
2790 maint_btrace_clear_packet_history_cmd (char *args, int from_tty)
2792 struct btrace_thread_info *btinfo;
2793 struct thread_info *tp;
2795 if (args != NULL && *args != 0)
2796 error (_("Invalid argument."));
2798 tp = find_thread_ptid (inferior_ptid);
2800 error (_("No thread."));
2802 btinfo = &tp->btrace;
2804 /* Must clear the maint data before - it depends on BTINFO->DATA. */
2805 btrace_maint_clear (btinfo);
2806 btrace_data_clear (&btinfo->data);
2809 /* The "maintenance btrace clear" command. */
2812 maint_btrace_clear_cmd (char *args, int from_tty)
2814 struct btrace_thread_info *btinfo;
2815 struct thread_info *tp;
2817 if (args != NULL && *args != 0)
2818 error (_("Invalid argument."));
2820 tp = find_thread_ptid (inferior_ptid);
2822 error (_("No thread."));
2827 /* The "maintenance btrace" command. */
2830 maint_btrace_cmd (char *args, int from_tty)
2832 help_list (maint_btrace_cmdlist, "maintenance btrace ", all_commands,
2836 /* The "maintenance set btrace" command. */
2839 maint_btrace_set_cmd (char *args, int from_tty)
2841 help_list (maint_btrace_set_cmdlist, "maintenance set btrace ", all_commands,
2845 /* The "maintenance show btrace" command. */
2848 maint_btrace_show_cmd (char *args, int from_tty)
2850 help_list (maint_btrace_show_cmdlist, "maintenance show btrace ",
2851 all_commands, gdb_stdout);
2854 /* The "maintenance set btrace pt" command. */
2857 maint_btrace_pt_set_cmd (char *args, int from_tty)
2859 help_list (maint_btrace_pt_set_cmdlist, "maintenance set btrace pt ",
2860 all_commands, gdb_stdout);
2863 /* The "maintenance show btrace pt" command. */
2866 maint_btrace_pt_show_cmd (char *args, int from_tty)
2868 help_list (maint_btrace_pt_show_cmdlist, "maintenance show btrace pt ",
2869 all_commands, gdb_stdout);
2872 /* The "maintenance info btrace" command. */
2875 maint_info_btrace_cmd (char *args, int from_tty)
2877 struct btrace_thread_info *btinfo;
2878 struct thread_info *tp;
2879 const struct btrace_config *conf;
2881 if (args != NULL && *args != 0)
2882 error (_("Invalid argument."));
2884 tp = find_thread_ptid (inferior_ptid);
2886 error (_("No thread."));
2888 btinfo = &tp->btrace;
2890 conf = btrace_conf (btinfo);
2892 error (_("No btrace configuration."));
2894 printf_unfiltered (_("Format: %s.\n"),
2895 btrace_format_string (conf->format));
2897 switch (conf->format)
2902 case BTRACE_FORMAT_BTS:
2903 printf_unfiltered (_("Number of packets: %u.\n"),
2904 VEC_length (btrace_block_s,
2905 btinfo->data.variant.bts.blocks));
2908 #if defined (HAVE_LIBIPT)
2909 case BTRACE_FORMAT_PT:
2911 struct pt_version version;
2913 version = pt_library_version ();
2914 printf_unfiltered (_("Version: %u.%u.%u%s.\n"), version.major,
2915 version.minor, version.build,
2916 version.ext != NULL ? version.ext : "");
2918 btrace_maint_update_pt_packets (btinfo);
2919 printf_unfiltered (_("Number of packets: %u.\n"),
2920 VEC_length (btrace_pt_packet_s,
2921 btinfo->maint.variant.pt.packets));
2924 #endif /* defined (HAVE_LIBIPT) */
2928 /* The "maint show btrace pt skip-pad" show value function. */
2931 show_maint_btrace_pt_skip_pad (struct ui_file *file, int from_tty,
2932 struct cmd_list_element *c,
2935 fprintf_filtered (file, _("Skip PAD packets is %s.\n"), value);
2939 /* Initialize btrace maintenance commands. */
2941 void _initialize_btrace (void);
2943 _initialize_btrace (void)
2945 add_cmd ("btrace", class_maintenance, maint_info_btrace_cmd,
2946 _("Info about branch tracing data."), &maintenanceinfolist);
2948 add_prefix_cmd ("btrace", class_maintenance, maint_btrace_cmd,
2949 _("Branch tracing maintenance commands."),
2950 &maint_btrace_cmdlist, "maintenance btrace ",
2951 0, &maintenancelist);
2953 add_prefix_cmd ("btrace", class_maintenance, maint_btrace_set_cmd, _("\
2954 Set branch tracing specific variables."),
2955 &maint_btrace_set_cmdlist, "maintenance set btrace ",
2956 0, &maintenance_set_cmdlist);
2958 add_prefix_cmd ("pt", class_maintenance, maint_btrace_pt_set_cmd, _("\
2959 Set Intel Processor Trace specific variables."),
2960 &maint_btrace_pt_set_cmdlist, "maintenance set btrace pt ",
2961 0, &maint_btrace_set_cmdlist);
2963 add_prefix_cmd ("btrace", class_maintenance, maint_btrace_show_cmd, _("\
2964 Show branch tracing specific variables."),
2965 &maint_btrace_show_cmdlist, "maintenance show btrace ",
2966 0, &maintenance_show_cmdlist);
2968 add_prefix_cmd ("pt", class_maintenance, maint_btrace_pt_show_cmd, _("\
2969 Show Intel Processor Trace specific variables."),
2970 &maint_btrace_pt_show_cmdlist, "maintenance show btrace pt ",
2971 0, &maint_btrace_show_cmdlist);
2973 add_setshow_boolean_cmd ("skip-pad", class_maintenance,
2974 &maint_btrace_pt_skip_pad, _("\
2975 Set whether PAD packets should be skipped in the btrace packet history."), _("\
2976 Show whether PAD packets should be skipped in the btrace packet history."),_("\
2977 When enabled, PAD packets are ignored in the btrace packet history."),
2978 NULL, show_maint_btrace_pt_skip_pad,
2979 &maint_btrace_pt_set_cmdlist,
2980 &maint_btrace_pt_show_cmdlist);
2982 add_cmd ("packet-history", class_maintenance, maint_btrace_packet_history_cmd,
2983 _("Print the raw branch tracing data.\n\
2984 With no argument, print ten more packets after the previous ten-line print.\n\
2985 With '-' as argument print ten packets before a previous ten-line print.\n\
2986 One argument specifies the starting packet of a ten-line print.\n\
2987 Two arguments with comma between specify starting and ending packets to \
2989 Preceded with '+'/'-' the second argument specifies the distance from the \
2991 &maint_btrace_cmdlist);
2993 add_cmd ("clear-packet-history", class_maintenance,
2994 maint_btrace_clear_packet_history_cmd,
2995 _("Clears the branch tracing packet history.\n\
2996 Discards the raw branch tracing data but not the execution history data.\n\
2998 &maint_btrace_cmdlist);
3000 add_cmd ("clear", class_maintenance, maint_btrace_clear_cmd,
3001 _("Clears the branch tracing data.\n\
3002 Discards the raw branch tracing data and the execution history data.\n\
3003 The next 'record' command will fetch the branch tracing data anew.\n\
3005 &maint_btrace_cmdlist);