From nobody Sun Oct 5 21:10:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1535406136333178.43645277740666; Mon, 27 Aug 2018 14:42:16 -0700 (PDT) Received: from localhost ([::1]:35220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuPH5-0000MN-8x for importer@patchew.org; Mon, 27 Aug 2018 17:42:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuPEi-0007PK-CN for qemu-devel@nongnu.org; Mon, 27 Aug 2018 17:39:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fuPEh-0008Jx-8l for qemu-devel@nongnu.org; Mon, 27 Aug 2018 17:39:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49584 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fuPEg-0008JS-Vo for qemu-devel@nongnu.org; Mon, 27 Aug 2018 17:39:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9048B40241C3; Mon, 27 Aug 2018 21:39:46 +0000 (UTC) Received: from red.redhat.com (ovpn-124-180.rdu2.redhat.com [10.10.124.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D77C1049487; Mon, 27 Aug 2018 21:39:46 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 27 Aug 2018 16:39:43 -0500 Message-Id: <20180827213943.33524-3-eblake@redhat.com> In-Reply-To: <20180827213943.33524-1-eblake@redhat.com> References: <20180827213943.33524-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 27 Aug 2018 21:39:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 27 Aug 2018 21:39:46 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 2/2] qapi: Add comments to aid debugging generated introspection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com, Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We consciously chose in commit 1a9a507b to hide QAPI type names from the introspection output on the wire, but added a command line option -u to unmask the type name when doing a debug build. The unmask option still remains useful to some other forms of automated analysis, so it will not be removed; however, when it is not in use, the generated .c file can be hard to read. At the time when we first introduced masking, the generated file consisted only of a monolithic C string, so there was no clean way to inject any comments. Later, in commit 7d0f982b, we switched the generation to output a QLit object, in part to make it easier for future addition of conditional compilation. In fact, commit d626b6c1 took advantage of this by passing a tuple instead of a bare object for encoding the output of conditionals. By extending that tuple, we can now interject strategic comments. For now, type name debug aid comments are only output once per meta-type, rather than at all uses of the number used to encode the type within the introspection data. But this is still a lot more convenient than having to regenerate the file with the unmask operation temporarily turned on - merely search the generated file for '"NNN" =3D' to learn the corresponding source name and associated definition of type NNN. The generated qapi-introspect.c changes only with the addition of comments, such as: | @@ -14755,6 +15240,7 @@ | { "name", QLIT_QSTR("[485]"), }, | {} | })), | + /* "485" =3D QCryptoBlockInfoLUKSSlot */ | QLIT_QDICT(((QLitDictEntry[]) { | { "members", QLIT_QLIST(((QLitObject[]) { | QLIT_QDICT(((QLitDictEntry[]) { Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster --- v2: rebase on conditional code additions, drop patch to remove -u, update documentation to match --- docs/devel/qapi-code-gen.txt | 1 + scripts/qapi/introspect.py | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index c2e11465f0f..9d5b1409e72 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -1412,6 +1412,7 @@ Example: { "name", QLIT_QSTR("Event") }, { } })), + /* "0" =3D q_empty */ QLIT_QDICT(((QLitDictEntry[]) { { "members", QLIT_QLIST(((QLitObject[]) { { } diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 43e81a06938..67d6106f77b 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -19,12 +19,17 @@ def to_qlit(obj, level=3D0, suppress_first_indent=3DFal= se): return level * 4 * ' ' if isinstance(obj, tuple): - ifobj, ifcond =3D obj - ret =3D gen_if(ifcond) + ifobj, extra =3D obj + ifcond =3D extra.get('if') + comment =3D extra.get('comment') + ret =3D '' + if comment: + ret +=3D indent(level) + '/* %s */\n' % comment + if ifcond: + ret +=3D gen_if(ifcond) ret +=3D to_qlit(ifobj, level) - endif =3D gen_endif(ifcond) - if endif: - ret +=3D '\n' + endif + if ifcond: + ret +=3D '\n' + gen_endif(ifcond) return ret ret =3D '' @@ -137,11 +142,21 @@ const QLitObject %(c_name)s =3D %(c_string)s; return self._name(typ.name) def _gen_qlit(self, name, mtype, obj, ifcond): + extra =3D {} if mtype not in ('command', 'event', 'builtin', 'array'): + if not self._unmask: + # Output a comment to make it easy to map masked names + # back to the source when reading the generated output. + extra['comment'] =3D '"%s" =3D %s' % (self._name(name), na= me) name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype - self._qlits.append((obj, ifcond)) + if ifcond: + extra['if'] =3D ifcond + if extra: + self._qlits.append((obj, extra)) + else: + self._qlits.append(obj) def _gen_member(self, member): ret =3D {'name': member.name, 'type': self._use_type(member.type)} --=20 2.17.1