From patchwork Sat Apr 19 06:03:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 622 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 4C1E236007E for ; Fri, 18 Apr 2014 23:06:37 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14314964) id E6F9062B80C97; Fri, 18 Apr 2014 23:06:36 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx23.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx23.g.dreamhost.com (Postfix) with ESMTPS id 7483E62B80C97 for ; Fri, 18 Apr 2014 23:06:36 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=SSifve1CTZrWXGpaTjpUAnChBJ4l4 Sxobe52ZAj/sGXWrQBkE4o8EYn9Gm7OVbJFw3IC83LaLr3TMHopZXGGtoe8Cr+kT 0b91haoLNVmJSA+TKrQjtE37JDK4mi0tUEYXfwqpQ5HFOaGqGHxtVAoCVyJ4R2NV 230ShNbwj+Bge0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=u+C4hEOVzrsoJHDaYPk4+EL+Ymk=; b=xK5 1rA1YU4mC6chH8ao0ZEltO1bhHAn/3OFNTfR8sOP1G0nKY1u5IXuatKQqeICJIXz jFFrP2awDvX7KJoJ3BZUNo0E5Y6yipV8SlHHB8lV98Gm7Ur4oSOEivlhWiwDFazN vfet0T0XAG+sEmhCm6MgPsqYNECzU72W+HDWW10A= Received: (qmail 32753 invoked by alias); 19 Apr 2014 06:06:34 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 32741 invoked by uid 89); 19 Apr 2014 06:06:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 19 Apr 2014 06:06:32 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1WbOQ1-0006Sj-27 from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Fri, 18 Apr 2014 23:06:29 -0700 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Fri, 18 Apr 2014 23:06:28 -0700 Received: from qiyao.dyndns.org.com (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.2.247.3; Fri, 18 Apr 2014 23:06:27 -0700 From: Yao Qi To: Subject: [PUSHED PATCH] Get trace_regblock_size from metadata instead of event Date: Sat, 19 Apr 2014 14:03:47 +0800 Message-ID: <1397887427-18674-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in 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. Patch is tested by running tests in gdb.trace on x86-linux with libbabeltrace installed. Patch is pushed. gdb: 2014-04-19 Yao Qi * 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 | 7 +++++++ gdb/ctf.c | 56 ++++++++++++++++++++++---------------------------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2d2b839..6bc9d87 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2014-04-19 Yao Qi + * 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 + * ctf.c (ctf_xfer_partial): Check 'name' is NULL before strcmp. 2014-04-18 Siva Chandra Reddy diff --git a/gdb/ctf.c b/gdb/ctf.c index f011738..aa63d5b 100644 --- a/gdb/ctf.c +++ b/gdb/ctf.c @@ -873,6 +873,7 @@ ctf_trace_file_writer_new (void) #include /* 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) \