You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Debug API: Add the ability to open source files using their source reference #32845
debugDebug viewlet, configurations, breakpoints, adapter issuesfeature-requestRequest for new features or functionalityverification-neededVerification of issue is requestedverifiedVerification succeeded
I'd like to implement a "Loaded Scripts Explorer" for the Firefox debug adapter but realized that I can only open the files shown in that explorer if they are "local", but not if they'd need to be fetched from Firefox via the debug adapter (e.g. third-party libraries loaded from a CDN, scripts injected by a Browser extension, etc.). However, the ability to view such "remote" files is one of the primary use cases for this explorer (IMHO).
It is already possible to view a "remote" file if it is referenced by a stackframe - in this case it is fetched via the debug adapter using its numeric source reference. But I can't do that in my explorer for two reasons:
I can't tell VS Code about source files and their associated source references (unless they show up in a stackframe)
I can't ask VS Code to open a file using its source reference
I was thinking about implementing a document provider to work around these limitations but that would only be a partial solution: VS Code wouldn't know about the relationship between the files from that content provider and the debugger, so it wouldn't be possible to set breakpoints and if the user stepped into that file later on, VS Code would open a second tab for the file (because it is fetched from the debug content provider and hence is a different file from VS Code's point of view).
My proposal would be:
add a NewSourceEvent (containing a Source object in its body) to the debug protocol
add the ability to open a file using a debugSessionId and a sourceReference
Since the "path" is not interpreted by VS Code in any you can encode whatever you like in it.
When constructing the explorer tree, we fetch paths from the DA. If a node in the tree is selected, we use the path to construct a uri and then open a document with it. VS Code sends the path back to the DA to load the content. So only the DA "knows" what's in a uri.
Yup, this works, thanks for the detailed explanation!
Of course this preliminary solution has the same limitation as the content provider approach that I described above, i.e. I can't set breakpoints in the opened "remote" file and when I step into this file, a second tab for the file is opened.
In the meantime I realized that part 1 of my proposal (the NewSourceEvent) may be unnecessary if VS Code doesn't require the sourceReference used in part 2 of my proposal to be already known - after all it only has to copy it into a SourceRequest and send that to the DA. But it would still need to get a filename for the source to show to the user.
Holger Benl (@hbenl) you can set breakpoints in the opened readonly file and they are even persisted by the VS Code frontend. And if you are getting a second tab for the same file, then your DA probably uses different paths for the same file.
Try node-debug and set breakpoints in internal modules or remote files. They should work like regular files on disk and they don't open in additional tabs.
You just have to make sure that your DA hands out and receives Source objects in a consistent way.
The Source.sourceReference is optional, so if you prefer a path, then please use Source.path.
Source.name is displayed in the UI and Source.path is shown if you hover over a name.
OK, I can set breakpoints now (I had set mimeType in the SourceResponse to application/javascript, but Code only recognizes the deprecated text/javascript).
But I still get 2 tabs for the same file, even though the path is identical.
I tried node-debug and it also gives me 2 tabs for the same file:
Set a breakpoint on the second line, start the debugger, click on <node_internals>/path.js in the Loaded Scripts Explorer, then click "Step Into". Result:
Breakpoints that were set in the tab opened by the Loaded Scripts Explorer are working, but they don't show up in the tab that is used when stepping through the code.
Another problem I have with opening a remote file using debug: uris is that I have to put the remote file's url inside the debug: uri. That would be OK if I could encode the url - but then I'd have to encode all urls in the Source objects in order to be consistent.
I actually tried that, but then I ran into the next problem: if the remote file's url contains an encoded character, it gets messed up somewhere along the way:
Let's say I have a remote file with the url http://host/test.js?x=%3F, the corresponding debug uri would be debug:http%3A%2F%2Fhost%2Ftest.js%3Fx%3D%253F?session=<uuid>. The path argument in the sourceRequest then becomes http://host/test.js%3Fx=%3F - which is wrong, because if I decode that, I get http://host/test.js?x=?...
I had only verified this on Linux, now I noticed that on Windows opening remote sources works but setting breakpoints in remote sources opened from the Loaded Scripts Explorer doesn't work (checked with the Chrome and Firefox debug adapters).
Here's the args of the sourceRequest when I open the remote source from the Loaded Scripts Explorer:
Verifiers:
This feature was reopened because it was not working correctly on Windows.
To verify you need a debugger that identifies source by http URLs (e.g. http://localhost:8080/test.js) not by file paths, e.g. the Chrome debugger.
You can use this VS Code project for verification.
On Windows:
unzip and open with VS Code
from VS Code integrated terminal do:
npm install
npm run start
run "Launch Chrome" debug session
in "Loaded Scripts" explorer find "myScript.js" and set breakpoint in line 5
debugDebug viewlet, configurations, breakpoints, adapter issuesfeature-requestRequest for new features or functionalityverification-neededVerification of issue is requestedverifiedVerification succeeded
Activity
weinand commentedon Aug 21, 2017
Until we have designed and implemented an official API for this you can use the same approach as node-debug:
https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/extension/loadedScripts.ts#L308
https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/parts/debug/browser/debugContentProvider.ts#L32
https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/nodeDebug.ts#L3397
Since the "path" is not interpreted by VS Code in any you can encode whatever you like in it.
When constructing the explorer tree, we fetch paths from the DA. If a node in the tree is selected, we use the path to construct a uri and then open a document with it. VS Code sends the path back to the DA to load the content. So only the DA "knows" what's in a uri.
hbenl commentedon Aug 21, 2017
Yup, this works, thanks for the detailed explanation!
Of course this preliminary solution has the same limitation as the content provider approach that I described above, i.e. I can't set breakpoints in the opened "remote" file and when I step into this file, a second tab for the file is opened.
In the meantime I realized that part 1 of my proposal (the
NewSourceEvent) may be unnecessary if VS Code doesn't require thesourceReferenceused in part 2 of my proposal to be already known - after all it only has to copy it into aSourceRequestand send that to the DA. But it would still need to get a filename for the source to show to the user.weinand commentedon Aug 21, 2017
Holger Benl (@hbenl) you can set breakpoints in the opened readonly file and they are even persisted by the VS Code frontend. And if you are getting a second tab for the same file, then your DA probably uses different paths for the same file.
Try node-debug and set breakpoints in internal modules or remote files. They should work like regular files on disk and they don't open in additional tabs.
You just have to make sure that your DA hands out and receives Source objects in a consistent way.
The Source.sourceReference is optional, so if you prefer a path, then please use Source.path.
Source.name is displayed in the UI and Source.path is shown if you hover over a name.
hbenl commentedon Aug 25, 2017
OK, I can set breakpoints now (I had set
mimeTypein theSourceResponsetoapplication/javascript, but Code only recognizes the deprecatedtext/javascript).But I still get 2 tabs for the same file, even though the path is identical.
I tried node-debug and it also gives me 2 tabs for the same file:
Set a breakpoint on the second line, start the debugger, click on

<node_internals>/path.jsin the Loaded Scripts Explorer, then click "Step Into". Result:Breakpoints that were set in the tab opened by the Loaded Scripts Explorer are working, but they don't show up in the tab that is used when stepping through the code.
hbenl commentedon Sep 10, 2017
Another problem I have with opening a remote file using
debug:uris is that I have to put the remote file's url inside thedebug:uri. That would be OK if I could encode the url - but then I'd have to encode all urls in theSourceobjects in order to be consistent.I actually tried that, but then I ran into the next problem: if the remote file's url contains an encoded character, it gets messed up somewhere along the way:
Let's say I have a remote file with the url
http://host/test.js?x=%3F, the corresponding debug uri would bedebug:http%3A%2F%2Fhost%2Ftest.js%3Fx%3D%253F?session=<uuid>. Thepathargument in the sourceRequest then becomeshttp://host/test.js%3Fx=%3F- which is wrong, because if I decode that, I gethttp://host/test.js?x=?...weinand commentedon Sep 10, 2017
Yes, I noticed that problem too and I'm working on a solution...
hbenl commentedon Sep 25, 2017
Fixed with #23194.
3 remaining items
weinand commentedon Sep 26, 2017
Holger Benl (@hbenl) thanks a lot for verifying this.
I've added the "Verified" label.
hbenl commentedon Oct 15, 2017
I had only verified this on Linux, now I noticed that on Windows opening remote sources works but setting breakpoints in remote sources opened from the Loaded Scripts Explorer doesn't work (checked with the Chrome and Firefox debug adapters).
Here's the
argsof thesourceRequestwhen I open the remote source from the Loaded Scripts Explorer:{ "sourceReference":5, "source":{ "path":"http://localhost:8080/test.js", "sourceReference":5 } }And here's the
argsof thesetBreakpointsRequestwhen I try to set a breakpoint in the opened tab:{ "source":{ "path":"http:\\localhost:8080\\test.js", "name":"test.js" }, "lines":[13], "breakpoints":[{"line":13}], "sourceModified":false }Note how the
sourceReferenceis lost in thesetBreakpointsRequestand thepathcontains a broken URL.This may also be related to #29985.
weinand commentedon Oct 30, 2017
Verifiers:
This feature was reopened because it was not working correctly on Windows.
To verify you need a debugger that identifies source by http URLs (e.g.
http://localhost:8080/test.js) not by file paths, e.g. the Chrome debugger.You can use this VS Code project for verification.
On Windows:
Breakpoint should be hit.
do not corrupt debug URIs; fixes microsoft#32845