From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id F3A1A385482A for ; Wed, 5 May 2021 21:01:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F3A1A385482A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x42f.google.com with SMTP id n2so3339682wrm.0 for ; Wed, 05 May 2021 14:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hd3J/9HRBsCWL2J78oocxW54CPN0vAiSLLS0kZ+80jM=; b=JYD56yH0voFO0J+QrtKquWWr4lm/eCUXUozo+54/AR9ojT2x0aP5/ePIlGMAJB+U/E uCbf6cANDkx3g0MqZawbpmwW+aAFPg5cVNSzCjo+w+rj/EWLJlV63yI6lGK3vV6wR8Va lYIjnpQwYUPq78YHn/d6lI5qAYnn2g7IS8zepGne9nL21LOJUqvfFpeKy/3d7aqIfwHc BLsHnhPAyK96KQUb167IceGVv8jWHzG+Q29nORClj6Y9PLVzaXkAaB7gGw5mbR9N54MA S/Jel5nuPA9Wf9B1juoON5gHRLi7biNksLtHJisj3c7OxIwVHUhEJM0X0QMqvr7B6o6P R7MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hd3J/9HRBsCWL2J78oocxW54CPN0vAiSLLS0kZ+80jM=; b=r4TbyX2U00Toa4u8q7HacHlCmrFFVNo7TJKdPMc1yR/EjgGykOr05tOQUqO1+l5o4l LCl3G3V4Zq/DMKPrioImnbFMbv31EKQGitrGt7UyJPTjIKMeHiAoKxtZQsyYYwnVeEI7 V1ReTZbaHZlAhueCxmbZsi12z//Uqo51DEEKpcnjSsEUJadR0ih/9JgKUDbDE69agyBL GdYPaq7Y4NzZ5GY0ZO3MnIEpQ0J6OrkIFs3VMjMIeVTCWWBzpjbdv4p3JABIZNM+Pguv KeIhKr1mYWJvOKARfbUZ0vyx3hQyUmIoW9PyBTIoj0LHx1giV8SnmhY06xiQYRzobQXr 9Z5g== X-Gm-Message-State: AOAM532xCfrqipZmc2jZ+cuj9d422+sKwBJLlJadpg+1lGFwStOBA9ng 7KlVeapAChxdYPNdbarQETpRsAr6MwZR1Q== X-Google-Smtp-Source: ABdhPJxqhmsZS/12/CELxWP7klO5EsQVBvtUO46r+VNpLJ1/PE0BgjDTBtagLhLnAZkP1xH95JrUUQ== X-Received: by 2002:adf:9b96:: with SMTP id d22mr994252wrc.225.1620248511868; Wed, 05 May 2021 14:01:51 -0700 (PDT) Received: from localhost (host109-151-46-70.range109-151.btcentralplus.com. [109.151.46.70]) by smtp.gmail.com with ESMTPSA id b12sm708322wro.28.2021.05.05.14.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 14:01:51 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCHv2 1/2] gdb/guile: perform tilde expansion when sourcing guile scripts Date: Wed, 5 May 2021 22:01:40 +0100 Message-Id: <6e22f6c142ac81db0ec98d3c9485be5efcf58eca.1620248278.git.andrew.burgess@embecosm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <87bl9pq9li.fsf@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham 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: Wed, 05 May 2021 21:01:54 -0000 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. And so, I think the best solution is for each language to perform its own tilde expansion if this is required, i.e. if the underlying language engine does not already handle tilde expansion. gdb/ChangeLog: * guile/scm-safe-call.c: Add 'gdbsupport/gdb_tilde_expand.h' include. (gdbscm_safe_source_script): Perform tilde expansion if the path is not absolute. gdb/testsuite/ChangeLog: * gdb.guile/guile.exp: Add an extra test. --- gdb/ChangeLog | 7 +++++++ gdb/guile/scm-safe-call.c | 4 +++- gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.guile/guile.exp | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gdb/guile/scm-safe-call.c b/gdb/guile/scm-safe-call.c index 2a38d6331fb..5bea970239b 100644 --- a/gdb/guile/scm-safe-call.c +++ b/gdb/guile/scm-safe-call.c @@ -24,6 +24,7 @@ #include "filenames.h" #include "guile-internal.h" #include "gdbsupport/pathstuff.h" +#include "gdbsupport/gdb_tilde_expand.h" /* Struct to marshall args to scscm_safe_call_body. */ @@ -444,7 +445,8 @@ gdbscm_safe_source_script (const char *filename) if (!IS_ABSOLUTE_PATH (filename)) { - abs_filename = gdb_realpath (filename); + abs_filename = gdb_tilde_expand_up (filename); + abs_filename = gdb_realpath (abs_filename.get ()); filename = abs_filename.get (); } diff --git a/gdb/testsuite/gdb.guile/guile.exp b/gdb/testsuite/gdb.guile/guile.exp index 6e464cc0e77..0fb82284f46 100644 --- a/gdb/testsuite/gdb.guile/guile.exp +++ b/gdb/testsuite/gdb.guile/guile.exp @@ -82,3 +82,10 @@ gdb_test_no_output "guile (define a (execute \"help\" #:to-string #t))" \ gdb_test "guile (print a)" "= .*aliases -- User-defined aliases of other commands.*" \ "verify help to uiout" + +# Verify that we can source a guile script using ~ for the HOME directory. +save_vars { env(HOME) } { + set env(HOME) $srcdir/$subdir + clean_restart + gdb_test "source ~/source2.scm" "yes" +} -- 2.25.4