34#include "gdbsupport/rsp-low.h"
61#define DEBUG(msg, args...) \
64 if (record_debug != 0) \
65 gdb_printf (gdb_stdlog, \
66 "[btrace] " msg "\n", ##args); \
70#define DEBUG_FTRACE(msg, args...) DEBUG ("[ftrace] " msg, ##args)
100 const char *filename;
107 filename =
"<unknown>";
121 return core_addr_to_string_nz (insn->
pc);
129 const char *fun, *file;
130 unsigned int ibegin, iend;
138 iend = ibegin + bfun->
insn.size ();
140 DEBUG_FTRACE (
"%s: fun = %s, file = %s, level = %d, insn = [%u; %u)",
141 prefix, fun, file, level, ibegin, iend);
156 return bfun->
insn.size ();
199 if (mfun != NULL && msym != NULL
204 if (fun != NULL && sym != NULL)
206 const char *bfname, *fname;
215 if (filename_cmp (fname, bfname) != 0)
220 if (!(msym == NULL && sym == NULL) && mfun == NULL && fun == NULL)
224 if (msym == NULL && sym == NULL && !(mfun == NULL && fun == NULL))
268 btrace_function_flags
flags)
286 btrace_function_flags
flags)
317 const unsigned int length = btinfo->
functions.size ();
337 const unsigned int length = btinfo->
functions.size ();
433 gdb_assert (caller->
next == 0);
442 bfun->
up = caller->
up;
462 while (
prev->up != 0)
523 std::vector<unsigned int> &gaps)
538 gaps.push_back (bfun->
number);
564 if (fun == NULL && mfun == NULL)
565 DEBUG_FTRACE (
"no symbol at %s", core_addr_to_string_nz (pc));
580 if (!bfun->
insn.empty ())
581 last = &bfun->
insn.back ();
601 if (strcmp (fname,
"_dl_runtime_resolve") == 0)
609 if (last->
pc + last->
size == pc)
629 if (strncmp (fname,
"_Unwind_", strlen (
"_Unwind_")) == 0)
691 catch (
const gdb_exception_error &error)
709 for (matches = 0; lhs != NULL && rhs != NULL; ++matches)
736 bfun->
level += adjustment;
755 unsigned int length = btinfo->
functions.size() - 1;
756 for (
unsigned int i = 0; i < length; ++i)
763 if (last->
insn.size () != 1)
784 gdb_assert (
prev->next == 0);
785 gdb_assert (
next->prev == 0);
796 const btrace_function_flags
flags =
next->flags;
805 else if (
next->up == 0)
807 const btrace_function_flags
flags =
prev->flags;
831 btrace_function_flags next_flags, prev_flags;
835 next_flags =
next->flags;
836 prev_flags =
prev->flags;
890 while (lhs != NULL && rhs != NULL)
921 DEBUG_FTRACE (
"checking gap at insn %u (req matches: %d)",
931 for (cand_l = lhs; cand_l != NULL;
933 for (cand_r = rhs; cand_r != NULL;
939 if (best_matches < matches)
941 best_matches = matches;
948 gdb_assert (min_matches > 0);
949 if (best_matches < min_matches)
977 std::vector<unsigned int> remaining;
980 DEBUG (
"bridge gaps");
988 for (min_matches = 5; min_matches > 0; --min_matches)
992 while (!gaps.empty ())
994 for (
const unsigned int number : gaps)
1007 if (lhs == NULL || lhs->
errcode != 0)
1012 while (rhs != NULL && rhs->
errcode != 0)
1025 remaining.push_back (
number);
1029 if (remaining.size () == gaps.size ())
1033 gaps.swap (remaining);
1052 const struct btrace_data_bts *btrace,
1053 std::vector<unsigned int> &gaps)
1068 blk = btrace->blocks->size ();
1073 level = -btinfo->
level;
1081 const btrace_block &
block = btrace->blocks->at (blk);
1096 warning (_(
"Recorded trace may be corrupted at instruction "
1098 core_addr_to_string_nz (
pc));
1108 level = std::min (level, bfun->
level);
1115 catch (
const gdb_exception_error &error)
1137 warning (_(
"Recorded trace may be incomplete at instruction %u "
1139 core_addr_to_string_nz (
pc));
1153 level = std::min (level, bfun->
level);
1160 btinfo->
level = -level;
1163#if defined (HAVE_LIBIPT)
1166pt_reclassify_insn (
enum pt_insn_class
iclass)
1186static btrace_insn_flags
1187pt_btrace_insn_flags (
const struct pt_insn &insn)
1189 btrace_insn_flags
flags = 0;
1191 if (insn.speculative)
1200pt_btrace_insn (
const struct pt_insn &insn)
1202 return {(CORE_ADDR) insn.ip, (gdb_byte) insn.
size,
1203 pt_reclassify_insn (insn.iclass),
1204 pt_btrace_insn_flags (insn)};
1211 struct pt_insn_decoder *decoder,
1212 std::vector<unsigned int> &gaps,
int status)
1214#if defined (HAVE_PT_INSN_EVENT)
1215 while (
status & pts_event_pending)
1218 struct pt_event event;
1221 status = pt_insn_event (decoder, &event,
sizeof (event));
1231 if (event.status_update != 0)
1234 if (event.variant.enabled.resumed == 0 && !btinfo->
functions.empty ())
1238 pt_insn_get_offset (decoder, &offset);
1240 warning (_(
"Non-contiguous trace at instruction %u (offset = 0x%"
1249 pt_insn_get_offset (decoder, &offset);
1251 warning (_(
"Overflow at instruction %u (offset = 0x%" PRIx64
")."),
1266 struct pt_insn_decoder *decoder,
1267 const struct pt_insn &insn,
1268 std::vector<unsigned int> &gaps)
1270#if defined (HAVE_STRUCT_PT_INSN_ENABLED)
1276 if (insn.enabled && !btinfo->
functions.empty ())
1283 pt_insn_get_offset (decoder, &offset);
1285 warning (_(
"Non-contiguous trace at instruction %u (offset = 0x%" PRIx64
1286 ", pc = 0x%" PRIx64
")."), bfun->
insn_offset - 1, offset,
1291#if defined (HAVE_STRUCT_PT_INSN_RESYNCED)
1300 pt_insn_get_offset (decoder, &offset);
1302 warning (_(
"Overflow at instruction %u (offset = 0x%" PRIx64
", pc = 0x%"
1312 struct pt_insn_decoder *decoder,
1314 std::vector<unsigned int> &gaps)
1322 struct pt_insn insn;
1324 status = pt_insn_sync_forward (decoder);
1328 warning (_(
"Failed to synchronize onto the Intel Processor "
1329 "Trace stream: %s."), pt_errstr (pt_errcode (
status)));
1336 status = handle_pt_insn_events (btinfo, decoder, gaps,
status);
1340 status = pt_insn_next (decoder, &insn,
sizeof(insn));
1345 handle_pt_insn_event_flags (btinfo, decoder, insn, gaps);
1350 *plevel = std::min (*plevel, bfun->
level);
1361 pt_insn_get_offset (decoder, &offset);
1363 warning (_(
"Decode error (%d) at instruction %u (offset = 0x%" PRIx64
1365 offset, insn.ip, pt_errstr (pt_errcode (
status)));
1373btrace_pt_readmem_callback (gdb_byte *buffer,
size_t size,
1374 const struct pt_asid *asid, uint64_t pc,
1377 int result, errcode;
1379 result = (int)
size;
1384 result = -pte_nomap;
1386 catch (
const gdb_exception_error &error)
1388 result = -pte_nomap;
1396static enum pt_cpu_vendor
1397pt_translate_cpu_vendor (
enum btrace_cpu_vendor vendor)
1411static void btrace_finalize_ftrace_pt (
struct pt_insn_decoder *decoder,
1414 pt_insn_free_decoder (decoder);
1419 tp->
btrace.level = -level;
1433 const struct btrace_data_pt *btrace,
1434 std::vector<unsigned int> &gaps)
1443 struct pt_insn_decoder *decoder;
1444 struct pt_config config;
1447 if (btrace->size == 0)
1454 level = -btinfo->
level;
1456 pt_config_init(&config);
1457 config.begin = btrace->data;
1458 config.end = btrace->data + btrace->size;
1461 if (btrace->config.cpu.vendor != CV_UNKNOWN)
1464 = pt_translate_cpu_vendor (btrace->config.cpu.vendor);
1465 config.cpu.family = btrace->config.cpu.family;
1466 config.cpu.model = btrace->config.cpu.model;
1467 config.cpu.stepping = btrace->config.cpu.stepping;
1469 errcode = pt_cpu_errata (&config.errata, &config.cpu);
1471 error (_(
"Failed to configure the Intel Processor Trace "
1472 "decoder: %s."), pt_errstr (pt_errcode (errcode)));
1475 decoder = pt_insn_alloc_decoder (&config);
1476 if (decoder == NULL)
1477 error (_(
"Failed to allocate the Intel Processor Trace decoder."));
1481 struct pt_image *image;
1483 image = pt_insn_get_image(decoder);
1485 error (_(
"Failed to configure the Intel Processor Trace decoder."));
1487 errcode = pt_image_set_callback(image, btrace_pt_readmem_callback, NULL);
1489 error (_(
"Failed to configure the Intel Processor Trace decoder: "
1490 "%s."), pt_errstr (pt_errcode (errcode)));
1492 ftrace_add_pt (btinfo, decoder, &level, gaps);
1494 catch (
const gdb_exception &error)
1497 if (error.reason == RETURN_QUIT && !btinfo->
functions.empty ())
1500 btrace_finalize_ftrace_pt (decoder, tp, level);
1505 btrace_finalize_ftrace_pt (decoder, tp, level);
1512 const struct btrace_data_pt *btrace,
1513 std::vector<unsigned int> &gaps)
1515 internal_error (_(
"Unexpected branch trace format."));
1527 struct btrace_data *btrace,
1528 const struct btrace_cpu *cpu,
1529 std::vector<unsigned int> &gaps)
1531 DEBUG (
"compute ftrace");
1533 switch (btrace->format)
1535 case BTRACE_FORMAT_NONE:
1538 case BTRACE_FORMAT_BTS:
1542 case BTRACE_FORMAT_PT:
1545 btrace->variant.pt.config.cpu = *cpu;
1551 internal_error (_(
"Unknown branch trace format."));
1559 tp->
btrace.ngaps += gaps.size ();
1566 const struct btrace_cpu *cpu)
1568 std::vector<unsigned int> gaps;
1574 catch (
const gdb_exception &error)
1589 struct btrace_data btrace;
1596 btrace.format = BTRACE_FORMAT_BTS;
1597 btrace.variant.bts.blocks =
new std::vector<btrace_block>;
1599 btrace.variant.bts.blocks->emplace_back (pc, pc);
1609 if (tp->
btrace.target != NULL)
1610 error (_(
"Recording already enabled on thread %s (%s)."),
1613#if !defined (HAVE_LIBIPT)
1614 if (conf->format == BTRACE_FORMAT_PT)
1615 error (_(
"Intel Processor Trace support was disabled at compile time."));
1619 tp->
ptid.to_string ().c_str ());
1623 if (tp->
btrace.target == NULL)
1624 error (_(
"Failed to enable recording on thread %s (%s)."),
1639 if (conf->format != BTRACE_FORMAT_PT
1643 catch (
const gdb_exception &exception)
1653const struct btrace_config *
1656 if (btinfo->
target == NULL)
1670 error (_(
"Recording not enabled on thread %s (%s)."),
1674 tp->
ptid.to_string ().c_str ());
1693 tp->
ptid.to_string ().c_str ());
1708 btrace_block *first_new_block;
1711 gdb_assert (!btinfo->
functions.empty ());
1712 gdb_assert (!btrace->blocks->empty ());
1719 if (last_bfun->
insn.empty ())
1721 btrace->blocks->pop_back ();
1728 first_new_block = &btrace->blocks->back ();
1739 if (first_new_block->end == last_insn.
pc && btrace->blocks->size () == 1)
1741 btrace->blocks->pop_back ();
1746 core_addr_to_string_nz (first_new_block->end));
1750 if (first_new_block->end < last_insn.
pc)
1752 warning (_(
"Error while trying to read delta trace. Falling back to "
1758 gdb_assert (first_new_block->begin == 0);
1759 first_new_block->begin = last_insn.
pc;
1765 DEBUG (
"pruning insn at %s for stitching",
1768 last_bfun->
insn.pop_back ();
1779 if (last_bfun->
number == 1 && last_bfun->
insn.empty ())
1795 if (btrace->empty ())
1798 switch (btrace->format)
1800 case BTRACE_FORMAT_NONE:
1803 case BTRACE_FORMAT_BTS:
1806 case BTRACE_FORMAT_PT:
1811 internal_error (_(
"Unknown branch trace format."));
1833 switch (btinfo->
data.format)
1838 case BTRACE_FORMAT_BTS:
1843#if defined (HAVE_LIBIPT)
1844 case BTRACE_FORMAT_PT:
1862 case BTRACE_FORMAT_BTS:
1866 return _(
"instruction overflow");
1869 return _(
"unknown instruction");
1876#if defined (HAVE_LIBIPT)
1877 case BTRACE_FORMAT_PT:
1881 return _(
"trace decode cancelled");
1884 return _(
"disabled");
1887 return _(
"overflow");
1891 return pt_errstr (pt_errcode (
errcode));
1901 return _(
"unknown");
1911 struct btrace_data btrace;
1915 tp->
ptid.to_string ().c_str ());
1925 if (btinfo->
replay != NULL)
1953 if (errcode == 0 && !btrace.empty ())
1969 error (_(
"Failed to read branch trace."));
1972 if (!btrace.empty ())
1976 btrace_data_append (&btinfo->
data, &btrace);
1992 tp->
ptid.to_string ().c_str ());
2005 btinfo->
data.clear ();
2014 DEBUG (
"free objfile");
2020#if defined (HAVE_LIBEXPAT)
2033 if (strcmp (
version,
"1.0") != 0)
2045 struct btrace_data *btrace;
2046 ULONGEST *begin, *end;
2048 btrace = (
struct btrace_data *)
user_data;
2050 switch (btrace->format)
2052 case BTRACE_FORMAT_BTS:
2055 case BTRACE_FORMAT_NONE:
2056 btrace->format = BTRACE_FORMAT_BTS;
2057 btrace->variant.bts.blocks =
new std::vector<btrace_block>;
2066 btrace->variant.bts.blocks->emplace_back (*begin, *end);
2073 gdb_byte **pdata,
size_t *psize)
2078 len = strlen (body_text);
2084 gdb::unique_xmalloc_ptr<gdb_byte> data ((gdb_byte *)
xmalloc (
size));
2095 if (hi == 0 || lo == 0)
2098 *bin++ = fromhex (hi) * 16 + fromhex (lo);
2102 *pdata = data.release ();
2114 struct btrace_data *btrace;
2116 ULONGEST *family, *model, *stepping;
2127 btrace = (
struct btrace_data *)
user_data;
2129 if (strcmp (vendor,
"GenuineIntel") == 0)
2130 btrace->variant.pt.config.cpu.vendor = CV_INTEL;
2132 btrace->variant.pt.config.cpu.family = *family;
2133 btrace->variant.pt.config.cpu.model = *model;
2134 btrace->variant.pt.config.cpu.stepping = *stepping;
2144 struct btrace_data *btrace;
2146 btrace = (
struct btrace_data *)
user_data;
2148 &btrace->variant.pt.size);
2159 struct btrace_data *btrace;
2161 btrace = (
struct btrace_data *)
user_data;
2162 btrace->format = BTRACE_FORMAT_PT;
2163 btrace->variant.pt.config.cpu.vendor = CV_UNKNOWN;
2164 btrace->variant.pt.data = NULL;
2165 btrace->variant.pt.size = 0;
2221#if defined (HAVE_LIBEXPAT)
2225 result.format = BTRACE_FORMAT_NONE;
2230 error (_(
"Error parsing branch trace."));
2233 *btrace = std::move (result);
2237 error (_(
"Cannot process branch trace. XML support was disabled at "
2243#if defined (HAVE_LIBEXPAT)
2253 struct btrace_config *conf;
2256 conf = (
struct btrace_config *)
user_data;
2257 conf->format = BTRACE_FORMAT_BTS;
2262 conf->bts.size = (
unsigned int) *(ULONGEST *)
size->value.get ();
2273 struct btrace_config *conf;
2276 conf = (
struct btrace_config *)
user_data;
2277 conf->format = BTRACE_FORMAT_PT;
2282 conf->pt.size = (
unsigned int) *(ULONGEST *)
size->value.get ();
2321#if defined (HAVE_LIBEXPAT)
2327 error (_(
"Error parsing branch trace configuration."));
2331 error (_(
"Cannot process the branch trace configuration. XML support "
2332 "was disabled at compile time."));
2343 unsigned int index, end;
2353 end = bfun->
insn.size ();
2354 gdb_assert (0 < end);
2355 gdb_assert (index < end);
2357 return &bfun->
insn[index];
2383 error (_(
"No trace."));
2397 unsigned int length;
2400 error (_(
"No trace."));
2403 length = bfun->
insn.size ();
2422 unsigned int index, steps;
2430 unsigned int end, space, adv;
2432 end = bfun->
insn.size ();
2453 gdb_assert (0 < end);
2454 gdb_assert (index < end);
2457 space = end - index;
2460 adv = std::min (space, stride);
2488 gdb_assert (adv > 0);
2504 unsigned int index, steps;
2525 index = bfun->
insn.size ();
2539 adv = std::min (index, stride);
2546 gdb_assert (adv > 0);
2578 unsigned int upper, lower;
2596 const unsigned int average = lower + (upper - lower) / 2;
2602 upper = average - 1;
2608 lower = average + 1;
2662 return it->
index + 1;
2672 error (_(
"No trace."));
2685 error (_(
"No trace."));
2698 if (it->
index + stride < length - 1)
2700 it->
index += stride;
2701 else if (it->
index + stride == length - 1)
2709 it->
index = length - 1;
2717 stride = length - it->
index - 1;
2719 stride = length - it->
index;
2735 gdb_assert (it->
index <= length);
2737 if (stride == 0 || it->
index == 0)
2744 if ((it->
index == length) && (length > 1))
2747 it->
index = length - 2;
2749 it->
index = length - 1;
2755 stride = std::min (stride, it->
index);
2757 it->
index -= stride;
2758 return steps + stride;
2778 const unsigned int length = btinfo->
functions.size ();
2823 return tp->
btrace.replay != NULL;
2845#if defined (HAVE_LIBIPT)
2850pt_print_packet (
const struct pt_packet *packet)
2852 switch (packet->type)
2872 packet->payload.ip.ipc,
2873 packet->payload.ip.ip);
2878 packet->payload.ip.ipc,
2879 packet->payload.ip.ip);
2884 packet->payload.ip.ipc,
2885 packet->payload.ip.ip);
2890 packet->payload.ip.ipc,
2891 packet->payload.ip.ip);
2896 packet->payload.tnt.bit_size,
2897 packet->payload.tnt.payload);
2902 packet->payload.tnt.bit_size,
2903 packet->payload.tnt.payload);
2907 gdb_printf ((
"pip %" PRIx64
"%s"), packet->payload.pip.cr3,
2908 packet->payload.pip.nr ? (
" nr") : (
""));
2912 gdb_printf ((
"tsc %" PRIx64
""), packet->payload.tsc.tsc);
2916 gdb_printf ((
"cbr %u"), packet->payload.cbr.ratio);
2920 switch (packet->payload.mode.leaf)
2923 gdb_printf ((
"mode %u"), packet->payload.mode.leaf);
2928 packet->payload.mode.bits.exec.csl
2930 packet->payload.mode.bits.exec.csd
2931 ? (
" cs.d") : (
""));
2936 packet->payload.mode.bits.tsx.intx
2938 packet->payload.mode.bits.tsx.abrt
2939 ? (
" abrt") : (
""));
2953 gdb_printf ((
"vmcs %" PRIx64
""), packet->payload.vmcs.base);
2957 gdb_printf ((
"tma %x %x"), packet->payload.tma.ctc,
2958 packet->payload.tma.fc);
2962 gdb_printf ((
"mtc %x"), packet->payload.mtc.ctc);
2966 gdb_printf ((
"cyc %" PRIx64
""), packet->payload.cyc.value);
2970 gdb_printf ((
"mnt %" PRIx64
""), packet->payload.mnt.payload);
2979 struct pt_packet_decoder *decoder)
2984 maint->
variant.pt.packets =
new std::vector<btrace_pt_packet>;
2988 struct btrace_pt_packet packet;
2990 errcode = pt_pkt_sync_forward (decoder);
2996 pt_pkt_get_offset (decoder, &packet.offset);
2998 errcode = pt_pkt_next (decoder, &packet.packet,
2999 sizeof(packet.packet));
3005 packet.errcode = pt_errcode (errcode);
3006 maint->
variant.pt.packets->push_back (packet);
3010 if (errcode == -pte_eos)
3013 packet.errcode = pt_errcode (errcode);
3014 maint->
variant.pt.packets->push_back (packet);
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)));
3030 struct pt_packet_decoder *decoder;
3031 const struct btrace_cpu *cpu;
3032 struct btrace_data_pt *pt;
3033 struct pt_config config;
3036 pt = &btinfo->
data.variant.pt;
3042 memset (&config, 0,
sizeof(config));
3044 config.size =
sizeof (config);
3045 config.begin = pt->data;
3046 config.end = pt->data + pt->size;
3050 cpu = &pt->config.cpu;
3053 if (cpu->vendor != CV_UNKNOWN)
3055 config.cpu.vendor = pt_translate_cpu_vendor (cpu->vendor);
3056 config.cpu.family = cpu->family;
3057 config.cpu.model = cpu->model;
3058 config.cpu.stepping = cpu->stepping;
3060 errcode = pt_cpu_errata (&config.errata, &config.cpu);
3062 error (_(
"Failed to configure the Intel Processor Trace "
3063 "decoder: %s."), pt_errstr (pt_errcode (errcode)));
3066 decoder = pt_pkt_alloc_decoder (&config);
3067 if (decoder == NULL)
3068 error (_(
"Failed to allocate the Intel Processor Trace decoder."));
3072 btrace_maint_decode_pt (&btinfo->
maint, decoder);
3074 catch (
const gdb_exception &except)
3076 pt_pkt_free_decoder (decoder);
3082 pt_pkt_free_decoder (decoder);
3093 unsigned int *begin,
unsigned int *end,
3094 unsigned int *from,
unsigned int *to)
3096 switch (btinfo->
data.format)
3105 case BTRACE_FORMAT_BTS:
3108 *end = btinfo->
data.variant.bts.blocks->size ();
3113#if defined (HAVE_LIBIPT)
3114 case BTRACE_FORMAT_PT:
3116 btinfo->
maint.
variant.pt.packets =
new std::vector<btrace_pt_packet>;
3119 btrace_maint_update_pt_packets (btinfo);
3135 unsigned int begin,
unsigned int end)
3137 switch (btinfo->
data.format)
3142 case BTRACE_FORMAT_BTS:
3144 const std::vector<btrace_block> &blocks
3145 = *btinfo->
data.variant.bts.blocks;
3148 for (blk = begin; blk < end; ++blk)
3150 const btrace_block &
block = blocks.at (blk);
3153 core_addr_to_string_nz (
block.begin),
3154 core_addr_to_string_nz (
block.
end));
3162#if defined (HAVE_LIBIPT)
3163 case BTRACE_FORMAT_PT:
3165 const std::vector<btrace_pt_packet> &packets
3169 for (pkt = begin; pkt < end; ++pkt)
3171 const struct btrace_pt_packet &packet = packets.at (pkt);
3174 gdb_printf (
"0x%" PRIx64
"\t", packet.offset);
3176 if (packet.errcode == pte_ok)
3177 pt_print_packet (&packet.packet);
3179 gdb_printf (
"[error: %s]", pt_errstr (packet.errcode));
3197 const char *begin, *pos;
3199 unsigned long number;
3202 pos = skip_spaces (begin);
3204 if (!isdigit (*pos))
3205 error (_(
"Expected positive number, got: %s."), pos);
3207 number = strtoul (pos, &end, 10);
3209 error (_(
"Number too big."));
3211 *arg += (end - begin);
3213 return (
unsigned int) number;
3221 const char *pos = skip_spaces (*arg);
3223 if (!isdigit (*pos))
3224 error (_(
"Expected positive number, got: %s."), pos);
3227 long result = strtol (pos, &end, 10);
3238 error (_(
"Junk after argument: %s."), arg);
3247 unsigned int size, begin, end, from, to;
3251 error (_(
"No thread."));
3263 if (arg == NULL || *arg == 0 || strcmp (arg,
"+") == 0)
3267 if (end - from <
size)
3271 else if (strcmp (arg,
"-") == 0)
3275 if (to - begin <
size)
3283 error (_(
"'%u' is out of range."), from);
3285 arg = skip_spaces (arg);
3288 arg = skip_spaces (++arg);
3297 if (end - from <
size)
3301 else if (*arg ==
'-')
3312 if (to - begin <
size)
3334 if (end - from <
size)
3350 if (args != NULL && *args != 0)
3351 error (_(
"Invalid argument."));
3354 error (_(
"No thread."));
3361 btinfo->
data.clear ();
3369 if (args != NULL && *args != 0)
3370 error (_(
"Invalid argument."));
3373 error (_(
"No thread."));
3385 const struct btrace_config *conf;
3387 if (args != NULL && *args != 0)
3388 error (_(
"Invalid argument."));
3391 error (_(
"No thread."));
3399 error (_(
"No btrace configuration."));
3402 btrace_format_string (conf->format));
3404 switch (conf->format)
3409 case BTRACE_FORMAT_BTS:
3411 btinfo->
data.variant.bts.blocks->size ());
3414#if defined (HAVE_LIBIPT)
3415 case BTRACE_FORMAT_PT:
3419 version = pt_library_version ();
3424 btrace_maint_update_pt_packets (btinfo);
3455 _(
"Branch tracing maintenance commands."),
3459 _(
"Set branch tracing specific variables."),
3460 _(
"Show branch tracing specific variables."),
3467 _(
"Set Intel Processor Trace specific variables."),
3468 _(
"Show Intel Processor Trace specific variables."),
3476Set whether PAD packets should be skipped in the btrace packet history."), _(
"\
3477Show whether PAD packets should be skipped in the btrace packet history."),_(
"\
3478When enabled, PAD packets are ignored in the btrace packet history."),
3484 _(
"Print the raw branch tracing data.\n\
3485With no argument, print ten more packets after the previous ten-line print.\n\
3486With '-' as argument print ten packets before a previous ten-line print.\n\
3487One argument specifies the starting packet of a ten-line print.\n\
3488Two arguments with comma between specify starting and ending packets to \
3490Preceded with '+'/'-' the second argument specifies the distance from the \
3496 _(
"Clears the branch tracing packet history.\n\
3497Discards the raw branch tracing data but not the execution history data."),
3501 _(
"Clears the branch tracing data.\n\
3502Discards the raw branch tracing data and the execution history data.\n\
3503The next 'record' command will fetch the branch tracing data anew."),
static struct @4 attributes[]
struct gdbarch * target_gdbarch(void)
struct symbol * find_pc_function(CORE_ADDR pc)
CORE_ADDR get_pc_function_start(CORE_ADDR pc)
void btrace_enable(struct thread_info *tp, const struct btrace_config *conf)
static void show_maint_btrace_pt_skip_pad(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static int btrace_stitch_bts(struct btrace_data_bts *btrace, struct thread_info *tp)
static struct btrace_function * ftrace_update_function(struct btrace_thread_info *btinfo, CORE_ADDR pc)
const struct btrace_function * btrace_call_get(const struct btrace_call_iterator *it)
static const struct gdb_xml_element btrace_pt_config_children[]
static void parse_xml_btrace_pt(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, std::vector< gdb_xml_value > &attributes)
unsigned int btrace_call_prev(struct btrace_call_iterator *it, unsigned int stride)
static void parse_xml_btrace_block(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, std::vector< gdb_xml_value > &attributes)
void _initialize_btrace()
static void no_chunk(const char *arg)
static void check_xml_btrace_version(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, std::vector< gdb_xml_value > &attributes)
unsigned int btrace_call_next(struct btrace_call_iterator *it, unsigned int stride)
unsigned int btrace_call_number(const struct btrace_call_iterator *it)
static struct cmd_list_element * maint_btrace_show_cmdlist
static const struct gdb_xml_attribute btrace_conf_pt_attributes[]
static enum btrace_insn_class ftrace_classify_insn(struct gdbarch *gdbarch, CORE_ADDR pc)
static const struct gdb_xml_element btrace_conf_elements[]
static int ftrace_bridge_gap(struct btrace_thread_info *btinfo, struct btrace_function *lhs, struct btrace_function *rhs, int min_matches)
void btrace_insn_end(struct btrace_insn_iterator *it, const struct btrace_thread_info *btinfo)
static struct btrace_function * ftrace_new_function(struct btrace_thread_info *btinfo, struct minimal_symbol *mfun, struct symbol *fun)
static struct btrace_function * ftrace_new_switch(struct btrace_thread_info *btinfo, struct minimal_symbol *mfun, struct symbol *fun)
int btrace_insn_cmp(const struct btrace_insn_iterator *lhs, const struct btrace_insn_iterator *rhs)
static bool btrace_ends_with_single_insn(const struct btrace_thread_info *btinfo)
static void btrace_compute_ftrace(struct thread_info *tp, struct btrace_data *btrace, const struct btrace_cpu *cpu)
static struct cmd_list_element * maint_btrace_cmdlist
static void btrace_add_pc(struct thread_info *tp)
static unsigned int ftrace_call_num_insn(const struct btrace_function *bfun)
static void ftrace_fixup_level(struct btrace_thread_info *btinfo, struct btrace_function *bfun, int adjustment)
static struct btrace_function * ftrace_find_call(struct btrace_thread_info *btinfo, struct btrace_function *bfun)
static void maint_btrace_clear_cmd(const char *args, int from_tty)
static void btrace_finalize_ftrace(struct thread_info *tp, std::vector< unsigned int > &gaps)
static const char * ftrace_print_insn_addr(const struct btrace_insn *insn)
static void ftrace_debug(const struct btrace_function *bfun, const char *prefix)
int btrace_find_insn_by_number(struct btrace_insn_iterator *it, const struct btrace_thread_info *btinfo, unsigned int number)
void btrace_free_objfile(struct objfile *objfile)
unsigned int btrace_insn_prev(struct btrace_insn_iterator *it, unsigned int stride)
static int btrace_stitch_trace(struct btrace_data *btrace, struct thread_info *tp)
static const struct gdb_xml_element btrace_elements[]
static const struct gdb_xml_attribute btrace_pt_config_cpu_attributes[]
void btrace_call_begin(struct btrace_call_iterator *it, const struct btrace_thread_info *btinfo)
static void btrace_compute_ftrace_pt(struct thread_info *tp, const struct btrace_data_pt *btrace, std::vector< unsigned int > &gaps)
static const struct gdb_xml_attribute btrace_attributes[]
const char * btrace_decode_error(enum btrace_format format, int errcode)
static void btrace_bridge_gaps(struct thread_info *tp, std::vector< unsigned int > &gaps)
static void ftrace_update_insns(struct btrace_function *bfun, const btrace_insn &insn)
static void parse_xml_raw(struct gdb_xml_parser *parser, const char *body_text, gdb_byte **pdata, size_t *psize)
#define DEBUG(msg, args...)
static struct btrace_function * ftrace_new_tailcall(struct btrace_thread_info *btinfo, struct minimal_symbol *mfun, struct symbol *fun)
static int ftrace_match_backtrace(struct btrace_thread_info *btinfo, struct btrace_function *lhs, struct btrace_function *rhs)
static void btrace_compute_ftrace_1(struct thread_info *tp, struct btrace_data *btrace, const struct btrace_cpu *cpu, std::vector< unsigned int > &gaps)
static const struct gdb_xml_element btrace_pt_children[]
static struct btrace_function * ftrace_get_caller(struct btrace_thread_info *btinfo, struct btrace_function *bfun)
int btrace_find_call_by_number(struct btrace_call_iterator *it, const struct btrace_thread_info *btinfo, unsigned int number)
static const struct gdb_xml_element btrace_conf_children[]
static void ftrace_update_caller(struct btrace_function *bfun, struct btrace_function *caller, btrace_function_flags flags)
void btrace_set_insn_history(struct btrace_thread_info *btinfo, const struct btrace_insn_iterator *begin, const struct btrace_insn_iterator *end)
void btrace_disable(struct thread_info *tp)
static struct btrace_function * ftrace_new_call(struct btrace_thread_info *btinfo, struct minimal_symbol *mfun, struct symbol *fun)
void btrace_fetch(struct thread_info *tp, const struct btrace_cpu *cpu)
static const char * ftrace_print_filename(const struct btrace_function *bfun)
static struct cmd_list_element * maint_btrace_pt_set_cmdlist
void btrace_set_call_history(struct btrace_thread_info *btinfo, const struct btrace_call_iterator *begin, const struct btrace_call_iterator *end)
void parse_xml_btrace(struct btrace_data *btrace, const char *buffer)
static void btrace_clear_history(struct btrace_thread_info *btinfo)
const struct btrace_config * btrace_conf(const struct btrace_thread_info *btinfo)
static int get_context_size(const char **arg)
static void ftrace_connect_backtrace(struct btrace_thread_info *btinfo, struct btrace_function *lhs, struct btrace_function *rhs)
unsigned int btrace_insn_next(struct btrace_insn_iterator *it, unsigned int stride)
static struct btrace_function * ftrace_new_gap(struct btrace_thread_info *btinfo, int errcode, std::vector< unsigned int > &gaps)
static void btrace_maint_print_packets(struct btrace_thread_info *btinfo, unsigned int begin, unsigned int end)
static struct cmd_list_element * maint_btrace_pt_show_cmdlist
static const struct gdb_xml_attribute block_attributes[]
static const char * ftrace_print_function_name(const struct btrace_function *bfun)
static void maint_btrace_packet_history_cmd(const char *arg, int from_tty)
static void maint_info_btrace_cmd(const char *args, int from_tty)
static bool maint_btrace_pt_skip_pad
#define DEBUG_FTRACE(msg, args...)
static void ftrace_fixup_caller(struct btrace_thread_info *btinfo, struct btrace_function *bfun, struct btrace_function *caller, btrace_function_flags flags)
static const struct gdb_xml_attribute btrace_conf_attributes[]
const struct btrace_insn * btrace_insn_get(const struct btrace_insn_iterator *it)
static void maint_btrace_clear_packet_history_cmd(const char *args, int from_tty)
void btrace_teardown(struct thread_info *tp)
static struct btrace_function * ftrace_new_return(struct btrace_thread_info *btinfo, struct minimal_symbol *mfun, struct symbol *fun)
static void ftrace_compute_global_level_offset(struct btrace_thread_info *btinfo)
static void parse_xml_btrace_conf_pt(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, std::vector< gdb_xml_value > &attributes)
static struct cmd_list_element * maint_btrace_set_cmdlist
static struct btrace_function * ftrace_find_call_by_number(struct btrace_thread_info *btinfo, unsigned int number)
unsigned int btrace_insn_number(const struct btrace_insn_iterator *it)
static void parse_xml_btrace_pt_raw(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, const char *body_text)
static struct btrace_function * ftrace_find_caller(struct btrace_thread_info *btinfo, struct btrace_function *bfun, struct minimal_symbol *mfun, struct symbol *fun)
int btrace_insn_get_error(const struct btrace_insn_iterator *it)
static int ftrace_function_switched(const struct btrace_function *bfun, const struct minimal_symbol *mfun, const struct symbol *fun)
static void ftrace_connect_bfun(struct btrace_thread_info *btinfo, struct btrace_function *prev, struct btrace_function *next)
static void btrace_compute_ftrace_bts(struct thread_info *tp, const struct btrace_data_bts *btrace, std::vector< unsigned int > &gaps)
static void parse_xml_btrace_conf_bts(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, std::vector< gdb_xml_value > &attributes)
static unsigned int get_uint(const char **arg)
static const struct gdb_xml_attribute btrace_conf_bts_attributes[]
static void parse_xml_btrace_pt_config_cpu(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, std::vector< gdb_xml_value > &attributes)
void parse_xml_btrace_conf(struct btrace_config *conf, const char *xml)
int btrace_is_empty(struct thread_info *tp)
void btrace_insn_begin(struct btrace_insn_iterator *it, const struct btrace_thread_info *btinfo)
static const struct gdb_xml_element btrace_children[]
void btrace_clear(struct thread_info *tp)
static void btrace_maint_update_packets(struct btrace_thread_info *btinfo, unsigned int *begin, unsigned int *end, unsigned int *from, unsigned int *to)
void btrace_call_end(struct btrace_call_iterator *it, const struct btrace_thread_info *btinfo)
int btrace_is_replaying(struct thread_info *tp)
int btrace_call_cmp(const struct btrace_call_iterator *lhs, const struct btrace_call_iterator *rhs)
static void btrace_maint_clear(struct btrace_thread_info *btinfo)
@ BFUN_UP_LINKS_TO_TAILCALL
@ BTRACE_INSN_FLAG_SPECULATIVE
struct cmd_list_element * maintenancelist
struct cmd_list_element * maintenanceinfolist
struct cmd_list_element * maintenance_show_cmdlist
struct cmd_list_element * maintenance_set_cmdlist
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
set_show_commands add_setshow_prefix_cmd(const char *name, command_class theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, cmd_list_element **set_list, cmd_list_element **show_list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * add_basic_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
int gdb_insn_length(struct gdbarch *gdbarch, CORE_ADDR addr)
void reinit_frame_cache(void)
int gdbarch_insn_is_call(struct gdbarch *gdbarch, CORE_ADDR addr)
int gdbarch_insn_is_ret(struct gdbarch *gdbarch, CORE_ADDR addr)
int gdbarch_insn_is_jump(struct gdbarch *gdbarch, CORE_ADDR addr)
thread_info * find_thread_ptid(inferior *inf, ptid_t ptid)
all_non_exited_threads_range all_non_exited_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
struct thread_info * inferior_thread(void)
void switch_to_thread(struct thread_info *thr)
bool can_access_registers_thread(struct thread_info *thread)
const char * print_thread_id(struct thread_info *thr)
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
struct inferior * current_inferior(void)
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
#define prefix(a, b, R, do)
const struct btrace_cpu * record_btrace_get_cpu(void)
unsigned int record_debug
CORE_ADDR regcache_read_pc(struct regcache *regcache)
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
const char * symtab_to_fullname(struct symtab *s)
const char * symtab_to_filename_for_display(struct symtab *symtab)
struct minimal_symbol * minsym
struct btrace_call_iterator begin
struct btrace_call_iterator end
const struct btrace_thread_info * btinfo
btrace_function_flags flags
struct minimal_symbol * msym
std::vector< btrace_insn > insn
struct btrace_insn_iterator begin
struct btrace_insn_iterator end
const struct btrace_thread_info * btinfo
enum btrace_insn_class iclass
union btrace_maint_info::@20 variant
struct btrace_maint_info::@20::@21 bts
struct btrace_maint_packet_history packet_history
struct btrace_target_info * target
std::vector< btrace_function > functions
struct btrace_insn_iterator * replay
struct btrace_maint_info maint
struct btrace_call_history * call_history
struct btrace_insn_history * insn_history
gdb::unique_xmalloc_ptr< void > value
const char * print_name() const
const char * linkage_name() const
int target_read_code(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
void target_disable_btrace(struct btrace_target_info *btinfo)
struct btrace_target_info * target_enable_btrace(thread_info *tp, const struct btrace_config *conf)
void target_teardown_btrace(struct btrace_target_info *btinfo)
std::string target_pid_to_str(ptid_t ptid)
enum btrace_error target_read_btrace(struct btrace_data *btrace, struct btrace_target_info *btinfo, enum btrace_read_type type)
const struct btrace_config * target_btrace_conf(const struct btrace_target_info *btinfo)
void gdb_printf(struct ui_file *stream, const char *format,...)
void gdb_xml_error(struct gdb_xml_parser *parser, const char *format,...)
int gdb_xml_parse_quick(const char *name, const char *dtd_name, const struct gdb_xml_element *elements, const char *document, void *user_data)
struct gdb_xml_value * xml_find_attribute(std::vector< gdb_xml_value > &attributes, const char *name)
gdb_xml_attribute_handler gdb_xml_parse_attr_ulongest