1*ef5ccd6cSJohn Marino /* Branch trace support for GDB, the GNU debugger. 2*ef5ccd6cSJohn Marino 3*ef5ccd6cSJohn Marino Copyright (C) 2013 Free Software Foundation, Inc. 4*ef5ccd6cSJohn Marino 5*ef5ccd6cSJohn Marino Contributed by Intel Corp. <markus.t.metzger@intel.com>. 6*ef5ccd6cSJohn Marino 7*ef5ccd6cSJohn Marino This file is part of GDB. 8*ef5ccd6cSJohn Marino 9*ef5ccd6cSJohn Marino This program is free software; you can redistribute it and/or modify 10*ef5ccd6cSJohn Marino it under the terms of the GNU General Public License as published by 11*ef5ccd6cSJohn Marino the Free Software Foundation; either version 3 of the License, or 12*ef5ccd6cSJohn Marino (at your option) any later version. 13*ef5ccd6cSJohn Marino 14*ef5ccd6cSJohn Marino This program is distributed in the hope that it will be useful, 15*ef5ccd6cSJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 16*ef5ccd6cSJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*ef5ccd6cSJohn Marino GNU General Public License for more details. 18*ef5ccd6cSJohn Marino 19*ef5ccd6cSJohn Marino You should have received a copy of the GNU General Public License 20*ef5ccd6cSJohn Marino along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21*ef5ccd6cSJohn Marino 22*ef5ccd6cSJohn Marino #ifndef BTRACE_H 23*ef5ccd6cSJohn Marino #define BTRACE_H 24*ef5ccd6cSJohn Marino 25*ef5ccd6cSJohn Marino /* Branch tracing (btrace) is a per-thread control-flow execution trace of the 26*ef5ccd6cSJohn Marino inferior. For presentation purposes, the branch trace is represented as a 27*ef5ccd6cSJohn Marino list of sequential control-flow blocks, one such list per thread. */ 28*ef5ccd6cSJohn Marino 29*ef5ccd6cSJohn Marino #include "btrace-common.h" 30*ef5ccd6cSJohn Marino 31*ef5ccd6cSJohn Marino struct thread_info; 32*ef5ccd6cSJohn Marino 33*ef5ccd6cSJohn Marino /* A branch trace instruction. 34*ef5ccd6cSJohn Marino 35*ef5ccd6cSJohn Marino This represents a single instruction in a branch trace. */ 36*ef5ccd6cSJohn Marino struct btrace_inst 37*ef5ccd6cSJohn Marino { 38*ef5ccd6cSJohn Marino /* The address of this instruction. */ 39*ef5ccd6cSJohn Marino CORE_ADDR pc; 40*ef5ccd6cSJohn Marino }; 41*ef5ccd6cSJohn Marino 42*ef5ccd6cSJohn Marino /* A branch trace function. 43*ef5ccd6cSJohn Marino 44*ef5ccd6cSJohn Marino This represents a function segment in a branch trace, i.e. a consecutive 45*ef5ccd6cSJohn Marino number of instructions belonging to the same function. */ 46*ef5ccd6cSJohn Marino struct btrace_func 47*ef5ccd6cSJohn Marino { 48*ef5ccd6cSJohn Marino /* The full and minimal symbol for the function. One of them may be NULL. */ 49*ef5ccd6cSJohn Marino struct minimal_symbol *msym; 50*ef5ccd6cSJohn Marino struct symbol *sym; 51*ef5ccd6cSJohn Marino 52*ef5ccd6cSJohn Marino /* The source line range of this function segment (both inclusive). */ 53*ef5ccd6cSJohn Marino int lbegin, lend; 54*ef5ccd6cSJohn Marino 55*ef5ccd6cSJohn Marino /* The instruction number range in the instruction trace corresponding 56*ef5ccd6cSJohn Marino to this function segment (both inclusive). */ 57*ef5ccd6cSJohn Marino unsigned int ibegin, iend; 58*ef5ccd6cSJohn Marino }; 59*ef5ccd6cSJohn Marino 60*ef5ccd6cSJohn Marino /* Branch trace may also be represented as a vector of: 61*ef5ccd6cSJohn Marino 62*ef5ccd6cSJohn Marino - branch trace instructions starting with the oldest instruction. 63*ef5ccd6cSJohn Marino - branch trace functions starting with the oldest function. */ 64*ef5ccd6cSJohn Marino typedef struct btrace_inst btrace_inst_s; 65*ef5ccd6cSJohn Marino typedef struct btrace_func btrace_func_s; 66*ef5ccd6cSJohn Marino 67*ef5ccd6cSJohn Marino /* Define functions operating on branch trace vectors. */ 68*ef5ccd6cSJohn Marino DEF_VEC_O (btrace_inst_s); 69*ef5ccd6cSJohn Marino DEF_VEC_O (btrace_func_s); 70*ef5ccd6cSJohn Marino 71*ef5ccd6cSJohn Marino /* Branch trace iteration state for "record instruction-history". */ 72*ef5ccd6cSJohn Marino struct btrace_insn_iterator 73*ef5ccd6cSJohn Marino { 74*ef5ccd6cSJohn Marino /* The instruction index range from begin (inclusive) to end (exclusive) 75*ef5ccd6cSJohn Marino that has been covered last time. 76*ef5ccd6cSJohn Marino If end < begin, the branch trace has just been updated. */ 77*ef5ccd6cSJohn Marino unsigned int begin; 78*ef5ccd6cSJohn Marino unsigned int end; 79*ef5ccd6cSJohn Marino }; 80*ef5ccd6cSJohn Marino 81*ef5ccd6cSJohn Marino /* Branch trace iteration state for "record function-call-history". */ 82*ef5ccd6cSJohn Marino struct btrace_func_iterator 83*ef5ccd6cSJohn Marino { 84*ef5ccd6cSJohn Marino /* The function index range from begin (inclusive) to end (exclusive) 85*ef5ccd6cSJohn Marino that has been covered last time. 86*ef5ccd6cSJohn Marino If end < begin, the branch trace has just been updated. */ 87*ef5ccd6cSJohn Marino unsigned int begin; 88*ef5ccd6cSJohn Marino unsigned int end; 89*ef5ccd6cSJohn Marino }; 90*ef5ccd6cSJohn Marino 91*ef5ccd6cSJohn Marino /* Branch trace information per thread. 92*ef5ccd6cSJohn Marino 93*ef5ccd6cSJohn Marino This represents the branch trace configuration as well as the entry point 94*ef5ccd6cSJohn Marino into the branch trace data. For the latter, it also contains the index into 95*ef5ccd6cSJohn Marino an array of branch trace blocks used for iterating though the branch trace 96*ef5ccd6cSJohn Marino blocks of a thread. */ 97*ef5ccd6cSJohn Marino struct btrace_thread_info 98*ef5ccd6cSJohn Marino { 99*ef5ccd6cSJohn Marino /* The target branch trace information for this thread. 100*ef5ccd6cSJohn Marino 101*ef5ccd6cSJohn Marino This contains the branch trace configuration as well as any 102*ef5ccd6cSJohn Marino target-specific information necessary for implementing branch tracing on 103*ef5ccd6cSJohn Marino the underlying architecture. */ 104*ef5ccd6cSJohn Marino struct btrace_target_info *target; 105*ef5ccd6cSJohn Marino 106*ef5ccd6cSJohn Marino /* The current branch trace for this thread. */ 107*ef5ccd6cSJohn Marino VEC (btrace_block_s) *btrace; 108*ef5ccd6cSJohn Marino VEC (btrace_inst_s) *itrace; 109*ef5ccd6cSJohn Marino VEC (btrace_func_s) *ftrace; 110*ef5ccd6cSJohn Marino 111*ef5ccd6cSJohn Marino /* The instruction history iterator. */ 112*ef5ccd6cSJohn Marino struct btrace_insn_iterator insn_iterator; 113*ef5ccd6cSJohn Marino 114*ef5ccd6cSJohn Marino /* The function call history iterator. */ 115*ef5ccd6cSJohn Marino struct btrace_func_iterator func_iterator; 116*ef5ccd6cSJohn Marino }; 117*ef5ccd6cSJohn Marino 118*ef5ccd6cSJohn Marino /* Enable branch tracing for a thread. */ 119*ef5ccd6cSJohn Marino extern void btrace_enable (struct thread_info *tp); 120*ef5ccd6cSJohn Marino 121*ef5ccd6cSJohn Marino /* Disable branch tracing for a thread. 122*ef5ccd6cSJohn Marino This will also delete the current branch trace data. */ 123*ef5ccd6cSJohn Marino extern void btrace_disable (struct thread_info *); 124*ef5ccd6cSJohn Marino 125*ef5ccd6cSJohn Marino /* Disable branch tracing for a thread during teardown. 126*ef5ccd6cSJohn Marino This is similar to btrace_disable, except that it will use 127*ef5ccd6cSJohn Marino target_teardown_btrace instead of target_disable_btrace. */ 128*ef5ccd6cSJohn Marino extern void btrace_teardown (struct thread_info *); 129*ef5ccd6cSJohn Marino 130*ef5ccd6cSJohn Marino /* Fetch the branch trace for a single thread. */ 131*ef5ccd6cSJohn Marino extern void btrace_fetch (struct thread_info *); 132*ef5ccd6cSJohn Marino 133*ef5ccd6cSJohn Marino /* Clear the branch trace for a single thread. */ 134*ef5ccd6cSJohn Marino extern void btrace_clear (struct thread_info *); 135*ef5ccd6cSJohn Marino 136*ef5ccd6cSJohn Marino /* Clear the branch trace for all threads when an object file goes away. */ 137*ef5ccd6cSJohn Marino extern void btrace_free_objfile (struct objfile *); 138*ef5ccd6cSJohn Marino 139*ef5ccd6cSJohn Marino /* Parse a branch trace xml document into a block vector. */ 140*ef5ccd6cSJohn Marino extern VEC (btrace_block_s) *parse_xml_btrace (const char*); 141*ef5ccd6cSJohn Marino 142*ef5ccd6cSJohn Marino #endif /* BTRACE_H */ 143