From nobody Wed Nov 5 16:36:24 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 1535484122959507.611124340664; Tue, 28 Aug 2018 12:22:02 -0700 (PDT) Received: from localhost ([::1]:39478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fujYs-0007PZ-Ue for importer@patchew.org; Tue, 28 Aug 2018 15:21:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fujWx-0006N8-0Q for qemu-devel@nongnu.org; Tue, 28 Aug 2018 15:20:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fujO7-0004qp-QY for qemu-devel@nongnu.org; Tue, 28 Aug 2018 15:10:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45436 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 1fujO7-0004n9-Fr for qemu-devel@nongnu.org; Tue, 28 Aug 2018 15:10:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 274C7B5CB for ; Tue, 28 Aug 2018 19:10:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-97.ams2.redhat.com [10.36.116.97]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8A41202704E; Tue, 28 Aug 2018 19:10:50 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9F23C113853C; Tue, 28 Aug 2018 21:10:48 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 28 Aug 2018 21:10:48 +0200 Message-Id: <20180828191048.29806-7-armbru@redhat.com> In-Reply-To: <20180828191048.29806-1-armbru@redhat.com> References: <20180828191048.29806-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 28 Aug 2018 19:10:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 28 Aug 2018 19:10:51 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@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] [PULL 6/6] 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: , 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" From: Eric Blake 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 Message-Id: <20180827213943.33524-3-eblake@redhat.com> Reviewed-by: Markus Armbruster [Rebased, update to qapi-code-gen.txt corrected] Signed-off-by: Markus Armbruster --- docs/devel/qapi-code-gen.txt | 3 +++ scripts/qapi/introspect.py | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 304c12d0ae..53eaf01f34 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -1428,6 +1428,7 @@ Example: { "name", QLIT_QSTR("MY_EVENT"), }, {} })), + /* "0" =3D q_obj_my-command-arg */ QLIT_QDICT(((QLitDictEntry[]) { { "members", QLIT_QLIST(((QLitObject[]) { QLIT_QDICT(((QLitDictEntry[]) { @@ -1441,6 +1442,7 @@ Example: { "name", QLIT_QSTR("0"), }, {} })), + /* "1" =3D UserDefOne */ QLIT_QDICT(((QLitDictEntry[]) { { "members", QLIT_QLIST(((QLitObject[]) { QLIT_QDICT(((QLitDictEntry[]) { @@ -1460,6 +1462,7 @@ Example: { "name", QLIT_QSTR("1"), }, {} })), + /* "2" =3D q_empty */ QLIT_QDICT(((QLitDictEntry[]) { { "members", QLIT_QLIST(((QLitObject[]) { {} diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 43e81a0693..67d6106f77 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 * ' ' =20 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 =20 ret =3D '' @@ -137,11 +142,21 @@ const QLitObject %(c_name)s =3D %(c_string)s; return self._name(typ.name) =20 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) =20 def _gen_member(self, member): ret =3D {'name': member.name, 'type': self._use_type(member.type)} --=20 2.17.1