From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHaGl-0001Kl-6S for qemu-devel@nongnu.org; Tue, 21 Jul 2015 12:19:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZHaGh-0001oB-SS for qemu-devel@nongnu.org; Tue, 21 Jul 2015 12:19:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44962) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHaGh-0001o5-LJ for qemu-devel@nongnu.org; Tue, 21 Jul 2015 12:19:47 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 37132B6F3D for ; Tue, 21 Jul 2015 16:19:47 +0000 (UTC) References: <1435001200-20610-1-git-send-email-armbru@redhat.com> <1435001200-20610-8-git-send-email-armbru@redhat.com> From: Eric Blake Message-ID: <55AE7121.3080509@redhat.com> Date: Tue, 21 Jul 2015 10:19:45 -0600 MIME-Version: 1.0 In-Reply-To: <1435001200-20610-8-git-send-email-armbru@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="fHH9HcMa5fBLejCqRaOwmNP5plMO3gNGC" 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: Markus Armbruster , qemu-devel@nongnu.org Cc: pbonzini@redhat.com, dgilbert@redhat.com, mst@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --fHH9HcMa5fBLejCqRaOwmNP5plMO3gNGC Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: >=20 > Unexpected error at /work/armbru/qemu/blockdev.c:322: > qemu-system-x86_64: -drive if=3Dnone,werror=3Dfoo: 'foo' invalid wr= ite error action > Aborted (core dumped) > [Exit 134 (SIGABRT)] >=20 > Note: to get this example output, I monkey-patched drive_new() to pass > &error_abort to blockdev_init(). >=20 > 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. >=20 > 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. >=20 > 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_ARG= S__) > +void error_setg_internal(Error **errp, const char *src, int line, > + const char *fmt, ...) GCC_FMT_ATTR(4, 5); > =20 > +#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? 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). 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. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --fHH9HcMa5fBLejCqRaOwmNP5plMO3gNGC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVrnEhAAoJEKeha0olJ0NqTxwH/1ALDaefwA7Op9LAkz49kndg TH+GBFGOOh+E8zqVwvHOM/EAt/rjoIBYX8aL5pnxlnrBjE0tXbq3RM9/sXPMAzAp Ia9KH91HsxLj1mYD/m+R+jfaK9zYROqLpWH7N3D7tdtZMS70xvEnQhCM6oTykJhJ O2Cs7IrxWSR2GSTPWVozBQgNxkPKVUAeP94jKOTBO8PQ1GDJVkP02hfPm6b7ivCv wD/4GHwgHt26LqKvWsluHpPy8XuUvGPk8kC1wqoMFUi9WJn3GosSxgqKloPZIGWg IZbHD+k0jnIOXbU4PI5QwbRPo5YHXH7oj6icenPmMXW2+tjuXUxoJS8CDQpqdQY= =siY2 -----END PGP SIGNATURE----- --fHH9HcMa5fBLejCqRaOwmNP5plMO3gNGC--