From 3ab1ec277626d8f72c6f4c4a0d38dcdded240e89 Mon Sep 17 00:00:00 2001 From: Phil Muldoon Date: Fri, 4 Nov 2011 12:07:53 +0000 Subject: [PATCH] 2011-11-04 Phil Muldoon PR Python/13345 * python/python.c (python_run_simple_file): Expand tilde in path. --- gdb/ChangeLog | 6 ++++++ gdb/python/python.c | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d9af3e505c7..c1db4f6a7c3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2011-11-04 Phil Muldoon + + PR Python/13345 + + * python/python.c (python_run_simple_file): Expand tilde in path. + 2011-11-04 Phil Muldoon PR Python/13363 diff --git a/gdb/python/python.c b/gdb/python/python.c index 3a5a6b5b2da..108e5428a60 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -30,6 +30,7 @@ #include "exceptions.h" #include "event-loop.h" #include "serial.h" +#include "readline/tilde.h" #include "python.h" #include @@ -162,13 +163,22 @@ ensure_python_env (struct gdbarch *gdbarch, static void python_run_simple_file (const char *filename) { - char *filename_copy; + char *full_path; PyObject *python_file; struct cleanup *cleanup; - filename_copy = xstrdup (filename); - cleanup = make_cleanup (xfree, filename_copy); - python_file = PyFile_FromString (filename_copy, "r"); + /* 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. */ + full_path = tilde_expand (filename); + cleanup = make_cleanup (xfree, full_path); + python_file = PyFile_FromString (full_path, "r"); + if (! python_file) + { + do_cleanups (cleanup); + gdbpy_print_stack (); + error (_("Error while opening file: %s"), full_path); + } + make_cleanup_py_decref (python_file); PyRun_SimpleFile (PyFile_AsFile (python_file), filename); do_cleanups (cleanup); -- 2.30.2