gdb/
Do not open script filenames twice. * cli/cli-cmds.c (source_script_from_stream): Pass to source_python_script also STREAM. * python/py-auto-load.c (source_section_scripts): Pass to source_python_script_for_objfile also STREAM. (auto_load_objfile_script): Pass to source_python_script_for_objfile also INPUT. * python/python-internal.h (source_python_script_for_objfile): New parameter file, rename parameter file to filename. * python/python.c (python_run_simple_file): Call PyRun_SimpleFile instead if !_WIN32. Update the function comment. (source_python_script, source_python_script_for_objfile) (source_python_script): New parameter file, rename parameter file to filename. Pass FILENAME to python_run_simple_file. * python/python.h (source_python_script): New parameter file, rename parameter file to filename.
This commit is contained in:
parent
88f38a0478
commit
4c63965b8a
6 changed files with 56 additions and 39 deletions
|
@ -1,3 +1,22 @@
|
||||||
|
2012-01-26 Jan Kratochvil <jan.kratochvil@redhat.com>
|
||||||
|
|
||||||
|
Do not open script filenames twice.
|
||||||
|
* cli/cli-cmds.c (source_script_from_stream): Pass to
|
||||||
|
source_python_script also STREAM.
|
||||||
|
* python/py-auto-load.c (source_section_scripts): Pass to
|
||||||
|
source_python_script_for_objfile also STREAM.
|
||||||
|
(auto_load_objfile_script): Pass to source_python_script_for_objfile
|
||||||
|
also INPUT.
|
||||||
|
* python/python-internal.h (source_python_script_for_objfile): New
|
||||||
|
parameter file, rename parameter file to filename.
|
||||||
|
* python/python.c (python_run_simple_file): Call PyRun_SimpleFile
|
||||||
|
instead if !_WIN32. Update the function comment.
|
||||||
|
(source_python_script, source_python_script_for_objfile)
|
||||||
|
(source_python_script): New parameter file, rename parameter file to
|
||||||
|
filename. Pass FILENAME to python_run_simple_file.
|
||||||
|
* python/python.h (source_python_script): New parameter file, rename
|
||||||
|
parameter file to filename.
|
||||||
|
|
||||||
2012-01-26 Pedro Alves <palves@redhat.com>
|
2012-01-26 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
* corelow.c (core_has_fake_pid): Delete.
|
* corelow.c (core_has_fake_pid): Delete.
|
||||||
|
|
|
@ -539,9 +539,7 @@ source_script_from_stream (FILE *stream, const char *file)
|
||||||
|
|
||||||
TRY_CATCH (e, RETURN_MASK_ERROR)
|
TRY_CATCH (e, RETURN_MASK_ERROR)
|
||||||
{
|
{
|
||||||
/* The python support reopens the file using python functions,
|
source_python_script (stream, file);
|
||||||
so there's no point in passing STREAM here. */
|
|
||||||
source_python_script (file);
|
|
||||||
}
|
}
|
||||||
if (e.reason < 0)
|
if (e.reason < 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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, full_path);
|
source_python_script_for_objfile (objfile, stream, full_path);
|
||||||
fclose (stream);
|
fclose (stream);
|
||||||
xfree (full_path);
|
xfree (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, debugfile);
|
source_python_script_for_objfile (objfile, input, debugfile);
|
||||||
fclose (input);
|
fclose (input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -289,8 +289,8 @@ 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 *file,
|
||||||
const char *file);
|
const char *filename);
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -151,34 +151,31 @@ ensure_python_env (struct gdbarch *gdbarch,
|
||||||
return make_cleanup (restore_python_env, env);
|
return make_cleanup (restore_python_env, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A wrapper around PyRun_SimpleFile. FILENAME is the name of
|
/* A wrapper around PyRun_SimpleFile. FILE is the Python script to run
|
||||||
the Python script to run.
|
named FILENAME.
|
||||||
|
|
||||||
One of the parameters of PyRun_SimpleFile is a FILE *.
|
On Windows hosts few users would build Python themselves (this is no
|
||||||
The problem is that type FILE is extremely system and compiler
|
trivial task on this platform), and thus use binaries built by
|
||||||
dependent. So, unless the Python library has been compiled using
|
someone else instead. There may happen situation where the Python
|
||||||
the same build environment as GDB, we run the risk of getting
|
library and GDB are using two different versions of the C runtime
|
||||||
a crash due to inconsistencies between the definition used by GDB,
|
library. Python, being built with VC, would use one version of the
|
||||||
and the definition used by Python. A mismatch can very likely
|
msvcr DLL (Eg. msvcr100.dll), while MinGW uses msvcrt.dll.
|
||||||
lead to a crash.
|
A FILE * from one runtime does not necessarily operate correctly in
|
||||||
|
|
||||||
There is also the situation where the Python library and GDB
|
|
||||||
are using two different versions of the C runtime library.
|
|
||||||
This is particularly visible on Windows, where few users would
|
|
||||||
build Python themselves (this is no trivial task on this platform),
|
|
||||||
and thus use binaries built by someone else instead. Python,
|
|
||||||
being built with VC, would use one version of the msvcr DLL
|
|
||||||
(Eg. msvcr100.dll), while MinGW uses msvcrt.dll. A FILE *
|
|
||||||
from one runtime does not necessarily operate correctly in
|
|
||||||
the other runtime.
|
the other runtime.
|
||||||
|
|
||||||
To work around this potential issue, we create the FILE object
|
To work around this potential issue, we create on Windows hosts the
|
||||||
using Python routines, thus making sure that it is compatible
|
FILE object using Python routines, thus making sure that it is
|
||||||
with the Python library. */
|
compatible with the Python library. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
python_run_simple_file (const char *filename)
|
python_run_simple_file (FILE *file, const char *filename)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
|
PyRun_SimpleFile (file, filename);
|
||||||
|
|
||||||
|
#else /* _WIN32 */
|
||||||
|
|
||||||
char *full_path;
|
char *full_path;
|
||||||
PyObject *python_file;
|
PyObject *python_file;
|
||||||
struct cleanup *cleanup;
|
struct cleanup *cleanup;
|
||||||
|
@ -198,6 +195,8 @@ python_run_simple_file (const char *filename)
|
||||||
make_cleanup_py_decref (python_file);
|
make_cleanup_py_decref (python_file);
|
||||||
PyRun_SimpleFile (PyFile_AsFile (python_file), filename);
|
PyRun_SimpleFile (PyFile_AsFile (python_file), filename);
|
||||||
do_cleanups (cleanup);
|
do_cleanups (cleanup);
|
||||||
|
|
||||||
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given a command_line, return a command string suitable for passing
|
/* Given a command_line, return a command string suitable for passing
|
||||||
|
@ -620,17 +619,17 @@ gdbpy_parse_and_eval (PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read a file as Python code.
|
/* Read a file as Python code.
|
||||||
FILE is the name of the file.
|
FILE is the file to run. FILENAME is name of the file FILE.
|
||||||
This does not throw any errors. If an exception occurs python will print
|
This does not throw any errors. If an exception occurs python will print
|
||||||
the traceback and clear the error indicator. */
|
the traceback and clear the error indicator. */
|
||||||
|
|
||||||
void
|
void
|
||||||
source_python_script (const char *file)
|
source_python_script (FILE *file, const char *filename)
|
||||||
{
|
{
|
||||||
struct cleanup *cleanup;
|
struct cleanup *cleanup;
|
||||||
|
|
||||||
cleanup = ensure_python_env (get_current_arch (), current_language);
|
cleanup = ensure_python_env (get_current_arch (), current_language);
|
||||||
python_run_simple_file (file);
|
python_run_simple_file (file, filename);
|
||||||
do_cleanups (cleanup);
|
do_cleanups (cleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -991,19 +990,20 @@ 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 FILE as Python code.
|
/* Set the current objfile to OBJFILE and then read FILE named FILENAME
|
||||||
This does not throw any errors. If an exception occurs python will print
|
as Python code. This does not throw any errors. If an exception
|
||||||
the traceback and clear the error indicator. */
|
occurs python will print the traceback and clear the error indicator. */
|
||||||
|
|
||||||
void
|
void
|
||||||
source_python_script_for_objfile (struct objfile *objfile, const char *file)
|
source_python_script_for_objfile (struct objfile *objfile, FILE *file,
|
||||||
|
const char *filename)
|
||||||
{
|
{
|
||||||
struct cleanup *cleanups;
|
struct cleanup *cleanups;
|
||||||
|
|
||||||
cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
|
cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
|
||||||
gdbpy_current_objfile = objfile;
|
gdbpy_current_objfile = objfile;
|
||||||
|
|
||||||
python_run_simple_file (file);
|
python_run_simple_file (file, filename);
|
||||||
|
|
||||||
do_cleanups (cleanups);
|
do_cleanups (cleanups);
|
||||||
gdbpy_current_objfile = NULL;
|
gdbpy_current_objfile = NULL;
|
||||||
|
@ -1079,7 +1079,7 @@ eval_python_from_control_command (struct command_line *cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
source_python_script (const char *file)
|
source_python_script (FILE *file, const char *filename)
|
||||||
{
|
{
|
||||||
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."));
|
||||||
|
|
|
@ -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 (const char *file);
|
void source_python_script (FILE *file, const char *filename);
|
||||||
|
|
||||||
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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue