Skip to content

Commit 1087d8d

Browse files
committed
Control socket pause.
1 parent 7aca123 commit 1087d8d

File tree

5 files changed

+119
-2
lines changed

5 files changed

+119
-2
lines changed

package-lock.json

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@vscode/debugadapter": "^1.57.0",
4747
"@vscode/debugprotocol": "^1.55.1",
4848
"@xmldom/xmldom": "^0.8.4",
49+
"abstract-socket": "^2.1.1",
4950
"buffer-crc32": "^0.2.13",
5051
"dotenv": "^16.0.3",
5152
"file-url": "^3.0.0",

src/abstract-socket.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference types="node" />
2+
declare module "abstract-socket" {
3+
export function createServer(listener: any): AbstractSocketServer;
4+
export function connect(name: any, connectListener: any): net.Socket;
5+
export function createConnection(name: any, connectListener: any): net.Socket;
6+
class AbstractSocketServer extends net.Server {
7+
// constructor(listener: any);
8+
// listen(path: string, listener: () => void): net.Socket;
9+
// listen(path: string, listeningListener?: () => void): this;
10+
}
11+
import net = require("net");
12+
export {};
13+
}

src/phpDebug.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { randomUUID } from 'crypto'
1919
import { getConfiguredEnvironment } from './envfile'
2020
import { XdebugCloudConnection } from './cloud'
2121
import { shouldIgnoreException } from './ignore'
22+
import * as abs from 'abstract-socket'
2223

2324
if (process.env['VSCODE_NLS_CONFIG']) {
2425
try {
@@ -1382,10 +1383,47 @@ class PhpDebugSession extends vscode.DebugSession {
13821383
}
13831384
}
13841385

1385-
protected pauseRequest(
1386+
protected async pauseRequest(
13861387
response: VSCodeDebugProtocol.PauseResponse,
13871388
args: VSCodeDebugProtocol.PauseArguments
1388-
): void {
1389+
): Promise<void> {
1390+
// test
1391+
let connection: xdebug.Connection | undefined
1392+
connection = this._connections.get(args.threadId)
1393+
if (!connection) {
1394+
return this.sendErrorResponse(response, new Error(`Unknown thread ID ${args.threadId}`))
1395+
}
1396+
1397+
let initPacket = await connection.waitForInitPacket()
1398+
const supportedControl =
1399+
process.platform === 'linux' &&
1400+
initPacket.engineName === 'Xdebug' &&
1401+
semver.valid(initPacket.engineVersion, { loose: true }) &&
1402+
(semver.gte(initPacket.engineVersion, '3.4.0', { loose: true }) || initPacket.engineVersion === '3.4.0-dev')
1403+
1404+
if (supportedControl) {
1405+
let cs = `\0xdebug-ctrl.${initPacket.appId}y`.padEnd(108, 'x')
1406+
try {
1407+
const sock = abs.connect(cs, () => {
1408+
sock.write("pause\0")
1409+
if (this._skippingFiles.has(args.threadId)) {
1410+
this._skippingFiles.set(args.threadId, false)
1411+
}
1412+
this.sendResponse(response)
1413+
})
1414+
sock.on('data', (data) => {
1415+
// todo
1416+
})
1417+
sock.on('error', (error) => {
1418+
this.sendErrorResponse(response, new Error('Cannot connect to Xdebug control socket'))
1419+
})
1420+
return
1421+
} catch (error) {
1422+
this.sendErrorResponse(response, new Error('Cannot connect to Xdebug control socket'))
1423+
return
1424+
}
1425+
}
1426+
// test
13891427
if (this._skippingFiles.has(args.threadId)) {
13901428
this._skippingFiles.set(args.threadId, false)
13911429
this.sendResponse(response)

src/xdebugConnection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export class InitPacket {
1818
engineVersion: string
1919
/** the name of the engine */
2020
engineName: string
21+
/** the app id (PID) */
22+
appId: string
2123
/**
2224
* @param {XMLDocument} document - An XML document to read from
2325
* @param {Connection} connection
@@ -30,6 +32,7 @@ export class InitPacket {
3032
this.ideKey = documentElement.getAttribute('idekey')!
3133
this.engineVersion = documentElement.getElementsByTagName('engine').item(0)?.getAttribute('version') ?? ''
3234
this.engineName = documentElement.getElementsByTagName('engine').item(0)?.textContent ?? ''
35+
this.appId = documentElement.getAttribute('appid') ?? ''
3336
this.connection = connection
3437
}
3538
}

0 commit comments

Comments
 (0)