From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 9AE1A3854826 for ; Mon, 19 Oct 2020 17:41:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9AE1A3854826 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=undo.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mbarisione@undo.io Received: by mail-wr1-x42a.google.com with SMTP id t9so630561wrq.11 for ; Mon, 19 Oct 2020 10:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=undo-io.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=89YeQD43QKRcP+jGYVdcpvAkAed0ehJK1MLzVAwNl6s=; b=uWpRHZ9aWvLWApqUIU2ChQupqTPA9Z6M7tgeyi1zCVyr0Jrqf37qU4L4n0KUOyFh+J YGfApyl2ewYKPZZK8jEsG91HrQYDaWNMuaWTUkA/UAkMo9aq2B6EzU85lU2s0taAW5Wq BbhH5hGoC8RyuuNBJmBQWzllYZiZOG+Z9YnBo7CQ3vaNpm7rkwKsbc0IFumDw8yz0OjW wj3ztk8M6i55zQa7HYgelnaJ6erwOXnmSRhhBW9RDLNglf/cCET9vc6q41FbM0T1wkVC I25mtT7of8e3CU+BaFOm5Ezw5ITAMDjsMC9ybmsOWwqp+WyE8u5XdhlHOFtRlyvG+rKL tJUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=89YeQD43QKRcP+jGYVdcpvAkAed0ehJK1MLzVAwNl6s=; b=I5fp95H06kvHHoUl+9SQxVasovhEKY/OQFXj0iU4Ta6UEcYMkvVKnD8uHhmH3mOREw VE8IbXKrOKajBKnOKnsya62/gP4wluML+Vh9Qw5bz57IGwxFg8cVqT7bkdQLNKqq5KlT iUE+IX5X65rto9WpHbr3J18SFd7EVHF8CFMjjB9r+YlELJt+i7Xyeb212vZKBKKpZejO l/XU5qfhR84LQdk+gAtElE3gZAsONyMX73m4P9LR6BAy9c/jPEn1/pp2bPXyJlqTowM4 2V5tsG7cKU09oxP4MgLtHaG6QM3PWc4dX5UByklxQszPVWqgRKHpX78ZSjZgstcQhOMv Zjow== X-Gm-Message-State: AOAM5317qun6J5idmNDAKYQpQsnvP1Zn49QIeVWaFEVT+d+hdL6X0/AD qLaPOWIrLpUQneErBhpgMunfzkIOXXyOrjWM X-Google-Smtp-Source: ABdhPJxtFX658rDlFkEwtlgH2h2vFbRJbmE+W3VielYjmpa3EYjvwKdSr7j5Z38CCTaCLfI/QEhXSQ== X-Received: by 2002:a5d:6287:: with SMTP id k7mr383480wru.402.1603129296224; Mon, 19 Oct 2020 10:41:36 -0700 (PDT) Received: from [192.168.0.114] (cpc159317-cmbg20-2-0-cust117.5-4.cable.virginm.net. [81.111.29.118]) by smtp.gmail.com with ESMTPSA id z6sm318233wmi.28.2020.10.19.10.41.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 10:41:35 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.0.3.2.82\)) Subject: Re: Add a way to invoke redefined (overridden) GDB commands From: Marco Barisione In-Reply-To: Date: Mon, 19 Oct 2020 18:41:31 +0100 Cc: gdb-patches@sourceware.org Content-Transfer-Encoding: quoted-printable Message-Id: <371BE292-EE03-4FBE-A963-64F08437A6A7@undo.io> References: <20200914093925.5442-1-mbarisione@undo.io> To: Pedro Alves X-Mailer: Apple Mail (2.3654.0.3.2.82) X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, KAM_SHORT, KAM_TK, RCVD_IN_DNSWL_NONE, 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 17:41:39 -0000 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. >>=20 >> 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. >>=20 >> 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: >>=20 >> (gdb) define run >> echo Will run!\n >> uplevel 0 run >> end >> (gdb) run >> Will run! >> [... normal output of run ...] >>=20 >>=20 >> 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. >=20 > 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. >=20 > 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. >=20 > 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: >=20 > https://www.tcl.tk/man/tcl8.4/TclCmd/rename.htm >=20 > So a user would do: >=20 > (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 ...] >=20 > (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. For instance: (gdb) # Rename "foo" to =E2=80=9Cbar": (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 --=20 Marco Barisione