Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement support for delayed stack loading #759

Merged
merged 2 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();