Skip to content

Commit

Permalink
minor runtime and styling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lloiser committed Apr 17, 2018
1 parent 99c8535 commit d01a91d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 29 deletions.
19 changes: 14 additions & 5 deletions lib/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,9 @@ export default class Debugger {
bp = getBreakpoint(this._store, file, line)

const fileAndLine = location(bp)
this._addOutputMessage(`Adding breakpoint @ ${fileAndLine}\n`)

return this._addBreakpoint(bp)
.then(({ id }) => {
this._addOutputMessage(`Added breakpoint @ ${fileAndLine}\n`)
this._store.dispatch({ type: 'EDIT_BREAKPOINT', bp: { name: bp.name, id, state: 'valid' } })
})
.catch((err) => {
Expand Down Expand Up @@ -150,12 +148,10 @@ export default class Debugger {
}

const fileAndLine = location(bp)
this._addOutputMessage(`Removing breakpoint @ ${fileAndLine}\n`)

this._store.dispatch({ type: 'EDIT_BREAKPOINT', bp: { name, state: 'busy' } })

return this._removeBreakpoint(bp)
.then(() => this._addOutputMessage(`Removed breakpoint @ ${fileAndLine}\n`))
.then(done)
.catch((err) => {
this._addOutputMessage(`Removing breakpoint @ ${fileAndLine} failed!\r\n Error: ${err}\n`)
Expand Down Expand Up @@ -258,6 +254,10 @@ export default class Debugger {
return Promise.resolve()
}

if (fn !== 'halt' && this.isBusy()) {
return Promise.resolve()
}

// clear the existing stacktrace and goroutines if the next delve
// request takes too long.
const id = setTimeout(() => {
Expand All @@ -266,10 +266,19 @@ export default class Debugger {
}, 500)

return this._updateState(
() => this._session[fn](),
() => this._session[fn]().catch((err) => {
this._addOutputMessage(`Failed to ${fn}!\r\n Error: ${err}\n`)
return null
}),
'running'
).then((newState) => {
clearTimeout(id)
if (!newState) {
return
}
if (newState.error) {
this._addOutputMessage(`Failed to ${fn}!\r\n Error: ${newState.error}\n`)
}
if (newState.exited) {
return this.stop()
}
Expand Down
3 changes: 2 additions & 1 deletion lib/delve-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export default class DelveConfiguration {
file: '',
configs: [
{ name: 'Debug', mode: 'debug' },
{ name: 'Test', mode: 'test' }
{ name: 'Test', mode: 'test' },
{ name: 'Attach', mode: 'attach' }
]
}
]
Expand Down
50 changes: 34 additions & 16 deletions lib/delve-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,33 @@ export default class DelveSession {
// stopping a running program which is not halted at the moment
// (so waiting for further debug commands like 'continue' or 'step')
// ends up here too, so simply return that it already has stopped
const exited = this._stopPromise ? true : !!State.exited
let goroutineID = -1
if (!exited) {
goroutineID = State.currentGoroutine ? State.currentGoroutine.id : -1
if (goroutineID === -1) {
goroutineID = State.currentThread ? State.currentThread.goroutineID : -1
}
}
return {
exited,
goroutineID
}
return this._stateToDebuggerState(State)
}).catch((err) => {
return this.getState().then(state => {
state.error = err
return state
})
})
}
getState () {
return this._call('State', {}).then(({ State }) => {
return this._stateToDebuggerState(State)
})
}
_stateToDebuggerState (state, error) {
const exited = this._stopPromise ? true : !!state.exited
let goroutineID = -1
if (!exited) {
goroutineID = (state.currentGoroutine && state.currentGoroutine.id) || -1
if (goroutineID === -1) {
goroutineID = (state.currentThread && state.currentThread.goroutineID) || -1
}
}
return {
exited,
goroutineID
}
}

// restart the delve session
restart () {
Expand All @@ -141,6 +154,10 @@ export default class DelveSession {
return Promise.resolve()
}
getStacktrace ({ goroutineID }) {
if (goroutineID === -1) {
return Promise.resolve([])
}

const args = {
id: goroutineID,
depth: 20
Expand All @@ -167,12 +184,13 @@ export default class DelveSession {
.then(this._prepareGoroutines.bind(this))
}
_prepareGoroutines ({ Goroutines: goroutines }) {
return goroutines.map(({ id, userCurrentLoc }) => {
return goroutines.map(({ id, userCurrentLoc, goStatementLoc }) => {
const loc = userCurrentLoc.file ? userCurrentLoc : goStatementLoc
return {
id,
file: userCurrentLoc.file,
line: userCurrentLoc.line - 1, // dlv = 1 indexed line / atom = 0 indexed line
func: userCurrentLoc.function.name.split('/').pop()
file: loc.file,
line: loc.line - 1, // dlv = 1 indexed line / atom = 0 indexed line
func: loc.function.name.split('/').pop()
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions lib/delve-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function create (rawVariables) {
}

rawVariables.forEach((variable) => {
const v = factory.variable(variable)
const v = factory.variable(variable, true)
v.path = v.name = variable.name
addVariable('', v)
})
Expand All @@ -48,13 +48,13 @@ function pathJoin (...items) {
}

const factory = {
variable (variable) {
variable (variable, top) {
let kind = KINDS[variable.kind]
if (variable.unreadable !== '') {
return { value: `(unreadable ${variable.unreadable})`, kind }
}

if (!variable.value && variable.addr === 0) {
if (!variable.value && variable.addr === 0 && !top) {
return { value: [shortType(variable.type), nil()], kind }
}

Expand Down
2 changes: 1 addition & 1 deletion lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function stacktrace (state = [], action) {
case 'UPDATE_STACKTRACE':
// attempt to copy the variables over to the new stacktrace
return action.stacktrace.map((stack) => {
const existingStack = state.find((st) => st.id === stack.id)
const existingStack = state.find((st, i) => i > 0 && st.id === stack.id)
if (!stack.variables && existingStack) {
stack.variables = existingStack.variables
}
Expand Down
4 changes: 1 addition & 3 deletions styles/go-debug.less
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ atom-text-editor {
flex-direction: column;
flex: 1;
position: relative;
background-color: @base-background-color;
}

.go-debug-panel-resizer {
Expand All @@ -76,7 +75,7 @@ atom-text-editor {
}

select {
background: @base-background-color;
background: @tool-panel-background-color;
flex: 1;
border: 0;
cursor: pointer;
Expand Down Expand Up @@ -235,7 +234,6 @@ atom-text-editor {

.go-debug-expandable-header.panel-heading {
padding: @component-padding / 2;
background-color: @tool-panel-background-color;
border-bottom: 1px solid @base-border-color;
cursor: pointer;
font-size: inherit;
Expand Down

0 comments on commit d01a91d

Please sign in to comment.