1 /* Branch trace support for GDB, the GNU debugger.
3 Copyright (C) 2013-2018 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
+ bfun
->insn
.size ();
136 DEBUG_FTRACE ("%s: fun = %s, file = %s, level = %d, insn = [%u; %u)",
137 prefix
, fun
, file
, level
, ibegin
, iend
);
140 /* Return the number of instructions in a given function call segment. */
143 ftrace_call_num_insn (const struct btrace_function
* bfun
)
148 /* A gap is always counted as one instruction. */
149 if (bfun
->errcode
!= 0)
152 return bfun
->insn
.size ();
155 /* Return the function segment with the given NUMBER or NULL if no such segment
156 exists. BTINFO is the branch trace information for the current thread. */
158 static struct btrace_function
*
159 ftrace_find_call_by_number (struct btrace_thread_info
*btinfo
,
162 if (number
== 0 || number
> btinfo
->functions
.size ())
165 return &btinfo
->functions
[number
- 1];
168 /* A const version of the function above. */
170 static const struct btrace_function
*
171 ftrace_find_call_by_number (const struct btrace_thread_info
*btinfo
,
174 if (number
== 0 || number
> btinfo
->functions
.size ())
177 return &btinfo
->functions
[number
- 1];
180 /* Return non-zero if BFUN does not match MFUN and FUN,
181 return zero otherwise. */
184 ftrace_function_switched (const struct btrace_function
*bfun
,
185 const struct minimal_symbol
*mfun
,
186 const struct symbol
*fun
)
188 struct minimal_symbol
*msym
;
194 /* If the minimal symbol changed, we certainly switched functions. */
195 if (mfun
!= NULL
&& msym
!= NULL
196 && strcmp (MSYMBOL_LINKAGE_NAME (mfun
), MSYMBOL_LINKAGE_NAME (msym
)) != 0)
199 /* If the symbol changed, we certainly switched functions. */
200 if (fun
!= NULL
&& sym
!= NULL
)
202 const char *bfname
, *fname
;
204 /* Check the function name. */
205 if (strcmp (SYMBOL_LINKAGE_NAME (fun
), SYMBOL_LINKAGE_NAME (sym
)) != 0)
208 /* Check the location of those functions, as well. */
209 bfname
= symtab_to_fullname (symbol_symtab (sym
));
210 fname
= symtab_to_fullname (symbol_symtab (fun
));
211 if (filename_cmp (fname
, bfname
) != 0)
215 /* If we lost symbol information, we switched functions. */
216 if (!(msym
== NULL
&& sym
== NULL
) && mfun
== NULL
&& fun
== NULL
)
219 /* If we gained symbol information, we switched functions. */
220 if (msym
== NULL
&& sym
== NULL
&& !(mfun
== NULL
&& fun
== NULL
))
226 /* Allocate and initialize a new branch trace function segment at the end of
228 BTINFO is the branch trace information for the current thread.
229 MFUN and FUN are the symbol information we have for this function.
230 This invalidates all struct btrace_function pointer currently held. */
232 static struct btrace_function
*
233 ftrace_new_function (struct btrace_thread_info
*btinfo
,
234 struct minimal_symbol
*mfun
,
238 unsigned int number
, insn_offset
;
240 if (btinfo
->functions
.empty ())
242 /* Start counting NUMBER and INSN_OFFSET at one. */
249 const struct btrace_function
*prev
= &btinfo
->functions
.back ();
251 number
= prev
->number
+ 1;
252 insn_offset
= prev
->insn_offset
+ ftrace_call_num_insn (prev
);
255 btinfo
->functions
.emplace_back (mfun
, fun
, number
, insn_offset
, level
);
256 return &btinfo
->functions
.back ();
259 /* Update the UP field of a function segment. */
262 ftrace_update_caller (struct btrace_function
*bfun
,
263 struct btrace_function
*caller
,
264 enum btrace_function_flag flags
)
267 ftrace_debug (bfun
, "updating caller");
269 bfun
->up
= caller
->number
;
272 ftrace_debug (bfun
, "set caller");
273 ftrace_debug (caller
, "..to");
276 /* Fix up the caller for all segments of a function. */
279 ftrace_fixup_caller (struct btrace_thread_info
*btinfo
,
280 struct btrace_function
*bfun
,
281 struct btrace_function
*caller
,
282 enum btrace_function_flag flags
)
284 unsigned int prev
, next
;
288 ftrace_update_caller (bfun
, caller
, flags
);
290 /* Update all function segments belonging to the same function. */
291 for (; prev
!= 0; prev
= bfun
->prev
)
293 bfun
= ftrace_find_call_by_number (btinfo
, prev
);
294 ftrace_update_caller (bfun
, caller
, flags
);
297 for (; next
!= 0; next
= bfun
->next
)
299 bfun
= ftrace_find_call_by_number (btinfo
, next
);
300 ftrace_update_caller (bfun
, caller
, flags
);
304 /* Add a new function segment for a call at the end of the trace.
305 BTINFO is the branch trace information for the current thread.
306 MFUN and FUN are the symbol information we have for this function. */
308 static struct btrace_function
*
309 ftrace_new_call (struct btrace_thread_info
*btinfo
,
310 struct minimal_symbol
*mfun
,
313 const unsigned int length
= btinfo
->functions
.size ();
314 struct btrace_function
*bfun
= ftrace_new_function (btinfo
, mfun
, fun
);
319 ftrace_debug (bfun
, "new call");
324 /* Add a new function segment for a tail call at the end of the trace.
325 BTINFO is the branch trace information for the current thread.
326 MFUN and FUN are the symbol information we have for this function. */
328 static struct btrace_function
*
329 ftrace_new_tailcall (struct btrace_thread_info
*btinfo
,
330 struct minimal_symbol
*mfun
,
333 const unsigned int length
= btinfo
->functions
.size ();
334 struct btrace_function
*bfun
= ftrace_new_function (btinfo
, mfun
, fun
);
338 bfun
->flags
|= BFUN_UP_LINKS_TO_TAILCALL
;
340 ftrace_debug (bfun
, "new tail call");
345 /* Return the caller of BFUN or NULL if there is none. This function skips
346 tail calls in the call chain. BTINFO is the branch trace information for
347 the current thread. */
348 static struct btrace_function
*
349 ftrace_get_caller (struct btrace_thread_info
*btinfo
,
350 struct btrace_function
*bfun
)
352 for (; bfun
!= NULL
; bfun
= ftrace_find_call_by_number (btinfo
, bfun
->up
))
353 if ((bfun
->flags
& BFUN_UP_LINKS_TO_TAILCALL
) == 0)
354 return ftrace_find_call_by_number (btinfo
, bfun
->up
);
359 /* Find the innermost caller in the back trace of BFUN with MFUN/FUN
360 symbol information. BTINFO is the branch trace information for the current
363 static struct btrace_function
*
364 ftrace_find_caller (struct btrace_thread_info
*btinfo
,
365 struct btrace_function
*bfun
,
366 struct minimal_symbol
*mfun
,
369 for (; bfun
!= NULL
; bfun
= ftrace_find_call_by_number (btinfo
, bfun
->up
))
371 /* Skip functions with incompatible symbol information. */
372 if (ftrace_function_switched (bfun
, mfun
, fun
))
375 /* This is the function segment we're looking for. */
382 /* Find the innermost caller in the back trace of BFUN, skipping all
383 function segments that do not end with a call instruction (e.g.
384 tail calls ending with a jump). BTINFO is the branch trace information for
385 the current thread. */
387 static struct btrace_function
*
388 ftrace_find_call (struct btrace_thread_info
*btinfo
,
389 struct btrace_function
*bfun
)
391 for (; bfun
!= NULL
; bfun
= ftrace_find_call_by_number (btinfo
, bfun
->up
))
394 if (bfun
->errcode
!= 0)
397 btrace_insn
&last
= bfun
->insn
.back ();
399 if (last
.iclass
== BTRACE_INSN_CALL
)
406 /* Add a continuation segment for a function into which we return at the end of
408 BTINFO is the branch trace information for the current thread.
409 MFUN and FUN are the symbol information we have for this function. */
411 static struct btrace_function
*
412 ftrace_new_return (struct btrace_thread_info
*btinfo
,
413 struct minimal_symbol
*mfun
,
416 struct btrace_function
*prev
, *bfun
, *caller
;
418 bfun
= ftrace_new_function (btinfo
, mfun
, fun
);
419 prev
= ftrace_find_call_by_number (btinfo
, bfun
->number
- 1);
421 /* It is important to start at PREV's caller. Otherwise, we might find
422 PREV itself, if PREV is a recursive function. */
423 caller
= ftrace_find_call_by_number (btinfo
, prev
->up
);
424 caller
= ftrace_find_caller (btinfo
, caller
, mfun
, fun
);
427 /* The caller of PREV is the preceding btrace function segment in this
428 function instance. */
429 gdb_assert (caller
->next
== 0);
431 caller
->next
= bfun
->number
;
432 bfun
->prev
= caller
->number
;
434 /* Maintain the function level. */
435 bfun
->level
= caller
->level
;
437 /* Maintain the call stack. */
438 bfun
->up
= caller
->up
;
439 bfun
->flags
= caller
->flags
;
441 ftrace_debug (bfun
, "new return");
445 /* We did not find a caller. This could mean that something went
446 wrong or that the call is simply not included in the trace. */
448 /* Let's search for some actual call. */
449 caller
= ftrace_find_call_by_number (btinfo
, prev
->up
);
450 caller
= ftrace_find_call (btinfo
, caller
);
453 /* There is no call in PREV's back trace. We assume that the
454 branch trace did not include it. */
456 /* Let's find the topmost function and add a new caller for it.
457 This should handle a series of initial tail calls. */
458 while (prev
->up
!= 0)
459 prev
= ftrace_find_call_by_number (btinfo
, prev
->up
);
461 bfun
->level
= prev
->level
- 1;
463 /* Fix up the call stack for PREV. */
464 ftrace_fixup_caller (btinfo
, prev
, bfun
, BFUN_UP_LINKS_TO_RET
);
466 ftrace_debug (bfun
, "new return - no caller");
470 /* There is a call in PREV's back trace to which we should have
471 returned but didn't. Let's start a new, separate back trace
472 from PREV's level. */
473 bfun
->level
= prev
->level
- 1;
475 /* We fix up the back trace for PREV but leave other function segments
476 on the same level as they are.
477 This should handle things like schedule () correctly where we're
478 switching contexts. */
479 prev
->up
= bfun
->number
;
480 prev
->flags
= BFUN_UP_LINKS_TO_RET
;
482 ftrace_debug (bfun
, "new return - unknown caller");
489 /* Add a new function segment for a function switch at the end of the trace.
490 BTINFO is the branch trace information for the current thread.
491 MFUN and FUN are the symbol information we have for this function. */
493 static struct btrace_function
*
494 ftrace_new_switch (struct btrace_thread_info
*btinfo
,
495 struct minimal_symbol
*mfun
,
498 struct btrace_function
*prev
, *bfun
;
500 /* This is an unexplained function switch. We can't really be sure about the
501 call stack, yet the best I can think of right now is to preserve it. */
502 bfun
= ftrace_new_function (btinfo
, mfun
, fun
);
503 prev
= ftrace_find_call_by_number (btinfo
, bfun
->number
- 1);
505 bfun
->flags
= prev
->flags
;
507 ftrace_debug (bfun
, "new switch");
512 /* Add a new function segment for a gap in the trace due to a decode error at
513 the end of the trace.
514 BTINFO is the branch trace information for the current thread.
515 ERRCODE is the format-specific error code. */
517 static struct btrace_function
*
518 ftrace_new_gap (struct btrace_thread_info
*btinfo
, int errcode
,
519 std::vector
<unsigned int> &gaps
)
521 struct btrace_function
*bfun
;
523 if (btinfo
->functions
.empty ())
524 bfun
= ftrace_new_function (btinfo
, NULL
, NULL
);
527 /* We hijack the previous function segment if it was empty. */
528 bfun
= &btinfo
->functions
.back ();
529 if (bfun
->errcode
!= 0 || !bfun
->insn
.empty ())
530 bfun
= ftrace_new_function (btinfo
, NULL
, NULL
);
533 bfun
->errcode
= errcode
;
534 gaps
.push_back (bfun
->number
);
536 ftrace_debug (bfun
, "new gap");
541 /* Update the current function segment at the end of the trace in BTINFO with
542 respect to the instruction at PC. This may create new function segments.
543 Return the chronologically latest function segment, never NULL. */
545 static struct btrace_function
*
546 ftrace_update_function (struct btrace_thread_info
*btinfo
, CORE_ADDR pc
)
548 struct bound_minimal_symbol bmfun
;
549 struct minimal_symbol
*mfun
;
551 struct btrace_function
*bfun
;
553 /* Try to determine the function we're in. We use both types of symbols
554 to avoid surprises when we sometimes get a full symbol and sometimes
555 only a minimal symbol. */
556 fun
= find_pc_function (pc
);
557 bmfun
= lookup_minimal_symbol_by_pc (pc
);
560 if (fun
== NULL
&& mfun
== NULL
)
561 DEBUG_FTRACE ("no symbol at %s", core_addr_to_string_nz (pc
));
563 /* If we didn't have a function, we create one. */
564 if (btinfo
->functions
.empty ())
565 return ftrace_new_function (btinfo
, mfun
, fun
);
567 /* If we had a gap before, we create a function. */
568 bfun
= &btinfo
->functions
.back ();
569 if (bfun
->errcode
!= 0)
570 return ftrace_new_function (btinfo
, mfun
, fun
);
572 /* Check the last instruction, if we have one.
573 We do this check first, since it allows us to fill in the call stack
574 links in addition to the normal flow links. */
575 btrace_insn
*last
= NULL
;
576 if (!bfun
->insn
.empty ())
577 last
= &bfun
->insn
.back ();
581 switch (last
->iclass
)
583 case BTRACE_INSN_RETURN
:
587 /* On some systems, _dl_runtime_resolve returns to the resolved
588 function instead of jumping to it. From our perspective,
589 however, this is a tailcall.
590 If we treated it as return, we wouldn't be able to find the
591 resolved function in our stack back trace. Hence, we would
592 lose the current stack back trace and start anew with an empty
593 back trace. When the resolved function returns, we would then
594 create a stack back trace with the same function names but
595 different frame id's. This will confuse stepping. */
596 fname
= ftrace_print_function_name (bfun
);
597 if (strcmp (fname
, "_dl_runtime_resolve") == 0)
598 return ftrace_new_tailcall (btinfo
, mfun
, fun
);
600 return ftrace_new_return (btinfo
, mfun
, fun
);
603 case BTRACE_INSN_CALL
:
604 /* Ignore calls to the next instruction. They are used for PIC. */
605 if (last
->pc
+ last
->size
== pc
)
608 return ftrace_new_call (btinfo
, mfun
, fun
);
610 case BTRACE_INSN_JUMP
:
614 start
= get_pc_function_start (pc
);
616 /* A jump to the start of a function is (typically) a tail call. */
618 return ftrace_new_tailcall (btinfo
, mfun
, fun
);
620 /* If we can't determine the function for PC, we treat a jump at
621 the end of the block as tail call if we're switching functions
622 and as an intra-function branch if we don't. */
623 if (start
== 0 && ftrace_function_switched (bfun
, mfun
, fun
))
624 return ftrace_new_tailcall (btinfo
, mfun
, fun
);
631 /* Check if we're switching functions for some other reason. */
632 if (ftrace_function_switched (bfun
, mfun
, fun
))
634 DEBUG_FTRACE ("switching from %s in %s at %s",
635 ftrace_print_insn_addr (last
),
636 ftrace_print_function_name (bfun
),
637 ftrace_print_filename (bfun
));
639 return ftrace_new_switch (btinfo
, mfun
, fun
);
645 /* Add the instruction at PC to BFUN's instructions. */
648 ftrace_update_insns (struct btrace_function
*bfun
, const btrace_insn
&insn
)
650 bfun
->insn
.push_back (insn
);
652 if (record_debug
> 1)
653 ftrace_debug (bfun
, "update insn");
656 /* Classify the instruction at PC. */
658 static enum btrace_insn_class
659 ftrace_classify_insn (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
661 enum btrace_insn_class iclass
;
663 iclass
= BTRACE_INSN_OTHER
;
666 if (gdbarch_insn_is_call (gdbarch
, pc
))
667 iclass
= BTRACE_INSN_CALL
;
668 else if (gdbarch_insn_is_ret (gdbarch
, pc
))
669 iclass
= BTRACE_INSN_RETURN
;
670 else if (gdbarch_insn_is_jump (gdbarch
, pc
))
671 iclass
= BTRACE_INSN_JUMP
;
673 CATCH (error
, RETURN_MASK_ERROR
)
681 /* Try to match the back trace at LHS to the back trace at RHS. Returns the
682 number of matching function segments or zero if the back traces do not
683 match. BTINFO is the branch trace information for the current thread. */
686 ftrace_match_backtrace (struct btrace_thread_info
*btinfo
,
687 struct btrace_function
*lhs
,
688 struct btrace_function
*rhs
)
692 for (matches
= 0; lhs
!= NULL
&& rhs
!= NULL
; ++matches
)
694 if (ftrace_function_switched (lhs
, rhs
->msym
, rhs
->sym
))
697 lhs
= ftrace_get_caller (btinfo
, lhs
);
698 rhs
= ftrace_get_caller (btinfo
, rhs
);
704 /* Add ADJUSTMENT to the level of BFUN and succeeding function segments.
705 BTINFO is the branch trace information for the current thread. */
708 ftrace_fixup_level (struct btrace_thread_info
*btinfo
,
709 struct btrace_function
*bfun
, int adjustment
)
714 DEBUG_FTRACE ("fixup level (%+d)", adjustment
);
715 ftrace_debug (bfun
, "..bfun");
719 bfun
->level
+= adjustment
;
720 bfun
= ftrace_find_call_by_number (btinfo
, bfun
->number
+ 1);
724 /* Recompute the global level offset. Traverse the function trace and compute
725 the global level offset as the negative of the minimal function level. */
728 ftrace_compute_global_level_offset (struct btrace_thread_info
*btinfo
)
735 if (btinfo
->functions
.empty ())
738 unsigned int length
= btinfo
->functions
.size() - 1;
739 for (unsigned int i
= 0; i
< length
; ++i
)
740 level
= std::min (level
, btinfo
->functions
[i
].level
);
742 /* The last function segment contains the current instruction, which is not
743 really part of the trace. If it contains just this one instruction, we
744 ignore the segment. */
745 struct btrace_function
*last
= &btinfo
->functions
.back();
746 if (last
->insn
.size () != 1)
747 level
= std::min (level
, last
->level
);
749 DEBUG_FTRACE ("setting global level offset: %d", -level
);
750 btinfo
->level
= -level
;
753 /* Connect the function segments PREV and NEXT in a bottom-to-top walk as in
754 ftrace_connect_backtrace. BTINFO is the branch trace information for the
758 ftrace_connect_bfun (struct btrace_thread_info
*btinfo
,
759 struct btrace_function
*prev
,
760 struct btrace_function
*next
)
762 DEBUG_FTRACE ("connecting...");
763 ftrace_debug (prev
, "..prev");
764 ftrace_debug (next
, "..next");
766 /* The function segments are not yet connected. */
767 gdb_assert (prev
->next
== 0);
768 gdb_assert (next
->prev
== 0);
770 prev
->next
= next
->number
;
771 next
->prev
= prev
->number
;
773 /* We may have moved NEXT to a different function level. */
774 ftrace_fixup_level (btinfo
, next
, prev
->level
- next
->level
);
776 /* If we run out of back trace for one, let's use the other's. */
779 const btrace_function_flags flags
= next
->flags
;
781 next
= ftrace_find_call_by_number (btinfo
, next
->up
);
784 DEBUG_FTRACE ("using next's callers");
785 ftrace_fixup_caller (btinfo
, prev
, next
, flags
);
788 else if (next
->up
== 0)
790 const btrace_function_flags flags
= prev
->flags
;
792 prev
= ftrace_find_call_by_number (btinfo
, prev
->up
);
795 DEBUG_FTRACE ("using prev's callers");
796 ftrace_fixup_caller (btinfo
, next
, prev
, flags
);
801 /* PREV may have a tailcall caller, NEXT can't. If it does, fixup the up
802 link to add the tail callers to NEXT's back trace.
804 This removes NEXT->UP from NEXT's back trace. It will be added back
805 when connecting NEXT and PREV's callers - provided they exist.
807 If PREV's back trace consists of a series of tail calls without an
808 actual call, there will be no further connection and NEXT's caller will
809 be removed for good. To catch this case, we handle it here and connect
810 the top of PREV's back trace to NEXT's caller. */
811 if ((prev
->flags
& BFUN_UP_LINKS_TO_TAILCALL
) != 0)
813 struct btrace_function
*caller
;
814 btrace_function_flags next_flags
, prev_flags
;
816 /* We checked NEXT->UP above so CALLER can't be NULL. */
817 caller
= ftrace_find_call_by_number (btinfo
, next
->up
);
818 next_flags
= next
->flags
;
819 prev_flags
= prev
->flags
;
821 DEBUG_FTRACE ("adding prev's tail calls to next");
823 prev
= ftrace_find_call_by_number (btinfo
, prev
->up
);
824 ftrace_fixup_caller (btinfo
, next
, prev
, prev_flags
);
826 for (; prev
!= NULL
; prev
= ftrace_find_call_by_number (btinfo
,
829 /* At the end of PREV's back trace, continue with CALLER. */
832 DEBUG_FTRACE ("fixing up link for tailcall chain");
833 ftrace_debug (prev
, "..top");
834 ftrace_debug (caller
, "..up");
836 ftrace_fixup_caller (btinfo
, prev
, caller
, next_flags
);
838 /* If we skipped any tail calls, this may move CALLER to a
839 different function level.
841 Note that changing CALLER's level is only OK because we
842 know that this is the last iteration of the bottom-to-top
843 walk in ftrace_connect_backtrace.
845 Otherwise we will fix up CALLER's level when we connect it
846 to PREV's caller in the next iteration. */
847 ftrace_fixup_level (btinfo
, caller
,
848 prev
->level
- caller
->level
- 1);
852 /* There's nothing to do if we find a real call. */
853 if ((prev
->flags
& BFUN_UP_LINKS_TO_TAILCALL
) == 0)
855 DEBUG_FTRACE ("will fix up link in next iteration");
863 /* Connect function segments on the same level in the back trace at LHS and RHS.
864 The back traces at LHS and RHS are expected to match according to
865 ftrace_match_backtrace. BTINFO is the branch trace information for the
869 ftrace_connect_backtrace (struct btrace_thread_info
*btinfo
,
870 struct btrace_function
*lhs
,
871 struct btrace_function
*rhs
)
873 while (lhs
!= NULL
&& rhs
!= NULL
)
875 struct btrace_function
*prev
, *next
;
877 gdb_assert (!ftrace_function_switched (lhs
, rhs
->msym
, rhs
->sym
));
879 /* Connecting LHS and RHS may change the up link. */
883 lhs
= ftrace_get_caller (btinfo
, lhs
);
884 rhs
= ftrace_get_caller (btinfo
, rhs
);
886 ftrace_connect_bfun (btinfo
, prev
, next
);
890 /* Bridge the gap between two function segments left and right of a gap if their
891 respective back traces match in at least MIN_MATCHES functions. BTINFO is
892 the branch trace information for the current thread.
894 Returns non-zero if the gap could be bridged, zero otherwise. */
897 ftrace_bridge_gap (struct btrace_thread_info
*btinfo
,
898 struct btrace_function
*lhs
, struct btrace_function
*rhs
,
901 struct btrace_function
*best_l
, *best_r
, *cand_l
, *cand_r
;
904 DEBUG_FTRACE ("checking gap at insn %u (req matches: %d)",
905 rhs
->insn_offset
- 1, min_matches
);
911 /* We search the back traces of LHS and RHS for valid connections and connect
912 the two functon segments that give the longest combined back trace. */
914 for (cand_l
= lhs
; cand_l
!= NULL
;
915 cand_l
= ftrace_get_caller (btinfo
, cand_l
))
916 for (cand_r
= rhs
; cand_r
!= NULL
;
917 cand_r
= ftrace_get_caller (btinfo
, cand_r
))
921 matches
= ftrace_match_backtrace (btinfo
, cand_l
, cand_r
);
922 if (best_matches
< matches
)
924 best_matches
= matches
;
930 /* We need at least MIN_MATCHES matches. */
931 gdb_assert (min_matches
> 0);
932 if (best_matches
< min_matches
)
935 DEBUG_FTRACE ("..matches: %d", best_matches
);
937 /* We will fix up the level of BEST_R and succeeding function segments such
938 that BEST_R's level matches BEST_L's when we connect BEST_L to BEST_R.
940 This will ignore the level of RHS and following if BEST_R != RHS. I.e. if
941 BEST_R is a successor of RHS in the back trace of RHS (phases 1 and 3).
943 To catch this, we already fix up the level here where we can start at RHS
944 instead of at BEST_R. We will ignore the level fixup when connecting
945 BEST_L to BEST_R as they will already be on the same level. */
946 ftrace_fixup_level (btinfo
, rhs
, best_l
->level
- best_r
->level
);
948 ftrace_connect_backtrace (btinfo
, best_l
, best_r
);
953 /* Try to bridge gaps due to overflow or decode errors by connecting the
954 function segments that are separated by the gap. */
957 btrace_bridge_gaps (struct thread_info
*tp
, std::vector
<unsigned int> &gaps
)
959 struct btrace_thread_info
*btinfo
= &tp
->btrace
;
960 std::vector
<unsigned int> remaining
;
963 DEBUG ("bridge gaps");
965 /* We require a minimum amount of matches for bridging a gap. The number of
966 required matches will be lowered with each iteration.
968 The more matches the higher our confidence that the bridging is correct.
969 For big gaps or small traces, however, it may not be feasible to require a
970 high number of matches. */
971 for (min_matches
= 5; min_matches
> 0; --min_matches
)
973 /* Let's try to bridge as many gaps as we can. In some cases, we need to
974 skip a gap and revisit it again after we closed later gaps. */
975 while (!gaps
.empty ())
977 for (const unsigned int number
: gaps
)
979 struct btrace_function
*gap
, *lhs
, *rhs
;
982 gap
= ftrace_find_call_by_number (btinfo
, number
);
984 /* We may have a sequence of gaps if we run from one error into
985 the next as we try to re-sync onto the trace stream. Ignore
986 all but the leftmost gap in such a sequence.
988 Also ignore gaps at the beginning of the trace. */
989 lhs
= ftrace_find_call_by_number (btinfo
, gap
->number
- 1);
990 if (lhs
== NULL
|| lhs
->errcode
!= 0)
993 /* Skip gaps to the right. */
994 rhs
= ftrace_find_call_by_number (btinfo
, gap
->number
+ 1);
995 while (rhs
!= NULL
&& rhs
->errcode
!= 0)
996 rhs
= ftrace_find_call_by_number (btinfo
, rhs
->number
+ 1);
998 /* Ignore gaps at the end of the trace. */
1002 bridged
= ftrace_bridge_gap (btinfo
, lhs
, rhs
, min_matches
);
1004 /* Keep track of gaps we were not able to bridge and try again.
1005 If we just pushed them to the end of GAPS we would risk an
1006 infinite loop in case we simply cannot bridge a gap. */
1008 remaining
.push_back (number
);
1011 /* Let's see if we made any progress. */
1012 if (remaining
.size () == gaps
.size ())
1016 gaps
.swap (remaining
);
1019 /* We get here if either GAPS is empty or if GAPS equals REMAINING. */
1026 /* We may omit this in some cases. Not sure it is worth the extra
1027 complication, though. */
1028 ftrace_compute_global_level_offset (btinfo
);
1031 /* Compute the function branch trace from BTS trace. */
1034 btrace_compute_ftrace_bts (struct thread_info
*tp
,
1035 const struct btrace_data_bts
*btrace
,
1036 std::vector
<unsigned int> &gaps
)
1038 struct btrace_thread_info
*btinfo
;
1039 struct gdbarch
*gdbarch
;
1043 gdbarch
= target_gdbarch ();
1044 btinfo
= &tp
->btrace
;
1045 blk
= VEC_length (btrace_block_s
, btrace
->blocks
);
1047 if (btinfo
->functions
.empty ())
1050 level
= -btinfo
->level
;
1054 btrace_block_s
*block
;
1059 block
= VEC_index (btrace_block_s
, btrace
->blocks
, blk
);
1064 struct btrace_function
*bfun
;
1065 struct btrace_insn insn
;
1068 /* We should hit the end of the block. Warn if we went too far. */
1069 if (block
->end
< pc
)
1071 /* Indicate the gap in the trace. */
1072 bfun
= ftrace_new_gap (btinfo
, BDE_BTS_OVERFLOW
, gaps
);
1074 warning (_("Recorded trace may be corrupted at instruction "
1075 "%u (pc = %s)."), bfun
->insn_offset
- 1,
1076 core_addr_to_string_nz (pc
));
1081 bfun
= ftrace_update_function (btinfo
, pc
);
1083 /* Maintain the function level offset.
1084 For all but the last block, we do it here. */
1086 level
= std::min (level
, bfun
->level
);
1091 size
= gdb_insn_length (gdbarch
, pc
);
1093 CATCH (error
, RETURN_MASK_ERROR
)
1100 insn
.iclass
= ftrace_classify_insn (gdbarch
, pc
);
1103 ftrace_update_insns (bfun
, insn
);
1105 /* We're done once we pushed the instruction at the end. */
1106 if (block
->end
== pc
)
1109 /* We can't continue if we fail to compute the size. */
1112 /* Indicate the gap in the trace. We just added INSN so we're
1113 not at the beginning. */
1114 bfun
= ftrace_new_gap (btinfo
, BDE_BTS_INSN_SIZE
, gaps
);
1116 warning (_("Recorded trace may be incomplete at instruction %u "
1117 "(pc = %s)."), bfun
->insn_offset
- 1,
1118 core_addr_to_string_nz (pc
));
1125 /* Maintain the function level offset.
1126 For the last block, we do it here to not consider the last
1128 Since the last instruction corresponds to the current instruction
1129 and is not really part of the execution history, it shouldn't
1130 affect the level. */
1132 level
= std::min (level
, bfun
->level
);
1136 /* LEVEL is the minimal function level of all btrace function segments.
1137 Define the global level offset to -LEVEL so all function levels are
1138 normalized to start at zero. */
1139 btinfo
->level
= -level
;
1142 #if defined (HAVE_LIBIPT)
1144 static enum btrace_insn_class
1145 pt_reclassify_insn (enum pt_insn_class iclass
)
1150 return BTRACE_INSN_CALL
;
1153 return BTRACE_INSN_RETURN
;
1156 return BTRACE_INSN_JUMP
;
1159 return BTRACE_INSN_OTHER
;
1163 /* Return the btrace instruction flags for INSN. */
1165 static btrace_insn_flags
1166 pt_btrace_insn_flags (const struct pt_insn
&insn
)
1168 btrace_insn_flags flags
= 0;
1170 if (insn
.speculative
)
1171 flags
|= BTRACE_INSN_FLAG_SPECULATIVE
;
1176 /* Return the btrace instruction for INSN. */
1179 pt_btrace_insn (const struct pt_insn
&insn
)
1181 return {(CORE_ADDR
) insn
.ip
, (gdb_byte
) insn
.size
,
1182 pt_reclassify_insn (insn
.iclass
),
1183 pt_btrace_insn_flags (insn
)};
1186 /* Handle instruction decode events (libipt-v2). */
1189 handle_pt_insn_events (struct btrace_thread_info
*btinfo
,
1190 struct pt_insn_decoder
*decoder
,
1191 std::vector
<unsigned int> &gaps
, int status
)
1193 #if defined (HAVE_PT_INSN_EVENT)
1194 while (status
& pts_event_pending
)
1196 struct btrace_function
*bfun
;
1197 struct pt_event event
;
1200 status
= pt_insn_event (decoder
, &event
, sizeof (event
));
1210 if (event
.variant
.enabled
.resumed
== 0 && !btinfo
->functions
.empty ())
1212 bfun
= ftrace_new_gap (btinfo
, BDE_PT_DISABLED
, gaps
);
1214 pt_insn_get_offset (decoder
, &offset
);
1216 warning (_("Non-contiguous trace at instruction %u (offset = 0x%"
1217 PRIx64
")."), bfun
->insn_offset
- 1, offset
);
1223 bfun
= ftrace_new_gap (btinfo
, BDE_PT_OVERFLOW
, gaps
);
1225 pt_insn_get_offset (decoder
, &offset
);
1227 warning (_("Overflow at instruction %u (offset = 0x%" PRIx64
")."),
1228 bfun
->insn_offset
- 1, offset
);
1233 #endif /* defined (HAVE_PT_INSN_EVENT) */
1238 /* Handle events indicated by flags in INSN (libipt-v1). */
1241 handle_pt_insn_event_flags (struct btrace_thread_info
*btinfo
,
1242 struct pt_insn_decoder
*decoder
,
1243 const struct pt_insn
&insn
,
1244 std::vector
<unsigned int> &gaps
)
1246 #if defined (HAVE_STRUCT_PT_INSN_ENABLED)
1247 /* Tracing is disabled and re-enabled each time we enter the kernel. Most
1248 times, we continue from the same instruction we stopped before. This is
1249 indicated via the RESUMED instruction flag. The ENABLED instruction flag
1250 means that we continued from some other instruction. Indicate this as a
1251 trace gap except when tracing just started. */
1252 if (insn
.enabled
&& !btinfo
->functions
.empty ())
1254 struct btrace_function
*bfun
;
1257 bfun
= ftrace_new_gap (btinfo
, BDE_PT_DISABLED
, gaps
);
1259 pt_insn_get_offset (decoder
, &offset
);
1261 warning (_("Non-contiguous trace at instruction %u (offset = 0x%" PRIx64
1262 ", pc = 0x%" PRIx64
")."), bfun
->insn_offset
- 1, offset
,
1265 #endif /* defined (HAVE_STRUCT_PT_INSN_ENABLED) */
1267 #if defined (HAVE_STRUCT_PT_INSN_RESYNCED)
1268 /* Indicate trace overflows. */
1271 struct btrace_function
*bfun
;
1274 bfun
= ftrace_new_gap (btinfo
, BDE_PT_OVERFLOW
, gaps
);
1276 pt_insn_get_offset (decoder
, &offset
);
1278 warning (_("Overflow at instruction %u (offset = 0x%" PRIx64
", pc = 0x%"
1279 PRIx64
")."), bfun
->insn_offset
- 1, offset
, insn
.ip
);
1281 #endif /* defined (HAVE_STRUCT_PT_INSN_RESYNCED) */
1284 /* Add function branch trace to BTINFO using DECODER. */
1287 ftrace_add_pt (struct btrace_thread_info
*btinfo
,
1288 struct pt_insn_decoder
*decoder
,
1290 std::vector
<unsigned int> &gaps
)
1292 struct btrace_function
*bfun
;
1298 struct pt_insn insn
;
1300 status
= pt_insn_sync_forward (decoder
);
1303 if (status
!= -pte_eos
)
1304 warning (_("Failed to synchronize onto the Intel Processor "
1305 "Trace stream: %s."), pt_errstr (pt_errcode (status
)));
1311 /* Handle events from the previous iteration or synchronization. */
1312 status
= handle_pt_insn_events (btinfo
, decoder
, gaps
, status
);
1316 status
= pt_insn_next (decoder
, &insn
, sizeof(insn
));
1320 /* Handle events indicated by flags in INSN. */
1321 handle_pt_insn_event_flags (btinfo
, decoder
, insn
, gaps
);
1323 bfun
= ftrace_update_function (btinfo
, insn
.ip
);
1325 /* Maintain the function level offset. */
1326 *plevel
= std::min (*plevel
, bfun
->level
);
1328 ftrace_update_insns (bfun
, pt_btrace_insn (insn
));
1331 if (status
== -pte_eos
)
1334 /* Indicate the gap in the trace. */
1335 bfun
= ftrace_new_gap (btinfo
, status
, gaps
);
1337 pt_insn_get_offset (decoder
, &offset
);
1339 warning (_("Decode error (%d) at instruction %u (offset = 0x%" PRIx64
1340 ", pc = 0x%" PRIx64
"): %s."), status
, bfun
->insn_offset
- 1,
1341 offset
, insn
.ip
, pt_errstr (pt_errcode (status
)));
1345 /* A callback function to allow the trace decoder to read the inferior's
1349 btrace_pt_readmem_callback (gdb_byte
*buffer
, size_t size
,
1350 const struct pt_asid
*asid
, uint64_t pc
,
1353 int result
, errcode
;
1355 result
= (int) size
;
1358 errcode
= target_read_code ((CORE_ADDR
) pc
, buffer
, size
);
1360 result
= -pte_nomap
;
1362 CATCH (error
, RETURN_MASK_ERROR
)
1364 result
= -pte_nomap
;
1371 /* Translate the vendor from one enum to another. */
1373 static enum pt_cpu_vendor
1374 pt_translate_cpu_vendor (enum btrace_cpu_vendor vendor
)
1386 /* Finalize the function branch trace after decode. */
1388 static void btrace_finalize_ftrace_pt (struct pt_insn_decoder
*decoder
,
1389 struct thread_info
*tp
, int level
)
1391 pt_insn_free_decoder (decoder
);
1393 /* LEVEL is the minimal function level of all btrace function segments.
1394 Define the global level offset to -LEVEL so all function levels are
1395 normalized to start at zero. */
1396 tp
->btrace
.level
= -level
;
1398 /* Add a single last instruction entry for the current PC.
1399 This allows us to compute the backtrace at the current PC using both
1400 standard unwind and btrace unwind.
1401 This extra entry is ignored by all record commands. */
1405 /* Compute the function branch trace from Intel Processor Trace
1409 btrace_compute_ftrace_pt (struct thread_info
*tp
,
1410 const struct btrace_data_pt
*btrace
,
1411 std::vector
<unsigned int> &gaps
)
1413 struct btrace_thread_info
*btinfo
;
1414 struct pt_insn_decoder
*decoder
;
1415 struct pt_config config
;
1418 if (btrace
->size
== 0)
1421 btinfo
= &tp
->btrace
;
1422 if (btinfo
->functions
.empty ())
1425 level
= -btinfo
->level
;
1427 pt_config_init(&config
);
1428 config
.begin
= btrace
->data
;
1429 config
.end
= btrace
->data
+ btrace
->size
;
1431 config
.cpu
.vendor
= pt_translate_cpu_vendor (btrace
->config
.cpu
.vendor
);
1432 config
.cpu
.family
= btrace
->config
.cpu
.family
;
1433 config
.cpu
.model
= btrace
->config
.cpu
.model
;
1434 config
.cpu
.stepping
= btrace
->config
.cpu
.stepping
;
1436 errcode
= pt_cpu_errata (&config
.errata
, &config
.cpu
);
1438 error (_("Failed to configure the Intel Processor Trace decoder: %s."),
1439 pt_errstr (pt_errcode (errcode
)));
1441 decoder
= pt_insn_alloc_decoder (&config
);
1442 if (decoder
== NULL
)
1443 error (_("Failed to allocate the Intel Processor Trace decoder."));
1447 struct pt_image
*image
;
1449 image
= pt_insn_get_image(decoder
);
1451 error (_("Failed to configure the Intel Processor Trace decoder."));
1453 errcode
= pt_image_set_callback(image
, btrace_pt_readmem_callback
, NULL
);
1455 error (_("Failed to configure the Intel Processor Trace decoder: "
1456 "%s."), pt_errstr (pt_errcode (errcode
)));
1458 ftrace_add_pt (btinfo
, decoder
, &level
, gaps
);
1460 CATCH (error
, RETURN_MASK_ALL
)
1462 /* Indicate a gap in the trace if we quit trace processing. */
1463 if (error
.reason
== RETURN_QUIT
&& !btinfo
->functions
.empty ())
1464 ftrace_new_gap (btinfo
, BDE_PT_USER_QUIT
, gaps
);
1466 btrace_finalize_ftrace_pt (decoder
, tp
, level
);
1468 throw_exception (error
);
1472 btrace_finalize_ftrace_pt (decoder
, tp
, level
);
1475 #else /* defined (HAVE_LIBIPT) */
1478 btrace_compute_ftrace_pt (struct thread_info
*tp
,
1479 const struct btrace_data_pt
*btrace
,
1480 std::vector
<unsigned int> &gaps
)
1482 internal_error (__FILE__
, __LINE__
, _("Unexpected branch trace format."));
1485 #endif /* defined (HAVE_LIBIPT) */
1487 /* Compute the function branch trace from a block branch trace BTRACE for
1488 a thread given by BTINFO. */
1491 btrace_compute_ftrace_1 (struct thread_info
*tp
, struct btrace_data
*btrace
,
1492 std::vector
<unsigned int> &gaps
)
1494 DEBUG ("compute ftrace");
1496 switch (btrace
->format
)
1498 case BTRACE_FORMAT_NONE
:
1501 case BTRACE_FORMAT_BTS
:
1502 btrace_compute_ftrace_bts (tp
, &btrace
->variant
.bts
, gaps
);
1505 case BTRACE_FORMAT_PT
:
1506 btrace_compute_ftrace_pt (tp
, &btrace
->variant
.pt
, gaps
);
1510 internal_error (__FILE__
, __LINE__
, _("Unkown branch trace format."));
1514 btrace_finalize_ftrace (struct thread_info
*tp
, std::vector
<unsigned int> &gaps
)
1518 tp
->btrace
.ngaps
+= gaps
.size ();
1519 btrace_bridge_gaps (tp
, gaps
);
1524 btrace_compute_ftrace (struct thread_info
*tp
, struct btrace_data
*btrace
)
1526 std::vector
<unsigned int> gaps
;
1530 btrace_compute_ftrace_1 (tp
, btrace
, gaps
);
1532 CATCH (error
, RETURN_MASK_ALL
)
1534 btrace_finalize_ftrace (tp
, gaps
);
1536 throw_exception (error
);
1540 btrace_finalize_ftrace (tp
, gaps
);
1543 /* Add an entry for the current PC. */
1546 btrace_add_pc (struct thread_info
*tp
)
1548 struct btrace_data btrace
;
1549 struct btrace_block
*block
;
1550 struct regcache
*regcache
;
1551 struct cleanup
*cleanup
;
1554 regcache
= get_thread_regcache (tp
->ptid
);
1555 pc
= regcache_read_pc (regcache
);
1557 btrace_data_init (&btrace
);
1558 btrace
.format
= BTRACE_FORMAT_BTS
;
1559 btrace
.variant
.bts
.blocks
= NULL
;
1561 cleanup
= make_cleanup_btrace_data (&btrace
);
1563 block
= VEC_safe_push (btrace_block_s
, btrace
.variant
.bts
.blocks
, NULL
);
1567 btrace_compute_ftrace (tp
, &btrace
);
1569 do_cleanups (cleanup
);
1575 btrace_enable (struct thread_info
*tp
, const struct btrace_config
*conf
)
1577 if (tp
->btrace
.target
!= NULL
)
1580 #if !defined (HAVE_LIBIPT)
1581 if (conf
->format
== BTRACE_FORMAT_PT
)
1582 error (_("Intel Processor Trace support was disabled at compile time."));
1583 #endif /* !defined (HAVE_LIBIPT) */
1585 DEBUG ("enable thread %s (%s)", print_thread_id (tp
),
1586 target_pid_to_str (tp
->ptid
));
1588 tp
->btrace
.target
= target_enable_btrace (tp
->ptid
, conf
);
1590 /* We're done if we failed to enable tracing. */
1591 if (tp
->btrace
.target
== NULL
)
1594 /* We need to undo the enable in case of errors. */
1597 /* Add an entry for the current PC so we start tracing from where we
1600 If we can't access TP's registers, TP is most likely running. In this
1601 case, we can't really say where tracing was enabled so it should be
1602 safe to simply skip this step.
1604 This is not relevant for BTRACE_FORMAT_PT since the trace will already
1605 start at the PC at which tracing was enabled. */
1606 if (conf
->format
!= BTRACE_FORMAT_PT
1607 && can_access_registers_ptid (tp
->ptid
))
1610 CATCH (exception
, RETURN_MASK_ALL
)
1612 btrace_disable (tp
);
1614 throw_exception (exception
);
1621 const struct btrace_config
*
1622 btrace_conf (const struct btrace_thread_info
*btinfo
)
1624 if (btinfo
->target
== NULL
)
1627 return target_btrace_conf (btinfo
->target
);
1633 btrace_disable (struct thread_info
*tp
)
1635 struct btrace_thread_info
*btp
= &tp
->btrace
;
1637 if (btp
->target
== NULL
)
1640 DEBUG ("disable thread %s (%s)", print_thread_id (tp
),
1641 target_pid_to_str (tp
->ptid
));
1643 target_disable_btrace (btp
->target
);
1652 btrace_teardown (struct thread_info
*tp
)
1654 struct btrace_thread_info
*btp
= &tp
->btrace
;
1656 if (btp
->target
== NULL
)
1659 DEBUG ("teardown thread %s (%s)", print_thread_id (tp
),
1660 target_pid_to_str (tp
->ptid
));
1662 target_teardown_btrace (btp
->target
);
1668 /* Stitch branch trace in BTS format. */
1671 btrace_stitch_bts (struct btrace_data_bts
*btrace
, struct thread_info
*tp
)
1673 struct btrace_thread_info
*btinfo
;
1674 struct btrace_function
*last_bfun
;
1675 btrace_block_s
*first_new_block
;
1677 btinfo
= &tp
->btrace
;
1678 gdb_assert (!btinfo
->functions
.empty ());
1679 gdb_assert (!VEC_empty (btrace_block_s
, btrace
->blocks
));
1681 last_bfun
= &btinfo
->functions
.back ();
1683 /* If the existing trace ends with a gap, we just glue the traces
1684 together. We need to drop the last (i.e. chronologically first) block
1685 of the new trace, though, since we can't fill in the start address.*/
1686 if (last_bfun
->insn
.empty ())
1688 VEC_pop (btrace_block_s
, btrace
->blocks
);
1692 /* Beware that block trace starts with the most recent block, so the
1693 chronologically first block in the new trace is the last block in
1694 the new trace's block vector. */
1695 first_new_block
= VEC_last (btrace_block_s
, btrace
->blocks
);
1696 const btrace_insn
&last_insn
= last_bfun
->insn
.back ();
1698 /* If the current PC at the end of the block is the same as in our current
1699 trace, there are two explanations:
1700 1. we executed the instruction and some branch brought us back.
1701 2. we have not made any progress.
1702 In the first case, the delta trace vector should contain at least two
1704 In the second case, the delta trace vector should contain exactly one
1705 entry for the partial block containing the current PC. Remove it. */
1706 if (first_new_block
->end
== last_insn
.pc
1707 && VEC_length (btrace_block_s
, btrace
->blocks
) == 1)
1709 VEC_pop (btrace_block_s
, btrace
->blocks
);
1713 DEBUG ("stitching %s to %s", ftrace_print_insn_addr (&last_insn
),
1714 core_addr_to_string_nz (first_new_block
->end
));
1716 /* Do a simple sanity check to make sure we don't accidentally end up
1717 with a bad block. This should not occur in practice. */
1718 if (first_new_block
->end
< last_insn
.pc
)
1720 warning (_("Error while trying to read delta trace. Falling back to "
1725 /* We adjust the last block to start at the end of our current trace. */
1726 gdb_assert (first_new_block
->begin
== 0);
1727 first_new_block
->begin
= last_insn
.pc
;
1729 /* We simply pop the last insn so we can insert it again as part of
1730 the normal branch trace computation.
1731 Since instruction iterators are based on indices in the instructions
1732 vector, we don't leave any pointers dangling. */
1733 DEBUG ("pruning insn at %s for stitching",
1734 ftrace_print_insn_addr (&last_insn
));
1736 last_bfun
->insn
.pop_back ();
1738 /* The instructions vector may become empty temporarily if this has
1739 been the only instruction in this function segment.
1740 This violates the invariant but will be remedied shortly by
1741 btrace_compute_ftrace when we add the new trace. */
1743 /* The only case where this would hurt is if the entire trace consisted
1744 of just that one instruction. If we remove it, we might turn the now
1745 empty btrace function segment into a gap. But we don't want gaps at
1746 the beginning. To avoid this, we remove the entire old trace. */
1747 if (last_bfun
->number
== 1 && last_bfun
->insn
.empty ())
1753 /* Adjust the block trace in order to stitch old and new trace together.
1754 BTRACE is the new delta trace between the last and the current stop.
1755 TP is the traced thread.
1756 May modifx BTRACE as well as the existing trace in TP.
1757 Return 0 on success, -1 otherwise. */
1760 btrace_stitch_trace (struct btrace_data
*btrace
, struct thread_info
*tp
)
1762 /* If we don't have trace, there's nothing to do. */
1763 if (btrace_data_empty (btrace
))
1766 switch (btrace
->format
)
1768 case BTRACE_FORMAT_NONE
:
1771 case BTRACE_FORMAT_BTS
:
1772 return btrace_stitch_bts (&btrace
->variant
.bts
, tp
);
1774 case BTRACE_FORMAT_PT
:
1775 /* Delta reads are not supported. */
1779 internal_error (__FILE__
, __LINE__
, _("Unkown branch trace format."));
1782 /* Clear the branch trace histories in BTINFO. */
1785 btrace_clear_history (struct btrace_thread_info
*btinfo
)
1787 xfree (btinfo
->insn_history
);
1788 xfree (btinfo
->call_history
);
1789 xfree (btinfo
->replay
);
1791 btinfo
->insn_history
= NULL
;
1792 btinfo
->call_history
= NULL
;
1793 btinfo
->replay
= NULL
;
1796 /* Clear the branch trace maintenance histories in BTINFO. */
1799 btrace_maint_clear (struct btrace_thread_info
*btinfo
)
1801 switch (btinfo
->data
.format
)
1806 case BTRACE_FORMAT_BTS
:
1807 btinfo
->maint
.variant
.bts
.packet_history
.begin
= 0;
1808 btinfo
->maint
.variant
.bts
.packet_history
.end
= 0;
1811 #if defined (HAVE_LIBIPT)
1812 case BTRACE_FORMAT_PT
:
1813 xfree (btinfo
->maint
.variant
.pt
.packets
);
1815 btinfo
->maint
.variant
.pt
.packets
= NULL
;
1816 btinfo
->maint
.variant
.pt
.packet_history
.begin
= 0;
1817 btinfo
->maint
.variant
.pt
.packet_history
.end
= 0;
1819 #endif /* defined (HAVE_LIBIPT) */
1826 btrace_decode_error (enum btrace_format format
, int errcode
)
1830 case BTRACE_FORMAT_BTS
:
1833 case BDE_BTS_OVERFLOW
:
1834 return _("instruction overflow");
1836 case BDE_BTS_INSN_SIZE
:
1837 return _("unknown instruction");
1844 #if defined (HAVE_LIBIPT)
1845 case BTRACE_FORMAT_PT
:
1848 case BDE_PT_USER_QUIT
:
1849 return _("trace decode cancelled");
1851 case BDE_PT_DISABLED
:
1852 return _("disabled");
1854 case BDE_PT_OVERFLOW
:
1855 return _("overflow");
1859 return pt_errstr (pt_errcode (errcode
));
1863 #endif /* defined (HAVE_LIBIPT) */
1869 return _("unknown");
1875 btrace_fetch (struct thread_info
*tp
)
1877 struct btrace_thread_info
*btinfo
;
1878 struct btrace_target_info
*tinfo
;
1879 struct btrace_data btrace
;
1880 struct cleanup
*cleanup
;
1883 DEBUG ("fetch thread %s (%s)", print_thread_id (tp
),
1884 target_pid_to_str (tp
->ptid
));
1886 btinfo
= &tp
->btrace
;
1887 tinfo
= btinfo
->target
;
1891 /* There's no way we could get new trace while replaying.
1892 On the other hand, delta trace would return a partial record with the
1893 current PC, which is the replay PC, not the last PC, as expected. */
1894 if (btinfo
->replay
!= NULL
)
1897 /* With CLI usage, TP->PTID always equals INFERIOR_PTID here. Now that we
1898 can store a gdb.Record object in Python referring to a different thread
1899 than the current one, temporarily set INFERIOR_PTID. */
1900 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
1901 inferior_ptid
= tp
->ptid
;
1903 /* We should not be called on running or exited threads. */
1904 gdb_assert (can_access_registers_ptid (tp
->ptid
));
1906 btrace_data_init (&btrace
);
1907 cleanup
= make_cleanup_btrace_data (&btrace
);
1909 /* Let's first try to extend the trace we already have. */
1910 if (!btinfo
->functions
.empty ())
1912 errcode
= target_read_btrace (&btrace
, tinfo
, BTRACE_READ_DELTA
);
1915 /* Success. Let's try to stitch the traces together. */
1916 errcode
= btrace_stitch_trace (&btrace
, tp
);
1920 /* We failed to read delta trace. Let's try to read new trace. */
1921 errcode
= target_read_btrace (&btrace
, tinfo
, BTRACE_READ_NEW
);
1923 /* If we got any new trace, discard what we have. */
1924 if (errcode
== 0 && !btrace_data_empty (&btrace
))
1928 /* If we were not able to read the trace, we start over. */
1932 errcode
= target_read_btrace (&btrace
, tinfo
, BTRACE_READ_ALL
);
1936 errcode
= target_read_btrace (&btrace
, tinfo
, BTRACE_READ_ALL
);
1938 /* If we were not able to read the branch trace, signal an error. */
1940 error (_("Failed to read branch trace."));
1942 /* Compute the trace, provided we have any. */
1943 if (!btrace_data_empty (&btrace
))
1945 /* Store the raw trace data. The stored data will be cleared in
1946 btrace_clear, so we always append the new trace. */
1947 btrace_data_append (&btinfo
->data
, &btrace
);
1948 btrace_maint_clear (btinfo
);
1950 btrace_clear_history (btinfo
);
1951 btrace_compute_ftrace (tp
, &btrace
);
1954 do_cleanups (cleanup
);
1960 btrace_clear (struct thread_info
*tp
)
1962 struct btrace_thread_info
*btinfo
;
1964 DEBUG ("clear thread %s (%s)", print_thread_id (tp
),
1965 target_pid_to_str (tp
->ptid
));
1967 /* Make sure btrace frames that may hold a pointer into the branch
1968 trace data are destroyed. */
1969 reinit_frame_cache ();
1971 btinfo
= &tp
->btrace
;
1973 btinfo
->functions
.clear ();
1976 /* Must clear the maint data before - it depends on BTINFO->DATA. */
1977 btrace_maint_clear (btinfo
);
1978 btrace_data_clear (&btinfo
->data
);
1979 btrace_clear_history (btinfo
);
1985 btrace_free_objfile (struct objfile
*objfile
)
1987 struct thread_info
*tp
;
1989 DEBUG ("free objfile");
1991 ALL_NON_EXITED_THREADS (tp
)
1995 #if defined (HAVE_LIBEXPAT)
1997 /* Check the btrace document version. */
2000 check_xml_btrace_version (struct gdb_xml_parser
*parser
,
2001 const struct gdb_xml_element
*element
,
2003 std::vector
<gdb_xml_value
> &attributes
)
2006 = (const char *) xml_find_attribute (attributes
, "version")->value
.get ();
2008 if (strcmp (version
, "1.0") != 0)
2009 gdb_xml_error (parser
, _("Unsupported btrace version: \"%s\""), version
);
2012 /* Parse a btrace "block" xml record. */
2015 parse_xml_btrace_block (struct gdb_xml_parser
*parser
,
2016 const struct gdb_xml_element
*element
,
2018 std::vector
<gdb_xml_value
> &attributes
)
2020 struct btrace_data
*btrace
;
2021 struct btrace_block
*block
;
2022 ULONGEST
*begin
, *end
;
2024 btrace
= (struct btrace_data
*) user_data
;
2026 switch (btrace
->format
)
2028 case BTRACE_FORMAT_BTS
:
2031 case BTRACE_FORMAT_NONE
:
2032 btrace
->format
= BTRACE_FORMAT_BTS
;
2033 btrace
->variant
.bts
.blocks
= NULL
;
2037 gdb_xml_error (parser
, _("Btrace format error."));
2040 begin
= (ULONGEST
*) xml_find_attribute (attributes
, "begin")->value
.get ();
2041 end
= (ULONGEST
*) xml_find_attribute (attributes
, "end")->value
.get ();
2043 block
= VEC_safe_push (btrace_block_s
, btrace
->variant
.bts
.blocks
, NULL
);
2044 block
->begin
= *begin
;
2048 /* Parse a "raw" xml record. */
2051 parse_xml_raw (struct gdb_xml_parser
*parser
, const char *body_text
,
2052 gdb_byte
**pdata
, size_t *psize
)
2054 struct cleanup
*cleanup
;
2055 gdb_byte
*data
, *bin
;
2058 len
= strlen (body_text
);
2060 gdb_xml_error (parser
, _("Bad raw data size."));
2064 bin
= data
= (gdb_byte
*) xmalloc (size
);
2065 cleanup
= make_cleanup (xfree
, data
);
2067 /* We use hex encoding - see common/rsp-low.h. */
2075 if (hi
== 0 || lo
== 0)
2076 gdb_xml_error (parser
, _("Bad hex encoding."));
2078 *bin
++ = fromhex (hi
) * 16 + fromhex (lo
);
2082 discard_cleanups (cleanup
);
2088 /* Parse a btrace pt-config "cpu" xml record. */
2091 parse_xml_btrace_pt_config_cpu (struct gdb_xml_parser
*parser
,
2092 const struct gdb_xml_element
*element
,
2094 std::vector
<gdb_xml_value
> &attributes
)
2096 struct btrace_data
*btrace
;
2098 ULONGEST
*family
, *model
, *stepping
;
2101 (const char *) xml_find_attribute (attributes
, "vendor")->value
.get ();
2103 = (ULONGEST
*) xml_find_attribute (attributes
, "family")->value
.get ();
2105 = (ULONGEST
*) xml_find_attribute (attributes
, "model")->value
.get ();
2107 = (ULONGEST
*) xml_find_attribute (attributes
, "stepping")->value
.get ();
2109 btrace
= (struct btrace_data
*) user_data
;
2111 if (strcmp (vendor
, "GenuineIntel") == 0)
2112 btrace
->variant
.pt
.config
.cpu
.vendor
= CV_INTEL
;
2114 btrace
->variant
.pt
.config
.cpu
.family
= *family
;
2115 btrace
->variant
.pt
.config
.cpu
.model
= *model
;
2116 btrace
->variant
.pt
.config
.cpu
.stepping
= *stepping
;
2119 /* Parse a btrace pt "raw" xml record. */
2122 parse_xml_btrace_pt_raw (struct gdb_xml_parser
*parser
,
2123 const struct gdb_xml_element
*element
,
2124 void *user_data
, const char *body_text
)
2126 struct btrace_data
*btrace
;
2128 btrace
= (struct btrace_data
*) user_data
;
2129 parse_xml_raw (parser
, body_text
, &btrace
->variant
.pt
.data
,
2130 &btrace
->variant
.pt
.size
);
2133 /* Parse a btrace "pt" xml record. */
2136 parse_xml_btrace_pt (struct gdb_xml_parser
*parser
,
2137 const struct gdb_xml_element
*element
,
2139 std::vector
<gdb_xml_value
> &attributes
)
2141 struct btrace_data
*btrace
;
2143 btrace
= (struct btrace_data
*) user_data
;
2144 btrace
->format
= BTRACE_FORMAT_PT
;
2145 btrace
->variant
.pt
.config
.cpu
.vendor
= CV_UNKNOWN
;
2146 btrace
->variant
.pt
.data
= NULL
;
2147 btrace
->variant
.pt
.size
= 0;
2150 static const struct gdb_xml_attribute block_attributes
[] = {
2151 { "begin", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
2152 { "end", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
2153 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2156 static const struct gdb_xml_attribute btrace_pt_config_cpu_attributes
[] = {
2157 { "vendor", GDB_XML_AF_NONE
, NULL
, NULL
},
2158 { "family", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
2159 { "model", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
2160 { "stepping", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
2161 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2164 static const struct gdb_xml_element btrace_pt_config_children
[] = {
2165 { "cpu", btrace_pt_config_cpu_attributes
, NULL
, GDB_XML_EF_OPTIONAL
,
2166 parse_xml_btrace_pt_config_cpu
, NULL
},
2167 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2170 static const struct gdb_xml_element btrace_pt_children
[] = {
2171 { "pt-config", NULL
, btrace_pt_config_children
, GDB_XML_EF_OPTIONAL
, NULL
,
2173 { "raw", NULL
, NULL
, GDB_XML_EF_OPTIONAL
, NULL
, parse_xml_btrace_pt_raw
},
2174 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2177 static const struct gdb_xml_attribute btrace_attributes
[] = {
2178 { "version", GDB_XML_AF_NONE
, NULL
, NULL
},
2179 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2182 static const struct gdb_xml_element btrace_children
[] = {
2183 { "block", block_attributes
, NULL
,
2184 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
, parse_xml_btrace_block
, NULL
},
2185 { "pt", NULL
, btrace_pt_children
, GDB_XML_EF_OPTIONAL
, parse_xml_btrace_pt
,
2187 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2190 static const struct gdb_xml_element btrace_elements
[] = {
2191 { "btrace", btrace_attributes
, btrace_children
, GDB_XML_EF_NONE
,
2192 check_xml_btrace_version
, NULL
},
2193 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2196 #endif /* defined (HAVE_LIBEXPAT) */
2201 parse_xml_btrace (struct btrace_data
*btrace
, const char *buffer
)
2203 struct cleanup
*cleanup
;
2206 #if defined (HAVE_LIBEXPAT)
2208 btrace
->format
= BTRACE_FORMAT_NONE
;
2210 cleanup
= make_cleanup_btrace_data (btrace
);
2211 errcode
= gdb_xml_parse_quick (_("btrace"), "btrace.dtd", btrace_elements
,
2214 error (_("Error parsing branch trace."));
2216 /* Keep parse results. */
2217 discard_cleanups (cleanup
);
2219 #else /* !defined (HAVE_LIBEXPAT) */
2221 error (_("Cannot process branch trace. XML support was disabled at "
2224 #endif /* !defined (HAVE_LIBEXPAT) */
2227 #if defined (HAVE_LIBEXPAT)
2229 /* Parse a btrace-conf "bts" xml record. */
2232 parse_xml_btrace_conf_bts (struct gdb_xml_parser
*parser
,
2233 const struct gdb_xml_element
*element
,
2235 std::vector
<gdb_xml_value
> &attributes
)
2237 struct btrace_config
*conf
;
2238 struct gdb_xml_value
*size
;
2240 conf
= (struct btrace_config
*) user_data
;
2241 conf
->format
= BTRACE_FORMAT_BTS
;
2244 size
= xml_find_attribute (attributes
, "size");
2246 conf
->bts
.size
= (unsigned int) *(ULONGEST
*) size
->value
.get ();
2249 /* Parse a btrace-conf "pt" xml record. */
2252 parse_xml_btrace_conf_pt (struct gdb_xml_parser
*parser
,
2253 const struct gdb_xml_element
*element
,
2255 std::vector
<gdb_xml_value
> &attributes
)
2257 struct btrace_config
*conf
;
2258 struct gdb_xml_value
*size
;
2260 conf
= (struct btrace_config
*) user_data
;
2261 conf
->format
= BTRACE_FORMAT_PT
;
2264 size
= xml_find_attribute (attributes
, "size");
2266 conf
->pt
.size
= (unsigned int) *(ULONGEST
*) size
->value
.get ();
2269 static const struct gdb_xml_attribute btrace_conf_pt_attributes
[] = {
2270 { "size", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2271 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2274 static const struct gdb_xml_attribute btrace_conf_bts_attributes
[] = {
2275 { "size", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2276 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2279 static const struct gdb_xml_element btrace_conf_children
[] = {
2280 { "bts", btrace_conf_bts_attributes
, NULL
, GDB_XML_EF_OPTIONAL
,
2281 parse_xml_btrace_conf_bts
, NULL
},
2282 { "pt", btrace_conf_pt_attributes
, NULL
, GDB_XML_EF_OPTIONAL
,
2283 parse_xml_btrace_conf_pt
, NULL
},
2284 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2287 static const struct gdb_xml_attribute btrace_conf_attributes
[] = {
2288 { "version", GDB_XML_AF_NONE
, NULL
, NULL
},
2289 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2292 static const struct gdb_xml_element btrace_conf_elements
[] = {
2293 { "btrace-conf", btrace_conf_attributes
, btrace_conf_children
,
2294 GDB_XML_EF_NONE
, NULL
, NULL
},
2295 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2298 #endif /* defined (HAVE_LIBEXPAT) */
2303 parse_xml_btrace_conf (struct btrace_config
*conf
, const char *xml
)
2307 #if defined (HAVE_LIBEXPAT)
2309 errcode
= gdb_xml_parse_quick (_("btrace-conf"), "btrace-conf.dtd",
2310 btrace_conf_elements
, xml
, conf
);
2312 error (_("Error parsing branch trace configuration."));
2314 #else /* !defined (HAVE_LIBEXPAT) */
2316 error (_("Cannot process the branch trace configuration. XML support "
2317 "was disabled at compile time."));
2319 #endif /* !defined (HAVE_LIBEXPAT) */
2324 const struct btrace_insn
*
2325 btrace_insn_get (const struct btrace_insn_iterator
*it
)
2327 const struct btrace_function
*bfun
;
2328 unsigned int index
, end
;
2330 index
= it
->insn_index
;
2331 bfun
= &it
->btinfo
->functions
[it
->call_index
];
2333 /* Check if the iterator points to a gap in the trace. */
2334 if (bfun
->errcode
!= 0)
2337 /* The index is within the bounds of this function's instruction vector. */
2338 end
= bfun
->insn
.size ();
2339 gdb_assert (0 < end
);
2340 gdb_assert (index
< end
);
2342 return &bfun
->insn
[index
];
2348 btrace_insn_get_error (const struct btrace_insn_iterator
*it
)
2350 return it
->btinfo
->functions
[it
->call_index
].errcode
;
2356 btrace_insn_number (const struct btrace_insn_iterator
*it
)
2358 return it
->btinfo
->functions
[it
->call_index
].insn_offset
+ it
->insn_index
;
2364 btrace_insn_begin (struct btrace_insn_iterator
*it
,
2365 const struct btrace_thread_info
*btinfo
)
2367 if (btinfo
->functions
.empty ())
2368 error (_("No trace."));
2370 it
->btinfo
= btinfo
;
2378 btrace_insn_end (struct btrace_insn_iterator
*it
,
2379 const struct btrace_thread_info
*btinfo
)
2381 const struct btrace_function
*bfun
;
2382 unsigned int length
;
2384 if (btinfo
->functions
.empty ())
2385 error (_("No trace."));
2387 bfun
= &btinfo
->functions
.back ();
2388 length
= bfun
->insn
.size ();
2390 /* The last function may either be a gap or it contains the current
2391 instruction, which is one past the end of the execution trace; ignore
2396 it
->btinfo
= btinfo
;
2397 it
->call_index
= bfun
->number
- 1;
2398 it
->insn_index
= length
;
2404 btrace_insn_next (struct btrace_insn_iterator
*it
, unsigned int stride
)
2406 const struct btrace_function
*bfun
;
2407 unsigned int index
, steps
;
2409 bfun
= &it
->btinfo
->functions
[it
->call_index
];
2411 index
= it
->insn_index
;
2415 unsigned int end
, space
, adv
;
2417 end
= bfun
->insn
.size ();
2419 /* An empty function segment represents a gap in the trace. We count
2420 it as one instruction. */
2423 const struct btrace_function
*next
;
2425 next
= ftrace_find_call_by_number (it
->btinfo
, bfun
->number
+ 1);
2438 gdb_assert (0 < end
);
2439 gdb_assert (index
< end
);
2441 /* Compute the number of instructions remaining in this segment. */
2442 space
= end
- index
;
2444 /* Advance the iterator as far as possible within this segment. */
2445 adv
= std::min (space
, stride
);
2450 /* Move to the next function if we're at the end of this one. */
2453 const struct btrace_function
*next
;
2455 next
= ftrace_find_call_by_number (it
->btinfo
, bfun
->number
+ 1);
2458 /* We stepped past the last function.
2460 Let's adjust the index to point to the last instruction in
2461 the previous function. */
2467 /* We now point to the first instruction in the new function. */
2472 /* We did make progress. */
2473 gdb_assert (adv
> 0);
2476 /* Update the iterator. */
2477 it
->call_index
= bfun
->number
- 1;
2478 it
->insn_index
= index
;
2486 btrace_insn_prev (struct btrace_insn_iterator
*it
, unsigned int stride
)
2488 const struct btrace_function
*bfun
;
2489 unsigned int index
, steps
;
2491 bfun
= &it
->btinfo
->functions
[it
->call_index
];
2493 index
= it
->insn_index
;
2499 /* Move to the previous function if we're at the start of this one. */
2502 const struct btrace_function
*prev
;
2504 prev
= ftrace_find_call_by_number (it
->btinfo
, bfun
->number
- 1);
2508 /* We point to one after the last instruction in the new function. */
2510 index
= bfun
->insn
.size ();
2512 /* An empty function segment represents a gap in the trace. We count
2513 it as one instruction. */
2523 /* Advance the iterator as far as possible within this segment. */
2524 adv
= std::min (index
, stride
);
2530 /* We did make progress. */
2531 gdb_assert (adv
> 0);
2534 /* Update the iterator. */
2535 it
->call_index
= bfun
->number
- 1;
2536 it
->insn_index
= index
;
2544 btrace_insn_cmp (const struct btrace_insn_iterator
*lhs
,
2545 const struct btrace_insn_iterator
*rhs
)
2547 gdb_assert (lhs
->btinfo
== rhs
->btinfo
);
2549 if (lhs
->call_index
!= rhs
->call_index
)
2550 return lhs
->call_index
- rhs
->call_index
;
2552 return lhs
->insn_index
- rhs
->insn_index
;
2558 btrace_find_insn_by_number (struct btrace_insn_iterator
*it
,
2559 const struct btrace_thread_info
*btinfo
,
2560 unsigned int number
)
2562 const struct btrace_function
*bfun
;
2563 unsigned int upper
, lower
;
2565 if (btinfo
->functions
.empty ())
2569 bfun
= &btinfo
->functions
[lower
];
2570 if (number
< bfun
->insn_offset
)
2573 upper
= btinfo
->functions
.size () - 1;
2574 bfun
= &btinfo
->functions
[upper
];
2575 if (number
>= bfun
->insn_offset
+ ftrace_call_num_insn (bfun
))
2578 /* We assume that there are no holes in the numbering. */
2581 const unsigned int average
= lower
+ (upper
- lower
) / 2;
2583 bfun
= &btinfo
->functions
[average
];
2585 if (number
< bfun
->insn_offset
)
2587 upper
= average
- 1;
2591 if (number
>= bfun
->insn_offset
+ ftrace_call_num_insn (bfun
))
2593 lower
= average
+ 1;
2600 it
->btinfo
= btinfo
;
2601 it
->call_index
= bfun
->number
- 1;
2602 it
->insn_index
= number
- bfun
->insn_offset
;
2606 /* Returns true if the recording ends with a function segment that
2607 contains only a single (i.e. the current) instruction. */
2610 btrace_ends_with_single_insn (const struct btrace_thread_info
*btinfo
)
2612 const btrace_function
*bfun
;
2614 if (btinfo
->functions
.empty ())
2617 bfun
= &btinfo
->functions
.back ();
2618 if (bfun
->errcode
!= 0)
2621 return ftrace_call_num_insn (bfun
) == 1;
2626 const struct btrace_function
*
2627 btrace_call_get (const struct btrace_call_iterator
*it
)
2629 if (it
->index
>= it
->btinfo
->functions
.size ())
2632 return &it
->btinfo
->functions
[it
->index
];
2638 btrace_call_number (const struct btrace_call_iterator
*it
)
2640 const unsigned int length
= it
->btinfo
->functions
.size ();
2642 /* If the last function segment contains only a single instruction (i.e. the
2643 current instruction), skip it. */
2644 if ((it
->index
== length
) && btrace_ends_with_single_insn (it
->btinfo
))
2647 return it
->index
+ 1;
2653 btrace_call_begin (struct btrace_call_iterator
*it
,
2654 const struct btrace_thread_info
*btinfo
)
2656 if (btinfo
->functions
.empty ())
2657 error (_("No trace."));
2659 it
->btinfo
= btinfo
;
2666 btrace_call_end (struct btrace_call_iterator
*it
,
2667 const struct btrace_thread_info
*btinfo
)
2669 if (btinfo
->functions
.empty ())
2670 error (_("No trace."));
2672 it
->btinfo
= btinfo
;
2673 it
->index
= btinfo
->functions
.size ();
2679 btrace_call_next (struct btrace_call_iterator
*it
, unsigned int stride
)
2681 const unsigned int length
= it
->btinfo
->functions
.size ();
2683 if (it
->index
+ stride
< length
- 1)
2684 /* Default case: Simply advance the iterator. */
2685 it
->index
+= stride
;
2686 else if (it
->index
+ stride
== length
- 1)
2688 /* We land exactly at the last function segment. If it contains only one
2689 instruction (i.e. the current instruction) it is not actually part of
2691 if (btrace_ends_with_single_insn (it
->btinfo
))
2694 it
->index
= length
- 1;
2698 /* We land past the last function segment and have to adjust the stride.
2699 If the last function segment contains only one instruction (i.e. the
2700 current instruction) it is not actually part of the trace. */
2701 if (btrace_ends_with_single_insn (it
->btinfo
))
2702 stride
= length
- it
->index
- 1;
2704 stride
= length
- it
->index
;
2715 btrace_call_prev (struct btrace_call_iterator
*it
, unsigned int stride
)
2717 const unsigned int length
= it
->btinfo
->functions
.size ();
2720 gdb_assert (it
->index
<= length
);
2722 if (stride
== 0 || it
->index
== 0)
2725 /* If we are at the end, the first step is a special case. If the last
2726 function segment contains only one instruction (i.e. the current
2727 instruction) it is not actually part of the trace. To be able to step
2728 over this instruction, we need at least one more function segment. */
2729 if ((it
->index
== length
) && (length
> 1))
2731 if (btrace_ends_with_single_insn (it
->btinfo
))
2732 it
->index
= length
- 2;
2734 it
->index
= length
- 1;
2740 stride
= std::min (stride
, it
->index
);
2742 it
->index
-= stride
;
2743 return steps
+ stride
;
2749 btrace_call_cmp (const struct btrace_call_iterator
*lhs
,
2750 const struct btrace_call_iterator
*rhs
)
2752 gdb_assert (lhs
->btinfo
== rhs
->btinfo
);
2753 return (int) (lhs
->index
- rhs
->index
);
2759 btrace_find_call_by_number (struct btrace_call_iterator
*it
,
2760 const struct btrace_thread_info
*btinfo
,
2761 unsigned int number
)
2763 const unsigned int length
= btinfo
->functions
.size ();
2765 if ((number
== 0) || (number
> length
))
2768 it
->btinfo
= btinfo
;
2769 it
->index
= number
- 1;
2776 btrace_set_insn_history (struct btrace_thread_info
*btinfo
,
2777 const struct btrace_insn_iterator
*begin
,
2778 const struct btrace_insn_iterator
*end
)
2780 if (btinfo
->insn_history
== NULL
)
2781 btinfo
->insn_history
= XCNEW (struct btrace_insn_history
);
2783 btinfo
->insn_history
->begin
= *begin
;
2784 btinfo
->insn_history
->end
= *end
;
2790 btrace_set_call_history (struct btrace_thread_info
*btinfo
,
2791 const struct btrace_call_iterator
*begin
,
2792 const struct btrace_call_iterator
*end
)
2794 gdb_assert (begin
->btinfo
== end
->btinfo
);
2796 if (btinfo
->call_history
== NULL
)
2797 btinfo
->call_history
= XCNEW (struct btrace_call_history
);
2799 btinfo
->call_history
->begin
= *begin
;
2800 btinfo
->call_history
->end
= *end
;
2806 btrace_is_replaying (struct thread_info
*tp
)
2808 return tp
->btrace
.replay
!= NULL
;
2814 btrace_is_empty (struct thread_info
*tp
)
2816 struct btrace_insn_iterator begin
, end
;
2817 struct btrace_thread_info
*btinfo
;
2819 btinfo
= &tp
->btrace
;
2821 if (btinfo
->functions
.empty ())
2824 btrace_insn_begin (&begin
, btinfo
);
2825 btrace_insn_end (&end
, btinfo
);
2827 return btrace_insn_cmp (&begin
, &end
) == 0;
2830 /* Forward the cleanup request. */
2833 do_btrace_data_cleanup (void *arg
)
2835 btrace_data_fini ((struct btrace_data
*) arg
);
2841 make_cleanup_btrace_data (struct btrace_data
*data
)
2843 return make_cleanup (do_btrace_data_cleanup
, data
);
2846 #if defined (HAVE_LIBIPT)
2848 /* Print a single packet. */
2851 pt_print_packet (const struct pt_packet
*packet
)
2853 switch (packet
->type
)
2856 printf_unfiltered (("[??: %x]"), packet
->type
);
2860 printf_unfiltered (("psb"));
2864 printf_unfiltered (("psbend"));
2868 printf_unfiltered (("pad"));
2872 printf_unfiltered (("tip %u: 0x%" PRIx64
""),
2873 packet
->payload
.ip
.ipc
,
2874 packet
->payload
.ip
.ip
);
2878 printf_unfiltered (("tip.pge %u: 0x%" PRIx64
""),
2879 packet
->payload
.ip
.ipc
,
2880 packet
->payload
.ip
.ip
);
2884 printf_unfiltered (("tip.pgd %u: 0x%" PRIx64
""),
2885 packet
->payload
.ip
.ipc
,
2886 packet
->payload
.ip
.ip
);
2890 printf_unfiltered (("fup %u: 0x%" PRIx64
""),
2891 packet
->payload
.ip
.ipc
,
2892 packet
->payload
.ip
.ip
);
2896 printf_unfiltered (("tnt-8 %u: 0x%" PRIx64
""),
2897 packet
->payload
.tnt
.bit_size
,
2898 packet
->payload
.tnt
.payload
);
2902 printf_unfiltered (("tnt-64 %u: 0x%" PRIx64
""),
2903 packet
->payload
.tnt
.bit_size
,
2904 packet
->payload
.tnt
.payload
);
2908 printf_unfiltered (("pip %" PRIx64
"%s"), packet
->payload
.pip
.cr3
,
2909 packet
->payload
.pip
.nr
? (" nr") : (""));
2913 printf_unfiltered (("tsc %" PRIx64
""), packet
->payload
.tsc
.tsc
);
2917 printf_unfiltered (("cbr %u"), packet
->payload
.cbr
.ratio
);
2921 switch (packet
->payload
.mode
.leaf
)
2924 printf_unfiltered (("mode %u"), packet
->payload
.mode
.leaf
);
2928 printf_unfiltered (("mode.exec%s%s"),
2929 packet
->payload
.mode
.bits
.exec
.csl
2931 packet
->payload
.mode
.bits
.exec
.csd
2932 ? (" cs.d") : (""));
2936 printf_unfiltered (("mode.tsx%s%s"),
2937 packet
->payload
.mode
.bits
.tsx
.intx
2939 packet
->payload
.mode
.bits
.tsx
.abrt
2940 ? (" abrt") : (""));
2946 printf_unfiltered (("ovf"));
2950 printf_unfiltered (("stop"));
2954 printf_unfiltered (("vmcs %" PRIx64
""), packet
->payload
.vmcs
.base
);
2958 printf_unfiltered (("tma %x %x"), packet
->payload
.tma
.ctc
,
2959 packet
->payload
.tma
.fc
);
2963 printf_unfiltered (("mtc %x"), packet
->payload
.mtc
.ctc
);
2967 printf_unfiltered (("cyc %" PRIx64
""), packet
->payload
.cyc
.value
);
2971 printf_unfiltered (("mnt %" PRIx64
""), packet
->payload
.mnt
.payload
);
2976 /* Decode packets into MAINT using DECODER. */
2979 btrace_maint_decode_pt (struct btrace_maint_info
*maint
,
2980 struct pt_packet_decoder
*decoder
)
2986 struct btrace_pt_packet packet
;
2988 errcode
= pt_pkt_sync_forward (decoder
);
2994 pt_pkt_get_offset (decoder
, &packet
.offset
);
2996 errcode
= pt_pkt_next (decoder
, &packet
.packet
,
2997 sizeof(packet
.packet
));
3001 if (maint_btrace_pt_skip_pad
== 0 || packet
.packet
.type
!= ppt_pad
)
3003 packet
.errcode
= pt_errcode (errcode
);
3004 VEC_safe_push (btrace_pt_packet_s
, maint
->variant
.pt
.packets
,
3009 if (errcode
== -pte_eos
)
3012 packet
.errcode
= pt_errcode (errcode
);
3013 VEC_safe_push (btrace_pt_packet_s
, maint
->variant
.pt
.packets
,
3016 warning (_("Error at trace offset 0x%" PRIx64
": %s."),
3017 packet
.offset
, pt_errstr (packet
.errcode
));
3020 if (errcode
!= -pte_eos
)
3021 warning (_("Failed to synchronize onto the Intel Processor Trace "
3022 "stream: %s."), pt_errstr (pt_errcode (errcode
)));
3025 /* Update the packet history in BTINFO. */
3028 btrace_maint_update_pt_packets (struct btrace_thread_info
*btinfo
)
3030 struct pt_packet_decoder
*decoder
;
3031 struct btrace_data_pt
*pt
;
3032 struct pt_config config
;
3035 pt
= &btinfo
->data
.variant
.pt
;
3037 /* Nothing to do if there is no trace. */
3041 memset (&config
, 0, sizeof(config
));
3043 config
.size
= sizeof (config
);
3044 config
.begin
= pt
->data
;
3045 config
.end
= pt
->data
+ pt
->size
;
3047 config
.cpu
.vendor
= pt_translate_cpu_vendor (pt
->config
.cpu
.vendor
);
3048 config
.cpu
.family
= pt
->config
.cpu
.family
;
3049 config
.cpu
.model
= pt
->config
.cpu
.model
;
3050 config
.cpu
.stepping
= pt
->config
.cpu
.stepping
;
3052 errcode
= pt_cpu_errata (&config
.errata
, &config
.cpu
);
3054 error (_("Failed to configure the Intel Processor Trace decoder: %s."),
3055 pt_errstr (pt_errcode (errcode
)));
3057 decoder
= pt_pkt_alloc_decoder (&config
);
3058 if (decoder
== NULL
)
3059 error (_("Failed to allocate the Intel Processor Trace decoder."));
3063 btrace_maint_decode_pt (&btinfo
->maint
, decoder
);
3065 CATCH (except
, RETURN_MASK_ALL
)
3067 pt_pkt_free_decoder (decoder
);
3069 if (except
.reason
< 0)
3070 throw_exception (except
);
3074 pt_pkt_free_decoder (decoder
);
3077 #endif /* !defined (HAVE_LIBIPT) */
3079 /* Update the packet maintenance information for BTINFO and store the
3080 low and high bounds into BEGIN and END, respectively.
3081 Store the current iterator state into FROM and TO. */
3084 btrace_maint_update_packets (struct btrace_thread_info
*btinfo
,
3085 unsigned int *begin
, unsigned int *end
,
3086 unsigned int *from
, unsigned int *to
)
3088 switch (btinfo
->data
.format
)
3097 case BTRACE_FORMAT_BTS
:
3098 /* Nothing to do - we operate directly on BTINFO->DATA. */
3100 *end
= VEC_length (btrace_block_s
, btinfo
->data
.variant
.bts
.blocks
);
3101 *from
= btinfo
->maint
.variant
.bts
.packet_history
.begin
;
3102 *to
= btinfo
->maint
.variant
.bts
.packet_history
.end
;
3105 #if defined (HAVE_LIBIPT)
3106 case BTRACE_FORMAT_PT
:
3107 if (VEC_empty (btrace_pt_packet_s
, btinfo
->maint
.variant
.pt
.packets
))
3108 btrace_maint_update_pt_packets (btinfo
);
3111 *end
= VEC_length (btrace_pt_packet_s
, btinfo
->maint
.variant
.pt
.packets
);
3112 *from
= btinfo
->maint
.variant
.pt
.packet_history
.begin
;
3113 *to
= btinfo
->maint
.variant
.pt
.packet_history
.end
;
3115 #endif /* defined (HAVE_LIBIPT) */
3119 /* Print packets in BTINFO from BEGIN (inclusive) until END (exclusive) and
3120 update the current iterator position. */
3123 btrace_maint_print_packets (struct btrace_thread_info
*btinfo
,
3124 unsigned int begin
, unsigned int end
)
3126 switch (btinfo
->data
.format
)
3131 case BTRACE_FORMAT_BTS
:
3133 VEC (btrace_block_s
) *blocks
;
3136 blocks
= btinfo
->data
.variant
.bts
.blocks
;
3137 for (blk
= begin
; blk
< end
; ++blk
)
3139 const btrace_block_s
*block
;
3141 block
= VEC_index (btrace_block_s
, blocks
, blk
);
3143 printf_unfiltered ("%u\tbegin: %s, end: %s\n", blk
,
3144 core_addr_to_string_nz (block
->begin
),
3145 core_addr_to_string_nz (block
->end
));
3148 btinfo
->maint
.variant
.bts
.packet_history
.begin
= begin
;
3149 btinfo
->maint
.variant
.bts
.packet_history
.end
= end
;
3153 #if defined (HAVE_LIBIPT)
3154 case BTRACE_FORMAT_PT
:
3156 VEC (btrace_pt_packet_s
) *packets
;
3159 packets
= btinfo
->maint
.variant
.pt
.packets
;
3160 for (pkt
= begin
; pkt
< end
; ++pkt
)
3162 const struct btrace_pt_packet
*packet
;
3164 packet
= VEC_index (btrace_pt_packet_s
, packets
, pkt
);
3166 printf_unfiltered ("%u\t", pkt
);
3167 printf_unfiltered ("0x%" PRIx64
"\t", packet
->offset
);
3169 if (packet
->errcode
== pte_ok
)
3170 pt_print_packet (&packet
->packet
);
3172 printf_unfiltered ("[error: %s]", pt_errstr (packet
->errcode
));
3174 printf_unfiltered ("\n");
3177 btinfo
->maint
.variant
.pt
.packet_history
.begin
= begin
;
3178 btinfo
->maint
.variant
.pt
.packet_history
.end
= end
;
3181 #endif /* defined (HAVE_LIBIPT) */
3185 /* Read a number from an argument string. */
3188 get_uint (const char **arg
)
3190 const char *begin
, *pos
;
3192 unsigned long number
;
3195 pos
= skip_spaces (begin
);
3197 if (!isdigit (*pos
))
3198 error (_("Expected positive number, got: %s."), pos
);
3200 number
= strtoul (pos
, &end
, 10);
3201 if (number
> UINT_MAX
)
3202 error (_("Number too big."));
3204 *arg
+= (end
- begin
);
3206 return (unsigned int) number
;
3209 /* Read a context size from an argument string. */
3212 get_context_size (const char **arg
)
3214 const char *pos
= skip_spaces (*arg
);
3216 if (!isdigit (*pos
))
3217 error (_("Expected positive number, got: %s."), pos
);
3220 long result
= strtol (pos
, &end
, 10);
3225 /* Complain about junk at the end of an argument string. */
3228 no_chunk (const char *arg
)
3231 error (_("Junk after argument: %s."), arg
);
3234 /* The "maintenance btrace packet-history" command. */
3237 maint_btrace_packet_history_cmd (const char *arg
, int from_tty
)
3239 struct btrace_thread_info
*btinfo
;
3240 struct thread_info
*tp
;
3241 unsigned int size
, begin
, end
, from
, to
;
3243 tp
= find_thread_ptid (inferior_ptid
);
3245 error (_("No thread."));
3248 btinfo
= &tp
->btrace
;
3250 btrace_maint_update_packets (btinfo
, &begin
, &end
, &from
, &to
);
3253 printf_unfiltered (_("No trace.\n"));
3257 if (arg
== NULL
|| *arg
== 0 || strcmp (arg
, "+") == 0)
3261 if (end
- from
< size
)
3265 else if (strcmp (arg
, "-") == 0)
3269 if (to
- begin
< size
)
3275 from
= get_uint (&arg
);
3277 error (_("'%u' is out of range."), from
);
3279 arg
= skip_spaces (arg
);
3282 arg
= skip_spaces (++arg
);
3287 size
= get_context_size (&arg
);
3291 if (end
- from
< size
)
3295 else if (*arg
== '-')
3298 size
= get_context_size (&arg
);
3302 /* Include the packet given as first argument. */
3306 if (to
- begin
< size
)
3312 to
= get_uint (&arg
);
3314 /* Include the packet at the second argument and silently
3315 truncate the range. */
3328 if (end
- from
< size
)
3336 btrace_maint_print_packets (btinfo
, from
, to
);
3339 /* The "maintenance btrace clear-packet-history" command. */
3342 maint_btrace_clear_packet_history_cmd (const char *args
, int from_tty
)
3344 struct btrace_thread_info
*btinfo
;
3345 struct thread_info
*tp
;
3347 if (args
!= NULL
&& *args
!= 0)
3348 error (_("Invalid argument."));
3350 tp
= find_thread_ptid (inferior_ptid
);
3352 error (_("No thread."));
3354 btinfo
= &tp
->btrace
;
3356 /* Must clear the maint data before - it depends on BTINFO->DATA. */
3357 btrace_maint_clear (btinfo
);
3358 btrace_data_clear (&btinfo
->data
);
3361 /* The "maintenance btrace clear" command. */
3364 maint_btrace_clear_cmd (const char *args
, int from_tty
)
3366 struct thread_info
*tp
;
3368 if (args
!= NULL
&& *args
!= 0)
3369 error (_("Invalid argument."));
3371 tp
= find_thread_ptid (inferior_ptid
);
3373 error (_("No thread."));
3378 /* The "maintenance btrace" command. */
3381 maint_btrace_cmd (const char *args
, int from_tty
)
3383 help_list (maint_btrace_cmdlist
, "maintenance btrace ", all_commands
,
3387 /* The "maintenance set btrace" command. */
3390 maint_btrace_set_cmd (const char *args
, int from_tty
)
3392 help_list (maint_btrace_set_cmdlist
, "maintenance set btrace ", all_commands
,
3396 /* The "maintenance show btrace" command. */
3399 maint_btrace_show_cmd (const char *args
, int from_tty
)
3401 help_list (maint_btrace_show_cmdlist
, "maintenance show btrace ",
3402 all_commands
, gdb_stdout
);
3405 /* The "maintenance set btrace pt" command. */
3408 maint_btrace_pt_set_cmd (const char *args
, int from_tty
)
3410 help_list (maint_btrace_pt_set_cmdlist
, "maintenance set btrace pt ",
3411 all_commands
, gdb_stdout
);
3414 /* The "maintenance show btrace pt" command. */
3417 maint_btrace_pt_show_cmd (const char *args
, int from_tty
)
3419 help_list (maint_btrace_pt_show_cmdlist
, "maintenance show btrace pt ",
3420 all_commands
, gdb_stdout
);
3423 /* The "maintenance info btrace" command. */
3426 maint_info_btrace_cmd (const char *args
, int from_tty
)
3428 struct btrace_thread_info
*btinfo
;
3429 struct thread_info
*tp
;
3430 const struct btrace_config
*conf
;
3432 if (args
!= NULL
&& *args
!= 0)
3433 error (_("Invalid argument."));
3435 tp
= find_thread_ptid (inferior_ptid
);
3437 error (_("No thread."));
3439 btinfo
= &tp
->btrace
;
3441 conf
= btrace_conf (btinfo
);
3443 error (_("No btrace configuration."));
3445 printf_unfiltered (_("Format: %s.\n"),
3446 btrace_format_string (conf
->format
));
3448 switch (conf
->format
)
3453 case BTRACE_FORMAT_BTS
:
3454 printf_unfiltered (_("Number of packets: %u.\n"),
3455 VEC_length (btrace_block_s
,
3456 btinfo
->data
.variant
.bts
.blocks
));
3459 #if defined (HAVE_LIBIPT)
3460 case BTRACE_FORMAT_PT
:
3462 struct pt_version version
;
3464 version
= pt_library_version ();
3465 printf_unfiltered (_("Version: %u.%u.%u%s.\n"), version
.major
,
3466 version
.minor
, version
.build
,
3467 version
.ext
!= NULL
? version
.ext
: "");
3469 btrace_maint_update_pt_packets (btinfo
);
3470 printf_unfiltered (_("Number of packets: %u.\n"),
3471 VEC_length (btrace_pt_packet_s
,
3472 btinfo
->maint
.variant
.pt
.packets
));
3475 #endif /* defined (HAVE_LIBIPT) */
3479 /* The "maint show btrace pt skip-pad" show value function. */
3482 show_maint_btrace_pt_skip_pad (struct ui_file
*file
, int from_tty
,
3483 struct cmd_list_element
*c
,
3486 fprintf_filtered (file
, _("Skip PAD packets is %s.\n"), value
);
3490 /* Initialize btrace maintenance commands. */
3493 _initialize_btrace (void)
3495 add_cmd ("btrace", class_maintenance
, maint_info_btrace_cmd
,
3496 _("Info about branch tracing data."), &maintenanceinfolist
);
3498 add_prefix_cmd ("btrace", class_maintenance
, maint_btrace_cmd
,
3499 _("Branch tracing maintenance commands."),
3500 &maint_btrace_cmdlist
, "maintenance btrace ",
3501 0, &maintenancelist
);
3503 add_prefix_cmd ("btrace", class_maintenance
, maint_btrace_set_cmd
, _("\
3504 Set branch tracing specific variables."),
3505 &maint_btrace_set_cmdlist
, "maintenance set btrace ",
3506 0, &maintenance_set_cmdlist
);
3508 add_prefix_cmd ("pt", class_maintenance
, maint_btrace_pt_set_cmd
, _("\
3509 Set Intel Processor Trace specific variables."),
3510 &maint_btrace_pt_set_cmdlist
, "maintenance set btrace pt ",
3511 0, &maint_btrace_set_cmdlist
);
3513 add_prefix_cmd ("btrace", class_maintenance
, maint_btrace_show_cmd
, _("\
3514 Show branch tracing specific variables."),
3515 &maint_btrace_show_cmdlist
, "maintenance show btrace ",
3516 0, &maintenance_show_cmdlist
);
3518 add_prefix_cmd ("pt", class_maintenance
, maint_btrace_pt_show_cmd
, _("\
3519 Show Intel Processor Trace specific variables."),
3520 &maint_btrace_pt_show_cmdlist
, "maintenance show btrace pt ",
3521 0, &maint_btrace_show_cmdlist
);
3523 add_setshow_boolean_cmd ("skip-pad", class_maintenance
,
3524 &maint_btrace_pt_skip_pad
, _("\
3525 Set whether PAD packets should be skipped in the btrace packet history."), _("\
3526 Show whether PAD packets should be skipped in the btrace packet history."),_("\
3527 When enabled, PAD packets are ignored in the btrace packet history."),
3528 NULL
, show_maint_btrace_pt_skip_pad
,
3529 &maint_btrace_pt_set_cmdlist
,
3530 &maint_btrace_pt_show_cmdlist
);
3532 add_cmd ("packet-history", class_maintenance
, maint_btrace_packet_history_cmd
,
3533 _("Print the raw branch tracing data.\n\
3534 With no argument, print ten more packets after the previous ten-line print.\n\
3535 With '-' as argument print ten packets before a previous ten-line print.\n\
3536 One argument specifies the starting packet of a ten-line print.\n\
3537 Two arguments with comma between specify starting and ending packets to \
3539 Preceded with '+'/'-' the second argument specifies the distance from the \
3541 &maint_btrace_cmdlist
);
3543 add_cmd ("clear-packet-history", class_maintenance
,
3544 maint_btrace_clear_packet_history_cmd
,
3545 _("Clears the branch tracing packet history.\n\
3546 Discards the raw branch tracing data but not the execution history data.\n\
3548 &maint_btrace_cmdlist
);
3550 add_cmd ("clear", class_maintenance
, maint_btrace_clear_cmd
,
3551 _("Clears the branch tracing data.\n\
3552 Discards the raw branch tracing data and the execution history data.\n\
3553 The next 'record' command will fetch the branch tracing data anew.\n\
3555 &maint_btrace_cmdlist
);