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

* Re: [PATCH] gdb: fix auto-load variable expansion when path is nontrivial
  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ć
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-07-14 16:32 UTC (permalink / raw)
  To: Arsen Arsenović via Gdb-patches; +Cc: Arsen Arsenović, Tom Tromey

>>>>> "Arsen" == Arsen Arsenović via Gdb-patches <gdb-patches@sourceware.org> writes:

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

Arsen> Likely broken by 02601231fdd91a7bd4837ce202906ea2ce661489.

Thanks for the patch.

I'm just going to revert that patch instead.  It was just a cleanup and
turns out to be pretty broken.  We can fix it again later if we want,
next time hopefully with more care.

Sorry about the breakage.

I'll send the reversion momentarily.

Tom

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

* Re: [PATCH] gdb: fix auto-load variable expansion when path is nontrivial
  2023-07-14 16:32 ` Tom Tromey
@ 2023-07-15  1:16   ` Arsen Arsenović
  0 siblings, 0 replies; 3+ messages in thread
From: Arsen Arsenović @ 2023-07-15  1:16 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Arsen Arsenović via Gdb-patches

[-- Attachment #1: Type: text/plain, Size: 930 bytes --]

Hi Tom,

Tom Tromey <tromey@adacore.com> writes:

> Thanks for the patch.
>
> I'm just going to revert that patch instead.  It was just a cleanup and
> turns out to be pretty broken.  We can fix it again later if we want,
> next time hopefully with more care.
>
> Sorry about the breakage.
>
> I'll send the reversion momentarily.

And I'll confirm that worked:

  [auto-load] auto_load_expand_dir_vars: Expanded $-variables to
  "/usr/lib/debug:/usr/share/gdb/auto-load".
  [auto-load] auto_load_objfile_script_1: Searching 'set auto-load
  scripts-directory' path "$debugdir:$datadir/auto-load".
  [auto-load] auto_load_objfile_script_1: Attempted file
  "/..../14/libstdc++.so.6.0.33-gdb.scm" does not exist.
  [auto-load] auto_load_objfile_script_1: Attempted file
  "/.../14/libstdc++.so.6.0.33-gdb.scm" does not exist.

Thank you for your promptness!

Have a lovely night.
-- 
Arsen Arsenović

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 381 bytes --]

^ 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).