btrace: improve enable error messages
Improve the error message when GDB fails to start recording branch trace. This patch also removes a zero buffer size check for PT to align with BTS. The buffer size can not be configured to be zero. gdb/ * nat/linux-btrace.c (perf_event_pt_event_type): Improve error message. Remove parameter and change return type. Update callers. Move it. (linux_enable_bts, linux_enable_pt): Improve error message. (linux_enable_pt): Remove zero buffer size check. (linux_enable_btrace): Improve error messages. Remove NULL return check.
This commit is contained in:
parent
de6242d307
commit
17ad2a4f46
|
@ -1,3 +1,12 @@
|
||||||
|
2018-02-09 Markus Metzger <markus.t.metzger@intel.com>
|
||||||
|
|
||||||
|
* nat/linux-btrace.c (perf_event_pt_event_type): Improve error message.
|
||||||
|
Remove parameter and change return type. Update callers. Move it.
|
||||||
|
(linux_enable_bts, linux_enable_pt): Improve error message.
|
||||||
|
(linux_enable_pt): Remove zero buffer size check.
|
||||||
|
(linux_enable_btrace): Improve error messages. Remove NULL return
|
||||||
|
check.
|
||||||
|
|
||||||
2018-02-09 Markus Metzger <markus.t.metzger@intel.com>
|
2018-02-09 Markus Metzger <markus.t.metzger@intel.com>
|
||||||
|
|
||||||
* btrace.c (btrace_enable): Remove target_supports_btrace call.
|
* btrace.c (btrace_enable): Remove target_supports_btrace call.
|
||||||
|
|
|
@ -448,7 +448,7 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf)
|
||||||
errno = 0;
|
errno = 0;
|
||||||
scoped_fd fd (syscall (SYS_perf_event_open, &bts->attr, pid, -1, -1, 0));
|
scoped_fd fd (syscall (SYS_perf_event_open, &bts->attr, pid, -1, -1, 0));
|
||||||
if (fd.get () < 0)
|
if (fd.get () < 0)
|
||||||
return nullptr;
|
error (_("Failed to start recording: %s"), safe_strerror (errno));
|
||||||
|
|
||||||
/* Convert the requested size in bytes to pages (rounding up). */
|
/* Convert the requested size in bytes to pages (rounding up). */
|
||||||
pages = ((size_t) conf->size / PAGE_SIZE
|
pages = ((size_t) conf->size / PAGE_SIZE
|
||||||
|
@ -484,6 +484,7 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf)
|
||||||
if ((__u64) length != data_size + PAGE_SIZE)
|
if ((__u64) length != data_size + PAGE_SIZE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
/* The number of pages we request needs to be a power of two. */
|
/* The number of pages we request needs to be a power of two. */
|
||||||
data.reset (nullptr, length, PROT_READ, MAP_SHARED, fd.get (), 0);
|
data.reset (nullptr, length, PROT_READ, MAP_SHARED, fd.get (), 0);
|
||||||
if (data.get () != MAP_FAILED)
|
if (data.get () != MAP_FAILED)
|
||||||
|
@ -491,7 +492,7 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pages == 0)
|
if (pages == 0)
|
||||||
return nullptr;
|
error (_("Failed to map trace buffer: %s."), safe_strerror (errno));
|
||||||
|
|
||||||
struct perf_event_mmap_page *header = (struct perf_event_mmap_page *)
|
struct perf_event_mmap_page *header = (struct perf_event_mmap_page *)
|
||||||
data.get ();
|
data.get ();
|
||||||
|
@ -509,7 +510,7 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf)
|
||||||
|
|
||||||
/* Check for overflows. */
|
/* Check for overflows. */
|
||||||
if ((__u64) size != data_size)
|
if ((__u64) size != data_size)
|
||||||
return nullptr;
|
error (_("Failed to determine trace buffer size."));
|
||||||
}
|
}
|
||||||
#endif /* defined (PERF_ATTR_SIZE_VER5) */
|
#endif /* defined (PERF_ATTR_SIZE_VER5) */
|
||||||
|
|
||||||
|
@ -528,21 +529,23 @@ linux_enable_bts (ptid_t ptid, const struct btrace_config_bts *conf)
|
||||||
|
|
||||||
#if defined (PERF_ATTR_SIZE_VER5)
|
#if defined (PERF_ATTR_SIZE_VER5)
|
||||||
|
|
||||||
/* Determine the event type.
|
/* Determine the event type. */
|
||||||
Returns zero on success and fills in TYPE; returns -1 otherwise. */
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
perf_event_pt_event_type (int *type)
|
perf_event_pt_event_type ()
|
||||||
{
|
{
|
||||||
gdb_file_up file =
|
static const char filename[] = "/sys/bus/event_source/devices/intel_pt/type";
|
||||||
gdb_fopen_cloexec ("/sys/bus/event_source/devices/intel_pt/type", "r");
|
|
||||||
if (file.get () == nullptr)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
int found = fscanf (file.get (), "%d", type);
|
errno = 0;
|
||||||
if (found == 1)
|
gdb_file_up file = gdb_fopen_cloexec (filename, "r");
|
||||||
return 0;
|
if (file.get () == nullptr)
|
||||||
return -1;
|
error (_("Failed to open %s: %s."), filename, safe_strerror (errno));
|
||||||
|
|
||||||
|
int type, found = fscanf (file.get (), "%d", &type);
|
||||||
|
if (found != 1)
|
||||||
|
error (_("Failed to read the PT event type from %s."), filename);
|
||||||
|
|
||||||
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable branch tracing in Intel Processor Trace format. */
|
/* Enable branch tracing in Intel Processor Trace format. */
|
||||||
|
@ -552,14 +555,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
|
||||||
{
|
{
|
||||||
struct btrace_tinfo_pt *pt;
|
struct btrace_tinfo_pt *pt;
|
||||||
size_t pages;
|
size_t pages;
|
||||||
int pid, pg, errcode, type;
|
int pid, pg;
|
||||||
|
|
||||||
if (conf->size == 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
errcode = perf_event_pt_event_type (&type);
|
|
||||||
if (errcode != 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
pid = ptid_get_lwp (ptid);
|
pid = ptid_get_lwp (ptid);
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
|
@ -573,7 +569,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
|
||||||
pt = &tinfo->variant.pt;
|
pt = &tinfo->variant.pt;
|
||||||
|
|
||||||
pt->attr.size = sizeof (pt->attr);
|
pt->attr.size = sizeof (pt->attr);
|
||||||
pt->attr.type = type;
|
pt->attr.type = perf_event_pt_event_type ();
|
||||||
|
|
||||||
pt->attr.exclude_kernel = 1;
|
pt->attr.exclude_kernel = 1;
|
||||||
pt->attr.exclude_hv = 1;
|
pt->attr.exclude_hv = 1;
|
||||||
|
@ -582,13 +578,13 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
|
||||||
errno = 0;
|
errno = 0;
|
||||||
scoped_fd fd (syscall (SYS_perf_event_open, &pt->attr, pid, -1, -1, 0));
|
scoped_fd fd (syscall (SYS_perf_event_open, &pt->attr, pid, -1, -1, 0));
|
||||||
if (fd.get () < 0)
|
if (fd.get () < 0)
|
||||||
return nullptr;
|
error (_("Failed to start recording: %s"), safe_strerror (errno));
|
||||||
|
|
||||||
/* Allocate the configuration page. */
|
/* Allocate the configuration page. */
|
||||||
scoped_mmap data (nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
|
scoped_mmap data (nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||||
fd.get (), 0);
|
fd.get (), 0);
|
||||||
if (data.get () == MAP_FAILED)
|
if (data.get () == MAP_FAILED)
|
||||||
return nullptr;
|
error (_("Failed to map trace user page: %s."), safe_strerror (errno));
|
||||||
|
|
||||||
struct perf_event_mmap_page *header = (struct perf_event_mmap_page *)
|
struct perf_event_mmap_page *header = (struct perf_event_mmap_page *)
|
||||||
data.get ();
|
data.get ();
|
||||||
|
@ -630,6 +626,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
|
||||||
|
|
||||||
header->aux_size = data_size;
|
header->aux_size = data_size;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
aux.reset (nullptr, length, PROT_READ, MAP_SHARED, fd.get (),
|
aux.reset (nullptr, length, PROT_READ, MAP_SHARED, fd.get (),
|
||||||
header->aux_offset);
|
header->aux_offset);
|
||||||
if (aux.get () != MAP_FAILED)
|
if (aux.get () != MAP_FAILED)
|
||||||
|
@ -637,7 +634,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pages == 0)
|
if (pages == 0)
|
||||||
return nullptr;
|
error (_("Failed to map trace buffer: %s."), safe_strerror (errno));
|
||||||
|
|
||||||
pt->pt.size = aux.size ();
|
pt->pt.size = aux.size ();
|
||||||
pt->pt.mem = (const uint8_t *) aux.release ();
|
pt->pt.mem = (const uint8_t *) aux.release ();
|
||||||
|
@ -656,8 +653,7 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
|
||||||
static struct btrace_target_info *
|
static struct btrace_target_info *
|
||||||
linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
|
linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
|
||||||
{
|
{
|
||||||
errno = EOPNOTSUPP;
|
error (_("Intel Processor Trace support was disabled at compile time."));
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !defined (PERF_ATTR_SIZE_VER5) */
|
#endif /* !defined (PERF_ATTR_SIZE_VER5) */
|
||||||
|
@ -667,27 +663,20 @@ linux_enable_pt (ptid_t ptid, const struct btrace_config_pt *conf)
|
||||||
struct btrace_target_info *
|
struct btrace_target_info *
|
||||||
linux_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
|
linux_enable_btrace (ptid_t ptid, const struct btrace_config *conf)
|
||||||
{
|
{
|
||||||
struct btrace_target_info *tinfo;
|
|
||||||
|
|
||||||
tinfo = NULL;
|
|
||||||
switch (conf->format)
|
switch (conf->format)
|
||||||
{
|
{
|
||||||
case BTRACE_FORMAT_NONE:
|
case BTRACE_FORMAT_NONE:
|
||||||
break;
|
error (_("Bad branch trace format."));
|
||||||
|
|
||||||
|
default:
|
||||||
|
error (_("Unknown branch trace format."));
|
||||||
|
|
||||||
case BTRACE_FORMAT_BTS:
|
case BTRACE_FORMAT_BTS:
|
||||||
tinfo = linux_enable_bts (ptid, &conf->bts);
|
return linux_enable_bts (ptid, &conf->bts);
|
||||||
break;
|
|
||||||
|
|
||||||
case BTRACE_FORMAT_PT:
|
case BTRACE_FORMAT_PT:
|
||||||
tinfo = linux_enable_pt (ptid, &conf->pt);
|
return linux_enable_pt (ptid, &conf->pt);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tinfo == NULL)
|
|
||||||
error (_("Unknown error."));
|
|
||||||
|
|
||||||
return tinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable BTS tracing. */
|
/* Disable BTS tracing. */
|
||||||
|
|
Loading…
Reference in New Issue