From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wwNxExlTk2AWFAAAWB0awg (envelope-from ) for ; Wed, 05 May 2021 22:23:21 -0400 Received: by simark.ca (Postfix, from userid 112) id 406301F11C; Wed, 5 May 2021 22:23:21 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7BFE21E813 for ; Wed, 5 May 2021 22:23:20 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F319383F432; Thu, 6 May 2021 02:23:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F319383F432 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620267800; bh=34u0HaTqPgWynaSeI8s7NRzCXirQa6H9HNtYcxfGgyo=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fpK5id6RxRhlVprEXXBNft6rJaqwvHg8nEn09gw1GTamhMqpdIQ9oWC7QWqzCz+BX L0H50RQFnEWGfDbTTatY/j5+7M5cqgV7RSTt2kPnIMnNw36INkcinUkak+fvS/5G24 /4TEHZMNpSCUMjQ90fZJEv0ih+NbR+M6t5qpQoxk= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 9238C385782E for ; Thu, 6 May 2021 02:23:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9238C385782E Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 1462NCf3017088 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 5 May 2021 22:23:17 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 1462NCf3017088 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 2DCD41E813; Wed, 5 May 2021 22:23:12 -0400 (EDT) Subject: Re: [PATCHv2 1/2] gdb/guile: perform tilde expansion when sourcing guile scripts To: Andrew Burgess , gdb-patches@sourceware.org References: <87bl9pq9li.fsf@tromey.com> <6e22f6c142ac81db0ec98d3c9485be5efcf58eca.1620248278.git.andrew.burgess@embecosm.com> Message-ID: Date: Wed, 5 May 2021 22:23:11 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <6e22f6c142ac81db0ec98d3c9485be5efcf58eca.1620248278.git.andrew.burgess@embecosm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 6 May 2021 02:23:12 +0000 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2021-05-05 5:01 p.m., Andrew Burgess wrote: > Before this patch: > > (gdb) source ~/script.scm > ERROR: In procedure apply-smob/1: > ERROR: In procedure primitive-load-path: Unable to find file "~/script.scm" in load path > Error while executing Scheme code. > (gdb) > > This is because the path is not tilde expanded. In contrast, when > sourcing a .py or .gdb script the path is tilde expanded. > > This commit fixes this oversight, and allows the above source command > to work as expected. > > The tilde expansion is done in guile/scm-safe-call.c rather than at a > higher level, for example, it might be tempting to add the tilde > expansion in cli/cli-cmds.c:source_script_from_stream, however, not > every extension language wants to see a tilde expanded file path. For > example, consider Python. Currently we pass in an unexpanded path and > we see this behaviour: > > (gdb) source ~/tmp/xxx.py > Traceback (most recent call last): > File "~/tmp/xxx.py", line 1, in > NameError: name 'undefined' is not defined > > If we performed tilde expansion prior to calling the Python sourcer > function (gdbpy_source_script), we would instead see: > > (gdb) source ~/tmp/xxx.py > Traceback (most recent call last): > File "/home/andrew/tmp/xxx.py", line 1, in > undefined > NameError: name 'undefined' is not defined > > Notice the path expansion in the second line of the error message, I > believe this is a change for the worse. I really don't have a strong opinion, but I don't think this would be a problematic change. The tilde-expansion thing is really a shell thing (and we replicate it in GDB). But once the paths are processed by programs such as Python, the tilde usually doesn't have a special meaning. If I do: $ python3 ~/foo.py I get: Traceback (most recent call last): File "/home/simark/foo.py", line 1, in blah NameError: name 'blah' is not defined Because the shell did the tilde-expansion before passing the file name to Python. If I do: $ python3 '~/foo.py' then I get: python3: can't open file '/home/simark/build/binutils-gdb-one-target/gdb/~/foo.py': [Errno 2] No such file or directory Python shows the tilde version of the path in our error messages just becore we tell it that's the name of the file, Python doesn't use that name otherwise (I think). We could tell it the filename is "potato", and it would say that the error is in file "potato". So in a sense, passing the tilde-expanded version would make it look more like the "regular" Python interpreter. But like I said, I don't have a strong opinion: in the end this is shown to the user, they will understand it either way. Otherwise, the patch LGTM. Simon