public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [commit 2/2] Move processing of .debug_gdb_scripts to auto-load.c
@ 2013-11-30  8:58 Doug Evans
  2014-02-23 21:24 ` [patch+7.7] Fix auto-load 7.7 regression [Re: [commit 2/2] Move processing of .debug_gdb_scripts to auto-load.c] Jan Kratochvil
  0 siblings, 1 reply; 7+ messages in thread
From: Doug Evans @ 2013-11-30  8:58 UTC (permalink / raw)
  To: gdb-patches

Hi.

This is the second of two patches that does two cleanups:
1) Move processing of .debug_gdb_scripts to auto-load.c.
2) Simplify handling of ${objfile}-${suffix} scripts.
[e.g. foo-gdb.gdb, libfoo-gdb.py]

Regression tested on amd64-linux, with/without python.

2013-11-29  Doug Evans  <xdje42@gmail.com>

	* auto-load.h (script_language): New members name, auto_load_enabled.
	Add missing comments on struct members.
	(auto_load_objfile_script): Delete.
	* auto-load.c: #include "cli/cli-cmds.h".
	(auto_load_gdb_scripts_enabled): New function.
	(script_language_gdb): Update, add new members.
	(source_gdb_script_for_objfile): Simplify, auto-load safe-checking
	and call to maybe_add_script moved to caller.
	(auto_load_objfile_script_1): Auto-load safe-checking and
	call to maybe_add_script moved here.
	(auto_load_objfile_script): Make static.  Early exit if support for
	scripting language hasn't been compiled in, or auto-loading has been
	disabled.
	(source_section_scripts): Argument "source_name" renamed to
	"section_name".  All uses updated.  Replace uses of AUTO_SECTION_NAME
	with section_name.  Skip loading script if support for scripting
	language hasn't been compiled in, or auto-loading has been disabled.
	Call language->source_script_for_objfile instead of calling
	source_python_script_for_objfile directly.
	(load_auto_scripts_for_objfile): Update.
	* python/py-auto-load.c: Delete #include "cli/cli-cmds.h".
	(gdbpy_load_auto_script_for_objfile): Delete.
	(auto_load_python_scripts_enabled): New function.
	(script_language_python): Update, add new members.
	(gdbpy_script_language_defn): New function.
	* python/python.h (gdbpy_load_auto_scripts_for_objfile): Delete.
	(gdbpy_script_language_defn): Declare.

diff --git a/gdb/auto-load.h b/gdb/auto-load.h
index 6a66622..2ddebc5 100644
--- a/gdb/auto-load.h
+++ b/gdb/auto-load.h
@@ -24,8 +24,18 @@ struct program_space;
 
 struct script_language
 {
+  /* The name of the language, lowercase.  */
+  const char *name;
+
+  /* The suffix added to objfiles to get their auto-load script.
+     E.g., "-gdb.py".  */
   const char *suffix;
 
+  /* Returns non-zero if auto-loading scripts in this language is enabled.  */
+  int (*auto_load_enabled) (void);
+
+  /* Worker routine to load the script.  It has already been opened and
+     deemed safe to load.  */
   void (*source_script_for_objfile) (struct objfile *objfile, FILE *file,
 				     const char *filename);
 };
@@ -42,8 +52,6 @@ extern int maybe_add_script (struct auto_load_pspace_info *pspace_info,
 			     int loaded, const char *name,
 			     const char *full_path,
 			     const struct script_language *language);
-extern void auto_load_objfile_script (struct objfile *objfile,
-				      const struct script_language *language);
 extern void load_auto_scripts_for_objfile (struct objfile *objfile);
 extern int
   script_not_found_warning_print (struct auto_load_pspace_info *pspace_info);
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 2a74e90..02b08be 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -30,6 +30,7 @@
 #include "exceptions.h"
 #include "cli/cli-script.h"
 #include "gdbcmd.h"
+#include "cli/cli-cmds.h"
 #include "cli/cli-decode.h"
 #include "cli/cli-setshow.h"
 #include "gdb_vecs.h"
@@ -87,6 +88,14 @@ show_auto_load_gdb_scripts (struct ui_file *file, int from_tty,
 		    value);
 }
 
+/* Return non-zero if auto-loading gdb scripts is enabled.  */
+
+static int
+auto_load_gdb_scripts_enabled (void)
+{
+  return auto_load_gdb_scripts;
+}
+
 /* Internal-use flag to enable/disable auto-loading.
    This is true if we should auto-load python code when an objfile is opened,
    false otherwise.
@@ -510,31 +519,20 @@ For more information about this security protection see the\n\
 
 /* Definition of script language for GDB canned sequences of commands.  */
 
-static const struct script_language script_language_gdb
-  = { GDB_AUTO_FILE_NAME, source_gdb_script_for_objfile };
+static const struct script_language script_language_gdb =
+{
+  "gdb",
+  GDB_AUTO_FILE_NAME,
+  auto_load_gdb_scripts_enabled,
+  source_gdb_script_for_objfile
+};
 
 static void
 source_gdb_script_for_objfile (struct objfile *objfile, FILE *file,
 			       const char *filename)
 {
-  int is_safe;
-  struct auto_load_pspace_info *pspace_info;
   volatile struct gdb_exception e;
 
-  is_safe = file_is_auto_load_safe (filename, _("auto-load: Loading canned "
-						"sequences of commands script "
-						"\"%s\" for objfile \"%s\".\n"),
-				    filename, objfile_name (objfile));
-
-  /* Add this script to the hash table too so "info auto-load gdb-scripts"
-     can print it.  */
-  pspace_info = get_auto_load_pspace_data_for_loading (current_program_space);
-  maybe_add_script (pspace_info, is_safe, filename, filename,
-		    &script_language_gdb);
-
-  if (!is_safe)
-    return;
-
   TRY_CATCH (e, RETURN_MASK_ALL)
     {
       script_from_file (file, filename);
@@ -788,14 +786,31 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
 
   if (input)
     {
+      int is_safe;
+      struct auto_load_pspace_info *pspace_info;
+
       make_cleanup_fclose (input);
 
+      is_safe
+	= file_is_auto_load_safe (filename,
+				  _("auto-load: Loading %s script \"%s\""
+				    " by extension for objfile \"%s\".\n"),
+				  language->name, filename,
+				  objfile_name (objfile));
+
+      /* Add this script to the hash table too so
+	 "info auto-load ${lang}-scripts" can print it.  */
+      pspace_info
+	= get_auto_load_pspace_data_for_loading (current_program_space);
+      maybe_add_script (pspace_info, is_safe, filename, filename, language);
+
       /* To preserve existing behaviour we don't check for whether the
 	 script was already in the table, and always load it.
 	 It's highly unlikely that we'd ever load it twice,
 	 and these scripts are required to be idempotent under multiple
 	 loads anyway.  */
-      language->source_script_for_objfile (objfile, input, debugfile);
+      if (is_safe)
+	language->source_script_for_objfile (objfile, input, debugfile);
 
       retval = 1;
     }
@@ -809,12 +824,21 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
 /* Look for the auto-load script in LANGUAGE associated with OBJFILE and load
    it.  */
 
-void
+static void
 auto_load_objfile_script (struct objfile *objfile,
 			  const struct script_language *language)
 {
-  char *realname = gdb_realpath (objfile_name (objfile));
-  struct cleanup *cleanups = make_cleanup (xfree, realname);
+  char *realname;
+  struct cleanup *cleanups;
+
+  /* Skip this script if support has not been compiled in or
+     auto-loading it has been disabled.  */
+  if (language == NULL
+      || !language->auto_load_enabled ())
+    return;
+
+  realname = gdb_realpath (objfile_name (objfile));
+  cleanups = make_cleanup (xfree, realname);
 
   if (!auto_load_objfile_script_1 (objfile, realname, language))
     {
@@ -842,17 +866,17 @@ auto_load_objfile_script (struct objfile *objfile,
 /* Load scripts specified in OBJFILE.
    START,END delimit a buffer containing a list of nul-terminated
    file names.
-   SOURCE_NAME is used in error messages.
+   SECTION_NAME is used in error messages.
 
    Scripts are found per normal "source -s" command processing.
    First the script is looked for in $cwd.  If not found there the
    source search path is used.
 
-   The section contains a list of path names of files containing
-   python code to load.  Each path is null-terminated.  */
+   The section contains a list of path names of script files to load.
+   Each path is null-terminated.  */
 
 static void
-source_section_scripts (struct objfile *objfile, const char *source_name,
+source_section_scripts (struct objfile *objfile, const char *section_name,
 			const char *start, const char *end)
 {
   const char *p;
@@ -867,10 +891,13 @@ source_section_scripts (struct objfile *objfile, const char *source_name,
       char *full_path;
       int opened, in_hash_table;
       struct cleanup *back_to;
+      /* At the moment we only support python scripts in .debug_gdb_scripts,
+	 but that can change.  */
+      const struct script_language *language = gdbpy_script_language_defn ();
 
       if (*p != 1)
 	{
-	  warning (_("Invalid entry in %s section"), AUTO_SECTION_NAME);
+	  warning (_("Invalid entry in %s section"), section_name);
 	  /* We could try various heuristics to find the next valid entry,
 	     but it's safer to just punt.  */
 	  break;
@@ -886,13 +913,22 @@ source_section_scripts (struct objfile *objfile, const char *source_name,
 	  memcpy (buf, file, p - file);
 	  buf[p - file] = '\0';
 	  warning (_("Non-null-terminated path in %s: %s"),
-		   source_name, buf);
+		   section_name, buf);
 	  /* Don't load it.  */
 	  break;
 	}
       if (p == file)
 	{
-	  warning (_("Empty path in %s"), source_name);
+	  warning (_("Empty path in %s"), section_name);
+	  continue;
+	}
+
+      /* Skip this script if support has not been compiled in or
+	 auto-loading it has been disabled.  */
+      if (language == NULL
+	  || !language->auto_load_enabled ())
+	{
+	  /* No message is printed, just skip it.  */
 	  continue;
 	}
 
@@ -906,10 +942,10 @@ source_section_scripts (struct objfile *objfile, const char *source_name,
 	  make_cleanup (xfree, full_path);
 
 	  if (!file_is_auto_load_safe (full_path,
-				       _("auto-load: Loading Python script "
+				       _("auto-load: Loading %s script "
 					 "\"%s\" from section \"%s\" of "
 					 "objfile \"%s\".\n"),
-				       full_path, AUTO_SECTION_NAME,
+				       language->name, full_path, section_name,
 				       objfile_name (objfile)))
 	    opened = 0;
 	}
@@ -928,16 +964,19 @@ source_section_scripts (struct objfile *objfile, const char *source_name,
 	  if (script_not_found_warning_print (pspace_info))
 	    warning (_("Missing auto-load scripts referenced in section %s\n\
 of file %s\n\
-Use `info auto-load python [REGEXP]' to list them."),
-		     AUTO_SECTION_NAME, objfile_name (objfile));
+Use `info auto-load %s-scripts [REGEXP]' to list them."),
+		     section_name, objfile_name (objfile), language->name);
 	}
 
       in_hash_table = maybe_add_script (pspace_info, opened, file, full_path,
-					&script_language_python);
+					language);
 
       /* If this file is not currently loaded, load it.  */
       if (opened && !in_hash_table)
-	source_python_script_for_objfile (objfile, stream, full_path);
+	{
+	  gdb_assert (language->source_script_for_objfile != NULL);
+	  language->source_script_for_objfile (objfile, stream, full_path);
+	}
 
       do_cleanups (back_to);
     }
@@ -979,10 +1018,10 @@ load_auto_scripts_for_objfile (struct objfile *objfile)
   if (!global_auto_load || (objfile->flags & OBJF_NOT_FILENAME) != 0)
     return;
 
-  if (auto_load_gdb_scripts)
-    auto_load_objfile_script (objfile, &script_language_gdb);
+  auto_load_objfile_script (objfile, &script_language_gdb);
+  auto_load_objfile_script (objfile, gdbpy_script_language_defn ());
 
-  gdbpy_load_auto_scripts_for_objfile (objfile);
+  auto_load_section_scripts (objfile, AUTO_SECTION_NAME);
 }
 
 /* This is a new_objfile observer callback to auto-load scripts.
diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c
index 0d498f8..d5450b3 100644
--- a/gdb/python/py-auto-load.c
+++ b/gdb/python/py-auto-load.c
@@ -24,7 +24,6 @@
 #include "gdbcmd.h"
 #include "objfiles.h"
 #include "python.h"
-#include "cli/cli-cmds.h"
 #include "auto-load.h"
 
 #ifdef HAVE_PYTHON
@@ -37,10 +36,6 @@
    objfile is opened, false otherwise.  */
 static int auto_load_python_scripts = 1;
 
-static void gdbpy_load_auto_script_for_objfile (struct objfile *objfile,
-						FILE *file,
-						const char *filename);
-
 /* "show" command for the auto_load_python_scripts configuration variable.  */
 
 static void
@@ -50,45 +45,30 @@ show_auto_load_python_scripts (struct ui_file *file, int from_tty,
   fprintf_filtered (file, _("Auto-loading of Python scripts is %s.\n"), value);
 }
 
-/* Definition of script language for Python scripts.  */
+/* Return non-zero if auto-loading Python scripts is enabled.  */
 
-static const struct script_language script_language_python
-  = { GDBPY_AUTO_FILE_NAME, gdbpy_load_auto_script_for_objfile };
+static int
+auto_load_python_scripts_enabled (void)
+{
+  return auto_load_python_scripts;
+}
 
-/* Wrapper of source_python_script_for_objfile for script_language_python.  */
+/* Definition of script language for Python scripts.  */
 
-static void
-gdbpy_load_auto_script_for_objfile (struct objfile *objfile, FILE *file,
-				    const char *filename)
+static const struct script_language script_language_python =
 {
-  int is_safe;
-  struct auto_load_pspace_info *pspace_info;
-
-  is_safe = file_is_auto_load_safe (filename,
-				    _("auto-load: Loading Python script \"%s\" "
-				      "by extension for objfile \"%s\".\n"),
-				    filename, objfile_name (objfile));
-
-  /* Add this script to the hash table too so "info auto-load python-scripts"
-     can print it.  */
-  pspace_info = get_auto_load_pspace_data_for_loading (current_program_space);
-  maybe_add_script (pspace_info, is_safe, filename, filename,
-		    &script_language_python);
-
-  if (is_safe)
-    source_python_script_for_objfile (objfile, file, filename);
-}
+  "python",
+  GDBPY_AUTO_FILE_NAME,
+  auto_load_python_scripts_enabled,
+  source_python_script_for_objfile
+};
 
-/* Load any Python auto-loaded scripts for OBJFILE.  */
+/* Return the Python script language definition.  */
 
-void
-gdbpy_load_auto_scripts_for_objfile (struct objfile *objfile)
+const struct script_language *
+gdbpy_script_language_defn (void)
 {
-  if (auto_load_python_scripts)
-    {
-      auto_load_objfile_script (objfile, &script_language_python);
-      auto_load_section_scripts (objfile, GDBPY_AUTO_SECTION_NAME);
-    }
+  return &script_language_python;
 }
 
 /* Wrapper for "info auto-load python-scripts".  */
@@ -148,9 +128,13 @@ Print the list of automatically loaded Python scripts, deprecated."));
 
 #else /* ! HAVE_PYTHON */
 
-void
-gdbpy_load_auto_scripts_for_objfile (struct objfile *objfile)
+/* Return the Python script language definition.
+   Since support isn't compiled in, return NULL.  */
+
+const struct script_language *
+gdbpy_script_language_defn (void)
 {
+  return NULL;
 }
 
 #endif /* ! HAVE_PYTHON */
diff --git a/gdb/python/python.h b/gdb/python/python.h
index 047fb4c..c07b2aa 100644
--- a/gdb/python/python.h
+++ b/gdb/python/python.h
@@ -109,7 +109,7 @@ enum py_bt_status apply_frame_filter (struct frame_info *frame, int flags,
 
 void preserve_python_values (struct objfile *objfile, htab_t copied_types);
 
-void gdbpy_load_auto_scripts_for_objfile (struct objfile *objfile);
+const struct script_language *gdbpy_script_language_defn (void);
 
 int gdbpy_should_stop (struct gdbpy_breakpoint_object *bp_obj);
 

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

* [patch+7.7] Fix auto-load 7.7 regression  [Re: [commit 2/2] Move processing of .debug_gdb_scripts to auto-load.c]
  2013-11-30  8:58 [commit 2/2] Move processing of .debug_gdb_scripts to auto-load.c Doug Evans
@ 2014-02-23 21:24 ` Jan Kratochvil
  2014-02-23 23:27   ` Doug Evans
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2014-02-23 21:24 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

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

Hi Doug,

the regression affects any loading from /usr/share/gdb/auto-load .

5b2bf9471f1499bee578fcd60c05afe85794e280 is the first bad commit
commit 5b2bf9471f1499bee578fcd60c05afe85794e280
Author: Doug Evans <xdje42@gmail.com>
Date:   Fri Nov 29 21:29:26 2013 -0800
    Move .debug_gdb_script processing to auto-load.c.
    Simplify handling of auto-loaded objfile scripts.

Fedora 20 x86_64
$ gdb -q /usr/lib64/libgobject-2.0.so
Reading symbols from /usr/lib64/libglib-2.0.so.0.3800.2...Reading symbols from /usr/lib/debug/usr/lib64/libglib-2.0.so.0.3800.2.debug...done.
done.
(gdb) _

Fedora Rawhide x86_64
$ gdb -q /usr/lib64/libgobject-2.0.so
Reading symbols from /usr/lib64/libglib-2.0.so...Reading symbols from /usr/lib/debug/usr/lib64/libglib-2.0.so.0.3990.0.debug...done.
done.
warning: File "/usr/lib64/libglib-2.0.so.0.3990.0-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load:/usr/bin/mono-gdb.py".
To enable execution of this file add
	add-auto-load-safe-path /usr/lib64/libglib-2.0.so.0.3990.0-gdb.py
line to your configuration file "/home/jkratoch/.gdbinit".
To completely disable this security protection add
	set auto-load safe-path /
line to your configuration file "/home/jkratoch/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
	info "(gdb)Auto-loading safe path"
(gdb) _

That is it tries to load "forbidden"
	/usr/lib64/libglib-2.0.so.0.3990.0-gdb.py
but it should load instead
	/usr/share/gdb/auto-load/usr/lib64/libglib-2.0.so.0.3990.0-gdb.py*
Although that is also not exactly this way, there does not exist any
	/usr/lib64/libglib-2.0.so.0.3990.0-gdb.py
despite regressed GDB says so.



Regards,
Jan

[-- Attachment #2: autoload.patch --]
[-- Type: text/plain, Size: 4947 bytes --]

gdb/
2014-02-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* auto-load.c (auto_load_objfile_script_1): Change filename to
	debugfile.

gdb/testsuite/
2014-02-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.base/auto-load-script: New file.
	* gdb.base/auto-load.c: New file.
	* gdb.base/auto-load.exp: New file.

diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 86d4e5e..1112ef2 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -778,17 +778,17 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
       make_cleanup_fclose (input);
 
       is_safe
-	= file_is_auto_load_safe (filename,
+	= file_is_auto_load_safe (debugfile,
 				  _("auto-load: Loading %s script \"%s\""
 				    " by extension for objfile \"%s\".\n"),
 				  ext_lang_name (language),
-				  filename, objfile_name (objfile));
+				  debugfile, objfile_name (objfile));
 
       /* Add this script to the hash table too so
 	 "info auto-load ${lang}-scripts" can print it.  */
       pspace_info
 	= get_auto_load_pspace_data_for_loading (current_program_space);
-      maybe_add_script (pspace_info, is_safe, filename, filename, language);
+      maybe_add_script (pspace_info, is_safe, debugfile, debugfile, language);
 
       /* To preserve existing behaviour we don't check for whether the
 	 script was already in the table, and always load it.
diff --git a/gdb/testsuite/gdb.base/auto-load-script b/gdb/testsuite/gdb.base/auto-load-script
new file mode 100644
index 0000000..d02bd1a
--- /dev/null
+++ b/gdb/testsuite/gdb.base/auto-load-script
@@ -0,0 +1,17 @@
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+echo script_loaded\n
+set $script_loaded=42
diff --git a/gdb/testsuite/gdb.base/auto-load.c b/gdb/testsuite/gdb.base/auto-load.c
new file mode 100644
index 0000000..4b94803
--- /dev/null
+++ b/gdb/testsuite/gdb.base/auto-load.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/auto-load.exp b/gdb/testsuite/gdb.base/auto-load.exp
new file mode 100644
index 0000000..9b8211d
--- /dev/null
+++ b/gdb/testsuite/gdb.base/auto-load.exp
@@ -0,0 +1,36 @@
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+    return -1
+}
+
+set targetdir "${binfile}.dir"
+set sourcescript "${binfile}-script"
+set targetscriptdir "${targetdir}/[file dirname ${sourcescript}]"
+set targetscript "${targetscriptdir}/${testfile}-gdb.gdb"
+
+remote_exec host "rm -rf ${targetdir}"
+remote_exec host "mkdir -p ${targetscriptdir}"
+remote_exec host "cp ${sourcescript} ${targetscript}"
+
+gdb_test_no_output "set auto-load scripts-directory ${targetdir}" "set auto-load scripts-directory"
+gdb_test_no_output "set auto-load safe-path ${targetscript}" "set auto-load safe-path"
+
+gdb_load ${binfile}
+
+gdb_test {print $script_loaded} " = 42"

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

* Re: [patch+7.7] Fix auto-load 7.7 regression [Re: [commit 2/2] Move processing of .debug_gdb_scripts to auto-load.c]
  2014-02-23 21:24 ` [patch+7.7] Fix auto-load 7.7 regression [Re: [commit 2/2] Move processing of .debug_gdb_scripts to auto-load.c] Jan Kratochvil
