diff options
author | Nasah Kuma <nasahnash19@gmail.com> | 2021-01-09 23:00:10 +0000 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2021-01-09 23:00:10 +0000 |
commit | f99809052ea826c06c239c631b52f4e0358b8d9b (patch) | |
tree | 87d3ad9ba008dce418d153b08567a7268f9d3c88 /modules | |
parent | 54d94597561c1128b7bccb50c6077e47bc50b238 (diff) | |
download | gjs-f99809052ea826c06c239c631b52f4e0358b8d9b.tar.gz |
Add backtrace full command to debugger
Closes: GNOME/gjs#208
Diffstat (limited to 'modules')
-rw-r--r-- | modules/script/_bootstrap/debugger.js | 40 |
1 files changed, 32 insertions, 8 deletions
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(' '); |