Skip to content

Commit 10aa10b

Browse files
committed
python-gdb.py: catch gdb.error on gdb.selected_frame()
1 parent 83e36bc commit 10aa10b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Tools/gdb/libpython.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,11 @@ def get_selected_frame(cls):
15271527
def get_selected_python_frame(cls):
15281528
'''Try to obtain the Frame for the python-related code in the selected
15291529
frame, or None'''
1530-
frame = cls.get_selected_frame()
1530+
try:
1531+
frame = cls.get_selected_frame()
1532+
except gdb.error:
1533+
# No frame: Python didn't start yet
1534+
return None
15311535

15321536
while frame:
15331537
if frame.is_python_frame():
@@ -1668,6 +1672,10 @@ def invoke(self, args, from_tty):
16681672
def move_in_stack(move_up):
16691673
'''Move up or down the stack (for the py-up/py-down command)'''
16701674
frame = Frame.get_selected_python_frame()
1675+
if not frame:
1676+
print('Unable to locate python frame')
1677+
return
1678+
16711679
while frame:
16721680
if move_up:
16731681
iter_frame = frame.older()
@@ -1730,6 +1738,10 @@ def __init__(self):
17301738

17311739
def invoke(self, args, from_tty):
17321740
frame = Frame.get_selected_python_frame()
1741+
if not frame:
1742+
print('Unable to locate python frame')
1743+
return
1744+
17331745
while frame:
17341746
if frame.is_python_frame():
17351747
frame.print_summary()
@@ -1747,8 +1759,12 @@ def __init__(self):
17471759

17481760

17491761
def invoke(self, args, from_tty):
1750-
sys.stdout.write('Traceback (most recent call first):\n')
17511762
frame = Frame.get_selected_python_frame()
1763+
if not frame:
1764+
print('Unable to locate python frame')
1765+
return
1766+
1767+
sys.stdout.write('Traceback (most recent call first):\n')
17521768
while frame:
17531769
if frame.is_python_frame():
17541770
frame.print_traceback()

0 commit comments

Comments
 (0)