public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: fix auto-load variable expansion when path is nontrivial
@ 2023-07-14  0:55 Arsen Arsenović
  2023-07-14 16:32 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Arsen Arsenović @ 2023-07-14  0:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey, Arsen Arsenović

This fixes the auto-load script-directory default of
"$debugdir:$datadir/auto-load", which has recently stopped trying to
load from the $datadir recently.

Likely broken by 02601231fdd91a7bd4837ce202906ea2ce661489.
---
Evening!

This patch addresses a bug I found in the expansion of the auto-load
path, where only strings equal to auto-load path placeholders would get
expanded, as reported on IRC.

It lacks a test, but I've ran out of time for the evening to figure out
the testsuite with, and so, I am sending the patch in to prevent
duplicate effort, even though it's incomplete.

Have a lovely day!

 gdb/auto-load.c | 38 +++++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 9d6fabe6bbc..b1e372cf2e4 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -183,19 +183,39 @@ auto_load_expand_dir_vars (const char *string)
 
   for (auto &elt : result)
     {
-      if (strcmp (elt.get (), "$datadir") == 0)
+      struct vd {
+	/* Substitutable variable name.  */
+	const char *name;
+	/* Substitutable variable value.  */
+	const char *value;
+      };
+
+      const vd *sub = nullptr;
+
+      const vd vars[] = {
+	{ "$debugdir", debug_file_directory.c_str () },
+	{ "$datadir", gdb_datadir.c_str () }
+      };
+      for (const auto &var : vars)
 	{
-	  elt = make_unique_xstrdup (gdb_datadir.c_str ());
-	  if (debug_auto_load)
-	    auto_load_debug_printf ("Expanded $datadir to \"%s\".",
-				    gdb_datadir.c_str ());
+	  if (!startswith (elt.get (), var.name))
+	    continue;
+
+	  sub = &var;
+	  break;
 	}
-      else if (strcmp (elt.get (), "$debugdir") == 0)
+
+      if (sub)
 	{
-	  elt = make_unique_xstrdup (debug_file_directory.c_str ());
+	  auto new_elt = xstrprintf ("%s%s",
+				     sub->value,
+				     &elt.get ()[strlen (sub->name)]);
 	  if (debug_auto_load)
-	    auto_load_debug_printf ("Expanded $debugdir to \"%s\".",
-				    debug_file_directory.c_str ());
+	    auto_load_debug_printf ("Expanded %s in \"%s\" to \"%s\".",
+				    sub->name,
+				    elt.get (),
+				    new_elt.get ());
+	  elt = std::move (new_elt);
 	}
     }
 
-- 
2.41.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-15  1:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14  0:55 [PATCH] gdb: fix auto-load variable expansion when path is nontrivial Arsen Arsenović
2023-07-14 16:32 ` Tom Tromey
2023-07-15  1:16   ` Arsen Arsenović

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).