Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH v3 11/15] Write tsv definition in CTF and read
Date: Sat, 09 Mar 2013 03:49:00 -0000	[thread overview]
Message-ID: <1362800844-27940-12-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 uploaded tsv to CTF, and also read
them out from CTF.

gdb:

2013-03-08  Yao Qi  <yao@codesourcery.com>

	* ctf.c (CTF_EVENT_ID_TSV_DEF): New macro.
	(ctf_save_metadata_header): Define new type alias in
	metadata.
	(ctf_write_header): Define new event type "tsv_def".
	(ctf_write_uploaded_tsv): Write TSV to CTF.
	(ctf_read_tsv): New.
	(ctf_open): Call ctf_read_tsv and
	merge_uploaded_trace_state_variables.
	* tracepoint.c (get_uploaded_tsv): Remove 'static'.
	* tracepoint.h (get_uploaded_tsv): Declare.
---
 gdb/ctf.c        |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 gdb/tracepoint.c |    2 +-
 gdb/tracepoint.h |    2 +
 3 files changed, 97 insertions(+), 6 deletions(-)

diff --git a/gdb/ctf.c b/gdb/ctf.c
index 7be9bb6..934ba10 100644
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -37,8 +37,9 @@
    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.
+   3. Uploaded trace variables.  Event "tsv_def" is defined in metata,
+   which is about all aspects of a uploaded trace variable.
+   Uploaded tracepoints.   Not implemented yet in CTF writer.
 
    4. Trace frames.  Each trace frame is composed by several blocks
    of different types ('R', 'M', 'V').  One trace frame is saved in
@@ -67,6 +68,7 @@
 #define CTF_EVENT_ID_MEMORY 2
 #define CTF_EVENT_ID_FRAME 3
 #define CTF_EVENT_ID_STATUS 4
+#define CTF_EVENT_ID_TSV_DEF 5
 
 /* The state kept while writing the CTF datastream file.  */
 
@@ -228,6 +230,12 @@ ctf_save_metadata_header (struct trace_write_handler *handler)
   ctf_save_write_metadata (handler,
 			   "typealias integer { size = 32; align = 32;"
 			   "signed = true; } := int32_t;\n");
+  ctf_save_write_metadata (handler,
+			   "typealias integer { size = 64; align = 64;"
+			   "signed = true; } := int64_t;\n");
+  ctf_save_write_metadata (handler,
+			   "typealias string { encoding = ascii;"
+			   " } := chars;\n");
   ctf_save_write_metadata (handler, "\n");
 
   ctf_save_write_metadata (handler, metadata_fmt,
@@ -352,6 +360,17 @@ ctf_write_header (struct trace_file_writer *self)
 			   "\t};\n"
 			   "};\n", CTF_EVENT_ID_FRAME);
 
+  ctf_save_write_metadata (&writer->tcs, "\n");
+  ctf_save_write_metadata (&writer->tcs,
+			  "event {\n\tname = \"tsv_def\";\n"
+			  "\tid = %u;\n\tfields := struct { \n"
+			  "\t\tint64_t initial_value;\n"
+			  "\t\tint32_t number;\n"
+			  "\t\tint32_t builtin;\n"
+			  "\t\tchars name;\n"
+			  "\t};\n"
+			  "};\n", CTF_EVENT_ID_TSV_DEF);
+
   gdb_assert (writer->tcs.content_size == 0);
   gdb_assert (writer->tcs.packet_start == 0);
 
