Skip to content

Commit d54a842

Browse files
committed
feat(pmdb): automatically enter the debugger on uncaught exceptions
1 parent f7e2a83 commit d54a842

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

python/pythonmonkey/lib/pmdb.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def enable(debuggerGlobalObject = pm.eval("debuggerGlobal")):
4747
return { command, rest }
4848
}
4949
50-
function enterDebuggerLoop (frame) {
50+
function enterDebuggerLoop (frame, checkIsBreakpoint = false) {
5151
const metadata = frame.script.getOffsetMetadata(frame.offset)
52-
if (!metadata.isBreakpoint) {
52+
if (checkIsBreakpoint && !metadata.isBreakpoint) {
5353
// This bytecode offset does not qualify as a breakpoint, skipping
5454
return
5555
}
@@ -65,7 +65,7 @@ def enable(debuggerGlobalObject = pm.eval("debuggerGlobal")):
6565
case "n":
6666
case "next":
6767
// Step next
68-
frame.onStep = function () { enterDebuggerLoop(this) } // add handler
68+
frame.onStep = function () { enterDebuggerLoop(this, /*checkIsBreakpoint*/ true) } // add handler
6969
break blockingLoop;
7070
case "bt":
7171
case "backtrace":
@@ -125,5 +125,18 @@ def enable(debuggerGlobalObject = pm.eval("debuggerGlobal")):
125125
}
126126
}
127127
128+
// Enter debugger on uncaught exceptions
129+
dbg.onExceptionUnwind = (frame, err) => {
130+
const isUncaught = !frame.script.isInCatchScope(frame.offset) // not in a catch block
131+
&& frame.older == null // this is the outermost frame
132+
if (isUncaught) {
133+
printErr("Uncaught exception:")
134+
printErr(err)
135+
enterDebuggerLoop(frame)
136+
}
137+
}
138+
139+
// Enter debugger on `debugger;` statement
128140
dbg.onDebuggerStatement = (frame) => enterDebuggerLoop(frame)
141+
129142
}""")(debuggerInput, print)

0 commit comments

Comments
 (0)