Blame SOURCES/gdb-linux_perf-bundle.patch

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