Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Joel Brobecker <brobecker@adacore.com>, gdb-patches@sourceware.org
Subject: Re: GDB 7.5: Problems with the auto-load safe-path feature
Date: Mon, 20 Aug 2012 15:08:00 -0000	[thread overview]
Message-ID: <20120820150725.GA2310@host2.jankratochvil.net> (raw)
In-Reply-To: <834no0gmca.fsf@gnu.org>

On Sat, 18 Aug 2012 19:07:49 +0200, Eli Zaretskii wrote:
> Like in the patch below?  I can drop the #ifdef, if no one objects (it
> could surprise Unix users who call their programs FOO.exe for some
> reason).

Yes, Joel also was for dropping the #ifdef.

Also I believe GDB should test the .exe-less filenames even
in 'set auto-load scripts-directory' entries.

What about the patch below?

Going to run a regression test (but auto-load does not have testcases).


Thanks,
Jan


> --- gdb/auto-load.c~	2012-08-18 15:47:48.953125000 +0300
> +++ gdb/auto-load.c	2012-08-18 19:44:20.859375000 +0300
> @@ -708,20 +708,6 @@ auto_load_objfile_script (struct objfile
>  
> @@ -735,6 +721,29 @@ auto_load_objfile_script (struct objfile
>      fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file \"%s\" %s.\n"),
>  			debugfile, input ? _("exists") : _("does not exist"));
>  
> +#if defined (__MSDOS__) || defined (__MINGW32__)
> +  /* For Windows/DOS .exe executables, strip the .exe suffix, so that
> +     FOO-gdb.gdb could be used for FOO.exe, and try again.  */
> +  if (!input)
> +    {
> +      const size_t lexe = sizeof (".exe") - 1;
> +
> +      if (len > lexe
> +	  && strcasecmp (realname + len - lexe, ".exe") == 0)
> +	{
> +	  len -= lexe;
> +	  realname[len] = '\0';
> +	  filename = xrealloc (filename, len + strlen (language->suffix) + 1);

Here is a bug, former FILENAME is already registered for xfree in cleanups.

> +	  memcpy (filename, realname, len);
> +	  strcpy (filename + len, language->suffix);
> +	  input = fopen (filename, "r");
> +	  debugfile = filename;
> +	  if (debug_auto_load)
> +	    fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file \"%s\" %s.\n"),
> +				debugfile, input ? _("exists") : _("does not exist"));
> +	}
> +    }
> +#endif
>    if (!input)
>      {
>        VEC (char_ptr) *vec;



gdb/
2012-08-20  Eli Zaretskii  <eliz@gnu.org>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* auto-load.c (auto_load_objfile_script): Rename to ...
	(auto_load_objfile_script_1): ... here, change variable realname to
	parameter realname, document it, add return value, add variable retval.
	(auto_load_objfile_script): New function.

gdb/doc/
2012-08-20  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (objfile-gdb.py file): New paragraph for .exe stripping.

diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 03a7539..f1cb5f8 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -693,27 +693,25 @@ clear_section_scripts (void)
     }
 }
 
-/* Look for the auto-load script in LANGUAGE associated with OBJFILE and load
-   it.  */
+/* Look for the auto-load script in LANGUAGE associated with OBJFILE where
+   OBJFILE's gdb_realpath is REALNAME and load it.  Return 1 if we found any
+   matching script, return 0 otherwise.  */
 
-void
-auto_load_objfile_script (struct objfile *objfile,
-			  const struct script_language *language)
+static int
+auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
+			    const struct script_language *language)
 {
-  char *realname;
   char *filename, *debugfile;
-  int len;
+  int len, retval;
   FILE *input;
   struct cleanup *cleanups;
 
-  realname = gdb_realpath (objfile->name);
   len = strlen (realname);
   filename = xmalloc (len + strlen (language->suffix) + 1);
   memcpy (filename, realname, len);
   strcpy (filename + len, language->suffix);
 
   cleanups = make_cleanup (xfree, filename);
-  make_cleanup (xfree, realname);
 
   input = fopen (filename, "r");
   debugfile = filename;
@@ -768,6 +766,44 @@ auto_load_objfile_script (struct objfile *objfile,
 	 and these scripts are required to be idempotent under multiple
 	 loads anyway.  */
       language->source_script_for_objfile (objfile, input, debugfile);
+
+      retval = 1;
+    }
+  else
+    retval = 0;
+
+  do_cleanups (cleanups);
+  return retval;
+}
+
+/* Look for the auto-load script in LANGUAGE associated with OBJFILE and load
+   it.  */
+
+void
+auto_load_objfile_script (struct objfile *objfile,
+			  const struct script_language *language)
+{
+  char *realname = gdb_realpath (objfile->name);
+  struct cleanup *cleanups = make_cleanup (xfree, realname);
+
+  if (!auto_load_objfile_script_1 (objfile, realname, language))
+    {
+      /* For Windows/DOS .exe executables, strip the .exe suffix, so that
+	 FOO-gdb.gdb could be used for FOO.exe, and try again.  */
+
+      size_t len = strlen (realname);
+      const size_t lexe = sizeof (".exe") - 1;
+
+      if (len > lexe && strcasecmp (realname + len - lexe, ".exe") == 0)
+	{
+	  len -= lexe;
+	  realname[len] = '\0';
+	  if (debug_auto_load)
+	    fprintf_unfiltered (gdb_stdlog, _("auto-load: Stripped .exe suffix, "
+					      "retrying with \"%s\".\n"),
+				realname);
+	  auto_load_objfile_script_1 (objfile, realname, language);
+	}
     }
 
   do_cleanups (cleanups);
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 08ba92d..66e217e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -25765,6 +25765,13 @@ If this file does not exist, then @value{GDBN} will look for
 Note that loading of this script file also requires accordingly configured
 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
 
+For object files using @file{.exe} suffix @value{GDBN} tries to load first the
+scripts normally according to its @file{.exe} filename.  But if no scripts are
+found @value{GDBN} also tries script filenames matching the object file without
+its @file{.exe} suffix.  This @file{.exe} stripping is case insensitive and it
+is attempted on any platform.  This makes the script filenames compatible
+between Unix and MS-Windows hosts.
+
 @table @code
 @anchor{set auto-load scripts-directory}
 @kindex set auto-load scripts-directory


  reply	other threads:[~2012-08-20 15:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-18 12:32 Eli Zaretskii
2012-08-18 13:21 ` Jan Kratochvil
2012-08-18 15:01   ` Eli Zaretskii
2012-08-18 16:19     ` Joel Brobecker
2012-08-18 17:11       ` Eli Zaretskii
2012-08-20 14:54   ` Tom Tromey
2012-08-27 16:48   ` [commit+7.5] apropos fix for auto-load texts [Re: GDB 7.5: Problems with the auto-load safe-path feature] Jan Kratochvil
2012-08-18 16:11 ` GDB 7.5: Problems with the auto-load safe-path feature Joel Brobecker
2012-08-18 17:07   ` Eli Zaretskii
2012-08-20 15:08     ` Jan Kratochvil [this message]
2012-08-20 16:36       ` Eli Zaretskii
2012-08-27 16:53       ` [commit+7.5] auto-load for .exe files [Re: GDB 7.5: Problems with the auto-load safe-path feature] Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120820150725.GA2310@host2.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox