From patchwork Thu Mar 4 15:56:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 46953 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3B497B7D05 for ; Fri, 5 Mar 2010 04:21:18 +1100 (EST) Received: from localhost ([127.0.0.1]:39325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnEja-0002db-1S for incoming@patchwork.ozlabs.org; Thu, 04 Mar 2010 12:21:14 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NnDXZ-0005hX-E9 for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:45 -0500 Received: from [199.232.76.173] (port=58587 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnDXZ-0005hN-2B for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:45 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NnDXO-0001Pv-HJ for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:43 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:47484) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NnDXM-0001On-Js for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:33 -0500 Received: from blackfin.pond.sub.org (pD9E38041.dip.t-dialin.net [217.227.128.65]) by oxygen.pond.sub.org (Postfix) with ESMTPA id EC55E276DA6 for ; Thu, 4 Mar 2010 17:04:29 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 273BF118; Thu, 4 Mar 2010 16:57:13 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 4 Mar 2010 16:56:43 +0100 Message-Id: <1267718231-13303-23-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1267718231-13303-1-git-send-email-armbru@redhat.com> References: <1267718231-13303-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Luiz Capitulino Subject: [Qemu-devel] [PATCH 22/50] error: Track locations on command line X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org New LOC_CMDLINE. Use it for tracking option with argument in lookup_opt(). We now report errors like this qemu: -device smbus-eeprom: Did not find I2C bus for smbus-eeprom Signed-off-by: Markus Armbruster --- qemu-error.c | 20 ++++++++++++++++++++ qemu-error.h | 3 ++- vl.c | 9 +++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/qemu-error.c b/qemu-error.c index 23176e1..5be6bea 100644 --- a/qemu-error.c +++ b/qemu-error.c @@ -114,6 +114,16 @@ void loc_set_none(void) } /* + * Change the current location to argument ARGV[IDX..IDX+CNT-1]. + */ +void loc_set_cmdline(char **argv, int idx, int cnt) +{ + cur_loc->kind = LOC_CMDLINE; + cur_loc->num = cnt; + cur_loc->ptr = argv + idx; +} + +/* * Change the current location to file FNAME, line LNO. */ void loc_set_file(const char *fname, int lno) @@ -143,12 +153,22 @@ void error_set_progname(const char *argv0) void error_print_loc(void) { const char *sep = ""; + int i; + const char *const *argp; if (!cur_mon) { fprintf(stderr, "%s:", progname); sep = " "; } switch (cur_loc->kind) { + case LOC_CMDLINE: + argp = cur_loc->ptr; + for (i = 0; i < cur_loc->num; i++) { + error_printf("%s%s", sep, argp[i]); + sep = " "; + } + error_printf(": "); + break; case LOC_FILE: error_printf("%s:", (const char *)cur_loc->ptr); if (cur_loc->num) { diff --git a/qemu-error.h b/qemu-error.h index 8f2a140..88e0b70 100644 --- a/qemu-error.h +++ b/qemu-error.h @@ -15,7 +15,7 @@ typedef struct Location { /* all members are private to qemu-error.c */ - enum { LOC_NONE, LOC_FILE } kind; + enum { LOC_NONE, LOC_CMDLINE, LOC_FILE } kind; int num; const void *ptr; struct Location *prev; @@ -27,6 +27,7 @@ Location *loc_pop(Location *loc); Location *loc_save(Location *loc); void loc_restore(Location *loc); void loc_set_none(void); +void loc_set_cmdline(char **argv, int idx, int cnt); void loc_set_file(const char *fname, int lno); void error_vprintf(const char *fmt, va_list ap); diff --git a/vl.c b/vl.c index 397b018..1b58759 100644 --- a/vl.c +++ b/vl.c @@ -4756,6 +4756,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv, char *r = argv[optind]; const char *optarg; + loc_set_cmdline(argv, optind, 1); optind++; /* Treat --foo the same as -foo. */ if (r[1] == '-') @@ -4763,8 +4764,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv, popt = qemu_options; for(;;) { if (!popt->name) { - fprintf(stderr, "%s: invalid option -- '%s'\n", - argv[0], r); + error_report("invalid option"); exit(1); } if (!strcmp(popt->name, r + 1)) @@ -4773,11 +4773,11 @@ static const QEMUOption *lookup_opt(int argc, char **argv, } if (popt->flags & HAS_ARG) { if (optind >= argc) { - fprintf(stderr, "%s: option '%s' requires an argument\n", - argv[0], r); + error_report("requires an argument"); exit(1); } optarg = argv[optind++]; + loc_set_cmdline(argv, optind - 2, 2); } else { optarg = NULL; } @@ -5614,6 +5614,7 @@ int main(int argc, char **argv, char **envp) } } } + loc_set_none(); /* If no data_dir is specified then try to find it relative to the executable path. */