[gjs: 2/7] debugger: Handle special return values from Environment.getVariable()
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 2/7] debugger: Handle special return values from Environment.getVariable()
- Date: Tue, 9 Feb 2021 03:30:22 +0000 (UTC)
commit e5b1e32ae2f2afe3e3ce388aafcc1245ae41545e
Author: Philip Chimento <philip chimento gmail com>
Date: Fri Dec 18 18:29:49 2020 -0800
debugger: Handle special return values from Environment.getVariable()
Debugger.Environment.getVariable() may return one of the three sentinel
values {missingArguments: true}, {optimizedOut: true}, or {uninitialized:
true} if a variable does not have a value for some reason. Handle these
special values in debuggeeValueToString().
"missingArguments" means that a function argument was optimized out,
"optimizedOut" means that a regular variable was optimized out, and
"uninitialized" means that a variable is present in the environment but
hasn't been initialized yet, for example when breaking on an exception
thrown while initializing it.
Also adds a test for the latter case (printing a backtrace with locals,
when breaking on an exception that leaves a local variable uninitialized.)
https://searchfox.org/mozilla-central/rev/6a6a366031680829746b5d2362610b868fd9571a/js/src/debugger/Debugger.cpp#1412-1435
installed-tests/debugger/backtrace.debugger | 4 ++++
installed-tests/debugger/backtrace.debugger.js | 10 ++++++++--
installed-tests/debugger/backtrace.debugger.output | 15 +++++++++++++++
modules/script/_bootstrap/debugger.js | 12 ++++++++++++
4 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/installed-tests/debugger/backtrace.debugger b/installed-tests/debugger/backtrace.debugger
index 261d388a..6f9d9516 100644
--- a/installed-tests/debugger/backtrace.debugger
+++ b/installed-tests/debugger/backtrace.debugger
@@ -7,4 +7,8 @@ c
backtrace full
bt full
where
+c
+# test printing locals when exception is thrown before initialization of a value
+c
+bt full
q
diff --git a/installed-tests/debugger/backtrace.debugger.js b/installed-tests/debugger/backtrace.debugger.js
index 9b84935b..7816d4d9 100644
--- a/installed-tests/debugger/backtrace.debugger.js
+++ b/installed-tests/debugger/backtrace.debugger.js
@@ -1,10 +1,16 @@
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2018 Philip Chimento <philip chimento gmail com>
debugger;
-[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]].forEach(array => {
+[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]].every(array => {
debugger;
- array.forEach(num => {
+ array.every(num => {
debugger;
print(num);
+ return false;
});
+ return false;
});
+function mistake(array) {
+ let {uninitialized_} = array.shift();
+}
+mistake([]);
diff --git a/installed-tests/debugger/backtrace.debugger.output
b/installed-tests/debugger/backtrace.debugger.output
index f5353e29..a74e0b06 100644
--- a/installed-tests/debugger/backtrace.debugger.output
+++ b/installed-tests/debugger/backtrace.debugger.output
@@ -22,5 +22,20 @@ array = [object Array]
db> where
#0 <anonymous>([object Array], 0, [object Array]) at backtrace.debugger.js:5:4
#1 toplevel at backtrace.debugger.js:4:36
+db> c
+Debugger statement, <anonymous>(1, 0, [object Array]) at backtrace.debugger.js:7:8
+db> # test printing locals when exception is thrown before initialization of a value
+db> c
+1
+Unwinding due to exception. (Type 'c' to continue unwinding.)
+#0 mistake([object Array]) at backtrace.debugger.js:14:33
+ 14 let {uninitialized_} = array.shift();
+Exception value is:
+$1 = [object Error]
+TypeError: array.shift() is undefined
+db> bt full
+#0 mistake([object Array]) at backtrace.debugger.js:14:33
+uninitialized_ = <uninitialized>
+#1 toplevel at backtrace.debugger.js:16:7
db> q
Program exited with code 0
diff --git a/modules/script/_bootstrap/debugger.js b/modules/script/_bootstrap/debugger.js
index d1b22ed9..0cffe703 100644
--- a/modules/script/_bootstrap/debugger.js
+++ b/modules/script/_bootstrap/debugger.js
@@ -48,6 +48,18 @@ function summarizeObject(dv) {
}
function debuggeeValueToString(dv, style = {pretty: options.pretty}) {
+ // Special sentinel values returned by Debugger.Environment.getVariable()
+ if (typeof dv === 'object' && dv !== null) {
+ if (dv.missingArguments)
+ return ['<missing>', undefined];
+ if (dv.optimizedOut)
+ return ['<optimized out>', undefined];
+ if (dv.uninitialized)
+ return ['<uninitialized>', undefined];
+ if (!(dv instanceof Debugger.Object))
+ return ['<unexpected object>', JSON.stringify(dv, null, 4)];
+ }
+
const dvrepr = dvToString(dv);
if (!style.pretty || dv === null || typeof dv !== 'object')
return [dvrepr, undefined];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]