From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH v3 06/15] Write status to CTF and read.
Date: Sat, 09 Mar 2013 03:49:00 -0000 [thread overview]
Message-ID: <1362800844-27940-7-git-send-email-yao@codesourcery.com> (raw)
In-Reply-To: <1362800844-27940-1-git-send-email-yao@codesourcery.com>
This patch teaches GDB to write trace status to CTF and also read
trace status from CTF trace file.
gdb:
2013-03-08 Yao Qi <yao@codesourcery.com>
* ctf.c (CTF_EVENT_ID_STATUS, ctf_save_write_int32): New
macros.
(ctf_save_metadata_header): Define new type alias in
metadata.
(ctf_write_header): Start a new faked packet for trace status.
(ctf_write_status): Write trace status to CTF.
(ctf_write_definition_end): End the faked packet.
(start_pos): New variable.
(SET_INT32_FIELD): New macro.
(ctf_read_status): New.
(ctf_open): Skip the first faked packet and assert on some
event types.
(ctf_trace_find): Set the iterator to the beginning of packet
including trace frames, instead of the first packet.
(ctf_get_trace_status): New.
(init_ctf_ops): Install ctf_get_trace_status to field
'to_get_trace_status'.
---
gdb/ctf.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 120 insertions(+), 7 deletions(-)
diff --git a/gdb/ctf.c b/gdb/ctf.c
index ec35b17..7be9bb6 100644
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -34,7 +34,8 @@
1. The length (in bytes) of register cache. Event "register" will
be defined in metadata, which includes the length.
- 2. Trace status. Not implemented yet in CTF writer.
+ 2. Trace status. Event "status" is defined in metadata, which
+ includes all aspects of trace status.
3. Uploaded trace variables and tracepoints. Not implemented yet
in CTF writer.
@@ -65,6 +66,7 @@
#define CTF_EVENT_ID_TSV 1
#define CTF_EVENT_ID_MEMORY 2
#define CTF_EVENT_ID_FRAME 3
+#define CTF_EVENT_ID_STATUS 4
/* The state kept while writing the CTF datastream file. */
@@ -119,6 +121,12 @@ ctf_save_write (struct trace_write_handler *handler,
#define ctf_save_write_uint32(HANDLER, U32) \
ctf_save_write (HANDLER, (gdb_byte *) &U32, 4)
+/* Write a signed 32-bit integer to datastream file represented by
+ HANDLER. */
+
+#define ctf_save_write_int32(HANDLER, INT32) \
+ ctf_save_write (HANDLER, (gdb_byte *) &INT32, 4)
+
/* Set datastream file position. Update HANDLER->content_size
if WHENCE is SEEK_CUR. */
@@ -217,6 +225,9 @@ ctf_save_metadata_header (struct trace_write_handler *handler)
"typealias integer { size = 64; align = 64;"
"signed = false; base = hex;}"
" := uint64_t;\n");
+ ctf_save_write_metadata (handler,
+ "typealias integer { size = 32; align = 32;"
+ "signed = true; } := int32_t;\n");
ctf_save_write_metadata (handler, "\n");
ctf_save_write_metadata (handler, metadata_fmt,
@@ -343,6 +354,9 @@ ctf_write_header (struct trace_file_writer *self)
gdb_assert (writer->tcs.content_size == 0);
gdb_assert (writer->tcs.packet_start == 0);
+
+ /* Create a new packet to contain this event. */
+ self->ops->frame_ops->start (self, 0);
}
/* This is the implementation of trace_file_write_ops method
@@ -373,8 +387,39 @@ static void
ctf_write_status (struct trace_file_writer *self,
struct trace_status *ts)
{
- /* It is not supported yet to write trace status into CTF trace
- data. */
+ struct ctf_trace_file_writer *writer
+ = (struct ctf_trace_file_writer *) self;
+ uint32_t id;
+ int32_t int32;
+
+ ctf_save_write_metadata (&writer->tcs, "\n");
+ ctf_save_write_metadata (&writer->tcs,
+ "event {\n\tname = \"status\";\n\tid = %u;\n"
+ "\tfields := struct { \n"
+ "\t\tint32_t stop_reason;\n"
+ "\t\tint32_t stopping_tracepoint;\n"
+ "\t\tint32_t traceframe_count;\n"
+ "\t\tint32_t traceframes_created;\n"
+ "\t\tint32_t buffer_free;\n"
+ "\t\tint32_t buffer_size;\n"
+ "\t\tint32_t disconnected_tracing;\n"
+ "\t\tint32_t circular_buffer;\n"
+ "\t};\n"
+ "};\n",
+ CTF_EVENT_ID_STATUS);
+
+ id = CTF_EVENT_ID_STATUS;
+ /* Event Id. */
+ ctf_save_align_write (&writer->tcs, (gdb_byte *) &id, 4, 4);
+
+ ctf_save_write_int32 (&writer->tcs, ts->stop_reason);
+ ctf_save_write_int32 (&writer->tcs, ts->stopping_tracepoint);
+ ctf_save_write_int32 (&writer->tcs, ts->traceframe_count);
+ ctf_save_write_int32 (&writer->tcs, ts->traceframes_created);
+ ctf_save_write_int32 (&writer->tcs, ts->buffer_free);
+ ctf_save_write_int32 (&writer->tcs, ts->buffer_size);
+ ctf_save_write_int32 (&writer->tcs, ts->disconnected_tracing);
+ ctf_save_write_int32 (&writer->tcs, ts->circular_buffer);
}
/* This is the implementation of trace_file_write_ops method
@@ -405,7 +450,10 @@ ctf_write_uploaded_tp (struct trace_file_writer *self,
static void
ctf_write_definition_end (struct trace_file_writer *self)
{
- /* Nothing to do for CTF. */
+ struct ctf_trace_file_writer *writer
+ = (struct ctf_trace_file_writer *) self;
+
+ self->ops->frame_ops->end (self);
}
/* The minimal file size of data stream. It is required by
@@ -661,6 +709,9 @@ ctf_trace_file_writer_new (void)
/* The struct pointer for current CTF directory. */
static struct bt_context *ctx = NULL;
static struct bt_ctf_iter *ctf_iter = NULL;
+/* The position of the first packet containing trace frame. */
+struct bt_iter_pos *start_pos;
+
/* The name of CTF directory. */
static char *trace_dirname;
@@ -747,15 +798,66 @@ ctf_open_dir (char *dirname)
}
+#define SET_INT32_FIELD(EVENT, SCOPE, VAR, FIELD) \
+ VAR->FIELD = (int) bt_ctf_get_int64 (bt_ctf_get_field (EVENT, \
+ SCOPE, \
+ #FIELD))
+
+/* EVENT is the "status" event and TS is filled in. */
+
+static void
+ctf_read_status (struct bt_ctf_event *event, struct trace_status *ts)
+{
+ const struct bt_definition *scope
+ = bt_ctf_get_top_level_scope (event, BT_EVENT_FIELDS);
+
+ SET_INT32_FIELD (event, scope, ts, stop_reason);
+ SET_INT32_FIELD (event, scope, ts, stopping_tracepoint);
+ SET_INT32_FIELD (event, scope, ts, traceframe_count);
+ SET_INT32_FIELD (event, scope, ts, traceframes_created);
+ SET_INT32_FIELD (event, scope, ts, buffer_free);
+ SET_INT32_FIELD (event, scope, ts, buffer_size);
+ SET_INT32_FIELD (event, scope, ts, disconnected_tracing);
+ SET_INT32_FIELD (event, scope, ts, circular_buffer);
+}
+
static void
ctf_open (char *dirname, int from_tty)
{
+ struct bt_ctf_event *event;
+ uint32_t event_id;
+ const struct bt_definition *scope;
+
target_preopen (from_tty);
if (!dirname)
error (_("No CTF directory specified."));
ctf_open_dir (dirname);
+ /* Skip the first packet which about the trace status. The first
+ event is "frame". */
+ event = bt_ctf_iter_read_event (ctf_iter);
+ scope = bt_ctf_get_top_level_scope (event, BT_STREAM_EVENT_HEADER);
+ event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "id"));
+ gdb_assert (event_id == CTF_EVENT_ID_FRAME);
+ /* The second event is "status". */
+ gdb_assert (bt_iter_next (bt_ctf_get_iter (ctf_iter)) >= 0);
+ event = bt_ctf_iter_read_event (ctf_iter);
+ scope = bt_ctf_get_top_level_scope (event, BT_STREAM_EVENT_HEADER);
+ event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "id"));
+ gdb_assert (event_id == CTF_EVENT_ID_STATUS);
+ ctf_read_status (event, current_trace_status ());
+
+ /* The third event is "frame". A new packet. */
+ gdb_assert (bt_iter_next (bt_ctf_get_iter (ctf_iter)) >= 0);
+ event = bt_ctf_iter_read_event (ctf_iter);
+ scope = bt_ctf_get_top_level_scope (event, BT_STREAM_EVENT_HEADER);
+ event_id = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope, "id"));
+ gdb_assert (event_id == CTF_EVENT_ID_FRAME);
+
+ start_pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
+ gdb_assert (start_pos->type == BT_SEEK_RESTORE);
+
trace_dirname = xstrdup (dirname);
push_target (&ctf_ops);
}
@@ -1176,9 +1278,8 @@ ctf_trace_find (enum trace_find_type type, int num,
return -1;
}
- /* Set iterator back to the beginning. */
- pos.type = BT_SEEK_BEGIN;
- bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), &pos);
+ /* Set iterator back to the start. */
+ bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), start_pos);
while (1)
{
@@ -1347,6 +1448,17 @@ ctf_traceframe_info (void)
return info;
}
+/* The trace status for a file is that tracing can never be run. */
+
+static int
+ctf_get_trace_status (struct trace_status *ts)
+{
+ /* Other bits of trace status were collected as part of opening the
+ trace files, so nothing to do here. */
+
+ return -1;
+}
+
static void
init_ctf_ops (void)
{
@@ -1359,6 +1471,7 @@ Specify the filename of the CTF directory.";
ctf_ops.to_fetch_registers = ctf_fetch_registers;
ctf_ops.to_xfer_partial = ctf_xfer_partial;
ctf_ops.to_files_info = ctf_files_info;
+ ctf_ops.to_get_trace_status = ctf_get_trace_status;
ctf_ops.to_trace_find = ctf_trace_find;
ctf_ops.to_get_trace_state_variable_value
= ctf_get_trace_state_variable_value;
--
1.7.7.6
next prev parent reply other threads:[~2013-03-09 3:49 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-09 3:48 [PATCH v3 00/15] CTF Support Yao Qi
2013-03-09 3:49 ` [PATCH v3 05/15] ctf test: report.exp Yao Qi
2013-03-12 19:25 ` Tom Tromey
2013-03-09 3:49 ` [PATCH v3 14/15] Test on saving tracepoint defs: CTF Yao Qi
2013-03-12 20:23 ` Tom Tromey
2013-03-13 9:55 ` Yao Qi
2013-03-13 15:49 ` Tom Tromey
2013-03-09 3:49 ` [PATCH v3 15/15] MAINTAINERS Yao Qi
2013-03-09 3:49 ` [PATCH v3 12/15] Write tracepoint definition in CTF and read Yao Qi
2013-03-12 20:02 ` Tom Tromey
2013-03-14 18:34 ` Doug Evans
2013-03-09 3:49 ` [PATCH v3 10/15] tstatus.exp: ctf Yao Qi
2013-03-12 19:48 ` Tom Tromey
2013-03-09 3:49 ` [PATCH v3 02/15] Save trace into CTF format Yao Qi
2013-03-12 18:49 ` Tom Tromey
2013-03-13 10:33 ` Yao Qi
2013-03-13 19:30 ` Tom Tromey
2013-03-14 17:49 ` Doug Evans
2013-03-09 3:49 ` [PATCH v3 04/15] ctf doc and NEWS Yao Qi
2013-03-09 3:49 ` [PATCH v3 03/15] Read CTF by the ctf target Yao Qi
2013-03-13 20:09 ` Tom Tromey
2013-03-14 13:23 ` Yao Qi
2013-03-14 14:59 ` Tom Tromey
2013-03-14 16:57 ` Doug Evans
2013-03-14 17:39 ` Doug Evans
2013-03-25 13:33 ` Yao Qi
2013-03-25 17:14 ` Doug Evans
2013-03-26 16:16 ` Yao Qi
2013-03-29 17:56 ` Doug Evans
2013-04-08 14:19 ` Yao Qi
2013-04-08 21:48 ` Doug Evans
2013-04-09 15:23 ` Yao Qi
2013-04-09 18:41 ` Doug Evans
2013-03-09 3:49 ` [PATCH v3 13/15] Test on saving tracepoint defs Yao Qi
2013-03-12 20:10 ` Tom Tromey
2013-03-13 9:48 ` Yao Qi
2013-03-13 14:58 ` Tom Tromey
2013-03-09 3:49 ` Yao Qi [this message]
2013-03-12 19:31 ` [PATCH v3 06/15] Write status to CTF and read Tom Tromey
2013-03-14 18:06 ` Doug Evans
2013-03-29 14:46 ` Yao Qi
2013-03-29 16:47 ` Doug Evans
2013-03-09 3:49 ` [PATCH v3 11/15] Write tsv definition in " Yao Qi
2013-03-12 19:56 ` Tom Tromey
2013-03-09 3:49 ` [PATCH v3 01/15] Refactor 'tsave' Yao Qi
2013-03-12 18:30 ` Tom Tromey
2013-03-13 10:33 ` Yao Qi
2013-03-13 19:26 ` Tom Tromey
2013-03-14 9:17 ` Yao Qi
2013-03-09 3:49 ` [PATCH v3 08/15] Write 'stop_desc' of trace status to tfile Yao Qi
2013-03-12 19:15 ` Tom Tromey
2013-03-09 3:49 ` [PATCH v3 09/15] Check the tstatus output on tfile target Yao Qi
2013-03-12 19:45 ` Tom Tromey
2013-03-09 3:49 ` [PATCH v3 07/15] Write trace notes and username into tfile Yao Qi
2013-03-12 19:35 ` Tom Tromey
2013-04-10 19:16 ` [PATCH v3 00/15] CTF Support Yao Qi
2013-04-11 22:59 ` [patch] Regenerate config.in [Re: [PATCH v3 00/15] CTF Support] Jan Kratochvil
2013-04-12 22:27 ` [commit] " Jan Kratochvil
2014-08-04 18:59 ` Incorrect placement of babeltrace gdb/NEWS item " Jan Kratochvil
2014-08-06 1:30 ` Yao Qi
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=1362800844-27940-7-git-send-email-yao@codesourcery.com \
--to=yao@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/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