From patchwork Wed Oct 19 12:56:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 120621 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3F925B71BF for ; Wed, 19 Oct 2011 23:56:41 +1100 (EST) Received: from localhost ([::1]:45451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGVhD-0006aP-7u for incoming@patchwork.ozlabs.org; Wed, 19 Oct 2011 08:56:35 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGVh6-0006aJ-W0 for qemu-devel@nongnu.org; Wed, 19 Oct 2011 08:56:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RGVh5-0007jA-91 for qemu-devel@nongnu.org; Wed, 19 Oct 2011 08:56:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15255) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGVh4-0007iw-TS for qemu-devel@nongnu.org; Wed, 19 Oct 2011 08:56:27 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9JCuLP0004421 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 19 Oct 2011 08:56:21 -0400 Received: from doriath (ovpn-113-110.phx2.redhat.com [10.3.113.110]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9JCuJPn031021; Wed, 19 Oct 2011 08:56:20 -0400 Date: Wed, 19 Oct 2011 10:56:19 -0200 From: Luiz Capitulino To: Wen Congyang Message-ID: <20111019105619.4e0813fa@doriath> In-Reply-To: <4E9E1D35.7040202@cn.fujitsu.com> References: <1318613203-25892-1-git-send-email-lcapitulino@redhat.com> <1318613203-25892-3-git-send-email-lcapitulino@redhat.com> <4E9E1D35.7040202@cn.fujitsu.com> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH 2/5] runstate: Print state transition when invalid X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Wed, 19 Oct 2011 08:43:33 +0800 Wen Congyang wrote: > At 10/15/2011 01:26 AM, Luiz Capitulino Write: > > Makes it easier to debug. > > > > Signed-off-by: Luiz Capitulino > > --- > > vl.c | 4 +++- > > 1 files changed, 3 insertions(+), 1 deletions(-) > > > > diff --git a/vl.c b/vl.c > > index dbf7778..6645720 100644 > > --- a/vl.c > > +++ b/vl.c > > @@ -397,7 +397,9 @@ void runstate_set(RunState new_state) > > { > > if (new_state >= RUN_STATE_MAX || > > !runstate_valid_transitions[current_run_state][new_state]) { > > - fprintf(stderr, "invalid runstate transition\n"); > > + fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n", > > + RunState_lookup[current_run_state], > > + RunState_lookup[new_state]); > > If new_state >= RUN_STATE_MAX, we can not use RunState_lookup. Good catch! > I think it's better to use: > new_state >= RUN_STATE_MAX ? "invalid state" : RunState_lookup[new_state] I prefer to do the following instead: diff --git a/vl.c b/vl.c index 2dce3ae..2a634a7 100644 --- a/vl.c +++ b/vl.c @@ -393,9 +393,12 @@ void runstate_init(void) /* This function will abort() on invalid state transitions */ void runstate_set(RunState new_state) { - if (new_state >= RUN_STATE_MAX || - !runstate_valid_transitions[current_run_state][new_state]) { - fprintf(stderr, "invalid runstate transition\n"); + assert(new_state < RUN_STATE_MAX); + + if (!runstate_valid_transitions[current_run_state][new_state]) { + fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n", + RunState_lookup[current_run_state], + RunState_lookup[new_state]); abort(); }