[PATCHv2 1/2] gdb/guile: perform tilde expansion when sourcing guile scripts
Andrew Burgess
andrew.burgess@embecosm.com
Fri May 7 21:23:24 GMT 2021
* Simon Marchi <simon.marchi@polymtl.ca> [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<char> 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 <andrew.burgess@embecosm.com>
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<char> 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"
+}
More information about the Gdb-patches
mailing list