Skip to content

Commit d52526a

Browse files
committed
Use provided control socket path in init packet.
1 parent f1141d1 commit d52526a

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ 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-
87
## [Unreleased]
98

109
- Xdebug control socket support for pause on Linux and Windows.
10+
1111
## [1.35.0]
1212

1313
- Support for DBGp stream command

src/controlSocket.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,34 @@ export class ControlSocket {
2020
this.supportedPlatform() &&
2121
initPacket.engineName === 'Xdebug' &&
2222
semver.valid(initPacket.engineVersion, { loose: true }) !== null &&
23-
(semver.gte(initPacket.engineVersion, '3.4.0', { loose: true }) || initPacket.engineVersion === '3.4.0-dev')
23+
(semver.gte(initPacket.engineVersion, '3.4.0', { loose: true }) ||
24+
initPacket.engineVersion.startsWith('3.4.0'))
2425
)
2526
}
2627

2728
/**
2829
*
29-
* @param pid appId returned in the init packet
30+
* @param ctrlSocket Control socket full path
3031
* @returns
3132
*/
32-
async requestPause(pid: string): Promise<void> {
33+
async requestPause(ctrlSocket: string): Promise<void> {
3334
let retval
3435
if (process.platform === 'linux') {
35-
retval = await this.executeLinux(pid, 'pause')
36+
retval = await this.executeLinux(ctrlSocket, 'pause')
3637
} else if (process.platform === 'win32') {
37-
retval = await this.executeWindows(pid, 'pause')
38+
retval = await this.executeWindows(ctrlSocket, 'pause')
3839
} else {
3940
throw new Error('Invalid platform for Xdebug control socket')
4041
}
4142
retval
4243
return
4344
}
4445

45-
private async executeLinux(pid: string, cmd: string): Promise<string> {
46+
private async executeLinux(ctrlSocket: string, cmd: string): Promise<string> {
4647
const abs = await import('abstract-socket')
4748
return new Promise<string>((resolve, reject) => {
48-
const cs = `\0xdebug-ctrl.${pid}y`.padEnd(108, 'x')
49+
// const cs = `\0xdebug-ctrl.${pid}y`.padEnd(108, 'x')
50+
const cs = `\0${ctrlSocket}`
4951
try {
5052
const s = abs.connect(cs, () => {
5153
s.write(`${cmd}\0`)
@@ -81,9 +83,10 @@ export class ControlSocket {
8183
})
8284
}
8385

84-
private async executeWindows(pid: string, cmd: string): Promise<string> {
86+
private async executeWindows(ctrlSocket: string, cmd: string): Promise<string> {
8587
return new Promise<string>((resolve, reject) => {
86-
const s = net.createConnection(`\\\\.\\pipe\\xdebug-ctrl.${pid}`, () => {
88+
//const s = net.createConnection(`\\\\.\\pipe\\xdebug-ctrl.${pid}`, () => {
89+
const s = net.createConnection(ctrlSocket, () => {
8790
s.end(`${cmd}\0`)
8891
})
8992
s.setTimeout(3000)

src/phpDebug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ class PhpDebugSession extends vscode.DebugSession {
13991399
this._skippingFiles.set(args.threadId, false)
14001400
}
14011401
try {
1402-
await controlSocket.requestPause(initPacket.appId)
1402+
await controlSocket.requestPause(initPacket.ctrlSocket)
14031403
this.sendResponse(response)
14041404
return
14051405
} catch (error) {

src/xdebugConnection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class InitPacket {
2020
engineName: string
2121
/** the app id (PID) */
2222
appId: string
23+
/** the control socket path */
24+
ctrlSocket: string
2325
/**
2426
* @param {XMLDocument} document - An XML document to read from
2527
* @param {Connection} connection
@@ -33,6 +35,7 @@ export class InitPacket {
3335
this.engineVersion = documentElement.getElementsByTagName('engine').item(0)?.getAttribute('version') ?? ''
3436
this.engineName = documentElement.getElementsByTagName('engine').item(0)?.textContent ?? ''
3537
this.appId = documentElement.getAttribute('appid') ?? ''
38+
this.ctrlSocket = documentElement.getAttributeNS('https://xdebug.org/dbgp/xdebug', 'ctrl_socket') ?? ''
3639
this.connection = connection
3740
}
3841
}

0 commit comments

Comments
 (0)