Blob Blame History Raw
http://sourceware.org/ml/gdb-cvs/2011-10/msg00197.html

### src/gdb/ChangeLog	2011/10/27 15:32:10	1.13467
### src/gdb/ChangeLog	2011/10/27 15:46:07	1.13468
## -1,3 +1,15 @@
+2011-10-27  Doug Evans  <dje@google.com>
+
+	* cli/cli-cmds.c (source_script_with_search): Pass full path to
+	source_script_from_stream if it may have been found on the search path.
+	* python/py-auto-load.c (source_section_scripts): Pass full path to
+	source_python_script_for_objfile.
+	* python/python.c (source_python_script): Delete stream parameter.
+	All callers updated.
+	(source_python_script_for_objfile): Ditto.
+	* python/python-internal.h (source_python_script_for_objfile): Update.
+	* python/python.h (source_python_script): Update.
+
 2011-10-27  Tom Tromey  <tromey@redhat.com>
 
 	* ada-lang.h (ada_start_decode_line_1, ada_finish_decode_line_1)
Index: gdb-7.3.50.20110722/gdb/cli/cli-cmds.c
===================================================================
--- gdb-7.3.50.20110722.orig/gdb/cli/cli-cmds.c	2011-06-07 19:26:46.000000000 +0200
+++ gdb-7.3.50.20110722/gdb/cli/cli-cmds.c	2012-04-18 23:38:50.808994431 +0200
@@ -534,7 +534,9 @@ source_script_from_stream (FILE *stream,
 
       TRY_CATCH (e, RETURN_MASK_ERROR)
 	{
-	  source_python_script (stream, file);
+          /* The python support reopens the file using python functions,
+             so there's no point in passing STREAM here.  */
+	  source_python_script (file);
 	}
       if (e.reason < 0)
 	{
@@ -576,7 +578,7 @@ source_script_with_search (const char *f
 
   if (!find_and_open_script (file, search_path, &stream, &full_path))
     {
-      /* The script wasn't found, or was otherwise inaccessible.  
+      /* The script wasn't found, or was otherwise inaccessible.
          If the source command was invoked interactively, throw an
 	 error.  Otherwise (e.g. if it was invoked by a script),
 	 silently ignore the error.  */
@@ -587,7 +589,12 @@ source_script_with_search (const char *f
     }
 
   old_cleanups = make_cleanup (xfree, full_path);
-  source_script_from_stream (stream, file);
+  /* The python support reopens the file, so we need to pass full_path here
+     in case the file was found on the search path.  It's useful to do this
+     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 (stream, search_path ? full_path : file);
   do_cleanups (old_cleanups);
 }
 
Index: gdb-7.3.50.20110722/gdb/python/py-auto-load.c
===================================================================
--- gdb-7.3.50.20110722.orig/gdb/python/py-auto-load.c	2012-04-18 23:38:42.000000000 +0200
+++ gdb-7.3.50.20110722/gdb/python/py-auto-load.c	2012-04-18 23:38:50.809994429 +0200
@@ -312,7 +312,7 @@ Use `info auto-load-scripts [REGEXP]' to
 	{
 	  /* If this file is not currently loaded, load it.  */
 	  if (! in_hash_table)
-	    source_python_script_for_objfile (objfile, stream, file);
+	    source_python_script_for_objfile (objfile, full_path);
 	  fclose (stream);
 	  free (full_path);
 	}
@@ -431,7 +431,7 @@ auto_load_objfile_script (struct objfile
 	 It's highly unlikely that we'd ever load it twice,
 	 and these scripts are required to be idempotent under multiple
 	 loads anyway.  */
-      source_python_script_for_objfile (objfile, input, debugfile);
+      source_python_script_for_objfile (objfile, debugfile);
       fclose (input);
     }
 
Index: gdb-7.3.50.20110722/gdb/python/python.c
===================================================================
--- gdb-7.3.50.20110722.orig/gdb/python/python.c	2012-04-18 23:38:42.000000000 +0200
+++ gdb-7.3.50.20110722/gdb/python/python.c	2012-04-18 23:38:50.809994429 +0200
@@ -594,21 +594,18 @@ gdbpy_parse_and_eval (PyObject *self, Py
   return value_to_value_object (result);
 }
 
-/* Read a file as Python code.  STREAM is the input file; FILE is the
-   name of the file.
-   STREAM is not closed, that is the caller's responsibility.  */
+/* Read a file as Python code.
+   FILE is the name of the file.
+   This does not throw any errors.  If an exception occurs python will print
+   the traceback and clear the error indicator.  */
 
 void
-source_python_script (FILE *stream, const char *file)
+source_python_script (const char *file)
 {
   struct cleanup *cleanup;
 
   cleanup = ensure_python_env (get_current_arch (), current_language);
-
-  /* Note: If an exception occurs python will print the traceback and
-     clear the error indicator.  */
   python_run_simple_file (file);
-
   do_cleanups (cleanup);
 }
 
@@ -983,15 +980,12 @@ gdbpy_progspaces (PyObject *unused1, PyO
    source_python_script_for_objfile; it is NULL at other times.  */
 static struct objfile *gdbpy_current_objfile;
 
-/* Set the current objfile to OBJFILE and then read STREAM,FILE as
-   Python code.
-   STREAM is left open, it is up to the caller to close it.
-   If an exception occurs python will print the traceback and
-   clear the error indicator.  */
+/* Set the current objfile to OBJFILE and then read FILE as Python code.
+   This does not throw any errors.  If an exception occurs python will print
+   the traceback and clear the error indicator.  */
 
 void
-source_python_script_for_objfile (struct objfile *objfile,
-				  FILE *stream, const char *file)
+source_python_script_for_objfile (struct objfile *objfile, const char *file)
 {
   struct cleanup *cleanups;
 
@@ -1074,7 +1068,7 @@ eval_python_from_control_command (struct
 }
 
 void
-source_python_script (FILE *stream, const char *file)
+source_python_script (const char *file)
 {
   throw_error (UNSUPPORTED_ERROR,
 	       _("Python scripting is not supported in this copy of GDB."));
Index: gdb-7.3.50.20110722/gdb/python/python.h
===================================================================
--- gdb-7.3.50.20110722.orig/gdb/python/python.h	2012-04-18 23:38:41.000000000 +0200
+++ gdb-7.3.50.20110722/gdb/python/python.h	2012-04-18 23:38:50.809994429 +0200
@@ -30,7 +30,7 @@ extern void finish_python_initialization
 
 void eval_python_from_control_command (struct command_line *);
 
-void source_python_script (FILE *stream, const char *file);
+void source_python_script (const char *file);
 
 void run_python_script (int argc, char **argv);
 
Index: gdb-7.3.50.20110722/gdb/python/python-internal.h
===================================================================
--- gdb-7.3.50.20110722.orig/gdb/python/python-internal.h	2011-06-28 15:09:12.000000000 +0200
+++ gdb-7.3.50.20110722/gdb/python/python-internal.h	2012-04-18 23:38:50.809994429 +0200
@@ -242,7 +242,7 @@ extern const struct language_defn *pytho
 void gdbpy_print_stack (void);
 
 void source_python_script_for_objfile (struct objfile *objfile,
-				       FILE *stream, const char *file);
+				       const char *file);
 
 PyObject *python_string_to_unicode (PyObject *obj);
 char *unicode_to_target_string (PyObject *unicode_str);
Index: gdb-7.3.50.20110722/gdb/testsuite/gdb.python/python.exp
===================================================================
--- gdb-7.3.50.20110722.orig/gdb/testsuite/gdb.python/python.exp	2011-07-21 13:03:48.000000000 +0200
+++ gdb-7.3.50.20110722/gdb/testsuite/gdb.python/python.exp	2012-04-18 23:38:50.810994427 +0200
@@ -75,6 +75,8 @@ gdb_py_test_multiple "indented multi-lin
 
 gdb_test "source $srcdir/$subdir/source2.py" "yes"
 
+gdb_test "source -s source2.py" "yes" "source -s source2.py"
+
 gdb_test "python print gdb.current_objfile()" "None"
 gdb_test "python print gdb.objfiles()" "\\\[\\\]"