This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 02/12] btrace: add format argument to supports_btrace
- From: Markus Metzger <markus dot t dot metzger at intel dot com>
- To: palves at redhat dot com
- Cc: gdb-patches at sourceware dot org
- Date: Mon, 14 Jul 2014 15:56:26 +0200
- Subject: [PATCH 02/12] btrace: add format argument to supports_btrace
- Authentication-results: sourceware.org; auth=none
- References: <1405346196-1804-1-git-send-email-markus dot t dot metzger at intel dot com>
Add a format argument to the various supports_btrace functions to check
for support of a specific btrace format. This is to prepare for a new
format.
Removed two redundant calls. The check will be made in the subsequent
btrace_enable call.
Moved declarations in btrace-common.h around to break a cyclic dependency
with gdbserver/server.h.
2014-07-14 Markus Metzger <markus.t.metzger@intel.com>
* btrace.c (btrace_enable): Pass BTRACE_FORMAT_BTS.
* common/btrace-common.h (btrace_format, btrace_target_info)
(btrace_read_type, btrace_error): Move.
* common/linux-btrace.c
(kernel_supports_btrace): Rename into ...
(kernel_supports_bts): ... this. Update users. Update warning text.
(intel_supports_btrace): Rename into ...
(intel_supports_bts): ... this. Update users.
(cpu_supports_btrace): Rename into ...
(cpu_supports_bts): ... this. Update users.
(linux_supports_btrace): Update parameters. Split into this and ...
(linux_supports_bts): ... this.
* common/linux-btrace.h (linux_supports_btrace): Update parameters.
* record-btrace.c (record_btrace_open): Remove call to
target_supports_btrace.
* remote.c (remote_supports_btrace): Update parameters.
* target.c (target_supports_btrace): Update parameters.
* target.h (to_supports_btrace, target_supports_btrace): Update
parameters.
* target-delegates.c: Regenerate.
gdbserver/
* server.c (handle_btrace_general_set): Remove call to
target_supports_btrace.
(supported_btrace_packets): New.
(handle_query): Call supported_btrace_packets.
* target.h: include btrace-common.h.
(btrace_target_info): Removed.
(supports_btrace, target_supports_btrace): Update parameters.
---
gdb/btrace.c | 2 +-
gdb/common/btrace-common.h | 94 +++++++++++++++++++++++-----------------------
gdb/gdbserver/server.c | 27 +++++++------
gdb/gdbserver/target.h | 8 ++--
gdb/nat/linux-btrace.c | 57 ++++++++++++++++++----------
gdb/nat/linux-btrace.h | 2 +-
gdb/record-btrace.c | 3 --
gdb/remote.c | 15 ++++++--
gdb/target-delegates.c | 6 +--
gdb/target.c | 8 ++++
gdb/target.h | 5 +--
11 files changed, 130 insertions(+), 97 deletions(-)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 567cc8c..7b6b828 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -731,7 +731,7 @@ btrace_enable (struct thread_info *tp)
if (tp->btrace.target != NULL)
return;
- if (!target_supports_btrace ())
+ if (!target_supports_btrace (BTRACE_FORMAT_BTS))
error (_("Target does not support branch tracing."));
DEBUG ("enable thread %d (%s)", tp->num, target_pid_to_str (tp->ptid));
diff --git a/gdb/common/btrace-common.h b/gdb/common/btrace-common.h
index d5f013c..a28dfff 100644
--- a/gdb/common/btrace-common.h
+++ b/gdb/common/btrace-common.h
@@ -26,6 +26,54 @@
inferior. For presentation purposes, the branch trace is represented as a
list of sequential control-flow blocks, one such list per thread. */
+
+/* Enumeration of btrace formats. */
+
+enum btrace_format
+{
+ /* No branch trace format. */
+ BTRACE_FORMAT_NONE,
+
+ /* Branch trace is in Branch Trace Store format.
+ Actually, the format is a sequence of blocks derived from BTS. */
+ BTRACE_FORMAT_BTS
+};
+
+/* Target specific branch trace information. */
+struct btrace_target_info;
+
+/* Enumeration of btrace read types. */
+
+enum btrace_read_type
+{
+ /* Send all available trace. */
+ BTRACE_READ_ALL,
+
+ /* Send all available trace, if it changed. */
+ BTRACE_READ_NEW,
+
+ /* Send the trace since the last request. This will fail if the trace
+ buffer overflowed. */
+ BTRACE_READ_DELTA
+};
+
+/* Enumeration of btrace errors. */
+
+enum btrace_error
+{
+ /* No error. Everything is OK. */
+ BTRACE_ERR_NONE,
+
+ /* An unknown error. */
+ BTRACE_ERR_UNKNOWN,
+
+ /* Branch tracing is not supported on this system. */
+ BTRACE_ERR_NOT_SUPPORTED,
+
+ /* The branch trace buffer overflowed; no delta read possible. */
+ BTRACE_ERR_OVERFLOW
+};
+
#ifdef GDBSERVER
# include "server.h"
#else
@@ -55,18 +103,6 @@ struct btrace_block
typedef struct btrace_block btrace_block_s;
DEF_VEC_O (btrace_block_s);
-/* Enumeration of btrace formats. */
-
-enum btrace_format
-{
- /* No branch trace format. */
- BTRACE_FORMAT_NONE,
-
- /* Branch trace is in Branch Trace Store format.
- Actually, the format is a sequence of blocks derived from BTS. */
- BTRACE_FORMAT_BTS
-};
-
/* Branch trace in BTS format. */
struct btrace_data_bts
{
@@ -87,40 +123,6 @@ struct btrace_data
} variant;
};
-/* Target specific branch trace information. */
-struct btrace_target_info;
-
-/* Enumeration of btrace read types. */
-
-enum btrace_read_type
-{
- /* Send all available trace. */
- BTRACE_READ_ALL,
-
- /* Send all available trace, if it changed. */
- BTRACE_READ_NEW,
-
- /* Send the trace since the last request. This will fail if the trace
- buffer overflowed. */
- BTRACE_READ_DELTA
-};
-
-/* Enumeration of btrace errors. */
-
-enum btrace_error
-{
- /* No error. Everything is OK. */
- BTRACE_ERR_NONE,
-
- /* An unknown error. */
- BTRACE_ERR_UNKNOWN,
-
- /* Branch tracing is not supported on this system. */
- BTRACE_ERR_NOT_SUPPORTED,
-
- /* The branch trace buffer overflowed; no delta read possible. */
- BTRACE_ERR_OVERFLOW
-};
/* Return a string representation of FORMAT. */
extern const char *btrace_format_string (enum btrace_format format);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index cf1dffe..146d95f 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -443,12 +443,6 @@ handle_btrace_general_set (char *own_buf)
op = own_buf + strlen ("Qbtrace:");
- if (!target_supports_btrace ())
- {
- strcpy (own_buf, "E.Target does not support branch tracing.");
- return -1;
- }
-
if (ptid_equal (general_thread, null_ptid)
|| ptid_equal (general_thread, minus_one_ptid))
{
@@ -1709,6 +1703,20 @@ crc32 (CORE_ADDR base, int len, unsigned int crc)
return (unsigned long long) crc;
}
+/* Add supported btrace packets to BUF. */
+
+static void
+supported_btrace_packets (char *buf)
+{
+ if (target_supports_btrace (BTRACE_FORMAT_BTS))
+ strcat (buf, ";Qbtrace:bts+");
+ else
+ return;
+
+ strcat (buf, ";Qbtrace:off+");
+ strcat (buf, ";qXfer:btrace:read+");
+}
+
/* Handle all of the extended 'q' packets. */
void
@@ -1940,12 +1948,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
if (target_supports_agent ())
strcat (own_buf, ";QAgent+");
- if (target_supports_btrace ())
- {
- strcat (own_buf, ";Qbtrace:bts+");
- strcat (own_buf, ";Qbtrace:off+");
- strcat (own_buf, ";qXfer:btrace:read+");
- }
+ supported_btrace_packets (own_buf);
return;
}
diff --git a/gdb/gdbserver/target.h b/gdb/gdbserver/target.h
index f5eda8a..b9aa00b 100644
--- a/gdb/gdbserver/target.h
+++ b/gdb/gdbserver/target.h
@@ -25,9 +25,9 @@
#include "target/wait.h"
#include "target/waitstatus.h"
#include "mem-break.h"
+#include "btrace-common.h"
struct emit_ops;
-struct btrace_target_info;
struct buffer;
struct process_info;
@@ -357,7 +357,7 @@ struct target_ops
int (*supports_agent) (void);
/* Check whether the target supports branch tracing. */
- int (*supports_btrace) (struct target_ops *);
+ int (*supports_btrace) (struct target_ops *, enum btrace_format);
/* Enable branch tracing for @ptid and allocate a branch trace target
information struct for reading and for disabling branch trace. */
@@ -498,9 +498,9 @@ int kill_inferior (int);
(the_target->supports_agent ? \
(*the_target->supports_agent) () : 0)
-#define target_supports_btrace() \
+#define target_supports_btrace(format) \
(the_target->supports_btrace \
- ? (*the_target->supports_btrace) (the_target) : 0)
+ ? (*the_target->supports_btrace) (the_target, format) : 0)
#define target_enable_btrace(ptid) \
(*the_target->enable_btrace) (ptid)
diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index 7ec5815..20b4ef0 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -262,10 +262,10 @@ perf_event_read_bts (struct btrace_target_info* tinfo, const uint8_t *begin,
return btrace;
}
-/* Check whether the kernel supports branch tracing. */
+/* Check whether the kernel supports BTS. */
static int
-kernel_supports_btrace (void)
+kernel_supports_bts (void)
{
struct perf_event_attr attr;
pid_t child, pid;
@@ -276,14 +276,14 @@ kernel_supports_btrace (void)
switch (child)
{
case -1:
- warning (_("test branch tracing: cannot fork: %s."), strerror (errno));
+ warning (_("test bts: cannot fork: %s."), strerror (errno));
return 0;
case 0:
status = ptrace (PTRACE_TRACEME, 0, NULL, NULL);
if (status != 0)
{
- warning (_("test branch tracing: cannot PTRACE_TRACEME: %s."),
+ warning (_("test bts: cannot PTRACE_TRACEME: %s."),
strerror (errno));
_exit (1);
}
@@ -291,7 +291,7 @@ kernel_supports_btrace (void)
status = raise (SIGTRAP);
if (status != 0)
{
- warning (_("test branch tracing: cannot raise SIGTRAP: %s."),
+ warning (_("test bts: cannot raise SIGTRAP: %s."),
strerror (errno));
_exit (1);
}
@@ -302,14 +302,14 @@ kernel_supports_btrace (void)
pid = waitpid (child, &status, 0);
if (pid != child)
{
- warning (_("test branch tracing: bad pid %ld, error: %s."),
+ warning (_("test bts: bad pid %ld, error: %s."),
(long) pid, strerror (errno));
return 0;
}
if (!WIFSTOPPED (status))
{
- warning (_("test branch tracing: expected stop. status: %d."),
+ warning (_("test bts: expected stop. status: %d."),
status);
return 0;
}
@@ -334,10 +334,10 @@ kernel_supports_btrace (void)
pid = waitpid (child, &status, 0);
if (pid != child)
{
- warning (_("test branch tracing: bad pid %ld, error: %s."),
+ warning (_("test bts: bad pid %ld, error: %s."),
(long) pid, strerror (errno));
if (!WIFSIGNALED (status))
- warning (_("test branch tracing: expected killed. status: %d."),
+ warning (_("test bts: expected killed. status: %d."),
status);
}
@@ -345,10 +345,10 @@ kernel_supports_btrace (void)
}
}
-/* Check whether an Intel cpu supports branch tracing. */
+/* Check whether an Intel cpu supports BTS. */
static int
-intel_supports_btrace (void)
+intel_supports_bts (void)
{
unsigned int cpuid, model, family;
@@ -386,10 +386,10 @@ intel_supports_btrace (void)
return 1;
}
-/* Check whether the cpu supports branch tracing. */
+/* Check whether the cpu supports BTS. */
static int
-cpu_supports_btrace (void)
+cpu_supports_bts (void)
{
unsigned int ebx, ecx, edx;
@@ -398,24 +398,24 @@ cpu_supports_btrace (void)
if (ebx == signature_INTEL_ebx && ecx == signature_INTEL_ecx
&& edx == signature_INTEL_edx)
- return intel_supports_btrace ();
+ return intel_supports_bts ();
/* Don't know about others. Let's assume they do. */
return 1;
}
-/* See linux-btrace.h. */
+/* Check whether the linux target supports BTS. */
-int
-linux_supports_btrace (struct target_ops *ops)
+static int
+linux_supports_bts (void)
{
static int cached;
if (cached == 0)
{
- if (!kernel_supports_btrace ())
+ if (!kernel_supports_bts ())
cached = -1;
- else if (!cpu_supports_btrace ())
+ else if (!cpu_supports_bts ())
cached = -1;
else
cached = 1;
@@ -426,6 +426,23 @@ linux_supports_btrace (struct target_ops *ops)
/* See linux-btrace.h. */
+int
+linux_supports_btrace (struct target_ops *ops, enum btrace_format format)
+{
+ switch (format)
+ {
+ case BTRACE_FORMAT_NONE:
+ return 0;
+
+ case BTRACE_FORMAT_BTS:
+ return linux_supports_bts ();
+ }
+
+ internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
+}
+
+/* See linux-btrace.h. */
+
struct btrace_target_info *
linux_enable_btrace (ptid_t ptid)
{
@@ -616,7 +633,7 @@ linux_read_btrace (struct btrace_data *btrace,
/* See linux-btrace.h. */
int
-linux_supports_btrace (struct target_ops *ops)
+linux_supports_btrace (struct target_ops *ops, enum btrace_format format)
{
return 0;
}
diff --git a/gdb/nat/linux-btrace.h b/gdb/nat/linux-btrace.h
index 5d713f4..7b02db5 100644
--- a/gdb/nat/linux-btrace.h
+++ b/gdb/nat/linux-btrace.h
@@ -62,7 +62,7 @@ struct btrace_target_info
};
/* See to_supports_btrace in target.h. */
-extern int linux_supports_btrace (struct target_ops *);
+extern int linux_supports_btrace (struct target_ops *, enum btrace_format);
/* See to_enable_btrace in target.h. */
extern struct btrace_target_info *linux_enable_btrace (ptid_t ptid);
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 5ba4e06..9715e8a 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -200,9 +200,6 @@ record_btrace_open (char *args, int from_tty)
if (!target_has_execution)
error (_("The program is not being run."));
- if (!target_supports_btrace ())
- error (_("Target does not support branch tracing."));
-
if (non_stop)
error (_("Record btrace can't debug inferior in non-stop mode."));
diff --git a/gdb/remote.c b/gdb/remote.c
index 1a390b9..aa2db4f 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -11244,16 +11244,23 @@ struct btrace_target_info
/* Check whether the target supports branch tracing. */
static int
-remote_supports_btrace (struct target_ops *self)
+remote_supports_btrace (struct target_ops *self, enum btrace_format format)
{
if (packet_support (PACKET_Qbtrace_off) != PACKET_ENABLE)
return 0;
- if (packet_support (PACKET_Qbtrace_bts) != PACKET_ENABLE)
- return 0;
if (packet_support (PACKET_qXfer_btrace) != PACKET_ENABLE)
return 0;
- return 1;
+ switch (format)
+ {
+ case BTRACE_FORMAT_NONE:
+ return 0;
+
+ case BTRACE_FORMAT_BTS:
+ return (packet_support (PACKET_Qbtrace_bts) == PACKET_ENABLE);
+ }
+
+ internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
}
/* Enable branch tracing. */
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index 5971ec2..0cbd382 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -1359,14 +1359,14 @@ tdefault_can_use_agent (struct target_ops *self)
}
static int
-delegate_supports_btrace (struct target_ops *self)
+delegate_supports_btrace (struct target_ops *self, enum btrace_format arg1)
{
self = self->beneath;
- return self->to_supports_btrace (self);
+ return self->to_supports_btrace (self, arg1);
}
static int
-tdefault_supports_btrace (struct target_ops *self)
+tdefault_supports_btrace (struct target_ops *self, enum btrace_format arg1)
{
return 0;
}
diff --git a/gdb/target.c b/gdb/target.c
index 52858a9..635dde0 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3400,6 +3400,14 @@ target_ranged_break_num_registers (void)
/* See target.h. */
+int
+target_supports_btrace (enum btrace_format format)
+{
+ return current_target.to_supports_btrace (¤t_target, format);
+}
+
+/* See target.h. */
+
struct btrace_target_info *
target_enable_btrace (ptid_t ptid)
{
diff --git a/gdb/target.h b/gdb/target.h
index 8b0282f..cc1a094 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -985,7 +985,7 @@ struct target_ops
TARGET_DEFAULT_RETURN (0);
/* Check whether the target supports branch tracing. */
- int (*to_supports_btrace) (struct target_ops *)
+ int (*to_supports_btrace) (struct target_ops *, enum btrace_format)
TARGET_DEFAULT_RETURN (0);
/* Enable branch tracing for PTID and allocate a branch trace target
@@ -2200,8 +2200,7 @@ extern void update_target_permissions (void);
/* Imported from machine dependent code. */
/* See to_supports_btrace in struct target_ops. */
-#define target_supports_btrace() \
- (current_target.to_supports_btrace (¤t_target))
+extern int target_supports_btrace (enum btrace_format);
/* See to_enable_btrace in struct target_ops. */
extern struct btrace_target_info *target_enable_btrace (ptid_t ptid);
--
1.8.3.1