Skip to content

Commit

Permalink
feat: implement support for delayed stack loading (#759)
Browse files Browse the repository at this point in the history
* feat: implement support for delayed stack loading

* Simplify slice logic, add tests.
  • Loading branch information
zobo committed Mar 2, 2022
1 parent c6588ba commit 84d7444
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.25.0]

- Implement delayed stack loading with startFrame and levels argument to StackTrace Request

## [1.24.3]

- Fox for broken property traversal #755
- Fix for broken property traversal #755

## [1.24.2]

Expand Down
6 changes: 5 additions & 1 deletion src/phpDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class PhpDebugSession extends vscode.DebugSession {
},
],
supportTerminateDebuggee: true,
supportsDelayedStackTraceLoading: false,
}
this.sendResponse(response)
}
Expand Down Expand Up @@ -741,7 +742,7 @@ class PhpDebugSession extends vscode.DebugSession {
if (!connection) {
throw new Error('Unknown thread ID')
}
const { stack } = await connection.sendStackGetCommand()
let { stack } = await connection.sendStackGetCommand()
// First delete the old stack trace info ???
// this._stackFrames.clear();
// this._properties.clear();
Expand Down Expand Up @@ -781,7 +782,10 @@ class PhpDebugSession extends vscode.DebugSession {
this._errorStackFrames.set(id, status)
response.body = { stackFrames: [{ id, name, source, line, column: 1 }] }
} else {
const totalFrames = stack.length
stack = stack.slice(args.startFrame, args.levels ? (args.startFrame ?? 0) + args.levels : undefined)
response.body = {
totalFrames,
stackFrames: stack.map((stackFrame): VSCodeDebugProtocol.StackFrame => {
let source: VSCodeDebugProtocol.Source
let line = stackFrame.line
Expand Down
19 changes: 19 additions & 0 deletions src/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,5 +817,24 @@ describe('PHP Debug Adapter', () => {
s1.end()
})
})
it('stack depth', async () => {
const program = path.join(TEST_PROJECT, 'stack.php')

await Promise.all([client.launch({ program }), client.configurationSequence()])
const event = (await client.waitForEvent('stopped')) as DebugProtocol.StoppedEvent
assert.propertyVal(event.body, 'reason', 'breakpoint')
const threadId = event.body.threadId!

const response = await client.stackTraceRequest({ threadId, levels: 1 })
assert.lengthOf(response.body.stackFrames, 1)
assert.equal(response.body.totalFrames, 4)
assert.equal(response.body.stackFrames[0].name, 'depth3')
const response2 = await client.stackTraceRequest({ threadId, startFrame: 1 /*, levels: 3*/ })
assert.lengthOf(response2.body.stackFrames, 3)
assert.equal(response2.body.totalFrames, 4)
assert.equal(response2.body.stackFrames[0].name, 'depth2')
assert.equal(response2.body.stackFrames[1].name, 'depth1')
assert.equal(response2.body.stackFrames[2].name, '{main}')
})
})
})
17 changes: 17 additions & 0 deletions testproject/stack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

// Test stack depth.

function depth1() {
depth2();
}

function depth2() {
depth3();
}

function depth3() {
xdebug_break();
}

depth1();

0 comments on commit 84d7444

Please sign in to comment.