gdb/guile: perform tilde expansion when sourcing guile scripts
authorAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 5 May 2021 15:50:17 +0000 (16:50 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 7 May 2021 21:20:47 +0000 (22:20 +0100)
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.

gdb/ChangeLog
gdb/cli/cli-cmds.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.guile/guile.exp

index 25ee791de61883fc9ee19fc93bea6a183c5e44e1..41fe042d184f68cdce39e841315b52bc1b8c3748 100644 (file)
@@ -1,3 +1,9 @@
+2021-05-07  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * cli/cli-cmds.c: Add 'gdbsupport/gdb_tilde_expand.h'
+       include.
+       (source_script_with_search): Perform tilde expansion.
+
 2021-05-07  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * target-descriptions.c (struct target_desc_info) <filename>:
index 68ef92eca4c9ea19fc85c10802da8580f550ddc3..62948f5fc7bef7cb131c456806d00d2970c94539 100644 (file)
@@ -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
index 2fac86e2cea905e585f245e9b586363006dd68dd..afdd887c72b4867c9e618e139587472eb76b9881 100644 (file)
@@ -1,3 +1,7 @@
+2021-05-07  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.guile/guile.exp: Add an extra test.
+
 2021-05-07  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.base/ptype-offsets.exp: Replace use of send_gdb with
index 6e464cc0e773d5156f3cbf8884b2fb8b433887cb..0fb82284f465b5b0b6d0f02a2aa74a98e7615e28 100644 (file)
@@ -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"
+}
This page took 0.037678 seconds and 4 git commands to generate.