@ 2014-02-23 23:27   ` Doug Evans
  2014-02-24  9:04     ` [patch+7.7] Fix auto-load 7.7 regression (PR gdb/16626) Jan Kratochvil
  0 siblings, 1 reply; 7+ messages in thread
From: Doug Evans @ 2014-02-23 23:27 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

On Sun, Feb 23, 2014 at 1:24 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> Hi Doug,
>
> the regression affects any loading from /usr/share/gdb/auto-load .
>
> 5b2bf9471f1499bee578fcd60c05afe85794e280 is the first bad commit
> commit 5b2bf9471f1499bee578fcd60c05afe85794e280
> Author: Doug Evans <xdje42@gmail.com>
> Date:   Fri Nov 29 21:29:26 2013 -0800
>     Move .debug_gdb_script processing to auto-load.c.
>     Simplify handling of auto-loaded objfile scripts.
>
> Fedora 20 x86_64
> $ gdb -q /usr/lib64/libgobject-2.0.so
> Reading symbols from /usr/lib64/libglib-2.0.so.0.3800.2...Reading symbols from /usr/lib/debug/usr/lib64/libglib-2.0.so.0.3800.2.debug...done.
> done.
> (gdb) _
>
> Fedora Rawhide x86_64
> $ gdb -q /usr/lib64/libgobject-2.0.so
> Reading symbols from /usr/lib64/libglib-2.0.so...Reading symbols from /usr/lib/debug/usr/lib64/libglib-2.0.so.0.3990.0.debug...done.
> done.
> warning: File "/usr/lib64/libglib-2.0.so.0.3990.0-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load:/usr/bin/mono-gdb.py".
> To enable execution of this file add
>         add-auto-load-safe-path /usr/lib64/libglib-2.0.so.0.3990.0-gdb.py
> line to your configuration file "/home/jkratoch/.gdbinit".
> To completely disable this security protection add
>         set auto-load safe-path /
> line to your configuration file "/home/jkratoch/.gdbinit".
> For more information about this security protection see the
> "Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
>         info "(gdb)Auto-loading safe path"
> (gdb) _
>
> That is it tries to load "forbidden"
>         /usr/lib64/libglib-2.0.so.0.3990.0-gdb.py
> but it should load instead
>         /usr/share/gdb/auto-load/usr/lib64/libglib-2.0.so.0.3990.0-gdb.py*
> Although that is also not exactly this way, there does not exist any
>         /usr/lib64/libglib-2.0.so.0.3990.0-gdb.py
> despite regressed GDB says so.
>
>
>
> Regards,
> Jan
>
> gdb/
> 2014-02-23  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
>         * auto-load.c (auto_load_objfile_script_1): Change filename to
>         debugfile.
>
> gdb/testsuite/
> 2014-02-23  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
>         * gdb.base/auto-load-script: New file.
>         * gdb.base/auto-load.c: New file.
>         * gdb.base/auto-load.exp: New file.

