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

sourceReference should be 0 for jupyter cells #113

Closed
rchiodo opened this issue Apr 10, 2020 · 4 comments
Closed

sourceReference should be 0 for jupyter cells #113

rchiodo opened this issue Apr 10, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@rchiodo
Copy link
Contributor

rchiodo commented Apr 10, 2020

Environment data

  • DEBUGPY version: '1.0.0b5'
  • PTVSD version: '4.3.2'
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7
  • Using VS Code or Visual Studio: VS code

Actual behavior

Stepping into functions doesn't work. Opens bogus file.

Expected behavior

Stepping into functions defined in other cells would open the appropriate file with the cell.

Steps to reproduce:

  1. Create file like so
# %% 
def baz():
   print('baz')

# %%
print('foo')
baz()
  1. Run first cell in the interactive window in VS code
  2. Debug second cell
  3. Step into the baz call
  4. It will not go to where the first cell is defined.

I'll attach logs in a second.

@int19h int19h self-assigned this Apr 11, 2020
@int19h int19h added the bug Something isn't working label Apr 11, 2020
@rchiodo
Copy link
Contributor Author

rchiodo commented Apr 11, 2020

PTVSD working:
ptvsd-25956.log

DEBUGPY Not (on the same code, doing the same steps)
debugpy.server-35680.log
debugpy.adapter-14836.log
debugpy.pydevd.35680.log

@int19h
Copy link
Contributor

int19h commented Apr 13, 2020

It looks like it did the mapping back to .py correctly, but when reporting that, also provided a "sourceReference":

D+00004.547: /handling #33 request "stackTrace" from Client[1]/
             Client[1] <-- {
                 "seq": 71,
                 "type": "response",
                 "request_seq": 33,
                 "success": true,
                 "command": "stackTrace",
                 "body": {
                     "stackFrames": [
                         {
                             "id": 26,
                             "name": "baz",
                             "line": 3,
                             "column": 1,
                             "source": {
                                 "path": "d:\\Training\\SnakePython\\foo.py",
                                 "sourceReference": 15
                             }
                         }
                     ],
                     "totalFrames": 2
                 }
             }

This causes VSCode to request the source directly instead of trying to open the file:

D+00004.625: Client[1] --> {
                 "seq": 34,
                 "type": "request",
                 "command": "source",
                 "arguments": {
                     "sourceReference": 15,
                     "source": {
                         "path": "d:\\Training\\SnakePython\\foo.py",
                         "sourceReference": 15
                     }
                 }
             }

D+00004.625: /handling #34 request "source" from Client[1]/
             Client[1] <-- {
                 "seq": 72,
                 "type": "response",
                 "request_seq": 34,
                 "success": true,
                 "command": "source",
                 "body": {
                     "content": "def baz():\n    print('baz')\n"
                 }
             }

@fabioz, could any of the recent changes to https://github.com/microsoft/debugpy/blame/master/src/debugpy/_vendored/pydevd/pydevd_file_utils.py regressed this?

@int19h
Copy link
Contributor

int19h commented Apr 13, 2020

I think it's this bit that regressed it, in 8fc238e. The actual path mapping code in file utils does map it correctly, producing "sourceReference": 0; but then here it is replaced. If this entire conditional is removed, everything works fine.

source_reference = pydevd_file_utils.get_client_filename_source_reference(filename_in_utf8)
if not source_reference:
# Check if someone added a source reference to the linecache (Python attrs does this).
if linecache.getline(original_filename, 0):
source_reference = pydevd_file_utils.create_source_reference_for_linecache(
original_filename, filename_in_utf8)
if not source_reference:
if getattr(frame.f_code, 'co_lnotab', None):
if not os.path.exists(original_filename):
# Create a source-reference to be used where we provide the source by decompiling the code.
source_reference = pydevd_file_utils.create_source_reference_for_frame_id(frame_id)

@fabioz
Copy link
Collaborator

fabioz commented Apr 14, 2020

Humm, you're right... just removing that condition will break other things, but I guess that checking if the file exists before proceeding should work...

i.e.:

if (not source_reference) and (not os.path.exists(original_filename)):
   ...

I'll provide a pull request with the fix tomorrow (with proper tests).

@fabioz fabioz self-assigned this Apr 15, 2020
@fabioz fabioz changed the title Stepping into cells is busted with DebugPy (works with PTVSD) sourceReference should be 0 for jupyter cells Apr 15, 2020
fabioz added a commit to fabioz/debugpy that referenced this issue Apr 15, 2020
@fabioz fabioz closed this as completed in 2f21b08 Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants