From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8807 invoked by alias); 21 Aug 2019 16:39:24 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 8798 invoked by uid 89); 21 Aug 2019 16:39:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=selling, recalled, gdbs, Due X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Aug 2019 16:39:23 +0000 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F04314ACDF for ; Wed, 21 Aug 2019 16:39:21 +0000 (UTC) Received: by mail-wr1-f72.google.com with SMTP id k8so1470516wrx.19 for ; Wed, 21 Aug 2019 09:39:21 -0700 (PDT) Received: from ?IPv6:2001:8a0:f913:f700:4c97:6d52:2cea:997b? ([2001:8a0:f913:f700:4c97:6d52:2cea:997b]) by smtp.gmail.com with ESMTPSA id g26sm283562wmh.32.2019.08.21.09.39.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Aug 2019 09:39:19 -0700 (PDT) Subject: Re: [PATCH 2/3] Add -P command line switch for executing Python scripts To: Tom Tromey , Kevin Buettner References: <20190721235427.21893-1-kevinb@redhat.com> <20190721235427.21893-3-kevinb@redhat.com> <87sgqwv6ql.fsf@tromey.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <21426c57-8db7-4e12-5090-4e35ae4aea4f@redhat.com> Date: Wed, 21 Aug 2019 16:39:00 -0000 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: <87sgqwv6ql.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-08/txt/msg00489.txt.bz2 On 7/23/19 9:25 PM, Tom Tromey wrote: >>>>>> "Kevin" == Kevin Buettner writes: > > Kevin> This commit introduces a new command line switch to GDB, a -P / > Kevin> --python switch which is used for executing a python script. > Kevin> Encountering -P curtails normal argument processing by GDB; any > Kevin> remaining arguments (after the script name) are passed to the > Kevin> script. > > Kevin> 1) After script execution, exit() was called which (obviously) > Kevin> caused GDB to exit. > Kevin> 2) The printing of GDB's banner (copyright info, bug reporting > Kevin> instructions, and help instructions) was suppressed. > Kevin> 3) Due to the exit() noted above, GDB's CLI was not (automatically) > Kevin> invoked. If the CLI was desired, it could be run from the Python > Kevin> script via use of the gdb.cli method, which was added as part of > Kevin> that work. > > Kevin> I've changed things so that exit() is no longer called. GDB's CLI > Kevin> will be invoked after script execution. Also, GDB's banner will be > Kevin> printed (or not) as normal. I.e, the banner will be printed unless > Kevin> the -q switch is specified. > > Kevin> If the script doesn't want the CLI for some reason, it can explicitly > Kevin> call exit(). It may be the case that the script would be better off > Kevin> calling a (yet to be written) gdb.exit() method for doing this > Kevin> instead. Such a method could make sure that GDB shuts down properly. > > The intent of -P was to provide a way to run gdb in a "Python script" > mode. I think this changes defeat this goal. > > For (2), printing the banner is just not great for an interpreter. The > default for interpreters should be silence, with the script being > interpreted choosing what to emit. "-q" isn't sufficient because it is > common for #! handling to only allow a single argument. I'm probably being dense, but I don't really understand this remark. Can you expand on what does "#! handling to only allow a single argument." mean? > > I think if -P is going to just mean "start gdb, but interpret some > Python script at startup", then it might as well not exist -- an > invocation like '-ex "source blah.py"' is just as good, and can be used > on older gdbs as well. A selling point that I recalled about the patch when we started discussing it internally was that you can pass arguments directly to the script from the command line, like: $ gdb -P blah.py py-arg1 py-arg2 I wonder if people find that feature itself useful, regardless of the original motivation for the patch? > (1) and (3) seem linked. Here the idea was to have a way to script gdb > where the command line was completely optional and under control of the > script. > > Maybe -P isn't the right vehicle for this. Later on, I was looking at > having a "Python" gdb interpreter -- not to actually interpret gdb > input, but to at least control gdb output. And, I looked into compiling > gdb PIE so that one could just "import gdb" from an ordinary Python > interpreter. FYI, and FWIW, we ended up dropping this patch from Fedora GDB. Thanks, Pedro Alves