|
|
93189d |
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
|
|
93189d |
From: Fedora GDB patches <invalid@email.com>
|
|
|
93189d |
Date: Fri, 27 Oct 2017 21:07:50 +0200
|
|
|
93189d |
Subject: gdb-linux_perf-bundle.patch
|
|
|
93189d |
|
|
|
93189d |
;; [dts+el7] [x86*] Bundle linux_perf.h for libipt (RH BZ 1256513).
|
|
|
93189d |
;;=fedora
|
|
|
93189d |
|
|
|
93189d |
diff --git a/gdb/gdb.c b/gdb/gdb.c
|
|
|
93189d |
--- a/gdb/gdb.c
|
|
|
93189d |
+++ b/gdb/gdb.c
|
|
|
93189d |
@@ -20,11 +20,19 @@
|
|
|
93189d |
#include "main.h"
|
|
|
93189d |
#include "interps.h"
|
|
|
93189d |
|
|
|
93189d |
+#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
|
|
|
93189d |
+extern "C" void __libipt_init(void);
|
|
|
93189d |
+#endif
|
|
|
93189d |
+
|
|
|
93189d |
int
|
|
|
93189d |
main (int argc, char **argv)
|
|
|
93189d |
{
|
|
|
93189d |
struct captured_main_args args;
|
|
|
93189d |
|
|
|
93189d |
+#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
|
|
|
93189d |
+ __libipt_init();
|
|
|
93189d |
+#endif
|
|
|
93189d |
+
|
|
|
93189d |
memset (&args, 0, sizeof args);
|
|
|
93189d |
args.argc = argc;
|
|
|
93189d |
args.argv = argv;
|
|
|
93189d |
diff --git a/gdb/nat/linux-btrace.h b/gdb/nat/linux-btrace.h
|
|
|
93189d |
--- a/gdb/nat/linux-btrace.h
|
|
|
93189d |
+++ b/gdb/nat/linux-btrace.h
|
|
|
93189d |
@@ -27,6 +27,177 @@
|
|
|
93189d |
# include <linux/perf_event.h>
|
|
|
93189d |
#endif
|
|
|
93189d |
|
|
|
93189d |
+#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
|
|
|
93189d |
+#ifndef HAVE_LINUX_PERF_EVENT_H
|
|
|
93189d |
+# error "PERF_ATTR_SIZE_VER5_BUNDLE && !HAVE_LINUX_PERF_EVENT_H"
|
|
|
93189d |
+#endif
|
|
|
93189d |
+#ifndef PERF_ATTR_SIZE_VER5
|
|
|
93189d |
+#define PERF_ATTR_SIZE_VER5
|
|
|
93189d |
+#define perf_event_mmap_page perf_event_mmap_page_bundle
|
|
|
93189d |
+// kernel-headers-3.10.0-493.el7.x86_64/usr/include/linux/perf_event.h
|
|
|
93189d |
+/*
|
|
|
93189d |
+ * Structure of the page that can be mapped via mmap
|
|
|
93189d |
+ */
|
|
|
93189d |
+struct perf_event_mmap_page {
|
|
|
93189d |
+ __u32 version; /* version number of this structure */
|
|
|
93189d |
+ __u32 compat_version; /* lowest version this is compat with */
|
|
|
93189d |
+
|
|
|
93189d |
+ /*
|
|
|
93189d |
+ * Bits needed to read the hw events in user-space.
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * u32 seq, time_mult, time_shift, index, width;
|
|
|
93189d |
+ * u64 count, enabled, running;
|
|
|
93189d |
+ * u64 cyc, time_offset;
|
|
|
93189d |
+ * s64 pmc = 0;
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * do {
|
|
|
93189d |
+ * seq = pc->lock;
|
|
|
93189d |
+ * barrier()
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * enabled = pc->time_enabled;
|
|
|
93189d |
+ * running = pc->time_running;
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * if (pc->cap_usr_time && enabled != running) {
|
|
|
93189d |
+ * cyc = rdtsc();
|
|
|
93189d |
+ * time_offset = pc->time_offset;
|
|
|
93189d |
+ * time_mult = pc->time_mult;
|
|
|
93189d |
+ * time_shift = pc->time_shift;
|
|
|
93189d |
+ * }
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * index = pc->index;
|
|
|
93189d |
+ * count = pc->offset;
|
|
|
93189d |
+ * if (pc->cap_user_rdpmc && index) {
|
|
|
93189d |
+ * width = pc->pmc_width;
|
|
|
93189d |
+ * pmc = rdpmc(index - 1);
|
|
|
93189d |
+ * }
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * barrier();
|
|
|
93189d |
+ * } while (pc->lock != seq);
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * NOTE: for obvious reason this only works on self-monitoring
|
|
|
93189d |
+ * processes.
|
|
|
93189d |
+ */
|
|
|
93189d |
+ __u32 lock; /* seqlock for synchronization */
|
|
|
93189d |
+ __u32 index; /* hardware event identifier */
|
|
|
93189d |
+ __s64 offset; /* add to hardware event value */
|
|
|
93189d |
+ __u64 time_enabled; /* time event active */
|
|
|
93189d |
+ __u64 time_running; /* time event on cpu */
|
|
|
93189d |
+ union {
|
|
|
93189d |
+ __u64 capabilities;
|
|
|
93189d |
+ struct {
|
|
|
93189d |
+ __u64 cap_bit0 : 1, /* Always 0, deprecated, see commit 860f085b74e9 */
|
|
|
93189d |
+ cap_bit0_is_deprecated : 1, /* Always 1, signals that bit 0 is zero */
|
|
|
93189d |
+
|
|
|
93189d |
+ cap_user_rdpmc : 1, /* The RDPMC instruction can be used to read counts */
|
|
|
93189d |
+ cap_user_time : 1, /* The time_* fields are used */
|
|
|
93189d |
+ cap_user_time_zero : 1, /* The time_zero field is used */
|
|
|
93189d |
+ cap_____res : 59;
|
|
|
93189d |
+ };
|
|
|
93189d |
+ };
|
|
|
93189d |
+
|
|
|
93189d |
+ /*
|
|
|
93189d |
+ * If cap_user_rdpmc this field provides the bit-width of the value
|
|
|
93189d |
+ * read using the rdpmc() or equivalent instruction. This can be used
|
|
|
93189d |
+ * to sign extend the result like:
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * pmc <<= 64 - width;
|
|
|
93189d |
+ * pmc >>= 64 - width; // signed shift right
|
|
|
93189d |
+ * count += pmc;
|
|
|
93189d |
+ */
|
|
|
93189d |
+ __u16 pmc_width;
|
|
|
93189d |
+
|
|
|
93189d |
+ /*
|
|
|
93189d |
+ * If cap_usr_time the below fields can be used to compute the time
|
|
|
93189d |
+ * delta since time_enabled (in ns) using rdtsc or similar.
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * u64 quot, rem;
|
|
|
93189d |
+ * u64 delta;
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * quot = (cyc >> time_shift);
|
|
|
93189d |
+ * rem = cyc & (((u64)1 << time_shift) - 1);
|
|
|
93189d |
+ * delta = time_offset + quot * time_mult +
|
|
|
93189d |
+ * ((rem * time_mult) >> time_shift);
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * Where time_offset,time_mult,time_shift and cyc are read in the
|
|
|
93189d |
+ * seqcount loop described above. This delta can then be added to
|
|
|
93189d |
+ * enabled and possible running (if index), improving the scaling:
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * enabled += delta;
|
|
|
93189d |
+ * if (index)
|
|
|
93189d |
+ * running += delta;
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * quot = count / running;
|
|
|
93189d |
+ * rem = count % running;
|
|
|
93189d |
+ * count = quot * enabled + (rem * enabled) / running;
|
|
|
93189d |
+ */
|
|
|
93189d |
+ __u16 time_shift;
|
|
|
93189d |
+ __u32 time_mult;
|
|
|
93189d |
+ __u64 time_offset;
|
|
|
93189d |
+ /*
|
|
|
93189d |
+ * If cap_usr_time_zero, the hardware clock (e.g. TSC) can be calculated
|
|
|
93189d |
+ * from sample timestamps.
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * time = timestamp - time_zero;
|
|
|
93189d |
+ * quot = time / time_mult;
|
|
|
93189d |
+ * rem = time % time_mult;
|
|
|
93189d |
+ * cyc = (quot << time_shift) + (rem << time_shift) / time_mult;
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * And vice versa:
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * quot = cyc >> time_shift;
|
|
|
93189d |
+ * rem = cyc & (((u64)1 << time_shift) - 1);
|
|
|
93189d |
+ * timestamp = time_zero + quot * time_mult +
|
|
|
93189d |
+ * ((rem * time_mult) >> time_shift);
|
|
|
93189d |
+ */
|
|
|
93189d |
+ __u64 time_zero;
|
|
|
93189d |
+ __u32 size; /* Header size up to __reserved[] fields. */
|
|
|
93189d |
+
|
|
|
93189d |
+ /*
|
|
|
93189d |
+ * Hole for extension of the self monitor capabilities
|
|
|
93189d |
+ */
|
|
|
93189d |
+
|
|
|
93189d |
+ __u8 __reserved[118*8+4]; /* align to 1k. */
|
|
|
93189d |
+
|
|
|
93189d |
+ /*
|
|
|
93189d |
+ * Control data for the mmap() data buffer.
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * User-space reading the @data_head value should issue an smp_rmb(),
|
|
|
93189d |
+ * after reading this value.
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * When the mapping is PROT_WRITE the @data_tail value should be
|
|
|
93189d |
+ * written by userspace to reflect the last read data, after issueing
|
|
|
93189d |
+ * an smp_mb() to separate the data read from the ->data_tail store.
|
|
|
93189d |
+ * In this case the kernel will not over-write unread data.
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * See perf_output_put_handle() for the data ordering.
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * data_{offset,size} indicate the location and size of the perf record
|
|
|
93189d |
+ * buffer within the mmapped area.
|
|
|
93189d |
+ */
|
|
|
93189d |
+ __u64 data_head; /* head in the data section */
|
|
|
93189d |
+ __u64 data_tail; /* user-space written tail */
|
|
|
93189d |
+ __u64 data_offset; /* where the buffer starts */
|
|
|
93189d |
+ __u64 data_size; /* data buffer size */
|
|
|
93189d |
+
|
|
|
93189d |
+ /*
|
|
|
93189d |
+ * AUX area is defined by aux_{offset,size} fields that should be set
|
|
|
93189d |
+ * by the userspace, so that
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * aux_offset >= data_offset + data_size
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * prior to mmap()ing it. Size of the mmap()ed area should be aux_size.
|
|
|
93189d |
+ *
|
|
|
93189d |
+ * Ring buffer pointers aux_{head,tail} have the same semantics as
|
|
|
93189d |
+ * data_{head,tail} and same ordering rules apply.
|
|
|
93189d |
+ */
|
|
|
93189d |
+ __u64 aux_head;
|
|
|
93189d |
+ __u64 aux_tail;
|
|
|
93189d |
+ __u64 aux_offset;
|
|
|
93189d |
+ __u64 aux_size;
|
|
|
93189d |
+};
|
|
|
93189d |
+#endif // PERF_ATTR_SIZE_VER5
|
|
|
93189d |
+#endif // PERF_ATTR_SIZE_VER5_BUNDLE
|
|
|
93189d |
+
|
|
|
93189d |
struct target_ops;
|
|
|
93189d |
|
|
|
93189d |
#if HAVE_LINUX_PERF_EVENT_H
|
|
|
93189d |
diff --git a/gdbsupport/common.m4 b/gdbsupport/common.m4
|
|
|
93189d |
--- a/gdbsupport/common.m4
|
|
|
93189d |
+++ b/gdbsupport/common.m4
|
|
|
93189d |
@@ -140,7 +140,7 @@ AC_DEFUN([GDB_AC_COMMON], [
|
|
|
93189d |
AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
|
|
|
93189d |
#include <linux/perf_event.h>
|
|
|
93189d |
#ifndef PERF_ATTR_SIZE_VER5
|
|
|
93189d |
- # error
|
|
|
93189d |
+ // error // PERF_ATTR_SIZE_VER5_BUNDLE is not available here - Fedora+RHEL
|
|
|
93189d |
#endif
|
|
|
93189d |
]])], [perf_event=yes], [perf_event=no])
|
|
|
93189d |
if test "$perf_event" != yes; then
|