Skip to content

Commit 84d7444

Browse files
authored
feat: implement support for delayed stack loading (#759)
* feat: implement support for delayed stack loading * Simplify slice logic, add tests.
1 parent c6588ba commit 84d7444

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ All notable changes to this project will be documented in this file.
44

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

7+
## [1.25.0]
8+
9+
- Implement delayed stack loading with startFrame and levels argument to StackTrace Request
10+
711
## [1.24.3]
812

9-
- Fox for broken property traversal #755
13+
- Fix for broken property traversal #755
1014

1115
## [1.24.2]
1216

src/phpDebug.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class PhpDebugSession extends vscode.DebugSession {
219219
},
220220
],
221221
supportTerminateDebuggee: true,
222+
supportsDelayedStackTraceLoading: false,
222223
}
223224
this.sendResponse(response)
224225
}
@@ -741,7 +742,7 @@ class PhpDebugSession extends vscode.DebugSession {
741742
if (!connection) {
742743
throw new Error('Unknown thread ID')
743744
}
744-
const { stack } = await connection.sendStackGetCommand()
745+
let { stack } = await connection.sendStackGetCommand()
745746
// First delete the old stack trace info ???
746747
// this._stackFrames.clear();
747748
// this._properties.clear();
@@ -781,7 +782,10 @@ class PhpDebugSession extends vscode.DebugSession {
781782
this._errorStackFrames.set(id, status)
782783
response.body = { stackFrames: [{ id, name, source, line, column: 1 }] }
783784
} else {
785+
const totalFrames = stack.length
786+
stack = stack.slice(args.startFrame, args.levels ? (args.startFrame ?? 0) + args.levels : undefined)
784787
response.body = {
788+
totalFrames,
785789
stackFrames: stack.map((stackFrame): VSCodeDebugProtocol.StackFrame => {
786790
let source: VSCodeDebugProtocol.Source
787791
let line = stackFrame.line

src/test/adapter.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,5 +817,24 @@ describe('PHP Debug Adapter', () => {
817817
s1.end()
818818
})
819819
})
820+
it('stack depth', async () => {
821+
const program = path.join(TEST_PROJECT, 'stack.php')
822+
823+
await Promise.all([client.launch({ program }), client.configurationSequence()])
824+
const event = (await client.waitForEvent('stopped')) as DebugProtocol.StoppedEvent
825+
assert.propertyVal(event.body, 'reason', 'breakpoint')
826+
const threadId = event.body.threadId!
827+
828+
const response = await client.stackTraceRequest({ threadId, levels: 1 })
829+
assert.lengthOf(response.body.stackFrames, 1)
830+
assert.equal(response.body.totalFrames, 4)
831+
assert.equal(response.body.stackFrames[0].name, 'depth3')
832+
const response2 = await client.stackTraceRequest({ threadId, startFrame: 1 /*, levels: 3*/ })
833+
assert.lengthOf(response2.body.stackFrames, 3)
834+
assert.equal(response2.body.totalFrames, 4)
835+
assert.equal(response2.body.stackFrames[0].name, 'depth2')
836+
assert.equal(response2.body.stackFrames[1].name, 'depth1')
837+
assert.equal(response2.body.stackFrames[2].name, '{main}')
838+
})
820839
})
821840
})

testproject/stack.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
// Test stack depth.
4+
5+
function depth1() {
6+
depth2();
7+
}
8+
9+
function depth2() {
10+
depth3();
11+
}
12+
13+
function depth3() {
14+
xdebug_break();
15+
}
16+
17+
depth1();

0 commit comments

Comments
 (0)