From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0BFDF3858C2C for ; Wed, 2 Feb 2022 16:57:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0BFDF3858C2C Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-663-LL9SQF7IPRy5dTnjZ_OOdg-1; Wed, 02 Feb 2022 11:57:49 -0500 X-MC-Unique: LL9SQF7IPRy5dTnjZ_OOdg-1 Received: by mail-wm1-f71.google.com with SMTP id l16-20020a1c7910000000b0034e4206ecb7so2729697wme.7 for ; Wed, 02 Feb 2022 08:57:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=QA+5chbJzoZaM2o+YUpIJVZpwZzm+g0Jvhi4ekO3ZkI=; b=CdaYxqdHV7bPQwWSiSqNg7xDdWLDwjmdMhqoFf0xlHLc+CKG9ekudkeRnco6bLeVaf wWEqkw9esFRHiNII1p/Rcv9rX2ZO9mji0zmNFB0pyTAmgJL2GWyyyqBnF27pdgBP8Pkp eY/zAeHrrrCDKjTu4dahDNYZkrhFDi0Xyp+totwG2HetxzzgmrORpJU3G2If6HAhoGAI dXhuOSFgHJnqgm0tskxgGtki/5I2DOAIahK1SXI18O6rDFBUGtvfCLAgkwrDWi2zi+cI U0V6BP4Tv/sDh5LwUx3Equ6TCPpH3HL6yyTenJAc64KKQT5Y5jxCjh2rbCZUVIHSqLf1 4XFQ== X-Gm-Message-State: AOAM532XIUP2KrUOuJtNot4rKjWid00ftkRzxHZd0ShQ+pmT5EddytNS LKYDknmJiaSFU9jhtxrRkZGWjLqRgO0qklDN7ljAc0+d//6EKIISL4wUksG0S4rKjBNVaa0vLfm cteKQU+CVeiWtByEibaLMlA== X-Received: by 2002:a5d:5052:: with SMTP id h18mr27599244wrt.350.1643821068497; Wed, 02 Feb 2022 08:57:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkdFUO0Q+paPPGDQ/4Q0LajMMjQBB2pOVP09GxgA5rpeCNl6L45r7HZIfBExR6YphLzA+e1w== X-Received: by 2002:a5d:5052:: with SMTP id h18mr27599232wrt.350.1643821068231; Wed, 02 Feb 2022 08:57:48 -0800 (PST) Received: from localhost (host86-140-92-93.range86-140.btcentralplus.com. [86.140.92.93]) by smtp.gmail.com with ESMTPSA id c14sm19697080wri.56.2022.02.02.08.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 08:57:47 -0800 (PST) From: Andrew Burgess To: Jan Vrany Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 0/5] create GDB/MI commands using python In-Reply-To: <76d0cb881222ca2b875aa4d13dd49b58a766171d.camel@labware.com> References: <20220117124425.2658516-1-jan.vrany@labware.com> <20220118135541.GG622389@redhat.com> <20220121152208.GK622389@redhat.com> <76d0cb881222ca2b875aa4d13dd49b58a766171d.camel@labware.com> Date: Wed, 02 Feb 2022 16:57:46 +0000 Message-ID: <874k5hqk8l.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2022 16:58:00 -0000 Jan Vrany via Gdb-patches writes: > On Fri, 2022-01-21 at 15:22 +0000, Andrew Burgess wrote: >> * Jan Vrany via Gdb-patches [2022-01-18 15:= 13:01 +0000]: >>=20 >> > On Tue, 2022-01-18 at 13:55 +0000, Andrew Burgess wrote: >> > > * Jan Vrany via Gdb-patches [2022-01-17= 12:44:20 +0000]: >> > >=20 >> > > > This is a restart of an earlier attempts to allow custom >> > > > GDB/MI commands written in Python. >> > >=20 >> > > Thanks for continuing to work on this feature. >> > >=20 >> > > I too had been looking at getting the remaining patches from your >> > > series upstream, and I'd like to discuss some of the differences >> > > between the approaches we took. >> >=20 >> > Great, thanks a lot! >> >=20 >> > >=20 >> > > At the end of this mail you'll find my current work-in-progress >> > > patch, it definitely needs the docs and NEWS entries adding, as well >> > > as a few extra tests. However, functionality wise I think its mostl= y >> > > there. >> > >=20 >> > > My patch includes two sets of tests, gdb.python/py-mi-cmd.exp and >> > > gdb.python/py-mi-cmd-orig.exp. The former is based on your tests, b= ut >> > > with some tweaks based on changes I made. The latter set is your >> > > tests taken from this m/l thread. >> > >=20 >> > > When running the gdb.python/py-mi-cmd-orig.exp tests there should be >> > > just 2 failures, both related to the same feature which is not prese= nt >> > > in my version, that is, the ability of a command to redefine itself, >> > > like this: >> > >=20 >> > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0class my_command(gdb.MICommand): >> > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0def invoke(self, arg= s): >> > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0my_comma= nd("-blah") >> > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return N= one >> > >=20 >> > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0my_command("-blah") >> > >=20 >> > > this works with your version, but not with mine, this is because I'm >> > > using python's own reference counting to track when a command can be >> > > redefined or not, and, when you are within a commands invoke method >> > > the reference count of the containing object is incremented, and thi= s >> > > prevents gdb from deleting the command. >> > >=20 >> > > My question then, is how important is this feature, and what use cas= e >> > > do you see for this? Or, was support for this just a happy side >> > > effect of the implementation approach you chose? >> >=20 >> > Initially I did not think of it and it was - IIRC - pointed out in >> > some review. I thought to be a corner case, but it turned out to be >> > (potentiality very useful feature.=20 >> >=20 >> > While developing custom commands, pretty printers and so on, it is use= ful >> > to be able to "reload" Python code into running GDB without need to re= start=C2=A0 >> > it. To support that, I created a "pr" command which reloads all custom= python=20 >> > code (well, tries to at least), see=20 >> >=20 >> > https://urldefense.proofpoint.com/v2/url?u=3Dhttps-3A__swing.fit.cvut.= cz_hg_jv-2Dvdb_file_tip_python_vdb_cli.py-23l20&d=3DDwIFAw&c=3DsPZ6DeHLiehU= HQWKIrsNwWp3t7snrE-az24ztT0w7Jc&r=3DWpFFGgYa98Yp-c29WHTCwU1wAGFBvszA6a4Rzgp= MSqc&m=3DaunQh9rOF7oPv3b6WEJbNxADRSv4-8Dy2BMsx38ToFU&s=3DjnwDUKw3EN3ruyHZoF= fwtAJykINwXr92bHBvZHlvn1k&e=3D=20 >> >=20 >> > So ultimately, this custom "pr" command's invoke() causes redefinition >> > of the "pr" command itself. I have not done it yet, but having=C2=A0 >> > menu item/icon in (my) GDB frontend using something like -python-reloa= d` >> > seems desirable from UX POV. >>=20 >> Thanks, that's not an unreasonable use case. I've tweaked things so >> that this case is now supported. >>=20 >> I've gone through that patch and ported over your NEWS and doc >> changes, with some updates based on Eli's feedback, as well as some >> new content to cover some of the changes in my patch. >>=20 >> For the testing, I have, for now, kept gdb.python/py-mi-cmd-orig.exp, >> which is your test file taken from your patch series. I added some >> 'setup_kfail' markers to 7 tests that now fail due to changes in error >> strings, hopefully, this will allow you to review what changed. >> However, except for the differences in error string, everything your >> original series supported is now supported by this patch. >>=20 >> From a user's point of view, I think the only differences with your >> patch are: >>=20 >> =C2=A01. New .name attribute, that returns the name of the command as a >> =C2=A0=C2=A0=C2=A0=C2=A0string, here's an example session: >>=20 >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python >> =C2=A0=C2=A0=C2=A0=C2=A0>class MyCommand(gdb.MICommand): >> =C2=A0=C2=A0=C2=A0=C2=A0> def __init__(self): >> =C2=A0=C2=A0=C2=A0=C2=A0> super(MyCommand, self).__init__("-my-comman= d") >> =C2=A0=C2=A0=C2=A0=C2=A0> def invoke(self, args): >> =C2=A0=C2=A0=C2=A0=C2=A0> return None >> =C2=A0=C2=A0=C2=A0=C2=A0> >> =C2=A0=C2=A0=C2=A0=C2=A0>end >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python cmd =3D MyCommand() >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python print(cmd.name) >> =C2=A0=C2=A0=C2=A0=C2=A0-my-command >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) >>=20 >> =C2=A02. New .installed attribute, that allows a command to be installed= or >> =C2=A0=C2=A0=C2=A0=C2=A0removed from the mi command table, here's an exa= mple session: >>=20 >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python >> =C2=A0=C2=A0=C2=A0=C2=A0>class MyCommand(gdb.MICommand): >> =C2=A0=C2=A0=C2=A0=C2=A0> def __init__(self, name, message): >> =C2=A0=C2=A0=C2=A0=C2=A0> self._message =3D message >> =C2=A0=C2=A0=C2=A0=C2=A0> super(MyCommand, self).__init__(name) >> =C2=A0=C2=A0=C2=A0=C2=A0> >> =C2=A0=C2=A0=C2=A0=C2=A0> def invoke(self, args): >> =C2=A0=C2=A0=C2=A0=C2=A0> return self._message >> =C2=A0=C2=A0=C2=A0=C2=A0> >> =C2=A0=C2=A0=C2=A0=C2=A0>end >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python cmd1 =3D MyCommand("-my-command", "= cmd1") >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python print(cmd1.installed) >> =C2=A0=C2=A0=C2=A0=C2=A0True >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) interpreter-exec mi "-my-command" >> =C2=A0=C2=A0=C2=A0=C2=A0^done,result=3D"cmd1" >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python cmd2 =3D MyCommand("-my-command", "= cmd2") >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python print(cmd2.installed) >> =C2=A0=C2=A0=C2=A0=C2=A0True >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python print(cmd1.installed) >> =C2=A0=C2=A0=C2=A0=C2=A0False >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) interpreter-exec mi "-my-command" >> =C2=A0=C2=A0=C2=A0=C2=A0^done,result=3D"cmd2" >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python cmd1.installed =3D True >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python print(cmd2.installed) >> =C2=A0=C2=A0=C2=A0=C2=A0False >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python print(cmd1.installed) >> =C2=A0=C2=A0=C2=A0=C2=A0True >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) interpreter-exec mi "-my-command" >> =C2=A0=C2=A0=C2=A0=C2=A0^done,result=3D"cmd1" >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python cmd1.installed =3D False >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) interpreter-exec mi "-my-command" >> =C2=A0=C2=A0=C2=A0=C2=A0^error,msg=3D"Undefined MI command: my-command",= code=3D"undefined-command" >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) >>=20 >> =C2=A03. The top level result name can be changed from 'result' to anyth= ing >> =C2=A0=C2=A0=C2=A0=C2=A0the user wants, here's an example session: >>=20 >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python >> =C2=A0=C2=A0=C2=A0=C2=A0>class MyCommand(gdb.MICommand): >> =C2=A0=C2=A0=C2=A0=C2=A0> def __init__(self): >> =C2=A0=C2=A0=C2=A0=C2=A0> super(MyCommand, self).__init__("-my-comman= d", "greeting") >> =C2=A0=C2=A0=C2=A0=C2=A0> def invoke(self, args): >> =C2=A0=C2=A0=C2=A0=C2=A0> return "Hello World" >> =C2=A0=C2=A0=C2=A0=C2=A0> >> =C2=A0=C2=A0=C2=A0=C2=A0>end >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) python cmd =3D MyCommand() >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) interpreter-exec mi "-my-command" >> =C2=A0=C2=A0=C2=A0=C2=A0^done,greeting=3D"Hello World" >> =C2=A0=C2=A0=C2=A0=C2=A0(gdb) >>=20 >> I'd love to hear your feedback on this iteration. > > I'm personally happy with this iteration. I like your improvements=C2=A0 > to the Python API! I also tested it briefly with my Python code &=C2=A0 > frontend just to see and it worked just fine. That's great news. > > Perhaps, I'd rename mi_commands module variable to _mi_commands to=C2=A0 > convey the fact it is "internal" to the implementation and should not > be touched (?). Thanks, using the '_' prefix was mentioned for another patch I was working on; I'll definitely make this change. I'll give this a little more time, hopefully we'll get some more reviews in. Thanks, Andrew