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