From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by sourceware.org (Postfix) with ESMTPS id 6901F3854826 for ; Mon, 19 Oct 2020 18:05:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6901F3854826 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=alves.ped@gmail.com Received: by mail-wm1-f66.google.com with SMTP id k21so508791wmi.1 for ; Mon, 19 Oct 2020 11:05:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+u4eR26+IQiFylqrswkZz0Nh89aG0KqHNRMNLSpLvr0=; b=sBtPANU6iA/nQljU+n6PpzzuQFHTJCJfg2CiAkUDNHFGmIL0FaaY7Z8yvPyI8+dg4A AnLVbK2brlL1fyhTynfeNZy8pP3NEaSyaFi3fOL4VYMuxrAMFa1ANuPhSv56VSeGr48/ JVXC9h34vunCMMBhJbTV7gJBamGBdcpd1VIfm/ur8x0aqcJ0egIsyXTRz82wSJ0XHKyx a0zOzTRJGmvSFkh6Q+1fOzlNb+u/i9Mt7FeJLpCiHFug6hkPjwhpJRgI4KT1fPfIJSCe EwFHBrXKR8ly57y3w8bjAJpKBcD4SKtrZp+SNquXFBhYHOS2BWGf0eMAzcCxnJmSmJDP uVTg== X-Gm-Message-State: AOAM530yugA+re4c/m0PJQuOO/D1RDmHyTY0U0PlBs8Fm7wr1hz2Yzc9 LwxAlcjikHMgXYm0LzjRXPGlOk9saRsw+w== X-Google-Smtp-Source: ABdhPJwGpPXUXnpkUFzNpC2bX/MllgCTRjbPqfzmOUveNjFgM0WpbnVbUEkBxvzkLPyE/xk/6uMScA== X-Received: by 2002:a7b:c953:: with SMTP id i19mr486218wml.52.1603130754182; Mon, 19 Oct 2020 11:05:54 -0700 (PDT) Received: from ?IPv6:2001:8a0:f91e:6d00:c80a:ea25:47ef:5f73? ([2001:8a0:f91e:6d00:c80a:ea25:47ef:5f73]) by smtp.gmail.com with ESMTPSA id x81sm421359wmb.11.2020.10.19.11.05.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Oct 2020 11:05:52 -0700 (PDT) Subject: Re: Add a way to invoke redefined (overridden) GDB commands To: Marco Barisione References: <20200914093925.5442-1-mbarisione@undo.io> <371BE292-EE03-4FBE-A963-64F08437A6A7@undo.io> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: Date: Mon, 19 Oct 2020 19:05:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <371BE292-EE03-4FBE-A963-64F08437A6A7@undo.io> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, KAM_TK, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Mon, 19 Oct 2020 18:05:58 -0000 On 10/19/20 6:41 PM, Marco Barisione wrote: > On 12 Oct 2020, at 12:50, Pedro Alves wrote: >> On 9/14/20 10:39 AM, Marco Barisione wrote: >>> Currently, when a GDB command is redefined, the original implementation is not >>> available any more. This makes it difficult to build features on top of >>> existing commands. >>> >>> Last year I submitted a patch to fix this but I ran out of time to address the >>> review comments (the original patch was sent on the 28th of October 2019). >>> These patches restart that work and should address all the comments I got last >>> time. As the patchea are very different and a long time passed, I'm >>> submitting as a new series. >>> >>> My patches add a new "uplevel" command and a new gdb.Command.invoke_uplevel >>> method inspired by TCL (as initially suggested by Andrew Burgess) so you can >>> do this: >>> >>> (gdb) define run >>> echo Will run!\n >>> uplevel 0 run >>> end >>> (gdb) run >>> Will run! >>> [... normal output of run ...] >>> >>> >>> There are a couple of other things which could be added to make the "uplevel" >>> command more helpful, but I think they are out of scope and my patches are >>> already useful as they are. >> >> So I'm looking at this afresh, and really questioning this "uplevel N" >> design. This it not really like TCL's "uplevel". With TCL's uplevel, >> you are accessing a different scope or frame, not a previous implementation >> of the function that was overwritten. To me, the naming choice is >> confusing, from that angle. If someone extends GDB's CLI to gain support >> for local variables, then a really-TCL-like uplevel is likely handy, and >> then calling that feature "uplevel" would be good. >> >> I also question whether "uplevel N" with "N>0" is really usable, since >> in general you don't know what other scripts may have overridden. E.g., >> you never know what "uplevel 3 cmd" will run, since you don't know how >> many scripts redefined/overridden cmd. >> >> If we stick with the TCL inspiration, I think a better approach would >> be to add support for renaming commands, like TCL's rename command: >> >> https://www.tcl.tk/man/tcl8.4/TclCmd/rename.htm >> >> So a user would do: >> >> (gdb) rename run org_run >> (gdb) define run >>> echo Will run!\n >>> org_run >>> end >> (gdb) run >> Will run! >> [... normal output of run ...] >> (gdb) org_run >> [... normal output of run ...] >> >> (You can find many examples of TCL's rename in use in GDB's testsuite.) > > I will try implementing this then, including the semantics for deleting > a command (copied from the TCL command). > > A problem with GDB is that commands can have spaces so: > (gdb) rename foo bar > Is ambiguous. Do you want to delete the "foo bar" command or rename the > "foo" command to "bar"? > Even without deleting command, this would be ambiguous: > (gdb) rename foo bar baz > > Unless somebody proposes something different I will use "--" to split > the two command names. ISTM that (optional) quotes would be the natural thing here: (gdb) rename "foo bar" "baz" (gdb) rename "foo" "bar baz" I'd rather leave "--" for the typical splitting of options from other arguments. Commands get that for free if they use the cli/cli-option.h framework. So "--" would be used like in other commands, to unambiguously split options from commands that may start with "-", like: (gdb) help - Scroll window backward. Usage: - [N] [WIN] Scroll window WIN N lines backwards. Both WIN and N are optional, N defaults to 1, and WIN defaults to the currently focused window. (gdb) (gdb) rename -someoption -- - scroll-backward Thanks, Pedro Alves > > For instance: > (gdb) # Rename "foo" to “bar": > (gdb) rename foo -- bar > (gdb) # Rename "foo bar" to "baz": > (gdb) rename foo bar -- baz > (gdb) # Delete "foo bar": > (gdb) rename foo bar -- > (gdb) # Invalid: > (gdb) rename -- > (gdb) rename -- hello > >