From patchwork Tue Jan 24 11:01:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 719069 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v75xy3bWJz9sxN for ; Tue, 24 Jan 2017 22:47:02 +1100 (AEDT) Received: from localhost ([::1]:48024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVzYx-0001FP-WD for incoming@patchwork.ozlabs.org; Tue, 24 Jan 2017 06:47:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVyrf-0002mo-60 for qemu-devel@nongnu.org; Tue, 24 Jan 2017 06:02:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVyre-0008TQ-Dr for qemu-devel@nongnu.org; Tue, 24 Jan 2017 06:02:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57620) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cVyre-0008TI-81 for qemu-devel@nongnu.org; Tue, 24 Jan 2017 06:02:14 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F9103A76B2; Tue, 24 Jan 2017 11:02:14 +0000 (UTC) Received: from t460.redhat.com (ovpn-116-159.ams2.redhat.com [10.36.116.159]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0OB1t2J016646; Tue, 24 Jan 2017 06:02:12 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Tue, 24 Jan 2017 11:01:51 +0000 Message-Id: <20170124110151.937-9-berrange@redhat.com> In-Reply-To: <20170124110151.937-1-berrange@redhat.com> References: <20170124110151.937-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 24 Jan 2017 11:02:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 8/8] trace: improve error reporting when parsing simpletrace header X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" When loading a simpletrace binary file we just report "Not a valid trace file!" which is not very helpful. Report exactly which field we found to be invalid. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Reviewed-by: Stefan Hajnoczi --- scripts/simpletrace.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py index 4ca903d..4c99004 100755 --- a/scripts/simpletrace.py +++ b/scripts/simpletrace.py @@ -73,10 +73,14 @@ def read_record(edict, idtoname, fobj): def read_trace_header(fobj): """Read and verify trace file header""" header = read_header(fobj, log_header_fmt) - if header is None or \ - header[0] != header_event_id or \ - header[1] != header_magic: + if header is None: raise ValueError('Not a valid trace file!') + if header[0] != header_event_id: + raise ValueError('Not a valid trace file, header id %d != %d' % + (header[0], header_event_id)) + if header[1] != header_magic: + raise ValueError('Not a valid trace file, header magic %d != %d' % + (header[1], header_magic)) log_version = header[2] if log_version not in [0, 2, 3, 4]: