[Python-checkins] cpython (merge 3.2 -> default): (merge 3.2) libpython.py (gdb) now catchs IOError in py-list and py-bt commands
victor.stinner
python-checkins at python.org
Fri Jul 1 12:59:36 CEST 2011
http://hg.python.org/cpython/rev/2aa2a7c25f2c
changeset: 71107:2aa2a7c25f2c
parent: 71105:588fe0fc7160
parent: 71106:316764e64b0a
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Fri Jul 01 12:59:30 2011 +0200
summary:
(merge 3.2) libpython.py (gdb) now catchs IOError in py-list and py-bt commands
py-list displays the error. py-bt ignores the error (the filename and line
number is already displayed).
files:
Tools/gdb/libpython.py | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -905,7 +905,11 @@
if self.is_optimized_out():
return '(frame information optimized out)'
filename = self.filename()
- with open(os_fsencode(filename), 'r') as f:
+ try:
+ f = open(os_fsencode(filename), 'r')
+ except IOError:
+ return None
+ with f:
all_lines = f.readlines()
# Convert from 1-based current_line_num to 0-based list offset:
return all_lines[self.current_line_num()-1]
@@ -1430,7 +1434,9 @@
if pyop:
line = pyop.get_truncated_repr(MAX_OUTPUT_LEN)
write_unicode(sys.stdout, '#%i %s\n' % (self.get_index(), line))
- sys.stdout.write(pyop.current_line())
+ line = pyop.current_line()
+ if line is not None:
+ sys.stdout.write(line)
else:
sys.stdout.write('#%i (unable to read python frame information)\n' % self.get_index())
else:
@@ -1441,7 +1447,9 @@
pyop = self.get_pyop()
if pyop:
pyop.print_traceback()
- sys.stdout.write(' %s\n' % pyop.current_line().strip())
+ line = pyop.current_line()
+ if line is not None:
+ sys.stdout.write(' %s\n' % line.strip())
else:
sys.stdout.write(' (unable to read python frame information)\n')
else:
@@ -1501,7 +1509,13 @@
if start<1:
start = 1
- with open(os_fsencode(filename), 'r') as f:
+ try:
+ f = open(os_fsencode(filename), 'r')
+ except IOError as err:
+ sys.stdout.write('Unable to open %s: %s\n'
+ % (filename, err))
+ return
+ with f:
all_lines = f.readlines()
# start and end are 1-based, all_lines is 0-based;
# so [start-1:end] as a python slice gives us [start, end] as a
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list