From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 4A8163A3E80C for ; Fri, 7 May 2021 21:23:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4A8163A3E80C 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-wm1-x331.google.com with SMTP id a10-20020a05600c068ab029014dcda1971aso5775432wmn.3 for ; Fri, 07 May 2021 14:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QTpY8zQPlinYhhcvg0z1zNLprkD42F5dxxxHoQnZSPw=; b=Lo590NR7fGqXYzpIgwN99pR74qN00mIGfMeT2FzKtOeWpc1YpbJKV7ffa0D9pkAhp+ bxnKgnAQzgRWiKlmZMYUYtzqOW7qK7xYy6CKsHk7TRAE3x7PcZugd72Mu2lFOzp9atyZ hIQ/BXPDTUl21feZM8W63O6V5UZyLCyWlfNOuU7nSFz3CBMBVStSdBS6crT8dIpmBUpG 3end2aeT0znzrkZCRkIiNf7poGi7TrY2nCYv0VHqDA2acTKpoyzQnG7kWi/LM8Oc9EEa XsZ8TAfDemhaZfdDJYCMGaR0yMlNLSwL1gkOYtbh4DJ7MKcbzZpp3TBJFInXfw21SAS+ gIXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QTpY8zQPlinYhhcvg0z1zNLprkD42F5dxxxHoQnZSPw=; b=JgQeVaAFz3Kjt593y9su60N8CqkADgc+/VTdlIJpk+5HGrOUKTzCETR/clFB1gnHve F2eeQfugAUKdqqtnVhKAi4BvdIeaepy6NiH71UKuI0c0KMkf0+lNecpzbE9IzLCZUOEf eTxu+qyRw2V4TA3I55fMclWcp7fsePvdhIzWunyOt1+XlRZ5uAMBpyy4ongag88JLpSR 01kt1cK7VMudi+XiBt1EfwGLG3Mql288FQ6XeRrKxnNSy97hqjA66XmwIVNRFHcOl/hd CTGvO9FQtFAGs+yFu5tFErRXCCiy6X7k+Dhv+rIcMTQZAxdjngjGOedzu4sBRLAvfDzI qf3g== X-Gm-Message-State: AOAM532j5kS+Yc/jdDtZMulTWYiMZPVBoDnF7PnDuGupZ2tBqXDPyx4B iRZRwHy0D8fJnEypAnFlH7k5uQ== X-Google-Smtp-Source: ABdhPJzzi8blCL3cK/6mxUjDt+yAW3KuXdRIZqm4IpHiumaiXbCd3F9RlBT71UkfsCsVrv9c8lazwA== X-Received: by 2002:a1c:a90c:: with SMTP id s12mr12397508wme.185.1620422605412; Fri, 07 May 2021 14:23:25 -0700 (PDT) Received: from localhost (host109-151-46-70.range109-151.btcentralplus.com. [109.151.46.70]) by smtp.gmail.com with ESMTPSA id y14sm9687031wrs.64.2021.05.07.14.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 14:23:24 -0700 (PDT) Date: Fri, 7 May 2021 22:23:24 +0100 From: Andrew Burgess To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCHv2 1/2] gdb/guile: perform tilde expansion when sourcing guile scripts Message-ID: <20210507212324.GM6612@embecosm.com> References: <87bl9pq9li.fsf@tromey.com> <6e22f6c142ac81db0ec98d3c9485be5efcf58eca.1620248278.git.andrew.burgess@embecosm.com> <20210507102910.GL6612@embecosm.com> <2bfc1a5d-d8ba-e0af-15b7-d241a6e2c274@polymtl.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2bfc1a5d-d8ba-e0af-15b7-d241a6e2c274@polymtl.ca> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 22:23:04 up 4 days, 10:17, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] 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: Fri, 07 May 2021 21:23:28 -0000 * Simon Marchi [2021-05-07 10:55:38 -0400]: > On 2021-05-07 6:29 a.m., Andrew Burgess wrote: > > @@ -737,8 +738,10 @@ source_script_with_search (const char *file, int from_tty, int search_path) > > anyway so that error messages show the actual file used. But only do > > this if we (may have) used search_path, as printing the full path in > > errors for the non-search case can be more noise than signal. */ > > + gdb::unique_xmalloc_ptr file_to_open = gdb_tilde_expand_up (file); > > source_script_from_stream (opened->stream.get (), file, > > - search_path ? opened->full_path.get () : file); > > + search_path ? opened->full_path.get () > > + : file_to_open.get ()); > > A minor detail, but the gdb_tilde_expand_up call is only necessary when > search_path is false. So if there's a easy way to avoid it otherwise, > it would be nice. But other than that, LGTM. Thanks. Below is what I pushed. --- commit 1845e254645efbc02248345ccdb557d265dd8ae1 Author: Andrew Burgess Date: Wed May 5 16:50:17 2021 +0100 gdb/guile: perform tilde expansion when sourcing guile scripts 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 the generic GDB code before we call the sourcer function for any particular extension language. gdb/ChangeLog: * cli/cli-cmds.c: Add 'gdbsupport/gdb_tilde_expand.h' include. (source_script_with_search): Perform tilde expansion. gdb/testsuite/ChangeLog: * gdb.guile/guile.exp: Add an extra test. diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 68ef92eca4c..62948f5fc7b 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -54,6 +54,7 @@ #include "extension.h" #include "gdbsupport/pathstuff.h" +#include "gdbsupport/gdb_tilde_expand.h" #ifdef TUI #include "tui/tui.h" /* For tui_active et.al. */ @@ -737,8 +738,16 @@ source_script_with_search (const char *file, int from_tty, int search_path) anyway so that error messages show the actual file used. But only do this if we (may have) used search_path, as printing the full path in errors for the non-search case can be more noise than signal. */ - source_script_from_stream (opened->stream.get (), file, - search_path ? opened->full_path.get () : file); + const char *file_to_open; + gdb::unique_xmalloc_ptr tilde_expanded_file; + if (search_path) + file_to_open = opened->full_path.get (); + else + { + tilde_expanded_file = gdb_tilde_expand_up (file); + file_to_open = tilde_expanded_file.get (); + } + source_script_from_stream (opened->stream.get (), file, file_to_open); } /* Wrapper around source_script_with_search to export it to main.c 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" +}