]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Get trace_regblock_size from metadata instead of event
authorYao Qi <yao@codesourcery.com>
Sat, 19 Apr 2014 02:14:58 +0000 (10:14 +0800)
committerYao Qi <yao@codesourcery.com>
Sat, 19 Apr 2014 06:05:48 +0000 (14:05 +0800)
In ctf trace, for each 'R' block, we save it as a "register" event,
as defined below in metadata.

event {
        name = "register";
        id = 0;
        fields := struct {
                ascii contents[440];
        };
}

Nowadays, we initialize trace_regblock_size by getting the length of
"contents" from a "register" event.  However, 'R' block may not exist
in traceframe, as a result, "register" event doesn't exist in trace file
and trace_regblock_size isn't set.

This patch changes to get trace_regblock_size from metadata (or declaration)
which always exists.

gdb:

2014-04-19  Yao Qi  <yao@codesourcery.com>

* ctf.c (handle_id): New static variable.
(ctf_open_dir): Get handle_id from bt_context_add_trace return
value.  Get the declaration of event "register" and get length
of field "contents".

gdb/ChangeLog
gdb/ctf.c

index 2d2b839888e972cce44fc98cd8e92efbb6dfb7fe..6bc9d879b5499b5e9b4fac85d7974083a3b4b282 100644 (file)
@@ -1,3 +1,10 @@
+2014-04-19  Yao Qi  <yao@codesourcery.com>
+
+       * ctf.c (handle_id): New static variable.
+       (ctf_open_dir): Get handle_id from bt_context_add_trace return
+       value.  Get the declaration of event "register" and get length
+       of field "contents".
+
 2014-04-19  Yao Qi  <yao@codesourcery.com>
 
        * ctf.c (ctf_xfer_partial): Check 'name' is NULL before strcmp.
index b684a3603f307d9ea9df8c2b42c621f0521ac5ab..2206e042614fd1e0847f89aa2e398147266bcd04 100644 (file)
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -873,6 +873,7 @@ ctf_trace_file_writer_new (void)
 #include <babeltrace/ctf/iterator.h>
 
 /* The struct pointer for current CTF directory.  */
+static int handle_id = -1;
 static struct bt_context *ctx = NULL;
 static struct bt_ctf_iter *ctf_iter = NULL;
 /* The position of the first packet containing trace frame.  */
@@ -905,15 +906,16 @@ ctf_destroy (void)
 static void
 ctf_open_dir (char *dirname)
 {
-  int ret;
   struct bt_iter_pos begin_pos;
   struct bt_iter_pos *pos;
+  unsigned int count, i;
+  struct bt_ctf_event_decl * const *list;
 
   ctx = bt_context_create ();
   if (ctx == NULL)
     error (_("Unable to create bt_context"));
-  ret = bt_context_add_trace (ctx, dirname, "ctf", NULL, NULL, NULL);
-  if (ret < 0)
+  handle_id = bt_context_add_trace (ctx, dirname, "ctf", NULL, NULL, NULL);
+  if (handle_id < 0)
     {
       ctf_destroy ();
       error (_("Unable to use libbabeltrace on directory \"%s\""),
@@ -928,42 +930,28 @@ ctf_open_dir (char *dirname)
       error (_("Unable to create bt_iterator"));
     }
 
-  /* Iterate over events, and look for an event for register block
-     to set trace_regblock_size.  */
+  /* Look for the declaration of register block.  Get the length of
+     array "contents" to set trace_regblock_size.  */
 
-  /* Save the current position.  */
-  pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
-  gdb_assert (pos->type == BT_SEEK_RESTORE);
+  bt_ctf_get_event_decl_list (handle_id, ctx, &list, &count);
+  for (i = 0; i < count; i++)
+    if (strcmp ("register", bt_ctf_get_decl_event_name (list[i])) == 0)
+      {
+       unsigned int j;
+       const struct bt_ctf_field_decl * const *field_list;
+       const struct bt_declaration *decl;
 
-  while (1)
-    {
-      const char *name;
-      struct bt_ctf_event *event;
+       bt_ctf_get_decl_fields (list[i], BT_EVENT_FIELDS, &field_list,
+                               &count);
 
-      event = bt_ctf_iter_read_event (ctf_iter);
-
-      name = bt_ctf_event_name (event);
+       gdb_assert (count == 1);
+       gdb_assert (0 == strcmp ("contents",
+                                bt_ctf_get_decl_field_name (field_list[0])));
+       decl = bt_ctf_get_decl_from_field_decl (field_list[0]);
+       trace_regblock_size = bt_ctf_get_array_len (decl);
 
-      if (name == NULL)
        break;
-      else if (strcmp (name, "register") == 0)
-       {
-         const struct bt_definition *scope
-           = bt_ctf_get_top_level_scope (event,
-                                         BT_EVENT_FIELDS);
-         const struct bt_definition *array
-           = bt_ctf_get_field (event, scope, "contents");
-
-         trace_regblock_size
-           = bt_ctf_get_array_len (bt_ctf_get_decl_from_def (array));
-       }
-
-      if (bt_iter_next (bt_ctf_get_iter (ctf_iter)) < 0)
-       break;
-    }
-
-  /* Restore the position.  */
-  bt_iter_set_pos (bt_ctf_get_iter (ctf_iter), pos);
+      }
 }
 
 #define SET_INT32_FIELD(EVENT, SCOPE, VAR, FIELD)                      \