[gjs: 1/2] Add backtrace full command to debugger
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/2] Add backtrace full command to debugger
- Date: Sat, 9 Jan 2021 23:00:11 +0000 (UTC)
commit f99809052ea826c06c239c631b52f4e0358b8d9b
Author: Nasah Kuma <nasahnash19 gmail com>
Date: Sat Jan 9 23:00:10 2021 +0000
Add backtrace full command to debugger
Closes: GNOME/gjs#208
installed-tests/debugger/backtrace.debugger | 2 ++
installed-tests/debugger/backtrace.debugger.output | 10 ++++++
modules/script/_bootstrap/debugger.js | 40 +++++++++++++++++-----
3 files changed, 44 insertions(+), 8 deletions(-)
---
diff --git a/installed-tests/debugger/backtrace.debugger b/installed-tests/debugger/backtrace.debugger
index 6aea227d..261d388a 100644
--- a/installed-tests/debugger/backtrace.debugger
+++ b/installed-tests/debugger/backtrace.debugger
@@ -4,5 +4,7 @@ backtrace
c
bt
c
+backtrace full
+bt full
where
q
diff --git a/installed-tests/debugger/backtrace.debugger.output
b/installed-tests/debugger/backtrace.debugger.output
index 0f338e53..f5353e29 100644
--- a/installed-tests/debugger/backtrace.debugger.output
+++ b/installed-tests/debugger/backtrace.debugger.output
@@ -9,6 +9,16 @@ db> bt
#0 toplevel at backtrace.debugger.js:3:0
db> c
Debugger statement, <anonymous>([object Array], 0, [object Array]) at backtrace.debugger.js:5:4
+db> backtrace full
+#0 <anonymous>([object Array], 0, [object Array]) at backtrace.debugger.js:5:4
+arguments = [object Arguments]
+array = [object Array]
+#1 toplevel at backtrace.debugger.js:4:36
+db> bt full
+#0 <anonymous>([object Array], 0, [object Array]) at backtrace.debugger.js:5:4
+arguments = [object Arguments]
+array = [object Array]
+#1 toplevel at backtrace.debugger.js:4:36
db> where
#0 <anonymous>([object Array], 0, [object Array]) at backtrace.debugger.js:5:4
#1 toplevel at backtrace.debugger.js:4:36
diff --git a/modules/script/_bootstrap/debugger.js b/modules/script/_bootstrap/debugger.js
index 601035cd..326ec8e9 100644
--- a/modules/script/_bootstrap/debugger.js
+++ b/modules/script/_bootstrap/debugger.js
@@ -140,7 +140,7 @@ Debugger.Script.prototype.describeOffset = function describeOffset(offset) {
return `${url}:${lineNumber}:${columnNumber}`;
};
-function showFrame(f, n) {
+function showFrame(f, n, option) {
if (f === undefined || f === null) {
f = focusedFrame;
if (f === null) {
@@ -153,10 +153,23 @@ function showFrame(f, n) {
if (n === undefined)
throw new Error('Internal error: frame not on stack');
}
-
- print(`#${n.toString().padEnd(4)} ${f.describeFull()}`);
+ if (!option) {
+ print(`#${n.toString().padEnd(4)} ${f.describeFull()}`);
+ } else {
+ const variables = f.environment.names();
+ print(`#${n.toString().padEnd(4)} ${f.describeFull()}`);
+ for (let i = 0; i < variables.length; i++) {
+ if (variables.length === 0)
+ print('No locals.');
+
+ const value = f.environment.getVariable(variables[i]);
+ const [brief] = debuggeeValueToString(value, {brief: false, pretty: false});
+ print(`${variables[i]} = ${brief}`);
+ }
+ }
}
+
function saveExcursion(fn) {
const tf = topFrame, ff = focusedFrame;
try {
@@ -187,15 +200,26 @@ quitCommand.summary = 'Quit the debugger';
quitCommand.helpText = `USAGE
quit`;
-function backtraceCommand() {
+function backtraceCommand(option) {
if (topFrame === null)
print('No stack.');
- for (var i = 0, f = topFrame; f; i++, f = f.older)
- showFrame(f, i);
+ if (option === '') {
+ for (let i = 0, f = topFrame; f; i++, f = f.older)
+ showFrame(f, i, false);
+ } else if (option === 'full') {
+ for (let i = 0, f = topFrame; f; i++, f = f.older)
+ showFrame(f, i, true);
+ } else {
+ print('Invalid option');
+ }
}
-backtraceCommand.summary = 'Print backtrace of all stack frames';
+backtraceCommand.summary = 'Print backtrace of all stack frames and details of all local variables if the
full option is added';
backtraceCommand.helpText = `USAGE
- bt`;
+ bt <option>
+
+PARAMETERS
+ · option: option name. Allowed options are:
+ · full: prints the local variables in a stack frame`;
function setCommand(rest) {
var space = rest.indexOf(' ');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]