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

	testsuite/
	* gdb.python/python.exp: Test source -s.
This commit is contained in:
Doug Evans 2011-10-27 15:46:11 +00:00
parent a08fc94222
commit d234ef5c0c
8 changed files with 44 additions and 25 deletions

View File

@ -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> 2011-10-27 Tom Tromey <tromey@redhat.com>
* ada-lang.h (ada_start_decode_line_1, ada_finish_decode_line_1) * ada-lang.h (ada_start_decode_line_1, ada_finish_decode_line_1)

View File

@ -535,7 +535,9 @@ source_script_from_stream (FILE *stream, const char *file)
TRY_CATCH (e, RETURN_MASK_ERROR) 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) if (e.reason < 0)
{ {
@ -577,7 +579,7 @@ source_script_with_search (const char *file, int from_tty, int search_path)
if (!find_and_open_script (file, search_path, &stream, &full_path)) 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 If the source command was invoked interactively, throw an
error. Otherwise (e.g. if it was invoked by a script), error. Otherwise (e.g. if it was invoked by a script),
silently ignore the error. */ silently ignore the error. */
@ -588,7 +590,12 @@ source_script_with_search (const char *file, int from_tty, int search_path)
} }
old_cleanups = make_cleanup (xfree, full_path); 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); do_cleanups (old_cleanups);
} }

View File

@ -312,7 +312,7 @@ Use `info auto-load-scripts [REGEXP]' to list them."),
{ {
/* If this file is not currently loaded, load it. */ /* If this file is not currently loaded, load it. */
if (! in_hash_table) if (! in_hash_table)
source_python_script_for_objfile (objfile, stream, file); source_python_script_for_objfile (objfile, full_path);
fclose (stream); fclose (stream);
free (full_path); free (full_path);
} }
@ -431,7 +431,7 @@ auto_load_objfile_script (struct objfile *objfile, const char *suffix)
It's highly unlikely that we'd ever load it twice, It's highly unlikely that we'd ever load it twice,
and these scripts are required to be idempotent under multiple and these scripts are required to be idempotent under multiple
loads anyway. */ loads anyway. */
source_python_script_for_objfile (objfile, input, debugfile); source_python_script_for_objfile (objfile, debugfile);
fclose (input); fclose (input);
} }

View File

@ -247,7 +247,7 @@ extern const struct language_defn *python_language;
void gdbpy_print_stack (void); void gdbpy_print_stack (void);
void source_python_script_for_objfile (struct objfile *objfile, void source_python_script_for_objfile (struct objfile *objfile,
FILE *stream, const char *file); const char *file);
PyObject *python_string_to_unicode (PyObject *obj); PyObject *python_string_to_unicode (PyObject *obj);
char *unicode_to_target_string (PyObject *unicode_str); char *unicode_to_target_string (PyObject *unicode_str);

View File

@ -599,21 +599,18 @@ gdbpy_parse_and_eval (PyObject *self, PyObject *args)
return value_to_value_object (result); return value_to_value_object (result);
} }
/* Read a file as Python code. STREAM is the input file; FILE is the /* Read a file as Python code.
name of the file. FILE is the name of the file.
STREAM is not closed, that is the caller's responsibility. */ This does not throw any errors. If an exception occurs python will print
the traceback and clear the error indicator. */
void void
source_python_script (FILE *stream, const char *file) source_python_script (const char *file)
{ {
struct cleanup *cleanup; struct cleanup *cleanup;
cleanup = ensure_python_env (get_current_arch (), current_language); 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); python_run_simple_file (file);
do_cleanups (cleanup); do_cleanups (cleanup);
} }
@ -941,15 +938,12 @@ gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
source_python_script_for_objfile; it is NULL at other times. */ source_python_script_for_objfile; it is NULL at other times. */
static struct objfile *gdbpy_current_objfile; static struct objfile *gdbpy_current_objfile;
/* Set the current objfile to OBJFILE and then read STREAM,FILE as /* Set the current objfile to OBJFILE and then read FILE as Python code.
Python code. This does not throw any errors. If an exception occurs python will print
STREAM is left open, it is up to the caller to close it. the traceback and clear the error indicator. */
If an exception occurs python will print the traceback and
clear the error indicator. */
void void
source_python_script_for_objfile (struct objfile *objfile, source_python_script_for_objfile (struct objfile *objfile, const char *file)
FILE *stream, const char *file)
{ {
struct cleanup *cleanups; struct cleanup *cleanups;
@ -1032,7 +1026,7 @@ eval_python_from_control_command (struct command_line *cmd)
} }
void void
source_python_script (FILE *stream, const char *file) source_python_script (const char *file)
{ {
throw_error (UNSUPPORTED_ERROR, throw_error (UNSUPPORTED_ERROR,
_("Python scripting is not supported in this copy of GDB.")); _("Python scripting is not supported in this copy of GDB."));

View File

@ -30,7 +30,7 @@ extern void finish_python_initialization (void);
void eval_python_from_control_command (struct command_line *); 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);
int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr, int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
int embedded_offset, CORE_ADDR address, int embedded_offset, CORE_ADDR address,

View File

@ -1,12 +1,16 @@
2011-10-27 Doug Evans <dje@google.com>
* gdb.python/python.exp: Test source -s.
2011-10-26 Paul Koning <paul_koning@dell.com> 2011-10-26 Paul Koning <paul_koning@dell.com>
* gdb.python/lib-types.cc (struct A): New structure. * gdb.python/lib-types.cc (struct A): New structure.
* gdb.python/lib-types.exp (deepitems): New tests. * gdb.python/lib-types.exp (deepitems): New tests.
2011-10-25 Paul Koning <paul_koning@dell.com> 2011-10-25 Paul Koning <paul_koning@dell.com>
PR python/13327 PR python/13327
* gdb.python/py-value.exp: Add testcases for is_lazy attribute, * gdb.python/py-value.exp: Add testcases for is_lazy attribute,
fetch_lazy method. fetch_lazy method.

View File

@ -77,6 +77,8 @@ gdb_py_test_multiple "indented multi-line python command" \
gdb_test "source $srcdir/$subdir/source2.py" "yes" "source source2.py" gdb_test "source $srcdir/$subdir/source2.py" "yes" "source source2.py"
gdb_test "source -s source2.py" "yes" "source -s source2.py"
gdb_test "python print gdb.current_objfile()" "None" gdb_test "python print gdb.current_objfile()" "None"
gdb_test "python print gdb.objfiles()" "\\\[\\\]" gdb_test "python print gdb.objfiles()" "\\\[\\\]"