From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id i71lELLYkmD1CAAAWB0awg (envelope-from ) for ; Wed, 05 May 2021 13:41:06 -0400 Received: by simark.ca (Postfix, from userid 112) id 3B1F01F11C; Wed, 5 May 2021 13:41:06 -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.5 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,RDNS_DYNAMIC,T_DKIM_INVALID,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 A34FD1E813 for ; Wed, 5 May 2021 13:41:04 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1861539C242D; Wed, 5 May 2021 17:41:04 +0000 (GMT) Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 88B00385802B for ; Wed, 5 May 2021 17:41:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 88B00385802B 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-x432.google.com with SMTP id s8so2735193wrw.10 for ; Wed, 05 May 2021 10:41:01 -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:mime-version :content-transfer-encoding; bh=YtqjKXZG/yLRJFydEUDnmOznblCrSGE40hnok3eBn5Q=; b=QhAvitL0AjflLriNArqj+asW/23gUcjNFENWIw/5XMQ/XpweZSwBbO3G+Q6FOAeZ3s MLrYfHC0Y57S/p81k3m8vAdsSiJyCjTHU4O8MKiDGyVS23VVC/HIndobvEEuwURbc2zv 6I6JJLLBvCeTEDuWj+uKx8zpkUUbC6v6cmpvponzKAG81+QOhYXv/EAyw00E+1XSWWGr L9/JscAthf6xkUClKv5Z6vHvQTQhTqwfBXtm/bOgg+5kbitvl74iInntDTR99U3RgyWJ PWncOytLtGpiZS+K4dpQdjl85H3zkorFc49YMvWNx9fxF/QQ+cIDwlqhoyQ+BTo05KdZ LDQg== 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:mime-version :content-transfer-encoding; bh=YtqjKXZG/yLRJFydEUDnmOznblCrSGE40hnok3eBn5Q=; b=V9uulk1oKC7HRhKdgj/pgA12UZn5h3PqqUjXh6LFeogrgkZN1o37Z36bWLNvYg7ODt xh88aO00/fzYnDe8ocrmdTS/rxdoOZXVLz6jX/pBJl/uYw+IVYlJtcxFshY/zMNbWg/S 0zhbZ5iqq2/kySqIOaWeUtBLc7FZYPrG6crZn5CrklWqYhMtnoRJg15qfJBFo1QS2hOr gOMKqCjsMQKRI1rGDi4IpnSi3G+r6+71m3P4f19oMSJoqCZRrOkeMh49BE9zQkby8762 B6cLVES83fpJbh4mXCnQQggigsbHs1zxaIbL7uky99VDDc1aB/2OSTgug8v0DsXDP07u KCHw== X-Gm-Message-State: AOAM533BBNqA5c/vHUWQmCQPTfuw5weP0vorEiBTc55018Xln7J8ckRx 25KZcFg9+xMx4LAyvUyEZO7jRZvIFP+enw== X-Google-Smtp-Source: ABdhPJxv6ErjTyku9QM+Lbh6QfPBbVcwLVFBsK2kljnW9CorzBfBV3KETvzJhkDIQXv3jpqxgVpHzA== X-Received: by 2002:adf:f8c8:: with SMTP id f8mr173194wrq.267.1620236460437; Wed, 05 May 2021 10:41:00 -0700 (PDT) Received: from localhost (host109-151-46-70.range109-151.btcentralplus.com. [109.151.46.70]) by smtp.gmail.com with ESMTPSA id i3sm22795308wrb.46.2021.05.05.10.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 10:41:00 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH] gdb/guile: perform tilde expansion when sourcing guile scripts Date: Wed, 5 May 2021 18:40:58 +0100 Message-Id: <20210505174058.2135104-1-andrew.burgess@embecosm.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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. While I was working on the function that performs the sourcing I added a use of gdb::unique_xmalloc_ptr, this allows me to remove some manual memory management. gdb/ChangeLog: * guile/guile.c: Add 'gdbsupport/gdb_tilde_expand.h' include. (gdbscm_source_script): Expand filename using gdb_tilde_expand, and wrap error message in gdb::unique_xmalloc_ptr to avoid manual memory management. gdb/testsuite/ChangeLog: * gdb.guile/guile.exp: Add an extra test. --- gdb/ChangeLog | 7 +++++++ gdb/guile/guile.c | 11 ++++++----- gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.guile/guile.exp | 8 ++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c index c6959f5b713..d91427f4536 100644 --- a/gdb/guile/guile.c +++ b/gdb/guile/guile.c @@ -37,6 +37,7 @@ #endif #include #include "gdbsupport/block-signals.h" +#include "gdbsupport/gdb_tilde_expand.h" /* The Guile version we're using. We *could* use the macros in libguile/version.h but that would preclude @@ -270,13 +271,13 @@ static void gdbscm_source_script (const struct extension_language_defn *extlang, FILE *file, const char *filename) { - char *msg = gdbscm_safe_source_script (filename); + std::string full_path = gdb_tilde_expand (filename); + + gdb::unique_xmalloc_ptr msg + (gdbscm_safe_source_script (full_path.c_str ())); if (msg != NULL) - { - fprintf_filtered (gdb_stderr, "%s\n", msg); - xfree (msg); - } + fprintf_filtered (gdb_stderr, "%s\n", msg.get ()); } /* (execute string [#:from-tty boolean] [#:to-string boolean]) diff --git a/gdb/testsuite/gdb.guile/guile.exp b/gdb/testsuite/gdb.guile/guile.exp index 6e464cc0e77..06b7c006ee6 100644 --- a/gdb/testsuite/gdb.guile/guile.exp +++ b/gdb/testsuite/gdb.guile/guile.exp @@ -82,3 +82,11 @@ 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