Received: from eggs.gnu.org ([2001:4830:134:3::10]:51375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHuUA-0006sA-6Z for qemu-devel@nongnu.org; Wed, 22 Jul 2015 09:55:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZHuU4-00077I-Iv for qemu-devel@nongnu.org; Wed, 22 Jul 2015 09:55:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHuU4-000770-C1 for qemu-devel@nongnu.org; Wed, 22 Jul 2015 09:54:56 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id CB3A491E97 for ; Wed, 22 Jul 2015 13:54:55 +0000 (UTC) From: Markus Armbruster References: <1435001200-20610-1-git-send-email-armbru@redhat.com> <1435001200-20610-8-git-send-email-armbru@redhat.com> <55AE7121.3080509@redhat.com> Date: Wed, 22 Jul 2015 15:54:53 +0200 In-Reply-To: <55AE7121.3080509@redhat.com> (Eric Blake's message of "Tue, 21 Jul 2015 10:19:45 -0600") Message-ID: <87vbdcjo0i.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 7/7] error: On abort, report where the error was created List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: pbonzini@redhat.com, mst@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com Eric Blake writes: > On 06/22/2015 01:26 PM, Markus Armbruster wrote: >> This is particularly useful when we abort in error_propagate(), >> because there the stack backtrace doesn't lead to where the error was >> created. Looks like this: >> >> Unexpected error at /work/armbru/qemu/blockdev.c:322: >> qemu-system-x86_64: -drive if=none,werror=foo: 'foo' invalid >> write error action >> Aborted (core dumped) >> [Exit 134 (SIGABRT)] >> >> Note: to get this example output, I monkey-patched drive_new() to pass >> &error_abort to blockdev_init(). >> >> To keep the error handling boiler plate from growing even more, all >> error_setFOO() become macros expanding into error_setFOO_internal() >> with additional __FILE__, __LINE__ arguments. Not exactly pretty, but >> it works. > > I agree with Laszlo that adding __func__ to the mix also helps. Okay, I'll give it a try. >> The macro trickery breaks down when you take the address of an >> error_setFOO(). Fortunately, we do that in just one place: qemu-ga's >> Windows VSS provider and requester DLL wants to call >> error_setg_win32() through a function pointer "to avoid linking glib >> to the DLL". Use error_setg_win32_internal() there. The use of the >> function pointer is already wrapped in a macro, so the churn isn't >> bad. >> >> Code size increases by some 14KiB for me (0.3%). Tolerable. Could be >> less if we passed relative rather than absolute source file names to >> the compiler. > > I also like it. > >> +#define error_setg(errp, fmt, ...) \ >> + error_setg_internal((errp), __FILE__, __LINE__, (fmt), ## __VA_ARGS__) >> +void error_setg_internal(Error **errp, const char *src, int line, >> + const char *fmt, ...) GCC_FMT_ATTR(4, 5); >> > >> +#define error_setg_errno(errp, os_error, fmt, ...) \ >> + error_setg_errno_internal((errp), __FILE__, __LINE__, (os_error), \ >> + (fmt), ## __VA_ARGS__) > > Nit - why the difference in \ alignment? I'm dense today... difference between where and where? > Nit - as used here, 'errp', 'fmt', and 'os_error' can be used > unambiguously; you don't need '(errp)' given the context of a > parenthesized comma-separated list (even if someone DID want to unusual > by passing in '(a,b)' with a comma operator for their 'errp' argument, > they'd have to supply the () because of the semantics of making the > macro call). I put parenthesis around macro parameters in the expansion pretty much unthinkingly, because thought is expensive :) > Nit - '## __VA_ARGS__' is a gcc-ism and not portable C99; but I think > clang supports it, and we don't really care about other compilers at the > moment. At any rate, we already use it elsewhere in qemu.git. Correct. For what it's worth, ./HACKING recommends it.