Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can debugger forward "source" requests to debugpy? #870

Open
vidartf opened this issue Feb 17, 2022 · 2 comments
Open

Can debugger forward "source" requests to debugpy? #870

vidartf opened this issue Feb 17, 2022 · 2 comments

Comments

@vidartf
Copy link

vidartf commented Feb 17, 2022

The current handler for "source" requests to the debugger is as follows:

async def source(self, message):
reply = {
'type': 'response',
'request_seq': message['seq'],
'command': message['command']
}
source_path = message["arguments"]["source"]["path"]
if os.path.isfile(source_path):
with open(source_path, encoding='utf-8') as f:
reply['success'] = True
reply['body'] = {
'content': f.read()
}
else:
reply['success'] = False
reply['message'] = 'source unavailable'
reply['body'] = {}
return reply

Intuitively, I would expect that the source request would be forwarded to debugpy, so that the more complete implementation of pydevd could handle the request. Some differences of that implementation:

  • Both implementations tries direct file access first.
  • pydevd then tries the linecache with the following comment:

    File might not exist at all, or we might not have a permission to read it, but it might also be inside a zipfile, or an IPython cell. In this case, linecache might still be able to retrieve the source.

  • Finally, pydevd falls back to using the sourceReference supplied (which would previously be given on e.g. "module" events I think).

One of the advantages of the approach of pydevd is that it also is able to handle modules that are loaded from custom module loaders (zip file loader, DB loaders, web loaders, etc.). It would therefore be good if someone could write out why we're not simply forwarding the request to debugpy, and if there is a solid reason for it, maybe we could improve upon it so that we can still support the sourceReference field?

@vidartf
Copy link
Author

vidartf commented Feb 17, 2022

(CC @JohanMabille )

@JohanMabille
Copy link
Contributor

Hi @vidartf ,

Sorry for the late reply, but I have now the whole story ;)

When sending a Source request, you need to provide a sourceReference argument because of old adapters. The issue is that the sources of notebook cells are never loaded, the are created by the kernel which dumps the content in temporary files. Therefore, there is no sourceReference for them. Besides, specifying sourceReference: 0 in the sourceRequest does not work; debugpy does not find the source if you do so, even if you provide a Source argument with the right path.

Therefore it is required that the kernel handles the request when sourceReference is 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants