Skip to content

Commit 506bcf6

Browse files
fix: change with gaotian
Signed-off-by: yihong0618 <zouzou0208@gmail.com> Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
1 parent 31c8dbc commit 506bcf6

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

Lib/pdb.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,16 @@ def set_trace(*, header=None, commands=None):
26472647
just before debugging begins. *commands* is an optional list of
26482648
pdb commands to run when the debugger starts.
26492649
"""
2650+
# Check if we're already in a pdb session by examining the call stack
2651+
frame = sys._getframe()
2652+
while frame:
2653+
if frame.f_code.co_name == 'interaction' and frame.f_code.co_filename.endswith('pdb.py'):
2654+
# We're already in a pdb session, just print a message and return
2655+
print("*** Nested breakpoint calls are not supported. "
2656+
"Already running in the debugger.", file=sys.stderr)
2657+
return
2658+
frame = frame.f_back
2659+
26502660
if Pdb._last_pdb_instance is not None:
26512661
pdb = Pdb._last_pdb_instance
26522662
else:
@@ -2662,6 +2672,16 @@ async def set_trace_async(*, header=None, commands=None):
26622672
if they enter the debugger with this function. Otherwise it's the same
26632673
as set_trace().
26642674
"""
2675+
# Check if we're already in a pdb session by examining the call stack
2676+
frame = sys._getframe()
2677+
while frame:
2678+
if frame.f_code.co_name == 'interaction' and frame.f_code.co_filename.endswith('pdb.py'):
2679+
# We're already in a pdb session, just print a message and return
2680+
print("*** Nested breakpoint calls are not supported. "
2681+
"Already running in the debugger.", file=sys.stderr)
2682+
return
2683+
frame = frame.f_back
2684+
26652685
if Pdb._last_pdb_instance is not None:
26662686
pdb = Pdb._last_pdb_instance
26672687
else:
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Fix: breakpoint() in pdb can cause crash.
1+
Prevent error when calling :func:`breakpoint` inside a :mod:`pdb` debugging session.
2+
Nested breakpoint calls now display a helpful error message instead of causing error.

0 commit comments

Comments
 (0)