X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fpython%2Fpython.c;h=cca7c4cd6bf8ce71e646fe15c50504c65328b49a;hb=272044897e178835f596c96740c5a1800ec6f9fb;hp=162470dcc022372664f64ac4a80441abae4b2c33;hpb=395fad095c9cbc5a8b10557443da981cc3f61885;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/python/python.c b/gdb/python/python.c index 162470dcc0..cca7c4cd6b 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -323,9 +323,8 @@ python_interactive_command (const char *arg, int from_tty) A FILE * from one runtime does not necessarily operate correctly in the other runtime. - To work around this potential issue, we create on Windows hosts the - FILE object using Python routines, thus making sure that it is - compatible with the Python library. */ + To work around this potential issue, we run code in Python to load + the script. */ static void python_run_simple_file (FILE *file, const char *filename) @@ -339,15 +338,21 @@ python_run_simple_file (FILE *file, const char *filename) /* Because we have a string for a filename, and are using Python to open the file, we need to expand any tilde in the path first. */ gdb::unique_xmalloc_ptr full_path (tilde_expand (filename)); - gdbpy_ref<> python_file (PyFile_FromString (full_path.get (), (char *) "r")); - if (python_file == NULL) + + if (gdb_python_module == nullptr + || ! PyObject_HasAttrString (gdb_python_module, "_execute_file")) + error (_("Installation error: gdb._execute_file function is missing")); + + gdbpy_ref<> return_value + (PyObject_CallMethod (gdb_python_module, "_execute_file", "s", + full_path.get ())); + if (return_value == nullptr) { - gdbpy_print_stack (); - error (_("Error while opening file: %s"), full_path.get ()); + /* Use PyErr_PrintEx instead of gdbpy_print_stack to better match the + behavior of the non-Windows codepath. */ + PyErr_PrintEx(0); } - PyRun_SimpleFile (PyFile_AsFile (python_file.get ()), filename); - #endif /* _WIN32 */ }