Crap.  "Sorry about that chief."

I filed this:
https://sourceware.org/bugzilla/show_bug.cgi?id=16626

If we make 7.7.1 this should definitely go in.

Your fix looks fine to me with one nit:
The .exp file is missing a test for native or a call to
gdb_remote_download to download the script.

You might also want to add a test to verify gdb won't load the wrong
file that it's trying to do now.

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

* Re: [patch+7.7] Fix auto-load 7.7 regression (PR gdb/16626)
  2014-02-23 23:27   ` Doug Evans
@ 2014-02-24  9:04     ` Jan Kratochvil
  2014-02-25 17:41       ` [commit+7.7] " Jan Kratochvil
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2014-02-24  9:04 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

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

On Mon, 24 Feb 2014 00:27:29 +0100, Doug Evans wrote:
> The .exp file is missing a test for native

Done.

> or a call to gdb_remote_download to download the script.

I am not sure how to derive there ${targetdir} from ${targetscript} (after
${targetscript} pathname transformatation by gdb_remote_download).

BTW I miss a setup for remote host in:
	https://sourceware.org/gdb/wiki/TestingGDB


> You might also want to add a test to verify gdb won't load the wrong
> file that it's trying to do now.

I do not see such test possible.  It now wrongly tries to load the script from
filename not using 'set auto-load scripts-directory'.  But such filename is
correct, it is tested first.  If such file exists it really should be loaded
first by the code above.


Thanks,
Jan

[-- Attachment #2: autoload.patch --]
[-- Type: text/plain, Size: 5019 bytes --]

gdb/
2014-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/16626
	* auto-load.c (auto_load_objfile_script_1): Change filename to
	debugfile.

gdb/testsuite/
2014-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/16626
	* gdb.base/auto-load-script: New file.
	* gdb.base/auto-load.c: New file.
	* gdb.base/auto-load.exp: New file.

diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 86d4e5e..1112ef2 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -778,17 +778,17 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
       make_cleanup_fclose (input);
 
       is_safe
-	= file_is_auto_load_safe (filename,
+	= file_is_auto_load_safe (debugfile,
 				  _("auto-load: Loading %s script \"%s\""
 				    " by extension for objfile \"%s\".\n"),
 				  ext_lang_name (language),
-				  filename, objfile_name (objfile));
+				  debugfile, objfile_name (objfile));
 
       /* Add this script to the hash table too so
 	 "info auto-load ${lang}-scripts" can print it.  */
       pspace_info
 	= get_auto_load_pspace_data_for_loading (current_program_space);
-      maybe_add_script (pspace_info, is_safe, filename, filename, language);
+      maybe_add_script (pspace_info, is_safe, debugfile, debugfile, language);
 
       /* To preserve existing behaviour we don't check for whether the
 	 script was already in the table, and always load it.
diff --git a/gdb/testsuite/gdb.base/auto-load-script b/gdb/testsuite/gdb.base/auto-load-script
new file mode 100644
index 0000000..d02bd1a
--- /dev/null
+++ b/gdb/testsuite/gdb.base/auto-load-script
@@ -0,0 +1,17 @@
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+echo script_loaded\n
+set $script_loaded=42
diff --git a/gdb/testsuite/gdb.base/auto-load.c b/gdb/testsuite/gdb.base/auto-load.c
new file mode 100644
index 0000000..4b94803
--- /dev/null
+++ b/gdb/testsuite/gdb.base/auto-load.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/auto-load.exp b/gdb/testsuite/gdb.base/auto-load.exp
new file mode 100644
index 0000000..226711f
--- /dev/null
+++ b/gdb/testsuite/gdb.base/auto-load.exp
@@ -0,0 +1,41 @@
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile
+
+if [is_remote host] {
+    return 0
+}
+
+set targetdir "${binfile}.dir"
+set sourcescript "${binfile}-script"
+set targetscriptdir "${targetdir}/[file dirname ${sourcescript}]"
+set targetscript "${targetscriptdir}/${testfile}-gdb.gdb"
+
+remote_exec host "rm -rf ${targetdir}"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+    return -1
+}
+
+remote_exec host "mkdir -p ${targetscriptdir}"
+remote_exec host "cp ${sourcescript} ${targetscript}"
+
+gdb_test_no_output "set auto-load scripts-directory ${targetdir}" "set auto-load scripts-directory"
+gdb_test_no_output "set auto-load safe-path ${targetscript}" "set auto-load safe-path"
+
+gdb_load ${binfile}
+
+gdb_test {print $script_loaded} " = 42"

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

* [commit+7.7] [patch+7.7] Fix auto-load 7.7 regression (PR gdb/16626)
  2014-02-24  9:04     ` [patch+7.7] Fix auto-load 7.7 regression (PR gdb/16626) Jan Kratochvil
