This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] store trace default-collect to target [3/6] tfile


On 04/11/2013 02:17 PM, Hui Zhu wrote:
>   /* This is the implementation of trace_file_write_ops method
> +   write_default_collect.  */
> +
> +static void
> +ctf_write_default_collect (struct trace_file_writer *self,
> +			   char *collect)
> +{
> +  /* It is not supported yet to write default collect
> +     into CTF trace data.  */
> +}
> +

It is pity to see "default-collect" is not written to CTF in this
patch.  The patch below is about teaching GDB to write
"default-collect" action in CTF and read "default-collect" action from
CTF.  Do you mind incorporating the patch below into your patch series,
so that your series is more complete.

-- 
Yao (éå)

gdb:

2013-04-11  Yao Qi  <yao@codesourcery.com>

	* ctf.c (CTF_EVENT_ID_DEFAULT_COLLECT): New macro.
	(ctf_write_header): Write metadata for "default-collect"
	action.
	(ctf_write_default_collect): Write "default-collect" action
	in CTF.
	(ctf_read_default_collect): New.
	(ctf_open): Call ctf_read_default_collect.
---
 gdb/ctf.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/gdb/ctf.c b/gdb/ctf.c
index 2dd2ed8..5757b47 100644
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -74,6 +74,7 @@
 #define CTF_EVENT_ID_STATUS 4
 #define CTF_EVENT_ID_TSV_DEF 5
 #define CTF_EVENT_ID_TP_DEF 6
+#define CTF_EVENT_ID_DEFAULT_COLLECT 7
 
 /* The state kept while writing the CTF datastream file.  */
 
@@ -428,6 +429,16 @@ ctf_write_header (struct trace_file_writer *self)
 			  "\t};\n"
 			  "};\n", CTF_EVENT_ID_TP_DEF);
 
+  ctf_save_write_metadata (&writer->tcs, "\n");
+  ctf_save_write_metadata (&writer->tcs,
+			   "event {\n\tname = \"default_collect\";\n"
+			   "\tid = %u;\n"
+			   "\tfields := struct { \n"
+			   "\t\tchars contents;\n"
+			   "\t};\n"
+			   "};\n",
+			   CTF_EVENT_ID_DEFAULT_COLLECT);
+
   gdb_assert (writer->tcs.content_size == 0);
   gdb_assert (writer->tcs.packet_start == 0);
 
@@ -622,8 +633,17 @@ static void
 ctf_write_default_collect (struct trace_file_writer *self,
 			   char *collect)
 {
-  /* It is not supported yet to write default collect
-     into CTF trace data.  */
+  struct ctf_trace_file_writer *writer
+    = (struct ctf_trace_file_writer *) self;
+  int32_t int32;
+
+  /* Event Id.  */
+  int32 = CTF_EVENT_ID_DEFAULT_COLLECT;
+  ctf_save_align_write (&writer->tcs, (gdb_byte *) &int32, 4, 4);
+
+  /* Contents.  */
+  ctf_save_write (&writer->tcs, collect, strlen (collect) + 1);
+
 }
 
 /* This is the implementation of trace_file_write_ops method
@@ -1149,6 +1169,39 @@ ctf_read_tp (struct uploaded_tp **uploaded_tps)
     }
 }
 
+/* Read a CTF event on "default-collect" and update the
+   "default-collect" action.  */
+
+static void
+ctf_read_default_collect (void)
+{
+  struct bt_ctf_event *event;
+  const struct bt_definition *scope;
+  uint32_t u32;
+  char *default_collect;
+
+  event = bt_ctf_iter_read_event (ctf_iter);
+  scope = bt_ctf_get_top_level_scope (event,
+				      BT_STREAM_EVENT_HEADER);
+  u32 = bt_ctf_get_uint64 (bt_ctf_get_field (event, scope,
+					     "id"));
+
+  if (u32 != CTF_EVENT_ID_DEFAULT_COLLECT)
+    error (_("Wrong event id!"));
+
+  default_collect
+    = bt_ctf_get_string (bt_ctf_get_field (event, scope, "contents"));
+
+  if (default_collect == NULL)
+    default_collect = xstrdup ("");
+  else
+    default_collect = xstrdup (default_collect);
+
+  trace_set_default_collect (default_collect);
+
+  bt_iter_next (bt_ctf_get_iter (ctf_iter));
+}
+
 /* This is the implementation of target_ops method to_open.  Open CTF
    trace data, read trace status, trace state variables and tracepoint
    definitions from the first packet.  Set the start position at the
@@ -1190,6 +1243,8 @@ ctf_open (char *dirname, int from_tty)
 
   ctf_read_tp (&uploaded_tps);
 
+  ctf_read_default_collect ();
+
   event = bt_ctf_iter_read_event (ctf_iter);
   /* EVENT can be NULL if we've already gone to the end of stream of
      events.  */
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]