From: Markus Metzger <markus.t.metzger@intel.com>
To: palves@redhat.com
Cc: gdb-patches@sourceware.org
Subject: [PATCH 4/5] btrace: store raw btrace data
Date: Tue, 23 Jun 2015 08:22:00 -0000 [thread overview]
Message-ID: <1435047418-21611-5-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1435047418-21611-1-git-send-email-markus.t.metzger@intel.com>
Store the raw branch trace data that has been read from the target.
This data can be used for maintenance commands as well as for generating
a core file for the "record save" command.
2015-06-23 Markus Metzger <markus.t.metzger@intel.com>
* btrace.c (btrace_fetch): Append the new trace data.
(btrace_clear): Clear the stored trace data.
* btrace.h (btrace_thread_info) <data>: New.
* common/btrace-common.h (btrace_data_clear)
(btrace_data_append): New.
* common/btrace-common.c (btrace_data_clear)
(btrace_data_append): New.
---
gdb/btrace.c | 5 +++
gdb/btrace.h | 3 ++
gdb/common/btrace-common.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++
gdb/common/btrace-common.h | 9 +++++
4 files changed, 104 insertions(+)
diff --git a/gdb/btrace.c b/gdb/btrace.c
index d3cdd19..561ccd6 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1249,6 +1249,10 @@ btrace_fetch (struct thread_info *tp)
/* Compute the trace, provided we have any. */
if (!btrace_data_empty (&btrace))
{
+ /* Store the raw trace data. The stored data will be cleared in
+ btrace_clear, so we always append the new trace. */
+ btrace_data_append (&btinfo->data, &btrace);
+
btrace_clear_history (btinfo);
btrace_compute_ftrace (tp, &btrace);
}
@@ -1285,6 +1289,7 @@ btrace_clear (struct thread_info *tp)
btinfo->end = NULL;
btinfo->ngaps = 0;
+ btrace_data_clear (&btinfo->data);
btrace_clear_history (btinfo);
}
diff --git a/gdb/btrace.h b/gdb/btrace.h
index c25dc84..0845b78 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -248,6 +248,9 @@ struct btrace_thread_info
the underlying architecture. */
struct btrace_target_info *target;
+ /* The raw branch trace data for the below branch trace. */
+ struct btrace_data data;
+
/* The current branch trace for this thread (both inclusive).
The last instruction of END is the current instruction, which is not
diff --git a/gdb/common/btrace-common.c b/gdb/common/btrace-common.c
index 676428e..95193eb 100644
--- a/gdb/common/btrace-common.c
+++ b/gdb/common/btrace-common.c
@@ -91,3 +91,90 @@ btrace_data_empty (struct btrace_data *data)
internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
}
+
+/* See btrace-common.h. */
+
+void
+btrace_data_clear (struct btrace_data *data)
+{
+ btrace_data_fini (data);
+ btrace_data_init (data);
+}
+
+/* See btrace-common.h. */
+
+int
+btrace_data_append (struct btrace_data *dst,
+ const struct btrace_data *src)
+{
+ switch (src->format)
+ {
+ case BTRACE_FORMAT_NONE:
+ return 0;
+
+ case BTRACE_FORMAT_BTS:
+ switch (dst->format)
+ {
+ default:
+ return -1;
+
+ case BTRACE_FORMAT_NONE:
+ dst->format = BTRACE_FORMAT_BTS;
+ dst->variant.bts.blocks = NULL;
+
+ /* Fall-through. */
+ case BTRACE_FORMAT_BTS:
+ {
+ unsigned int blk;
+
+ /* We copy blocks in reverse order to have the oldest block at
+ index zero. */
+ blk = VEC_length (btrace_block_s, src->variant.bts.blocks);
+ while (blk != 0)
+ {
+ btrace_block_s *block;
+
+ block = VEC_index (btrace_block_s, src->variant.bts.blocks,
+ --blk);
+
+ VEC_safe_push (btrace_block_s, dst->variant.bts.blocks, block);
+ }
+ }
+ }
+ return 0;
+
+ case BTRACE_FORMAT_PT:
+ switch (dst->format)
+ {
+ default:
+ return -1;
+
+ case BTRACE_FORMAT_NONE:
+ dst->format = BTRACE_FORMAT_PT;
+ dst->variant.pt.data = NULL;
+ dst->variant.pt.size = 0;
+
+ /* fall-through. */
+ case BTRACE_FORMAT_BTS:
+ {
+ gdb_byte *data;
+ unsigned long size;
+
+ size = src->variant.pt.size + dst->variant.pt.size;
+ data = xmalloc (size);
+
+ memcpy (data, dst->variant.pt.data, dst->variant.pt.size);
+ memcpy (data + dst->variant.pt.size, src->variant.pt.data,
+ src->variant.pt.size);
+
+ xfree (dst->variant.pt.data);
+
+ dst->variant.pt.data = data;
+ dst->variant.pt.size = size;
+ }
+ }
+ return 0;
+ }
+
+ internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
+}
diff --git a/gdb/common/btrace-common.h b/gdb/common/btrace-common.h
index ebae17e..f22efc5 100644
--- a/gdb/common/btrace-common.h
+++ b/gdb/common/btrace-common.h
@@ -214,7 +214,16 @@ extern void btrace_data_init (struct btrace_data *data);
/* Cleanup DATA. */
extern void btrace_data_fini (struct btrace_data *data);
+/* Clear DATA. */
+extern void btrace_data_clear (struct btrace_data *data);
+
/* Return non-zero if DATA is empty; zero otherwise. */
extern int btrace_data_empty (struct btrace_data *data);
+/* Append the branch trace data from SRC to the end of DST.
+ Both SRC and DST must use the same format.
+ Returns zero on success; a negative number otherwise. */
+extern int btrace_data_append (struct btrace_data *dst,
+ const struct btrace_data *src);
+
#endif /* BTRACE_COMMON_H */
--
1.8.3.1
next prev parent reply other threads:[~2015-06-23 8:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-23 8:22 [PATCH 0/5] Support Intel(R) Processor Trace Markus Metzger
2015-06-23 8:22 ` [PATCH 1/5] configure: check for libipt Markus Metzger
2015-06-30 12:56 ` Pedro Alves
2015-06-30 14:54 ` Metzger, Markus T
2015-06-30 15:01 ` Pedro Alves
2015-06-23 8:22 ` [PATCH 3/5] btrace, linux: use data_size and data_offset Markus Metzger
2015-06-30 12:56 ` Pedro Alves
2015-06-23 8:22 ` [PATCH 5/5] btrace: maintenance commands Markus Metzger
2015-06-23 15:28 ` Eli Zaretskii
2015-06-24 7:05 ` Metzger, Markus T
2015-06-24 14:38 ` Eli Zaretskii
2015-06-30 12:57 ` Pedro Alves
2015-06-23 8:22 ` Markus Metzger [this message]
2015-06-30 12:56 ` [PATCH 4/5] btrace: store raw btrace data Pedro Alves
2015-06-23 8:23 ` [PATCH 2/5] btrace: support Intel(R) Processor Trace Markus Metzger
2015-06-23 15:32 ` Eli Zaretskii
2015-06-30 12:56 ` Pedro Alves
2015-06-30 14:54 ` Metzger, Markus T
2015-06-30 15:08 ` Pedro Alves
2015-07-01 8:39 ` Metzger, Markus T
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1435047418-21611-5-git-send-email-markus.t.metzger@intel.com \
--to=markus.t.metzger@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).