microsoft / vscode-js-debug

A DAP-compatible JavaScript debugger. Used in VS Code, VS, + more
MIT License
1.67k stars 282 forks source link

dapDebugServer.ts #1659

Closed airportyh closed 1 year ago

airportyh commented 1 year ago

Describe the bug Following up on this issue: I am trying to use dapDebugServer.ts as the entry point for a DAP server. I am testing it with a hand-made client, written in Go. I'll try to explain the scenario by just sending a log of the protocol messages, but if required I could produce the source code.

Log File

-> {"seq":100,"type":"request","command":"initialize","arguments":{"clientID":"replit","clientName":"replit.com","columnsStartAt1":true,"linesStartAt1":true,"locale":"en-us","pathFormat":"path","supportsInvalidatedEvent":true,"supportsProgressReporting":true,"supportsRunInTerminalRequest":true,"supportsVariablePaging":true,"supportsVariableType":true}}
<- {"seq":1,"type":"response","request_seq":100,"command":"initialize","success":true,"body":{"supportsConfigurationDoneRequest":true,"supportsFunctionBreakpoints":false,"supportsConditionalBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsEvaluateForHovers":true,"supportsReadMemoryRequest":true,"supportsWriteMemoryRequest":true,"exceptionBreakpointFilters":[{"filter":"all","label":"Caught Exceptions","default":false,"supportsCondition":true,"description":"Breaks on all throw errors, even if they're caught later.","conditionDescription":"error.name == \"MyError\""},{"filter":"uncaught","label":"Uncaught Exceptions","default":false,"supportsCondition":true,"description":"Breaks only on errors or promise rejections that are not handled.","conditionDescription":"error.name == \"MyError\""}],"supportsStepBack":false,"supportsSetVariable":true,"supportsRestartFrame":true,"supportsGotoTargetsRequest":false,"supportsStepInTargetsRequest":true,"supportsCompletionsRequest":true,"supportsModulesRequest":false,"additionalModuleColumns":[],"supportedChecksumAlgorithms":[],"supportsRestartRequest":true,"supportsExceptionOptions":false,"supportsValueFormattingOptions":true,"supportsExceptionInfoRequest":true,"supportTerminateDebuggee":false,"supportsDelayedStackTraceLoading":true,"supportsLoadedSourcesRequest":true,"supportsLogPoints":true,"supportsTerminateThreadsRequest":false,"supportsSetExpression":true,"supportsTerminateRequest":false,"completionTriggerCharacters":[".","[","\"","'"],"supportsBreakpointLocationsRequest":true,"supportsClipboardContext":true,"supportsExceptionFilterOptions":true,"supportsEvaluationOptions":false,"supportsDebuggerProperties":false,"supportsSetSymbolOptions":false}}
<- {"seq":2,"type":"event","event":"initialized","body":{}}
-> {"seq":101,"type":"request","command":"setBreakpoints","arguments":{"breakpoints":[{"line":1}],"source":{"name":"test.js","path":"test.js"}}}
<- {"seq":3,"type":"response","request_seq":101,"command":"setBreakpoints","success":true,"body":{"breakpoints":[{"id":1,"verified":false,"message":"breakpoint.provisionalBreakpoint"}]}}
-> {"seq":102,"type":"request","command":"configurationDone"}
<- {"seq":4,"type":"response","request_seq":102,"command":"configurationDone","success":true,"body":{}}
-> {"seq":103,"type":"request","command":"launch","arguments":{"args":[],"console":"externalTerminal","cwd":".","environment":[],"pauseForSourceMap":false,"program":"./test.js","request":"launch","sourceMaps":true,"stopOnEntry":false,"type":"pwa-node"}}
<- {"seq":5,"type":"event","event":"output","body":{"category":"telemetry","output":"js-debug/launch","data":{"type":"pwa-node","request":"launch","os":"linux x64","nodeVersion":"v16.13.2","adapterVersion":"1.77.0","parameters":"{\"type\":\"pwa-node\",\"name\":\"<string>\",\"request\":\"launch\",\"trace\":false,\"outputCapture\":\"console\",\"timeout\":10000,\"timeouts\":{},\"showAsyncStacks\":true,\"skipFiles\":[\"<string>\"],\"smartStep\":true,\"sourceMaps\":true,\"sourceMapRenames\":true,\"pauseForSourceMap\":false,\"resolveSourceMapLocations\":null,\"outFiles\":[\"<string>\"],\"sourceMapPathOverrides\":{\"webpack:///./~/*\":\"<string>\",\"webpack:////*\":\"<string>\",\"webpack://@?:*/?:*/*\":\"<string>\",\"webpack://?:*/*\":\"<string>\",\"webpack:///([a-z]):/(.+)\":\"<string>\",\"meteor://💻app/*\":\"<string>\"},\"enableContentValidation\":true,\"cascadeTerminateToConfigurations\":[],\"__workspaceFolder\":\"<string>\",\"__breakOnConditionalError\":false,\"cwd\":\"<string>\",\"env\":{},\"envFile\":null,\"localRoot\":null,\"remoteRoot\":null,\"autoAttachChildProcesses\":true,\"runtimeSourcemapPausePatterns\":[],\"enableTurboSourcemaps\":true,\"program\":\"<string>\",\"stopOnEntry\":false,\"console\":\"<string>\",\"restart\":false,\"args\":[],\"runtimeExecutable\":\"node\",\"runtimeVersion\":\"default\",\"runtimeArgs\":[],\"profileStartup\":false,\"attachSimplePort\":null,\"killBehavior\":\"forceful\",\"environment\":[]}"}}}
<- {"seq":6,"type":"request","command":"runInTerminal","arguments":{"kind":"external","title":"","cwd":".","args":["/home/toby/.nvm/versions/node/v16.13.2/bin/node","./test.js"],"env":{"NODE_OPTIONS":"--require /home/toby/replit/vscode-js-debug/dist/src/bootloader.js --inspect-publish-uid=http","VSCODE_INSPECTOR_OPTIONS":"{\"inspectorIpc\":\"/tmp/node-cdp.1140399-1b49b2f1-0.sock\",\"deferredMode\":false,\"waitForDebugger\":\"\",\"execPath\":\"/home/toby/.nvm/versions/node/v16.13.2/bin/node\",\"onlyEntrypoint\":false,\"autoAttachMode\":\"always\",\"fileCallback\":\"/tmp/node-debug-callback-023a0bed3588ee7a\"}"},"argsCanBeInterpretedByShell":false}}
-> {"seq":104,"type":"response","request_seq":6,"success":true,"command":"runInTerminal","body":{"processId":1140430}}
<- {"seq":7,"type":"response","request_seq":103,"command":"launch","success":true,"body":{}}
<- {"seq":8,"type":"request","command":"startDebugging","arguments":{"request":"launch","configuration":{"type":"pwa-node","name":"test.js [1140430]","__pendingTargetId":"4e980b62ed06f10a5ceec3d0"}}}
-> {"seq":105,"type":"response","request_seq":8,"success":true,"command":"startDebugging"}

After the above exchange, plus my client program having ran the program specified by the runInTerminal request, I am expecting a thread started event followed by a stop event due to the breakpoint being hit, but that never happened. Is there a more correct order for me to administer the events?

connor4312 commented 1 year ago

What did the DAP client do in response to the startDebugging request?

airportyh commented 1 year ago

It just acknowledges it. Is that enough? Or is there a shell command I should run or something else I need to do?

connor4312 commented 1 year ago

Please refer to the docs here: https://microsoft.github.io/debug-adapter-protocol/specification#Reverse_Requests_StartDebugging

The nested session should come in as a new connection to the same server process.

airportyh commented 1 year ago

Ah I see, I need to make another launch request... let me see how that works out.