mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-18 06:13:55 -07:00
Adds initial support for the Debug Adapter Protocol (DAP) to SpiderMonkey via debugger.js. This JavaScript-based implementation enables external debuggers (e.g., VS Code) to interact with the JS runtime using the DAP interface. Implemented DAP requests and events: - attach - initialize (capabilities) - stopped event - threads - scopes - variables (globalThis pending) - continue - stepIn - stepOut - setBreakpoints - Handling of debugger statements This forms the foundation for interactive debugging of in-game scripts, providing smoother integration with developer tools.
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
import { logger } from 'tools/dap/logger.js';
|
|
|
|
export class DapProtocolHandler {
|
|
constructor(jsDebugger) {
|
|
this.commands = {};
|
|
this.jsDebugger = jsDebugger;
|
|
this.logger = logger.getLogger("DAPProtocolHandler");
|
|
}
|
|
|
|
registerCommand(name, fn) {
|
|
this.logger.info(`Registering command: ${name}`);
|
|
this.commands[name] = fn;
|
|
}
|
|
|
|
handleRequest(req) {
|
|
if (req.type !== 'request' || !req.command)
|
|
{
|
|
this.logger.error(`Invalid request: ${JSON.stringify(req)}`);
|
|
return this.errorResponse(req, 'Invalid request format');
|
|
}
|
|
|
|
const handler = this.commands[req.command];
|
|
if (!handler)
|
|
return this.errorResponse(req, `Unknown command ${req.command}`);
|
|
|
|
try
|
|
{
|
|
this.logger.info(`Handling command: ${req.command}`);
|
|
return handler(req);
|
|
}
|
|
catch (error)
|
|
{
|
|
this.logger.error(`Error handling command ${req.command}:`, error);
|
|
this.logger.error(uneval(error.stack));
|
|
return this.errorResponse(req, error.message || 'An error occurred while processing the request');
|
|
}
|
|
}
|
|
|
|
successResponse(req, result) {
|
|
this.logger.info(`Response to ${req.command}`, result);
|
|
const response = {
|
|
'type': 'response',
|
|
'request_seq': req.seq,
|
|
'success': true,
|
|
'command': req.command,
|
|
'body': result
|
|
};
|
|
return response;
|
|
}
|
|
|
|
errorResponse(req, error) {
|
|
this.logger.error(`Error in ${req.command}: ${error}`);
|
|
const response = {
|
|
'type': 'response',
|
|
'request_seq': req.seq,
|
|
'success': false,
|
|
'command': req.command,
|
|
'body': {
|
|
'error': error
|
|
}
|
|
};
|
|
return response;
|
|
}
|
|
}
|