@ 2014-02-25 17:41       ` Jan Kratochvil
  2014-02-25 19:07         ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2014-02-25 17:41 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

On Mon, 24 Feb 2014 10:03:56 +0100, Jan Kratochvil wrote:
> gdb/
> 2014-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	PR gdb/16626
> 	* auto-load.c (auto_load_objfile_script_1): Change filename to
> 	debugfile.
> 
> gdb/testsuite/
> 2014-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	PR gdb/16626
> 	* gdb.base/auto-load-script: New file.
> 	* gdb.base/auto-load.c: New file.
> 	* gdb.base/auto-load.exp: New file.

Checked in:
	849c862eb2637990692ffe31d16dc779f9bf30c5
and for gdb-7.7-branch:
	5b91e80ee94bc100df71fab5472f8adb2c9a88fd


Jan

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

* Re: [commit+7.7] [patch+7.7] Fix auto-load 7.7 regression (PR gdb/16626)
  2014-02-25 17:41       ` [commit+7.7] " Jan Kratochvil
@ 2014-02-25 19:07         ` Tom Tromey
  2014-02-25 19:50           ` [commit#2+7.7] " Jan Kratochvil
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2014-02-25 19:07 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

>> * gdb.base/auto-load-script: New file.
>> * gdb.base/auto-load.c: New file.
>> * gdb.base/auto-load.exp: New file.

Jan> Checked in:
Jan> 	849c862eb2637990692ffe31d16dc779f9bf30c5
Jan> and for gdb-7.7-branch:
Jan> 	5b91e80ee94bc100df71fab5472f8adb2c9a88fd

This new test fails for me on x86-64 Fedora 18.
I'm building outside the source tree in case that matters.

    FAIL: gdb.base/auto-load.exp: print $script_loaded

gdb.log says:

    (gdb) print $script_loaded
    $1 = void

I didn't look into it.

Tom

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

* [commit#2+7.7] [commit+7.7] [patch+7.7] Fix auto-load 7.7 regression (PR gdb/16626)
  2014-02-25 19:07         ` Tom Tromey
@ 2014-02-25 19:50           ` Jan Kratochvil
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Kratochvil @ 2014-02-25 19:50 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

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

On Tue, 25 Feb 2014 20:06:54 +0100, Tom Tromey wrote:
> This new test fails for me on x86-64 Fedora 18.
> I'm building outside the source tree in case that matters.
> 
>     FAIL: gdb.base/auto-load.exp: print $script_loaded

You are right, I did not test it out-of-srctree.

Checked in master and in 7.7.


Thanks,
Jan

[-- Attachment #2: Type: message/rfc822, Size: 1517 bytes --]

From: Jan Kratochvil <jan.kratochvil@redhat.com>
Subject: [PATCH] PR gdb/16626
Date: Tue, 25 Feb 2014 20:47:09 +0100

gdb/testsuite/
2014-02-25  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/16626
	* gdb.base/auto-load.exp: Fix out-of-srctree run.

Message-ID: <87k3cjt3jl.fsf@fleche.redhat.com>
---
 gdb/testsuite/ChangeLog              | 3 +++
 gdb/testsuite/gdb.base/auto-load.exp | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 1a2b358..d54ed98 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -5,6 +5,9 @@
 	* gdb.base/auto-load.c: New file.
 	* gdb.base/auto-load.exp: New file.
 
+	PR gdb/16626
+	* gdb.base/auto-load.exp: Fix out-of-srctree run.
+
 2014-02-25  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	Fix dw2-icycle.exp -fsanitize=address GDB crash.
diff --git a/gdb/testsuite/gdb.base/auto-load.exp b/gdb/testsuite/gdb.base/auto-load.exp
index 226711f..d0e93f0 100644
--- a/gdb/testsuite/gdb.base/auto-load.exp
+++ b/gdb/testsuite/gdb.base/auto-load.exp
@@ -20,8 +20,8 @@ if [is_remote host] {
 }
 
 set targetdir "${binfile}.dir"
-set sourcescript "${binfile}-script"
-set targetscriptdir "${targetdir}/[file dirname ${sourcescript}]"
+set sourcescript "${srcdir}/${subdir}/${testfile}-script"
+set targetscriptdir "${targetdir}/[file dirname ${binfile}]"
 set targetscript "${targetscriptdir}/${testfile}-gdb.gdb"
 
 remote_exec host "rm -rf ${targetdir}"
-- 
1.8.5.3

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

end of thread, other threads:[~2014-02-25 19:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-30  8:58 [commit 2/2] Move processing of .debug_gdb_scripts to auto-load.c Doug Evans
2014-02-23 21:24 ` [patch+7.7] Fix auto-load 7.7 regression [Re: [commit 2/2] Move processing of .debug_gdb_scripts to auto-load.c] Jan Kratochvil
2014-02-23 23:27   ` Doug Evans
2014-02-24  9:04     ` [patch+7.7] Fix auto-load 7.7 regression (PR gdb/16626) Jan Kratochvil
2014-02-25 17:41       ` [commit+7.7] " Jan Kratochvil
2014-02-25 19:07         ` Tom Tromey
2014-02-25 19:50           ` [commit#2+7.7] " Jan Kratochvil

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