diff options
author | Florian Müllner <fmuellner@gnome.org> | 2021-08-11 00:17:49 +0200 |
---|---|---|
committer | Florian Müllner <fmuellner@gnome.org> | 2021-08-13 07:53:19 +0200 |
commit | 86a6d3fa42beaee5cc353f8049ee9cc473934db5 (patch) | |
tree | c0efee1c95b18c65da5c4484cbe84baa87fe7c78 | |
parent | 6ca7779479dbf261a1b2ddcb4012dc42281fd292 (diff) | |
download | gjs-86a6d3fa42beaee5cc353f8049ee9cc473934db5.tar.gz |
debugger: Add option to ignore caught exceptions
Right now execution stops whenever an exception is thrown,
regardless of whether the exception was handled or not.
This gets annoying fast when exceptions are expected, for
example when handling EEXISTS after attempted file operations
instead of doing (racy) existence checks.
Address this by ignoring handled exceptions by default, with
the option to restore the old behavior.
https://gitlab.gnome.org/GNOME/gjs/-/issues/431
-rw-r--r-- | installed-tests/debugger/throw-ignored.debugger | 4 | ||||
-rw-r--r-- | installed-tests/debugger/throw-ignored.debugger.js | 16 | ||||
-rw-r--r-- | installed-tests/debugger/throw-ignored.debugger.output | 13 | ||||
-rw-r--r-- | installed-tests/debugger/throw.debugger | 1 | ||||
-rw-r--r-- | installed-tests/debugger/throw.debugger.output | 1 | ||||
-rw-r--r-- | installed-tests/meson.build | 1 | ||||
-rw-r--r-- | modules/script/_bootstrap/debugger.js | 15 |
7 files changed, 50 insertions, 1 deletions
diff --git a/installed-tests/debugger/throw-ignored.debugger b/installed-tests/debugger/throw-ignored.debugger new file mode 100644 index 00000000..54f6ddfa --- /dev/null +++ b/installed-tests/debugger/throw-ignored.debugger @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +# SPDX-FileCopyrightText: 2021 Florian Müllner <fmuellner@gnome.org> +c +q diff --git a/installed-tests/debugger/throw-ignored.debugger.js b/installed-tests/debugger/throw-ignored.debugger.js new file mode 100644 index 00000000..c05f57d6 --- /dev/null +++ b/installed-tests/debugger/throw-ignored.debugger.js @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +// SPDX-FileCopyrightText: 2021 Florian Müllner <fmuellner@gnome.org> + +let count = 0; + +function a() { + throw new Error(`Exception nº ${++count}`); +} + +try { + a(); +} catch (e) { + print(`Caught exception: ${e}`); +} + +a(); diff --git a/installed-tests/debugger/throw-ignored.debugger.output b/installed-tests/debugger/throw-ignored.debugger.output new file mode 100644 index 00000000..a2ac43d1 --- /dev/null +++ b/installed-tests/debugger/throw-ignored.debugger.output @@ -0,0 +1,13 @@ +GJS debugger. Type "help" for help +db> # SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +db> # SPDX-FileCopyrightText: 2021 Florian Müllner <fmuellner@gnome.org> +db> c +Caught exception: Error: Exception nº 1 +Unwinding due to exception. (Type 'c' to continue unwinding.) +#0 a() at throw-ignored.debugger.js:7:10 + 7 throw new Error(`Exception nº ${++count}`); +Exception value is: +$1 = [object Error] +Error: Exception nº 2 +db> q +Program exited with code 0 diff --git a/installed-tests/debugger/throw.debugger b/installed-tests/debugger/throw.debugger index 0130698a..b5e6dfb4 100644 --- a/installed-tests/debugger/throw.debugger +++ b/installed-tests/debugger/throw.debugger @@ -1,5 +1,6 @@ # SPDX-License-Identifier: MIT OR LGPL-2.0-or-later # SPDX-FileCopyrightText: 2018 Philip Chimento <philip.chimento@gmail.com> +set ignoreCaughtExceptions false c throw 'foobar' + 3.14; fin diff --git a/installed-tests/debugger/throw.debugger.output b/installed-tests/debugger/throw.debugger.output index 3dd87088..f3d4b1a4 100644 --- a/installed-tests/debugger/throw.debugger.output +++ b/installed-tests/debugger/throw.debugger.output @@ -1,6 +1,7 @@ GJS debugger. Type "help" for help db> # SPDX-License-Identifier: MIT OR LGPL-2.0-or-later db> # SPDX-FileCopyrightText: 2018 Philip Chimento <philip.chimento@gmail.com> +db> set ignoreCaughtExceptions false db> c Debugger statement, a() at throw.debugger.js:4:4 db> throw 'foobar' + 3.14; diff --git a/installed-tests/meson.build b/installed-tests/meson.build index 10ac735a..d695dbec 100644 --- a/installed-tests/meson.build +++ b/installed-tests/meson.build @@ -72,6 +72,7 @@ debugger_tests = [ 'set', 'step', 'throw', + 'throw-ignored', 'until', ] diff --git a/modules/script/_bootstrap/debugger.js b/modules/script/_bootstrap/debugger.js index 8bb2f8f8..6b5020fe 100644 --- a/modules/script/_bootstrap/debugger.js +++ b/modules/script/_bootstrap/debugger.js @@ -21,7 +21,7 @@ var topFrame = null; var debuggeeValues = {}; var nextDebuggeeValueIndex = 1; var lastExc = null; -var options = {pretty: true, colors: true}; +var options = {pretty: true, colors: true, ignoreCaughtExceptions: true}; var breakpoints = [undefined]; // Breakpoint numbers start at 1 // Cleanup functions to run when we next re-enter the repl. @@ -308,6 +308,7 @@ PARAMETERS · option: option name. Allowed options are: · pretty: set print mode to pretty or brief. Allowed value true or false · colors: set printing with colors to true or false. + · ignoreCaughtExceptions: do not stop on handled exceptions. Allowed value true or false · value: option value`; function splitPrintOptions(s, style) { @@ -930,6 +931,18 @@ dbg.onDebuggerStatement = function (frame) { }); }; dbg.onExceptionUnwind = function (frame, value) { + const willBeCaught = currentFrame => { + while (currentFrame) { + if (currentFrame.script.isInCatchScope(currentFrame.offset)) + return true; + currentFrame = currentFrame.older; + } + return false; + }; + + if (options.ignoreCaughtExceptions && willBeCaught(frame)) + return undefined; + return saveExcursion(() => { topFrame = focusedFrame = frame; print("Unwinding due to exception. (Type 'c' to continue unwinding.)"); |