@@ -429,8 +448,31 @@ static void
 ctf_write_uploaded_tsv (struct trace_file_writer *self,
 			struct uploaded_tsv *tsv)
 {
-  /* It is not supported yet to write uploaded trace variables
-     into CTF trace data.  */
+  struct ctf_trace_file_writer *writer
+    = (struct ctf_trace_file_writer *) self;
+  int32_t int32;
+  int64_t int64;
+  unsigned int len;
+  const gdb_byte zero = 0;
+
+  /* Event Id.  */
+  int32 = CTF_EVENT_ID_TSV_DEF;
+  ctf_save_align_write (&writer->tcs, (gdb_byte *) &int32, 4, 4);
+
+  /* initial_value */
+  int64 = tsv->initial_value;
+  ctf_save_align_write (&writer->tcs, (gdb_byte *) &int64, 8, 8);
+
+  /* number */
+  ctf_save_write_int32 (&writer->tcs, tsv->number);
+
+  /* builtin */
+  ctf_save_write_int32 (&writer->tcs, tsv->builtin);
+
+  /* name */
+  if (tsv->name != NULL)
+    ctf_save_write (&writer->tcs, tsv->name, strlen (tsv->name));
+  ctf_save_write (&writer->tcs, &zero, 1);
 }
 
 /* This is the implementation of trace_file_write_ops method
@@ -821,12 +863,56 @@ ctf_read_status (struct bt_ctf_event *event, struct trace_status *ts)
   SET_INT32_FIELD (event, scope, ts, circular_buffer);
 }
 
+/* Read the events "tsv_def" one by one, extract its contents and fill
+   in the list UPLOADED_TSVS.  */
+
+static void
+ctf_read_tsv (struct uploaded_tsv **uploaded_tsvs)
+{
+  while (1)
+    {
+      struct bt_ctf_event *event;
+      const struct bt_definition *scope;
+      const struct bt_definition *def;
+      uint32_t event_id;
+      struct uploaded_tsv *utsv = NULL;
+
+      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"));
+      if (event_id != CTF_EVENT_ID_TSV_DEF)
+	break;
+
+      scope = bt_ctf_get_top_level_scope (event,
+					  BT_EVENT_FIELDS);
+
+      def = bt_ctf_get_field (event, scope, "number");
+      utsv = get_uploaded_tsv ((int32_t) bt_ctf_get_int64 (def),
+			       uploaded_tsvs);
+
+      def = bt_ctf_get_field (event, scope, "builtin");
+      utsv->builtin = (int32_t) bt_ctf_get_int64 (def);
+      def = bt_ctf_get_field (event, scope, "initial_value");
+      utsv->initial_value = bt_ctf_get_int64 (def);
+
+      def = bt_ctf_get_field (event, scope, "name");
+      utsv->name =  xstrdup (bt_ctf_get_string (def));
+
+      if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
+	break;
+    }
+
+}
+
 static void
 ctf_open (char *dirname, int from_tty)
 {
   struct bt_ctf_event *event;
   uint32_t event_id;
   const struct bt_definition *scope;
+  struct uploaded_tsv *uploaded_tsvs = NULL;
 
   target_preopen (from_tty);
   if (!dirname)
@@ -848,8 +934,9 @@ ctf_open (char *dirname, int from_tty)
   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);
+  ctf_read_tsv (&uploaded_tsvs);
+
   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"));
@@ -860,6 +947,8 @@ ctf_open (char *dirname, int from_tty)
 
   trace_dirname = xstrdup (dirname);
   push_target (&ctf_ops);
+
+  merge_uploaded_trace_state_variables (&uploaded_tsvs);
 }
 
 static void
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 850adb9..3656767 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -3798,7 +3798,7 @@ free_uploaded_tps (struct uploaded_tp **utpp)
 /* Given a number and address, return an uploaded tracepoint with that
    number, creating if necessary.  */
 
-static struct uploaded_tsv *
+struct uploaded_tsv *
 get_uploaded_tsv (int num, struct uploaded_tsv **utsvp)
 {
   struct uploaded_tsv *utsv;
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
index 8762d1c..765f455 100644
--- a/gdb/tracepoint.h
+++ b/gdb/tracepoint.h
@@ -378,6 +378,8 @@ extern void parse_tsv_definition (char *line, struct uploaded_tsv **utsvp);
 
 extern struct uploaded_tp *get_uploaded_tp (int num, ULONGEST addr,
 					    struct uploaded_tp **utpp);
+extern struct uploaded_tsv *get_uploaded_tsv (int num,
+					      struct uploaded_tsv **utsvp);
 extern struct tracepoint *create_tracepoint_from_upload (struct uploaded_tp *utp);
 extern void merge_uploaded_tracepoints (struct uploaded_tp **utpp);
 extern void merge_uploaded_trace_state_variables (struct uploaded_tsv **utsvp);
-- 
1.7.7.6


  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 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 05/15] ctf test: report.exp Yao Qi
2013-03-12 19:25   ` Tom Tromey
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 04/15] ctf doc and NEWS 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 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 ` [PATCH v3 06/15] Write status to CTF and read Yao Qi
2013-03-12 19:31   ` 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 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 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 07/15] Write trace notes and username into tfile Yao Qi
2013-03-12 19:35   ` 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 ` Yao Qi [this message]
2013-03-12 19:56   ` [PATCH v3 11/15] Write tsv definition in CTF and read 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-12-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