Received: from eggs.gnu.org ([2001:4830:134:3::10]:41292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YyFAW-00050N-Kg for qemu-devel@nongnu.org; Fri, 29 May 2015 03:57:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YyFAR-0003BL-6d for qemu-devel@nongnu.org; Fri, 29 May 2015 03:57:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YyFAR-0003BE-0r for qemu-devel@nongnu.org; Fri, 29 May 2015 03:57:23 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 1AC2734ADD9 for ; Fri, 29 May 2015 07:57:21 +0000 (UTC) From: Markus Armbruster References: <1432768754-28523-1-git-send-email-bsd@redhat.com> <1432768754-28523-2-git-send-email-bsd@redhat.com> <87h9qxi322.fsf@blackfin.pond.sub.org> <55677108.8090205@redhat.com> Date: Fri, 29 May 2015 09:57:19 +0200 In-Reply-To: (Bandan Das's message of "Thu, 28 May 2015 16:24:33 -0400") Message-ID: <87siafn7ds.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v3 1/2] monitor: cleanup parsing of cmd name and cmd arguments List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bandan Das Cc: qemu-devel@nongnu.org Bandan Das writes: > Eric Blake writes: > >> On 05/28/2015 12:48 PM, Bandan Das wrote: >>> Markus Armbruster writes: >>> >>>> Bandan Das writes: >>>> >>>>> There's too much going on in monitor_parse_command(). >>>>> Split up the arguments parsing bits into a separate function >>>>> monitor_parse_arguments(). Let the original function check for >>>>> command validity and sub-commands if any and return data (*cmd) >>>>> that the newly introduced function can process and return a >>>>> QDict. Also, pass a pointer to the cmdline to track current >>>>> parser location. >> >>>>> >>>>> #ifdef DEBUG >>>>> - monitor_printf(mon, "command='%s', start='%d'\n", cmdline, start); >>>>> + monitor_printf(mon, "command='%s', start='%d'\n", cmdline, *start); >>>> >>>> Would this compile if we defined DEBUG? >>> >>> No, it won't :) Sorry, will fix. >> >> That's why I like solutions that can't bitrot; something like this >> framework (needs a bit more to actually compile, but you get the picture): >> >> #ifdef DEBUG >> # define DEBUG_MONITOR 1 >> #else >> # define DEBUG_MONITOR 0 >> #endif >> #define DEBUG_MONITOR_PRINTF(stuff...) do { \ >> if (DEBUG_MONITOR) { \ >> monitor_printf(stuff...); \ >> } \ >> } while (0) >> >> then you can avoid the #ifdef in the function body, and just do >> DEBUG_MONITOR_PRINTF(mon, "command='%s'....) and the compiler will >> always check for correct format vs. arguments, even when debugging is off. >> >> Of course, adding such a framework in this file would be a separate >> patch, and does not have to be done as a prerequisite of this series. > > Thanks, Eric. Ok, I will post patch(es) separately. The preferred solution in QEMU is tracepoints. In this case, I wouldn't mind ditching the debugging prints instead. All three of them.