Skip to content

Commit

Permalink
Only load the variables of the current stack.
Browse files Browse the repository at this point in the history
This should increase the performance when stepping through code with large stacks with/or a lot of variables
  • Loading branch information
lloiser committed Sep 2, 2017
1 parent b9b3694 commit a34e3d8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
40 changes: 28 additions & 12 deletions lib/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export default class Debugger {
const id = setTimeout(() => {
this._store.dispatch({ type: 'UPDATE_STACKTRACE', stacktrace: [] })
this._store.dispatch({ type: 'UPDATE_GOROUTINES', goroutines: [] })
}, 250)
}, 500)

return this._updateState(
() => this._session[fn](),
Expand All @@ -273,9 +273,7 @@ export default class Debugger {
return this.stop()
}
return this.getGoroutines() // get the new goroutines
.then(() => this._selectGoroutine(newState.goroutineID)) // select the current goroutine
.then(() => this._selectStacktrace(0)) // reselect the first stacktrace entry
.then(() => this._evaluateWatchExpressions())
.then(() => this.selectGoroutine(newState.goroutineID)) // select the current goroutine
})
}

Expand All @@ -300,9 +298,9 @@ export default class Debugger {
* @return {Promise}
*/
selectStacktrace (index) {
return this._selectStacktrace(index).then(() => {
return this._evaluateWatchExpressions()
})
return this._selectStacktrace(index)
.then(() => this._getVariables())
.then(() => this._evaluateWatchExpressions())
}
_selectStacktrace (index) {
if (this._store.getState().delve.selectedStacktrace === index) {
Expand All @@ -323,24 +321,23 @@ export default class Debugger {
* @return {Promise}
*/
selectGoroutine (id) {
return this._selectGoroutine(id).then(() => {
return this._evaluateWatchExpressions()
})
return this._selectGoroutine(id)
.then(() => this.getStacktrace(id))
.then(() => this.selectStacktrace(0)) // reselect the first stacktrace entry
}
_selectGoroutine (id) {
if (!this.isStarted()) {
return Promise.resolve()
}
if (this._store.getState().delve.selectedGoroutine === id) {
// no need to change
return this.getStacktrace(id)
return Promise.resolve()
}

return this._updateState(
() => this._session.selectGoroutine({ id })
).then(() => {
this._store.dispatch({ type: 'SET_SELECTED_GOROUTINE', id })
return this.getStacktrace(id)
})
}

Expand Down Expand Up @@ -368,6 +365,25 @@ export default class Debugger {
})
}

_getVariables () {
const { selectedGoroutine, selectedStacktrace, stacktrace } = this._store.getState().delve

const st = stacktrace[selectedStacktrace]
if (!st || st.variables) {
return Promise.resolve()
}

const scope = {
goroutineID: selectedGoroutine,
frame: selectedStacktrace
}
return this._updateState(
() => this._session.getVariables(scope)
).then((variables) => {
this._store.dispatch({ type: 'UPDATE_VARIABLES', variables, stacktraceIndex: selectedStacktrace })
})
}

evaluate (expr) {
if (!this.isStarted()) {
return Promise.resolve()
Expand Down
30 changes: 26 additions & 4 deletions lib/delve-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import * as DelveVariables from './delve-variables'
const RPC_ENDPOINT = 'RPCServer.'
const breakpointProps = ['id', 'name', 'file', 'line', 'cond']

// note: mimic the "full" flag in the "Stacktrace" call
const defaultVariableCfg = {
followPointers: true,
maxVariableRecurse: 1,
maxStringLen: 64,
maxArrayValues: 64,
maxStructFields: -1
}

export default class DelveSession {
constructor (process, connection, mode) {
this._process = process
Expand Down Expand Up @@ -132,8 +141,7 @@ export default class DelveSession {
getStacktrace ({ goroutineID }) {
const args = {
id: goroutineID,
depth: 20,
full: true
depth: 20
}
return this._call('Stacktrace', args)
.then(this._prepareStacktrace.bind(this))
Expand All @@ -144,8 +152,7 @@ export default class DelveSession {
id: stack.pc,
file: stack.file,
line: stack.line - 1, // delve = 1 indexed line / atom = 0 indexed line
func: stack.function.name.split('/').pop(),
variables: DelveVariables.create(stack.Locals.concat(stack.Arguments))
func: stack.function.name.split('/').pop()
}
})
}
Expand All @@ -168,6 +175,21 @@ export default class DelveSession {
})
}

getVariables (scope, cfg = defaultVariableCfg) {
return Promise.all([
this._getLocalVariables(scope, cfg),
this._getFunctionArguments(scope, cfg)
]).then(([locals, args]) => {
return DelveVariables.create(locals.concat(args))
})
}
_getLocalVariables (scope, cfg) {
return this._call('ListLocalVars', { scope, cfg }).then((o) => o.Variables)
}
_getFunctionArguments (scope, cfg) {
return this._call('ListFunctionArgs', { scope, cfg }).then((o) => o.Args)
}

evaluate ({ expr, scope }) {
return this._call('Eval', { expr, scope })
.then((result) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class Editor {
try {
this._gutter.destroy()
} catch (e) {
console.warn('debug', e)
console.warn('go-debug', e)
}

this._gutter = null
Expand Down

0 comments on commit a34e3d8

Please sign in to comment.