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