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 function and add a new caller for it.
391 This should handle a series of initial tail calls. */
392 while (prev->up != NULL)
395 bfun->level = prev->level - 1;
397 /* Fix up the call stack for PREV. */
398 ftrace_fixup_caller (prev, bfun, BFUN_UP_LINKS_TO_RET);
400 ftrace_debug (bfun, "new return - no caller");
404 /* There is a call in PREV's back trace to which we should have
405 returned but didn't. Let's start a new, separate back trace
406 from PREV's level. */
407 bfun->level = prev->level - 1;
409 /* We fix up the back trace for PREV but leave other function segments
410 on the same level as they are.
411 This should handle things like schedule () correctly where we're
412 switching contexts. */
414 prev->flags = BFUN_UP_LINKS_TO_RET;
416 ftrace_debug (bfun, "new return - unknown caller");
423 /* Add a new function segment for a function switch.
424 PREV is the chronologically preceding function segment.
425 MFUN and FUN are the symbol information we have for this function. */
427 static struct btrace_function *
428 ftrace_new_switch (struct btrace_function *prev,
429 struct minimal_symbol *mfun,
432 struct btrace_function *bfun;
434 /* This is an unexplained function switch. The call stack will likely
435 be wrong at this point. */
436 bfun = ftrace_new_function (prev, mfun, fun);
438 ftrace_debug (bfun, "new switch");
443 /* Add a new function segment for a gap in the trace due to a decode error.
444 PREV is the chronologically preceding function segment.
445 ERRCODE is the format-specific error code. */
447 static struct btrace_function *
448 ftrace_new_gap (struct btrace_function *prev, int errcode)
450 struct btrace_function *bfun;
452 /* We hijack prev if it was empty. */
453 if (prev != NULL && prev->errcode == 0
454 && VEC_empty (btrace_insn_s, prev->insn))
457 bfun = ftrace_new_function (prev, NULL, NULL);
459 bfun->errcode = errcode;
461 ftrace_debug (bfun, "new gap");
466 /* Update BFUN with respect to the instruction at PC. This may create new
468 Return the chronologically latest function segment, never NULL. */
470 static struct btrace_function *
471 ftrace_update_function (struct btrace_function *bfun, CORE_ADDR pc)
473 struct bound_minimal_symbol bmfun;
474 struct minimal_symbol *mfun;
476 struct btrace_insn *last;
478 /* Try to determine the function we're in. We use both types of symbols
479 to avoid surprises when we sometimes get a full symbol and sometimes
480 only a minimal symbol. */
481 fun = find_pc_function (pc);
482 bmfun = lookup_minimal_symbol_by_pc (pc);
485 if (fun == NULL && mfun == NULL)
486 DEBUG_FTRACE ("no symbol at %s", core_addr_to_string_nz (pc));
488 /* If we didn't have a function or if we had a gap before, we create one. */
489 if (bfun == NULL || bfun->errcode != 0)
490 return ftrace_new_function (bfun, mfun, fun);
492 /* Check the last instruction, if we have one.
493 We do this check first, since it allows us to fill in the call stack
494 links in addition to the normal flow links. */
496 if (!VEC_empty (btrace_insn_s, bfun->insn))
497 last = VEC_last (btrace_insn_s, bfun->insn);
501 switch (last->iclass)
503 case BTRACE_INSN_RETURN:
507 /* On some systems, _dl_runtime_resolve returns to the resolved
508 function instead of jumping to it. From our perspective,
509 however, this is a tailcall.
510 If we treated it as return, we wouldn't be able to find the
511 resolved function in our stack back trace. Hence, we would
512 lose the current stack back trace and start anew with an empty
513 back trace. When the resolved function returns, we would then
514 create a stack back trace with the same function names but
515 different frame id's. This will confuse stepping. */
516 fname = ftrace_print_function_name (bfun);
517 if (strcmp (fname, "_dl_runtime_resolve") == 0)
518 return ftrace_new_tailcall (bfun, mfun, fun);
520 return ftrace_new_return (bfun, mfun, fun);
523 case BTRACE_INSN_CALL:
524 /* Ignore calls to the next instruction. They are used for PIC. */
525 if (last->pc + last->size == pc)
528 return ftrace_new_call (bfun, mfun, fun);
530 case BTRACE_INSN_JUMP:
534 start = get_pc_function_start (pc);
536 /* A jump to the start of a function is (typically) a tail call. */
538 return ftrace_new_tailcall (bfun, mfun, fun);
540 /* If we can't determine the function for PC, we treat a jump at
541 the end of the block as tail call if we're switching functions
542 and as an intra-function branch if we don't. */
543 if (start == 0 && ftrace_function_switched (bfun, mfun, fun))
544 return ftrace_new_tailcall (bfun, mfun, fun);
551 /* Check if we're switching functions for some other reason. */
552 if (ftrace_function_switched (bfun, mfun, fun))
554 DEBUG_FTRACE ("switching from %s in %s at %s",
555 ftrace_print_insn_addr (last),
556 ftrace_print_function_name (bfun),
557 ftrace_print_filename (bfun));
559 return ftrace_new_switch (bfun, mfun, fun);
565 /* Add the instruction at PC to BFUN's instructions. */
568 ftrace_update_insns (struct btrace_function *bfun,
569 const struct btrace_insn *insn)
571 VEC_safe_push (btrace_insn_s, bfun->insn, insn);
573 if (record_debug > 1)
574 ftrace_debug (bfun, "update insn");
577 /* Classify the instruction at PC. */
579 static enum btrace_insn_class
580 ftrace_classify_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
582 enum btrace_insn_class iclass;
584 iclass = BTRACE_INSN_OTHER;
587 if (gdbarch_insn_is_call (gdbarch, pc))
588 iclass = BTRACE_INSN_CALL;
589 else if (gdbarch_insn_is_ret (gdbarch, pc))
590 iclass = BTRACE_INSN_RETURN;
591 else if (gdbarch_insn_is_jump (gdbarch, pc))
592 iclass = BTRACE_INSN_JUMP;
594 CATCH (error, RETURN_MASK_ERROR)
602 /* Compute the function branch trace from BTS trace. */
605 btrace_compute_ftrace_bts (struct thread_info *tp,
606 const struct btrace_data_bts *btrace)
608 struct btrace_thread_info *btinfo;
609 struct btrace_function *begin, *end;
610 struct gdbarch *gdbarch;
611 unsigned int blk, ngaps;
614 gdbarch = target_gdbarch ();
615 btinfo = &tp->btrace;
616 begin = btinfo->begin;
618 ngaps = btinfo->ngaps;
619 level = begin != NULL ? -btinfo->level : INT_MAX;
620 blk = VEC_length (btrace_block_s, btrace->blocks);
624 btrace_block_s *block;
629 block = VEC_index (btrace_block_s, btrace->blocks, blk);
634 struct btrace_insn insn;
637 /* We should hit the end of the block. Warn if we went too far. */
640 /* Indicate the gap in the trace. */
641 end = ftrace_new_gap (end, BDE_BTS_OVERFLOW);
647 warning (_("Recorded trace may be corrupted at instruction "
648 "%u (pc = %s)."), end->insn_offset - 1,
649 core_addr_to_string_nz (pc));
654 end = ftrace_update_function (end, pc);
658 /* Maintain the function level offset.
659 For all but the last block, we do it here. */
661 level = std::min (level, end->level);
666 size = gdb_insn_length (gdbarch, pc);
668 CATCH (error, RETURN_MASK_ERROR)
675 insn.iclass = ftrace_classify_insn (gdbarch, pc);
678 ftrace_update_insns (end, &insn);
680 /* We're done once we pushed the instruction at the end. */
681 if (block->end == pc)
684 /* We can't continue if we fail to compute the size. */
687 /* Indicate the gap in the trace. We just added INSN so we're
688 not at the beginning. */
689 end = ftrace_new_gap (end, BDE_BTS_INSN_SIZE);
692 warning (_("Recorded trace may be incomplete at instruction %u "
693 "(pc = %s)."), end->insn_offset - 1,
694 core_addr_to_string_nz (pc));
701 /* Maintain the function level offset.
702 For the last block, we do it here to not consider the last
704 Since the last instruction corresponds to the current instruction
705 and is not really part of the execution history, it shouldn't
708 level = std::min (level, end->level);
712 btinfo->begin = begin;
714 btinfo->ngaps = ngaps;
716 /* LEVEL is the minimal function level of all btrace function segments.
717 Define the global level offset to -LEVEL so all function levels are
718 normalized to start at zero. */
719 btinfo->level = -level;
722 #if defined (HAVE_LIBIPT)
724 static enum btrace_insn_class
725 pt_reclassify_insn (enum pt_insn_class iclass)
730 return BTRACE_INSN_CALL;
733 return BTRACE_INSN_RETURN;
736 return BTRACE_INSN_JUMP;
739 return BTRACE_INSN_OTHER;
743 /* Return the btrace instruction flags for INSN. */
745 static btrace_insn_flags
746 pt_btrace_insn_flags (const struct pt_insn *insn)
748 btrace_insn_flags flags = 0;
750 if (insn->speculative)
751 flags |= BTRACE_INSN_FLAG_SPECULATIVE;
756 /* Add function branch trace using DECODER. */
759 ftrace_add_pt (struct pt_insn_decoder *decoder,
760 struct btrace_function **pbegin,
761 struct btrace_function **pend, int *plevel,
764 struct btrace_function *begin, *end, *upd;
772 struct btrace_insn btinsn;
775 errcode = pt_insn_sync_forward (decoder);
778 if (errcode != -pte_eos)
779 warning (_("Failed to synchronize onto the Intel Processor "
780 "Trace stream: %s."), pt_errstr (pt_errcode (errcode)));
784 memset (&btinsn, 0, sizeof (btinsn));
787 errcode = pt_insn_next (decoder, &insn, sizeof(insn));
791 /* Look for gaps in the trace - unless we're at the beginning. */
794 /* Tracing is disabled and re-enabled each time we enter the
795 kernel. Most times, we continue from the same instruction we
796 stopped before. This is indicated via the RESUMED instruction
797 flag. The ENABLED instruction flag means that we continued
798 from some other instruction. Indicate this as a trace gap. */
801 *pend = end = ftrace_new_gap (end, BDE_PT_DISABLED);
804 pt_insn_get_offset (decoder, &offset);
806 warning (_("Non-contiguous trace at instruction %u (offset "
807 "= 0x%" PRIx64 ", pc = 0x%" PRIx64 ")."),
808 end->insn_offset - 1, offset, insn.ip);
812 /* Indicate trace overflows. */
815 *pend = end = ftrace_new_gap (end, BDE_PT_OVERFLOW);
817 *pbegin = begin = end;
821 pt_insn_get_offset (decoder, &offset);
823 warning (_("Overflow at instruction %u (offset = 0x%" PRIx64
824 ", pc = 0x%" PRIx64 ")."), end->insn_offset - 1,
828 upd = ftrace_update_function (end, insn.ip);
834 *pbegin = begin = upd;
837 /* Maintain the function level offset. */
838 *plevel = std::min (*plevel, end->level);
840 btinsn.pc = (CORE_ADDR) insn.ip;
841 btinsn.size = (gdb_byte) insn.size;
842 btinsn.iclass = pt_reclassify_insn (insn.iclass);
843 btinsn.flags = pt_btrace_insn_flags (&insn);
845 ftrace_update_insns (end, &btinsn);
848 if (errcode == -pte_eos)
851 /* Indicate the gap in the trace. */
852 *pend = end = ftrace_new_gap (end, errcode);
854 *pbegin = begin = end;
857 pt_insn_get_offset (decoder, &offset);
859 warning (_("Decode error (%d) at instruction %u (offset = 0x%" PRIx64
860 ", pc = 0x%" PRIx64 "): %s."), errcode, end->insn_offset - 1,
861 offset, insn.ip, pt_errstr (pt_errcode (errcode)));
865 /* A callback function to allow the trace decoder to read the inferior's
869 btrace_pt_readmem_callback (gdb_byte *buffer, size_t size,
870 const struct pt_asid *asid, uint64_t pc,
878 errcode = target_read_code ((CORE_ADDR) pc, buffer, size);
882 CATCH (error, RETURN_MASK_ERROR)
891 /* Translate the vendor from one enum to another. */
893 static enum pt_cpu_vendor
894 pt_translate_cpu_vendor (enum btrace_cpu_vendor vendor)
906 /* Finalize the function branch trace after decode. */
908 static void btrace_finalize_ftrace_pt (struct pt_insn_decoder *decoder,
909 struct thread_info *tp, int level)
911 pt_insn_free_decoder (decoder);
913 /* LEVEL is the minimal function level of all btrace function segments.
914 Define the global level offset to -LEVEL so all function levels are
915 normalized to start at zero. */
916 tp->btrace.level = -level;
918 /* Add a single last instruction entry for the current PC.
919 This allows us to compute the backtrace at the current PC using both
920 standard unwind and btrace unwind.
921 This extra entry is ignored by all record commands. */
925 /* Compute the function branch trace from Intel Processor Trace
929 btrace_compute_ftrace_pt (struct thread_info *tp,
930 const struct btrace_data_pt *btrace)
932 struct btrace_thread_info *btinfo;
933 struct pt_insn_decoder *decoder;
934 struct pt_config config;
937 if (btrace->size == 0)
940 btinfo = &tp->btrace;
941 level = btinfo->begin != NULL ? -btinfo->level : INT_MAX;
943 pt_config_init(&config);
944 config.begin = btrace->data;
945 config.end = btrace->data + btrace->size;
947 config.cpu.vendor = pt_translate_cpu_vendor (btrace->config.cpu.vendor);
948 config.cpu.family = btrace->config.cpu.family;
949 config.cpu.model = btrace->config.cpu.model;
950 config.cpu.stepping = btrace->config.cpu.stepping;
952 errcode = pt_cpu_errata (&config.errata, &config.cpu);
954 error (_("Failed to configure the Intel Processor Trace decoder: %s."),
955 pt_errstr (pt_errcode (errcode)));
957 decoder = pt_insn_alloc_decoder (&config);
959 error (_("Failed to allocate the Intel Processor Trace decoder."));
963 struct pt_image *image;
965 image = pt_insn_get_image(decoder);
967 error (_("Failed to configure the Intel Processor Trace decoder."));
969 errcode = pt_image_set_callback(image, btrace_pt_readmem_callback, NULL);
971 error (_("Failed to configure the Intel Processor Trace decoder: "
972 "%s."), pt_errstr (pt_errcode (errcode)));
974 ftrace_add_pt (decoder, &btinfo->begin, &btinfo->end, &level,
977 CATCH (error, RETURN_MASK_ALL)
979 /* Indicate a gap in the trace if we quit trace processing. */
980 if (error.reason == RETURN_QUIT && btinfo->end != NULL)
982 btinfo->end = ftrace_new_gap (btinfo->end, BDE_PT_USER_QUIT);
986 btrace_finalize_ftrace_pt (decoder, tp, level);
988 throw_exception (error);
992 btrace_finalize_ftrace_pt (decoder, tp, level);
995 #else /* defined (HAVE_LIBIPT) */
998 btrace_compute_ftrace_pt (struct thread_info *tp,
999 const struct btrace_data_pt *btrace)
1001 internal_error (__FILE__, __LINE__, _("Unexpected branch trace format."));
1004 #endif /* defined (HAVE_LIBIPT) */
1006 /* Compute the function branch trace from a block branch trace BTRACE for
1007 a thread given by BTINFO. */
1010 btrace_compute_ftrace (struct thread_info *tp, struct btrace_data *btrace)
1012 DEBUG ("compute ftrace");
1014 switch (btrace->format)
1016 case BTRACE_FORMAT_NONE:
1019 case BTRACE_FORMAT_BTS:
1020 btrace_compute_ftrace_bts (tp, &btrace->variant.bts);
1023 case BTRACE_FORMAT_PT:
1024 btrace_compute_ftrace_pt (tp, &btrace->variant.pt);
1028 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
1031 /* Add an entry for the current PC. */
1034 btrace_add_pc (struct thread_info *tp)
1036 struct btrace_data btrace;
1037 struct btrace_block *block;
1038 struct regcache *regcache;
1039 struct cleanup *cleanup;
1042 regcache = get_thread_regcache (tp->ptid);
1043 pc = regcache_read_pc (regcache);
1045 btrace_data_init (&btrace);
1046 btrace.format = BTRACE_FORMAT_BTS;
1047 btrace.variant.bts.blocks = NULL;
1049 cleanup = make_cleanup_btrace_data (&btrace);
1051 block = VEC_safe_push (btrace_block_s, btrace.variant.bts.blocks, NULL);
1055 btrace_compute_ftrace (tp, &btrace);
1057 do_cleanups (cleanup);
1063 btrace_enable (struct thread_info *tp, const struct btrace_config *conf)
1065 if (tp->btrace.target != NULL)
1068 #if !defined (HAVE_LIBIPT)
1069 if (conf->format == BTRACE_FORMAT_PT)
1070 error (_("GDB does not support Intel Processor Trace."));
1071 #endif /* !defined (HAVE_LIBIPT) */
1073 if (!target_supports_btrace (conf->format))
1074 error (_("Target does not support branch tracing."));
1076 DEBUG ("enable thread %s (%s)", print_thread_id (tp),
1077 target_pid_to_str (tp->ptid));
1079 tp->btrace.target = target_enable_btrace (tp->ptid, conf);
1081 /* Add an entry for the current PC so we start tracing from where we
1083 if (tp->btrace.target != NULL)
1089 const struct btrace_config *
1090 btrace_conf (const struct btrace_thread_info *btinfo)
1092 if (btinfo->target == NULL)
1095 return target_btrace_conf (btinfo->target);
1101 btrace_disable (struct thread_info *tp)
1103 struct btrace_thread_info *btp = &tp->btrace;
1106 if (btp->target == NULL)
1109 DEBUG ("disable thread %s (%s)", print_thread_id (tp),
1110 target_pid_to_str (tp->ptid));
1112 target_disable_btrace (btp->target);
1121 btrace_teardown (struct thread_info *tp)
1123 struct btrace_thread_info *btp = &tp->btrace;
1126 if (btp->target == NULL)
1129 DEBUG ("teardown thread %s (%s)", print_thread_id (tp),
1130 target_pid_to_str (tp->ptid));
1132 target_teardown_btrace (btp->target);
1138 /* Stitch branch trace in BTS format. */
1141 btrace_stitch_bts (struct btrace_data_bts *btrace, struct thread_info *tp)
1143 struct btrace_thread_info *btinfo;
1144 struct btrace_function *last_bfun;
1145 struct btrace_insn *last_insn;
1146 btrace_block_s *first_new_block;
1148 btinfo = &tp->btrace;
1149 last_bfun = btinfo->end;
1150 gdb_assert (last_bfun != NULL);
1151 gdb_assert (!VEC_empty (btrace_block_s, btrace->blocks));
1153 /* If the existing trace ends with a gap, we just glue the traces
1154 together. We need to drop the last (i.e. chronologically first) block
1155 of the new trace, though, since we can't fill in the start address.*/
1156 if (VEC_empty (btrace_insn_s, last_bfun->insn))
1158 VEC_pop (btrace_block_s, btrace->blocks);
1162 /* Beware that block trace starts with the most recent block, so the
1163 chronologically first block in the new trace is the last block in
1164 the new trace's block vector. */
1165 first_new_block = VEC_last (btrace_block_s, btrace->blocks);
1166 last_insn = VEC_last (btrace_insn_s, last_bfun->insn);
1168 /* If the current PC at the end of the block is the same as in our current
1169 trace, there are two explanations:
1170 1. we executed the instruction and some branch brought us back.
1171 2. we have not made any progress.
1172 In the first case, the delta trace vector should contain at least two
1174 In the second case, the delta trace vector should contain exactly one
1175 entry for the partial block containing the current PC. Remove it. */
1176 if (first_new_block->end == last_insn->pc
1177 && VEC_length (btrace_block_s, btrace->blocks) == 1)
1179 VEC_pop (btrace_block_s, btrace->blocks);
1183 DEBUG ("stitching %s to %s", ftrace_print_insn_addr (last_insn),
1184 core_addr_to_string_nz (first_new_block->end));
1186 /* Do a simple sanity check to make sure we don't accidentally end up
1187 with a bad block. This should not occur in practice. */
1188 if (first_new_block->end < last_insn->pc)
1190 warning (_("Error while trying to read delta trace. Falling back to "
1195 /* We adjust the last block to start at the end of our current trace. */
1196 gdb_assert (first_new_block->begin == 0);
1197 first_new_block->begin = last_insn->pc;
1199 /* We simply pop the last insn so we can insert it again as part of
1200 the normal branch trace computation.
1201 Since instruction iterators are based on indices in the instructions
1202 vector, we don't leave any pointers dangling. */
1203 DEBUG ("pruning insn at %s for stitching",
1204 ftrace_print_insn_addr (last_insn));
1206 VEC_pop (btrace_insn_s, last_bfun->insn);
1208 /* The instructions vector may become empty temporarily if this has
1209 been the only instruction in this function segment.
1210 This violates the invariant but will be remedied shortly by
1211 btrace_compute_ftrace when we add the new trace. */
1213 /* The only case where this would hurt is if the entire trace consisted
1214 of just that one instruction. If we remove it, we might turn the now
1215 empty btrace function segment into a gap. But we don't want gaps at
1216 the beginning. To avoid this, we remove the entire old trace. */
1217 if (last_bfun == btinfo->begin && VEC_empty (btrace_insn_s, last_bfun->insn))
1223 /* Adjust the block trace in order to stitch old and new trace together.
1224 BTRACE is the new delta trace between the last and the current stop.
1225 TP is the traced thread.
1226 May modifx BTRACE as well as the existing trace in TP.
1227 Return 0 on success, -1 otherwise. */
1230 btrace_stitch_trace (struct btrace_data *btrace, struct thread_info *tp)
1232 /* If we don't have trace, there's nothing to do. */
1233 if (btrace_data_empty (btrace))
1236 switch (btrace->format)
1238 case BTRACE_FORMAT_NONE:
1241 case BTRACE_FORMAT_BTS:
1242 return btrace_stitch_bts (&btrace->variant.bts, tp);
1244 case BTRACE_FORMAT_PT:
1245 /* Delta reads are not supported. */
1249 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
1252 /* Clear the branch trace histories in BTINFO. */
1255 btrace_clear_history (struct btrace_thread_info *btinfo)
1257 xfree (btinfo->insn_history);
1258 xfree (btinfo->call_history);
1259 xfree (btinfo->replay);
1261 btinfo->insn_history = NULL;
1262 btinfo->call_history = NULL;
1263 btinfo->replay = NULL;
1266 /* Clear the branch trace maintenance histories in BTINFO. */
1269 btrace_maint_clear (struct btrace_thread_info *btinfo)
1271 switch (btinfo->data.format)
1276 case BTRACE_FORMAT_BTS:
1277 btinfo->maint.variant.bts.packet_history.begin = 0;
1278 btinfo->maint.variant.bts.packet_history.end = 0;
1281 #if defined (HAVE_LIBIPT)
1282 case BTRACE_FORMAT_PT:
1283 xfree (btinfo->maint.variant.pt.packets);
1285 btinfo->maint.variant.pt.packets = NULL;
1286 btinfo->maint.variant.pt.packet_history.begin = 0;
1287 btinfo->maint.variant.pt.packet_history.end = 0;
1289 #endif /* defined (HAVE_LIBIPT) */
1296 btrace_fetch (struct thread_info *tp)
1298 struct btrace_thread_info *btinfo;
1299 struct btrace_target_info *tinfo;
1300 struct btrace_data btrace;
1301 struct cleanup *cleanup;
1304 DEBUG ("fetch thread %s (%s)", print_thread_id (tp),
1305 target_pid_to_str (tp->ptid));
1307 btinfo = &tp->btrace;
1308 tinfo = btinfo->target;
1312 /* There's no way we could get new trace while replaying.
1313 On the other hand, delta trace would return a partial record with the
1314 current PC, which is the replay PC, not the last PC, as expected. */
1315 if (btinfo->replay != NULL)
1318 btrace_data_init (&btrace);
1319 cleanup = make_cleanup_btrace_data (&btrace);
1321 /* Let's first try to extend the trace we already have. */
1322 if (btinfo->end != NULL)
1324 errcode = target_read_btrace (&btrace, tinfo, BTRACE_READ_DELTA);
1327 /* Success. Let's try to stitch the traces together. */
1328 errcode = btrace_stitch_trace (&btrace, tp);
1332 /* We failed to read delta trace. Let's try to read new trace. */
1333 errcode = target_read_btrace (&btrace, tinfo, BTRACE_READ_NEW);
1335 /* If we got any new trace, discard what we have. */
1336 if (errcode == 0 && !btrace_data_empty (&btrace))
1340 /* If we were not able to read the trace, we start over. */
1344 errcode = target_read_btrace (&btrace, tinfo, BTRACE_READ_ALL);
1348 errcode = target_read_btrace (&btrace, tinfo, BTRACE_READ_ALL);
1350 /* If we were not able to read the branch trace, signal an error. */
1352 error (_("Failed to read branch trace."));
1354 /* Compute the trace, provided we have any. */
1355 if (!btrace_data_empty (&btrace))
1357 /* Store the raw trace data. The stored data will be cleared in
1358 btrace_clear, so we always append the new trace. */
1359 btrace_data_append (&btinfo->data, &btrace);
1360 btrace_maint_clear (btinfo);
1362 btrace_clear_history (btinfo);
1363 btrace_compute_ftrace (tp, &btrace);
1366 do_cleanups (cleanup);
1372 btrace_clear (struct thread_info *tp)
1374 struct btrace_thread_info *btinfo;
1375 struct btrace_function *it, *trash;
1377 DEBUG ("clear thread %s (%s)", print_thread_id (tp),
1378 target_pid_to_str (tp->ptid));
1380 /* Make sure btrace frames that may hold a pointer into the branch
1381 trace data are destroyed. */
1382 reinit_frame_cache ();
1384 btinfo = &tp->btrace;
1395 btinfo->begin = NULL;
1399 /* Must clear the maint data before - it depends on BTINFO->DATA. */
1400 btrace_maint_clear (btinfo);
1401 btrace_data_clear (&btinfo->data);
1402 btrace_clear_history (btinfo);
1408 btrace_free_objfile (struct objfile *objfile)
1410 struct thread_info *tp;
1412 DEBUG ("free objfile");
1414 ALL_NON_EXITED_THREADS (tp)
1418 #if defined (HAVE_LIBEXPAT)
1420 /* Check the btrace document version. */
1423 check_xml_btrace_version (struct gdb_xml_parser *parser,
1424 const struct gdb_xml_element *element,
1425 void *user_data, VEC (gdb_xml_value_s) *attributes)
1428 = (const char *) xml_find_attribute (attributes, "version")->value;
1430 if (strcmp (version, "1.0") != 0)
1431 gdb_xml_error (parser, _("Unsupported btrace version: \"%s\""), version);
1434 /* Parse a btrace "block" xml record. */
1437 parse_xml_btrace_block (struct gdb_xml_parser *parser,
1438 const struct gdb_xml_element *element,
1439 void *user_data, VEC (gdb_xml_value_s) *attributes)
1441 struct btrace_data *btrace;
1442 struct btrace_block *block;
1443 ULONGEST *begin, *end;
1445 btrace = (struct btrace_data *) user_data;
1447 switch (btrace->format)
1449 case BTRACE_FORMAT_BTS:
1452 case BTRACE_FORMAT_NONE:
1453 btrace->format = BTRACE_FORMAT_BTS;
1454 btrace->variant.bts.blocks = NULL;
1458 gdb_xml_error (parser, _("Btrace format error."));
1461 begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value;
1462 end = (ULONGEST *) xml_find_attribute (attributes, "end")->value;
1464 block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
1465 block->begin = *begin;
1469 /* Parse a "raw" xml record. */
1472 parse_xml_raw (struct gdb_xml_parser *parser, const char *body_text,
1473 gdb_byte **pdata, size_t *psize)
1475 struct cleanup *cleanup;
1476 gdb_byte *data, *bin;
1479 len = strlen (body_text);
1481 gdb_xml_error (parser, _("Bad raw data size."));
1485 bin = data = (gdb_byte *) xmalloc (size);
1486 cleanup = make_cleanup (xfree, data);
1488 /* We use hex encoding - see common/rsp-low.h. */
1496 if (hi == 0 || lo == 0)
1497 gdb_xml_error (parser, _("Bad hex encoding."));
1499 *bin++ = fromhex (hi) * 16 + fromhex (lo);
1503 discard_cleanups (cleanup);
1509 /* Parse a btrace pt-config "cpu" xml record. */
1512 parse_xml_btrace_pt_config_cpu (struct gdb_xml_parser *parser,
1513 const struct gdb_xml_element *element,
1515 VEC (gdb_xml_value_s) *attributes)
1517 struct btrace_data *btrace;
1519 ULONGEST *family, *model, *stepping;
1521 vendor = (const char *) xml_find_attribute (attributes, "vendor")->value;
1522 family = (ULONGEST *) xml_find_attribute (attributes, "family")->value;
1523 model = (ULONGEST *) xml_find_attribute (attributes, "model")->value;
1524 stepping = (ULONGEST *) xml_find_attribute (attributes, "stepping")->value;
1526 btrace = (struct btrace_data *) user_data;
1528 if (strcmp (vendor, "GenuineIntel") == 0)
1529 btrace->variant.pt.config.cpu.vendor = CV_INTEL;
1531 btrace->variant.pt.config.cpu.family = *family;
1532 btrace->variant.pt.config.cpu.model = *model;
1533 btrace->variant.pt.config.cpu.stepping = *stepping;
1536 /* Parse a btrace pt "raw" xml record. */
1539 parse_xml_btrace_pt_raw (struct gdb_xml_parser *parser,
1540 const struct gdb_xml_element *element,
1541 void *user_data, const char *body_text)
1543 struct btrace_data *btrace;
1545 btrace = (struct btrace_data *) user_data;
1546 parse_xml_raw (parser, body_text, &btrace->variant.pt.data,
1547 &btrace->variant.pt.size);
1550 /* Parse a btrace "pt" xml record. */
1553 parse_xml_btrace_pt (struct gdb_xml_parser *parser,
1554 const struct gdb_xml_element *element,
1555 void *user_data, VEC (gdb_xml_value_s) *attributes)
1557 struct btrace_data *btrace;
1559 btrace = (struct btrace_data *) user_data;
1560 btrace->format = BTRACE_FORMAT_PT;
1561 btrace->variant.pt.config.cpu.vendor = CV_UNKNOWN;
1562 btrace->variant.pt.data = NULL;
1563 btrace->variant.pt.size = 0;
1566 static const struct gdb_xml_attribute block_attributes[] = {
1567 { "begin", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1568 { "end", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1569 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1572 static const struct gdb_xml_attribute btrace_pt_config_cpu_attributes[] = {
1573 { "vendor", GDB_XML_AF_NONE, NULL, NULL },
1574 { "family", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1575 { "model", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1576 { "stepping", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
1577 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1580 static const struct gdb_xml_element btrace_pt_config_children[] = {
1581 { "cpu", btrace_pt_config_cpu_attributes, NULL, GDB_XML_EF_OPTIONAL,
1582 parse_xml_btrace_pt_config_cpu, NULL },
1583 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1586 static const struct gdb_xml_element btrace_pt_children[] = {
1587 { "pt-config", NULL, btrace_pt_config_children, GDB_XML_EF_OPTIONAL, NULL,
1589 { "raw", NULL, NULL, GDB_XML_EF_OPTIONAL, NULL, parse_xml_btrace_pt_raw },
1590 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1593 static const struct gdb_xml_attribute btrace_attributes[] = {
1594 { "version", GDB_XML_AF_NONE, NULL, NULL },
1595 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1598 static const struct gdb_xml_element btrace_children[] = {
1599 { "block", block_attributes, NULL,
1600 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, parse_xml_btrace_block, NULL },
1601 { "pt", NULL, btrace_pt_children, GDB_XML_EF_OPTIONAL, parse_xml_btrace_pt,
1603 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1606 static const struct gdb_xml_element btrace_elements[] = {
1607 { "btrace", btrace_attributes, btrace_children, GDB_XML_EF_NONE,
1608 check_xml_btrace_version, NULL },
1609 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1612 #endif /* defined (HAVE_LIBEXPAT) */
1617 parse_xml_btrace (struct btrace_data *btrace, const char *buffer)
1619 struct cleanup *cleanup;
1622 #if defined (HAVE_LIBEXPAT)
1624 btrace->format = BTRACE_FORMAT_NONE;
1626 cleanup = make_cleanup_btrace_data (btrace);
1627 errcode = gdb_xml_parse_quick (_("btrace"), "btrace.dtd", btrace_elements,
1630 error (_("Error parsing branch trace."));
1632 /* Keep parse results. */
1633 discard_cleanups (cleanup);
1635 #else /* !defined (HAVE_LIBEXPAT) */
1637 error (_("Cannot process branch trace. XML parsing is not supported."));
1639 #endif /* !defined (HAVE_LIBEXPAT) */
1642 #if defined (HAVE_LIBEXPAT)
1644 /* Parse a btrace-conf "bts" xml record. */
1647 parse_xml_btrace_conf_bts (struct gdb_xml_parser *parser,
1648 const struct gdb_xml_element *element,
1649 void *user_data, VEC (gdb_xml_value_s) *attributes)
1651 struct btrace_config *conf;
1652 struct gdb_xml_value *size;
1654 conf = (struct btrace_config *) user_data;
1655 conf->format = BTRACE_FORMAT_BTS;
1658 size = xml_find_attribute (attributes, "size");
1660 conf->bts.size = (unsigned int) *(ULONGEST *) size->value;
1663 /* Parse a btrace-conf "pt" xml record. */
1666 parse_xml_btrace_conf_pt (struct gdb_xml_parser *parser,
1667 const struct gdb_xml_element *element,
1668 void *user_data, VEC (gdb_xml_value_s) *attributes)
1670 struct btrace_config *conf;
1671 struct gdb_xml_value *size;
1673 conf = (struct btrace_config *) user_data;
1674 conf->format = BTRACE_FORMAT_PT;
1677 size = xml_find_attribute (attributes, "size");
1679 conf->pt.size = (unsigned int) *(ULONGEST *) size->value;
1682 static const struct gdb_xml_attribute btrace_conf_pt_attributes[] = {
1683 { "size", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
1684 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1687 static const struct gdb_xml_attribute btrace_conf_bts_attributes[] = {
1688 { "size", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
1689 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1692 static const struct gdb_xml_element btrace_conf_children[] = {
1693 { "bts", btrace_conf_bts_attributes, NULL, GDB_XML_EF_OPTIONAL,
1694 parse_xml_btrace_conf_bts, NULL },
1695 { "pt", btrace_conf_pt_attributes, NULL, GDB_XML_EF_OPTIONAL,
1696 parse_xml_btrace_conf_pt, NULL },
1697 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1700 static const struct gdb_xml_attribute btrace_conf_attributes[] = {
1701 { "version", GDB_XML_AF_NONE, NULL, NULL },
1702 { NULL, GDB_XML_AF_NONE, NULL, NULL }
1705 static const struct gdb_xml_element btrace_conf_elements[] = {
1706 { "btrace-conf", btrace_conf_attributes, btrace_conf_children,
1707 GDB_XML_EF_NONE, NULL, NULL },
1708 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
1711 #endif /* defined (HAVE_LIBEXPAT) */
1716 parse_xml_btrace_conf (struct btrace_config *conf, const char *xml)
1720 #if defined (HAVE_LIBEXPAT)
1722 errcode = gdb_xml_parse_quick (_("btrace-conf"), "btrace-conf.dtd",
1723 btrace_conf_elements, xml, conf);
1725 error (_("Error parsing branch trace configuration."));
1727 #else /* !defined (HAVE_LIBEXPAT) */
1729 error (_("XML parsing is not supported."));
1731 #endif /* !defined (HAVE_LIBEXPAT) */
1736 const struct btrace_insn *
1737 btrace_insn_get (const struct btrace_insn_iterator *it)
1739 const struct btrace_function *bfun;
1740 unsigned int index, end;
1743 bfun = it->function;
1745 /* Check if the iterator points to a gap in the trace. */
1746 if (bfun->errcode != 0)
1749 /* The index is within the bounds of this function's instruction vector. */
1750 end = VEC_length (btrace_insn_s, bfun->insn);
1751 gdb_assert (0 < end);
1752 gdb_assert (index < end);
1754 return VEC_index (btrace_insn_s, bfun->insn, index);
1760 btrace_insn_number (const struct btrace_insn_iterator *it)
1762 const struct btrace_function *bfun;
1764 bfun = it->function;
1766 /* Return zero if the iterator points to a gap in the trace. */
1767 if (bfun->errcode != 0)
1770 return bfun->insn_offset + it->index;
1776 btrace_insn_begin (struct btrace_insn_iterator *it,
1777 const struct btrace_thread_info *btinfo)
1779 const struct btrace_function *bfun;
1781 bfun = btinfo->begin;
1783 error (_("No trace."));
1785 it->function = bfun;
1792 btrace_insn_end (struct btrace_insn_iterator *it,
1793 const struct btrace_thread_info *btinfo)
1795 const struct btrace_function *bfun;
1796 unsigned int length;
1800 error (_("No trace."));
1802 length = VEC_length (btrace_insn_s, bfun->insn);
1804 /* The last function may either be a gap or it contains the current
1805 instruction, which is one past the end of the execution trace; ignore
1810 it->function = bfun;
1817 btrace_insn_next (struct btrace_insn_iterator *it, unsigned int stride)
1819 const struct btrace_function *bfun;
1820 unsigned int index, steps;
1822 bfun = it->function;
1828 unsigned int end, space, adv;
1830 end = VEC_length (btrace_insn_s, bfun->insn);
1832 /* An empty function segment represents a gap in the trace. We count
1833 it as one instruction. */
1836 const struct btrace_function *next;
1838 next = bfun->flow.next;
1851 gdb_assert (0 < end);
1852 gdb_assert (index < end);
1854 /* Compute the number of instructions remaining in this segment. */
1855 space = end - index;
1857 /* Advance the iterator as far as possible within this segment. */
1858 adv = std::min (space, stride);
1863 /* Move to the next function if we're at the end of this one. */
1866 const struct btrace_function *next;
1868 next = bfun->flow.next;
1871 /* We stepped past the last function.
1873 Let's adjust the index to point to the last instruction in
1874 the previous function. */
1880 /* We now point to the first instruction in the new function. */
1885 /* We did make progress. */
1886 gdb_assert (adv > 0);
1889 /* Update the iterator. */
1890 it->function = bfun;
1899 btrace_insn_prev (struct btrace_insn_iterator *it, unsigned int stride)
1901 const struct btrace_function *bfun;
1902 unsigned int index, steps;
1904 bfun = it->function;
1912 /* Move to the previous function if we're at the start of this one. */
1915 const struct btrace_function *prev;
1917 prev = bfun->flow.prev;
1921 /* We point to one after the last instruction in the new function. */
1923 index = VEC_length (btrace_insn_s, bfun->insn);
1925 /* An empty function segment represents a gap in the trace. We count
1926 it as one instruction. */
1936 /* Advance the iterator as far as possible within this segment. */
1937 adv = std::min (index, stride);
1943 /* We did make progress. */
1944 gdb_assert (adv > 0);
1947 /* Update the iterator. */
1948 it->function = bfun;
1957 btrace_insn_cmp (const struct btrace_insn_iterator *lhs,
1958 const struct btrace_insn_iterator *rhs)
1960 unsigned int lnum, rnum;
1962 lnum = btrace_insn_number (lhs);
1963 rnum = btrace_insn_number (rhs);
1965 /* A gap has an instruction number of zero. Things are getting more
1966 complicated if gaps are involved.
1968 We take the instruction number offset from the iterator's function.
1969 This is the number of the first instruction after the gap.
1971 This is OK as long as both lhs and rhs point to gaps. If only one of
1972 them does, we need to adjust the number based on the other's regular
1973 instruction number. Otherwise, a gap might compare equal to an
1976 if (lnum == 0 && rnum == 0)
1978 lnum = lhs->function->insn_offset;
1979 rnum = rhs->function->insn_offset;
1983 lnum = lhs->function->insn_offset;
1990 rnum = rhs->function->insn_offset;
1996 return (int) (lnum - rnum);
2002 btrace_find_insn_by_number (struct btrace_insn_iterator *it,
2003 const struct btrace_thread_info *btinfo,
2004 unsigned int number)
2006 const struct btrace_function *bfun;
2007 unsigned int end, length;
2009 for (bfun = btinfo->end; bfun != NULL; bfun = bfun->flow.prev)
2012 if (bfun->errcode != 0)
2015 if (bfun->insn_offset <= number)
2022 length = VEC_length (btrace_insn_s, bfun->insn);
2023 gdb_assert (length > 0);
2025 end = bfun->insn_offset + length;
2029 it->function = bfun;
2030 it->index = number - bfun->insn_offset;
2037 const struct btrace_function *
2038 btrace_call_get (const struct btrace_call_iterator *it)
2040 return it->function;
2046 btrace_call_number (const struct btrace_call_iterator *it)
2048 const struct btrace_thread_info *btinfo;
2049 const struct btrace_function *bfun;
2052 btinfo = it->btinfo;
2053 bfun = it->function;
2055 return bfun->number;
2057 /* For the end iterator, i.e. bfun == NULL, we return one more than the
2058 number of the last function. */
2060 insns = VEC_length (btrace_insn_s, bfun->insn);
2062 /* If the function contains only a single instruction (i.e. the current
2063 instruction), it will be skipped and its number is already the number
2066 return bfun->number;
2068 /* Otherwise, return one more than the number of the last function. */
2069 return bfun->number + 1;
2075 btrace_call_begin (struct btrace_call_iterator *it,
2076 const struct btrace_thread_info *btinfo)
2078 const struct btrace_function *bfun;
2080 bfun = btinfo->begin;
2082 error (_("No trace."));
2084 it->btinfo = btinfo;
2085 it->function = bfun;
2091 btrace_call_end (struct btrace_call_iterator *it,
2092 const struct btrace_thread_info *btinfo)
2094 const struct btrace_function *bfun;
2098 error (_("No trace."));
2100 it->btinfo = btinfo;
2101 it->function = NULL;
2107 btrace_call_next (struct btrace_call_iterator *it, unsigned int stride)
2109 const struct btrace_function *bfun;
2112 bfun = it->function;
2114 while (bfun != NULL)
2116 const struct btrace_function *next;
2119 next = bfun->flow.next;
2122 /* Ignore the last function if it only contains a single
2123 (i.e. the current) instruction. */
2124 insns = VEC_length (btrace_insn_s, bfun->insn);
2129 if (stride == steps)
2136 it->function = bfun;
2143 btrace_call_prev (struct btrace_call_iterator *it, unsigned int stride)
2145 const struct btrace_thread_info *btinfo;
2146 const struct btrace_function *bfun;
2149 bfun = it->function;
2156 btinfo = it->btinfo;
2161 /* Ignore the last function if it only contains a single
2162 (i.e. the current) instruction. */
2163 insns = VEC_length (btrace_insn_s, bfun->insn);
2165 bfun = bfun->flow.prev;
2173 while (steps < stride)
2175 const struct btrace_function *prev;
2177 prev = bfun->flow.prev;
2185 it->function = bfun;
2192 btrace_call_cmp (const struct btrace_call_iterator *lhs,
2193 const struct btrace_call_iterator *rhs)
2195 unsigned int lnum, rnum;
2197 lnum = btrace_call_number (lhs);
2198 rnum = btrace_call_number (rhs);
2200 return (int) (lnum - rnum);
2206 btrace_find_call_by_number (struct btrace_call_iterator *it,
2207 const struct btrace_thread_info *btinfo,
2208 unsigned int number)
2210 const struct btrace_function *bfun;
2212 for (bfun = btinfo->end; bfun != NULL; bfun = bfun->flow.prev)
2216 bnum = bfun->number;
2219 it->btinfo = btinfo;
2220 it->function = bfun;
2224 /* Functions are ordered and numbered consecutively. We could bail out
2225 earlier. On the other hand, it is very unlikely that we search for
2226 a nonexistent function. */
2235 btrace_set_insn_history (struct btrace_thread_info *btinfo,
2236 const struct btrace_insn_iterator *begin,
2237 const struct btrace_insn_iterator *end)
2239 if (btinfo->insn_history == NULL)
2240 btinfo->insn_history = XCNEW (struct btrace_insn_history);
2242 btinfo->insn_history->begin = *begin;
2243 btinfo->insn_history->end = *end;
2249 btrace_set_call_history (struct btrace_thread_info *btinfo,
2250 const struct btrace_call_iterator *begin,
2251 const struct btrace_call_iterator *end)
2253 gdb_assert (begin->btinfo == end->btinfo);
2255 if (btinfo->call_history == NULL)
2256 btinfo->call_history = XCNEW (struct btrace_call_history);
2258 btinfo->call_history->begin = *begin;
2259 btinfo->call_history->end = *end;
2265 btrace_is_replaying (struct thread_info *tp)
2267 return tp->btrace.replay != NULL;
2273 btrace_is_empty (struct thread_info *tp)
2275 struct btrace_insn_iterator begin, end;
2276 struct btrace_thread_info *btinfo;
2278 btinfo = &tp->btrace;
2280 if (btinfo->begin == NULL)
2283 btrace_insn_begin (&begin, btinfo);
2284 btrace_insn_end (&end, btinfo);
2286 return btrace_insn_cmp (&begin, &end) == 0;
2289 /* Forward the cleanup request. */
2292 do_btrace_data_cleanup (void *arg)
2294 btrace_data_fini ((struct btrace_data *) arg);
2300 make_cleanup_btrace_data (struct btrace_data *data)
2302 return make_cleanup (do_btrace_data_cleanup, data);
2305 #if defined (HAVE_LIBIPT)
2307 /* Print a single packet. */
2310 pt_print_packet (const struct pt_packet *packet)
2312 switch (packet->type)
2315 printf_unfiltered (("[??: %x]"), packet->type);
2319 printf_unfiltered (("psb"));
2323 printf_unfiltered (("psbend"));
2327 printf_unfiltered (("pad"));
2331 printf_unfiltered (("tip %u: 0x%" PRIx64 ""),
2332 packet->payload.ip.ipc,
2333 packet->payload.ip.ip);
2337 printf_unfiltered (("tip.pge %u: 0x%" PRIx64 ""),
2338 packet->payload.ip.ipc,
2339 packet->payload.ip.ip);
2343 printf_unfiltered (("tip.pgd %u: 0x%" PRIx64 ""),
2344 packet->payload.ip.ipc,
2345 packet->payload.ip.ip);
2349 printf_unfiltered (("fup %u: 0x%" PRIx64 ""),
2350 packet->payload.ip.ipc,
2351 packet->payload.ip.ip);
2355 printf_unfiltered (("tnt-8 %u: 0x%" PRIx64 ""),
2356 packet->payload.tnt.bit_size,
2357 packet->payload.tnt.payload);
2361 printf_unfiltered (("tnt-64 %u: 0x%" PRIx64 ""),
2362 packet->payload.tnt.bit_size,
2363 packet->payload.tnt.payload);
2367 printf_unfiltered (("pip %" PRIx64 "%s"), packet->payload.pip.cr3,
2368 packet->payload.pip.nr ? (" nr") : (""));
2372 printf_unfiltered (("tsc %" PRIx64 ""), packet->payload.tsc.tsc);
2376 printf_unfiltered (("cbr %u"), packet->payload.cbr.ratio);
2380 switch (packet->payload.mode.leaf)
2383 printf_unfiltered (("mode %u"), packet->payload.mode.leaf);
2387 printf_unfiltered (("mode.exec%s%s"),
2388 packet->payload.mode.bits.exec.csl
2390 packet->payload.mode.bits.exec.csd
2391 ? (" cs.d") : (""));
2395 printf_unfiltered (("mode.tsx%s%s"),
2396 packet->payload.mode.bits.tsx.intx
2398 packet->payload.mode.bits.tsx.abrt
2399 ? (" abrt") : (""));
2405 printf_unfiltered (("ovf"));
2409 printf_unfiltered (("stop"));
2413 printf_unfiltered (("vmcs %" PRIx64 ""), packet->payload.vmcs.base);
2417 printf_unfiltered (("tma %x %x"), packet->payload.tma.ctc,
2418 packet->payload.tma.fc);
2422 printf_unfiltered (("mtc %x"), packet->payload.mtc.ctc);
2426 printf_unfiltered (("cyc %" PRIx64 ""), packet->payload.cyc.value);
2430 printf_unfiltered (("mnt %" PRIx64 ""), packet->payload.mnt.payload);
2435 /* Decode packets into MAINT using DECODER. */
2438 btrace_maint_decode_pt (struct btrace_maint_info *maint,
2439 struct pt_packet_decoder *decoder)
2445 struct btrace_pt_packet packet;
2447 errcode = pt_pkt_sync_forward (decoder);
2453 pt_pkt_get_offset (decoder, &packet.offset);
2455 errcode = pt_pkt_next (decoder, &packet.packet,
2456 sizeof(packet.packet));
2460 if (maint_btrace_pt_skip_pad == 0 || packet.packet.type != ppt_pad)
2462 packet.errcode = pt_errcode (errcode);
2463 VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
2468 if (errcode == -pte_eos)
2471 packet.errcode = pt_errcode (errcode);
2472 VEC_safe_push (btrace_pt_packet_s, maint->variant.pt.packets,
2475 warning (_("Error at trace offset 0x%" PRIx64 ": %s."),
2476 packet.offset, pt_errstr (packet.errcode));
2479 if (errcode != -pte_eos)
2480 warning (_("Failed to synchronize onto the Intel Processor Trace "
2481 "stream: %s."), pt_errstr (pt_errcode (errcode)));
2484 /* Update the packet history in BTINFO. */
2487 btrace_maint_update_pt_packets (struct btrace_thread_info *btinfo)
2489 volatile struct gdb_exception except;
2490 struct pt_packet_decoder *decoder;
2491 struct btrace_data_pt *pt;
2492 struct pt_config config;
2495 pt = &btinfo->data.variant.pt;
2497 /* Nothing to do if there is no trace. */
2501 memset (&config, 0, sizeof(config));
2503 config.size = sizeof (config);
2504 config.begin = pt->data;
2505 config.end = pt->data + pt->size;
2507 config.cpu.vendor = pt_translate_cpu_vendor (pt->config.cpu.vendor);
2508 config.cpu.family = pt->config.cpu.family;
2509 config.cpu.model = pt->config.cpu.model;
2510 config.cpu.stepping = pt->config.cpu.stepping;
2512 errcode = pt_cpu_errata (&config.errata, &config.cpu);
2514 error (_("Failed to configure the Intel Processor Trace decoder: %s."),
2515 pt_errstr (pt_errcode (errcode)));
2517 decoder = pt_pkt_alloc_decoder (&config);
2518 if (decoder == NULL)
2519 error (_("Failed to allocate the Intel Processor Trace decoder."));
2523 btrace_maint_decode_pt (&btinfo->maint, decoder);
2525 CATCH (except, RETURN_MASK_ALL)
2527 pt_pkt_free_decoder (decoder);
2529 if (except.reason < 0)
2530 throw_exception (except);
2534 pt_pkt_free_decoder (decoder);
2537 #endif /* !defined (HAVE_LIBIPT) */
2539 /* Update the packet maintenance information for BTINFO and store the
2540 low and high bounds into BEGIN and END, respectively.
2541 Store the current iterator state into FROM and TO. */
2544 btrace_maint_update_packets (struct btrace_thread_info *btinfo,
2545 unsigned int *begin, unsigned int *end,
2546 unsigned int *from, unsigned int *to)
2548 switch (btinfo->data.format)
2557 case BTRACE_FORMAT_BTS:
2558 /* Nothing to do - we operate directly on BTINFO->DATA. */
2560 *end = VEC_length (btrace_block_s, btinfo->data.variant.bts.blocks);
2561 *from = btinfo->maint.variant.bts.packet_history.begin;
2562 *to = btinfo->maint.variant.bts.packet_history.end;
2565 #if defined (HAVE_LIBIPT)
2566 case BTRACE_FORMAT_PT:
2567 if (VEC_empty (btrace_pt_packet_s, btinfo->maint.variant.pt.packets))
2568 btrace_maint_update_pt_packets (btinfo);
2571 *end = VEC_length (btrace_pt_packet_s, btinfo->maint.variant.pt.packets);
2572 *from = btinfo->maint.variant.pt.packet_history.begin;
2573 *to = btinfo->maint.variant.pt.packet_history.end;
2575 #endif /* defined (HAVE_LIBIPT) */
2579 /* Print packets in BTINFO from BEGIN (inclusive) until END (exclusive) and
2580 update the current iterator position. */
2583 btrace_maint_print_packets (struct btrace_thread_info *btinfo,
2584 unsigned int begin, unsigned int end)
2586 switch (btinfo->data.format)
2591 case BTRACE_FORMAT_BTS:
2593 VEC (btrace_block_s) *blocks;
2596 blocks = btinfo->data.variant.bts.blocks;
2597 for (blk = begin; blk < end; ++blk)
2599 const btrace_block_s *block;
2601 block = VEC_index (btrace_block_s, blocks, blk);
2603 printf_unfiltered ("%u\tbegin: %s, end: %s\n", blk,
2604 core_addr_to_string_nz (block->begin),
2605 core_addr_to_string_nz (block->end));
2608 btinfo->maint.variant.bts.packet_history.begin = begin;
2609 btinfo->maint.variant.bts.packet_history.end = end;
2613 #if defined (HAVE_LIBIPT)
2614 case BTRACE_FORMAT_PT:
2616 VEC (btrace_pt_packet_s) *packets;
2619 packets = btinfo->maint.variant.pt.packets;
2620 for (pkt = begin; pkt < end; ++pkt)
2622 const struct btrace_pt_packet *packet;
2624 packet = VEC_index (btrace_pt_packet_s, packets, pkt);
2626 printf_unfiltered ("%u\t", pkt);
2627 printf_unfiltered ("0x%" PRIx64 "\t", packet->offset);
2629 if (packet->errcode == pte_ok)
2630 pt_print_packet (&packet->packet);
2632 printf_unfiltered ("[error: %s]", pt_errstr (packet->errcode));
2634 printf_unfiltered ("\n");
2637 btinfo->maint.variant.pt.packet_history.begin = begin;
2638 btinfo->maint.variant.pt.packet_history.end = end;
2641 #endif /* defined (HAVE_LIBIPT) */
2645 /* Read a number from an argument string. */
2648 get_uint (char **arg)
2650 char *begin, *end, *pos;
2651 unsigned long number;
2654 pos = skip_spaces (begin);
2656 if (!isdigit (*pos))
2657 error (_("Expected positive number, got: %s."), pos);
2659 number = strtoul (pos, &end, 10);
2660 if (number > UINT_MAX)
2661 error (_("Number too big."));
2663 *arg += (end - begin);
2665 return (unsigned int) number;
2668 /* Read a context size from an argument string. */
2671 get_context_size (char **arg)
2676 pos = skip_spaces (*arg);
2678 if (!isdigit (*pos))
2679 error (_("Expected positive number, got: %s."), pos);
2681 return strtol (pos, arg, 10);
2684 /* Complain about junk at the end of an argument string. */
2687 no_chunk (char *arg)
2690 error (_("Junk after argument: %s."), arg);
2693 /* The "maintenance btrace packet-history" command. */
2696 maint_btrace_packet_history_cmd (char *arg, int from_tty)
2698 struct btrace_thread_info *btinfo;
2699 struct thread_info *tp;
2700 unsigned int size, begin, end, from, to;
2702 tp = find_thread_ptid (inferior_ptid);
2704 error (_("No thread."));
2707 btinfo = &tp->btrace;
2709 btrace_maint_update_packets (btinfo, &begin, &end, &from, &to);
2712 printf_unfiltered (_("No trace.\n"));
2716 if (arg == NULL || *arg == 0 || strcmp (arg, "+") == 0)
2720 if (end - from < size)
2724 else if (strcmp (arg, "-") == 0)
2728 if (to - begin < size)
2734 from = get_uint (&arg);
2736 error (_("'%u' is out of range."), from);
2738 arg = skip_spaces (arg);
2741 arg = skip_spaces (++arg);
2746 size = get_context_size (&arg);
2750 if (end - from < size)
2754 else if (*arg == '-')
2757 size = get_context_size (&arg);
2761 /* Include the packet given as first argument. */
2765 if (to - begin < size)
2771 to = get_uint (&arg);
2773 /* Include the packet at the second argument and silently
2774 truncate the range. */
2787 if (end - from < size)
2795 btrace_maint_print_packets (btinfo, from, to);
2798 /* The "maintenance btrace clear-packet-history" command. */
2801 maint_btrace_clear_packet_history_cmd (char *args, int from_tty)
2803 struct btrace_thread_info *btinfo;
2804 struct thread_info *tp;
2806 if (args != NULL && *args != 0)
2807 error (_("Invalid argument."));
2809 tp = find_thread_ptid (inferior_ptid);
2811 error (_("No thread."));
2813 btinfo = &tp->btrace;
2815 /* Must clear the maint data before - it depends on BTINFO->DATA. */
2816 btrace_maint_clear (btinfo);
2817 btrace_data_clear (&btinfo->data);
2820 /* The "maintenance btrace clear" command. */
2823 maint_btrace_clear_cmd (char *args, int from_tty)
2825 struct btrace_thread_info *btinfo;
2826 struct thread_info *tp;
2828 if (args != NULL && *args != 0)
2829 error (_("Invalid argument."));
2831 tp = find_thread_ptid (inferior_ptid);
2833 error (_("No thread."));
2838 /* The "maintenance btrace" command. */
2841 maint_btrace_cmd (char *args, int from_tty)
2843 help_list (maint_btrace_cmdlist, "maintenance btrace ", all_commands,
2847 /* The "maintenance set btrace" command. */
2850 maint_btrace_set_cmd (char *args, int from_tty)
2852 help_list (maint_btrace_set_cmdlist, "maintenance set btrace ", all_commands,
2856 /* The "maintenance show btrace" command. */
2859 maint_btrace_show_cmd (char *args, int from_tty)
2861 help_list (maint_btrace_show_cmdlist, "maintenance show btrace ",
2862 all_commands, gdb_stdout);
2865 /* The "maintenance set btrace pt" command. */
2868 maint_btrace_pt_set_cmd (char *args, int from_tty)
2870 help_list (maint_btrace_pt_set_cmdlist, "maintenance set btrace pt ",
2871 all_commands, gdb_stdout);
2874 /* The "maintenance show btrace pt" command. */
2877 maint_btrace_pt_show_cmd (char *args, int from_tty)
2879 help_list (maint_btrace_pt_show_cmdlist, "maintenance show btrace pt ",
2880 all_commands, gdb_stdout);
2883 /* The "maintenance info btrace" command. */
2886 maint_info_btrace_cmd (char *args, int from_tty)
2888 struct btrace_thread_info *btinfo;
2889 struct thread_info *tp;
2890 const struct btrace_config *conf;
2892 if (args != NULL && *args != 0)
2893 error (_("Invalid argument."));
2895 tp = find_thread_ptid (inferior_ptid);
2897 error (_("No thread."));
2899 btinfo = &tp->btrace;
2901 conf = btrace_conf (btinfo);
2903 error (_("No btrace configuration."));
2905 printf_unfiltered (_("Format: %s.\n"),
2906 btrace_format_string (conf->format));
2908 switch (conf->format)
2913 case BTRACE_FORMAT_BTS:
2914 printf_unfiltered (_("Number of packets: %u.\n"),
2915 VEC_length (btrace_block_s,
2916 btinfo->data.variant.bts.blocks));
2919 #if defined (HAVE_LIBIPT)
2920 case BTRACE_FORMAT_PT:
2922 struct pt_version version;
2924 version = pt_library_version ();
2925 printf_unfiltered (_("Version: %u.%u.%u%s.\n"), version.major,
2926 version.minor, version.build,
2927 version.ext != NULL ? version.ext : "");
2929 btrace_maint_update_pt_packets (btinfo);
2930 printf_unfiltered (_("Number of packets: %u.\n"),
2931 VEC_length (btrace_pt_packet_s,
2932 btinfo->maint.variant.pt.packets));
2935 #endif /* defined (HAVE_LIBIPT) */
2939 /* The "maint show btrace pt skip-pad" show value function. */
2942 show_maint_btrace_pt_skip_pad (struct ui_file *file, int from_tty,
2943 struct cmd_list_element *c,
2946 fprintf_filtered (file, _("Skip PAD packets is %s.\n"), value);
2950 /* Initialize btrace maintenance commands. */
2952 void _initialize_btrace (void);
2954 _initialize_btrace (void)
2956 add_cmd ("btrace", class_maintenance, maint_info_btrace_cmd,
2957 _("Info about branch tracing data."), &maintenanceinfolist);
2959 add_prefix_cmd ("btrace", class_maintenance, maint_btrace_cmd,
2960 _("Branch tracing maintenance commands."),
2961 &maint_btrace_cmdlist, "maintenance btrace ",
2962 0, &maintenancelist);
2964 add_prefix_cmd ("btrace", class_maintenance, maint_btrace_set_cmd, _("\
2965 Set branch tracing specific variables."),
2966 &maint_btrace_set_cmdlist, "maintenance set btrace ",
2967 0, &maintenance_set_cmdlist);
2969 add_prefix_cmd ("pt", class_maintenance, maint_btrace_pt_set_cmd, _("\
2970 Set Intel Processor Trace specific variables."),
2971 &maint_btrace_pt_set_cmdlist, "maintenance set btrace pt ",
2972 0, &maint_btrace_set_cmdlist);
2974 add_prefix_cmd ("btrace", class_maintenance, maint_btrace_show_cmd, _("\
2975 Show branch tracing specific variables."),
2976 &maint_btrace_show_cmdlist, "maintenance show btrace ",
2977 0, &maintenance_show_cmdlist);
2979 add_prefix_cmd ("pt", class_maintenance, maint_btrace_pt_show_cmd, _("\
2980 Show Intel Processor Trace specific variables."),
2981 &maint_btrace_pt_show_cmdlist, "maintenance show btrace pt ",
2982 0, &maint_btrace_show_cmdlist);
2984 add_setshow_boolean_cmd ("skip-pad", class_maintenance,
2985 &maint_btrace_pt_skip_pad, _("\
2986 Set whether PAD packets should be skipped in the btrace packet history."), _("\
2987 Show whether PAD packets should be skipped in the btrace packet history."),_("\
2988 When enabled, PAD packets are ignored in the btrace packet history."),
2989 NULL, show_maint_btrace_pt_skip_pad,
2990 &maint_btrace_pt_set_cmdlist,
2991 &maint_btrace_pt_show_cmdlist);
2993 add_cmd ("packet-history", class_maintenance, maint_btrace_packet_history_cmd,
2994 _("Print the raw branch tracing data.\n\
2995 With no argument, print ten more packets after the previous ten-line print.\n\
2996 With '-' as argument print ten packets before a previous ten-line print.\n\
2997 One argument specifies the starting packet of a ten-line print.\n\
2998 Two arguments with comma between specify starting and ending packets to \
3000 Preceded with '+'/'-' the second argument specifies the distance from the \
3002 &maint_btrace_cmdlist);
3004 add_cmd ("clear-packet-history", class_maintenance,
3005 maint_btrace_clear_packet_history_cmd,
3006 _("Clears the branch tracing packet history.\n\
3007 Discards the raw branch tracing data but not the execution history data.\n\
3009 &maint_btrace_cmdlist);
3011 add_cmd ("clear", class_maintenance, maint_btrace_clear_cmd,
3012 _("Clears the branch tracing data.\n\
3013 Discards the raw branch tracing data and the execution history data.\n\
3014 The next 'record' command will fetch the branch tracing data anew.\n\
3016 &maint_btrace_cmdlist);