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

Cannot step into external programs even when "justMyCode" is set to false #817

Closed
1 task done
seishiroono opened this issue Jan 11, 2022 · 19 comments
Closed
1 task done

Comments

@seishiroono
Copy link

seishiroono commented Jan 11, 2022

VS Code version

1.63.2

Extension version

2021.12.1559732655

OS type

macOS

OS version

Monterey 12.1

Python distribution

python.org

Python version

3.9.9

Language server

None or Disabled

Expected behaviour

The debugger can step into external (or standard) packages.
In particular, when we set a breakpoint at mol.build() in the following example, the debugger steps into mole.py.

Actual behaviour

It cannot step into external (or standard) packages, i.e., it ignores them.
However, the program works well, and I can obtain the collect result.

Steps to reproduce

My json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Debug Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "stopOnEntry": true,
            "justMyCode": false
        }
    ]
}

setting.json

{
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "terminal.integrated.inheritEnv": false,
    "python.pythonPath": "/usr/local/bin/python3"
}

Sample program

import numpy as np
from pyscf import gto

mol = gto.Mole()
mol.verbose = 0
mol.atom="""8            .000000     .000000     .119262
1            .000000     .763239    -.477047
1            .000000    -.763239    -.477047"""
mol.charge=0
mol.spin  = 0
mol.basis = "6-31G"
mol.build() # I set a breakpoint here.

print(mol.atom)

I saw other issues (e.g., microsoft/vscode-python#7347, microsoft/vscode-python#10637). However, the solution seems not to work for me.

Logs

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@karthiknadig
Copy link
Member

@seishiroono randn for numpy redirects to code implemented in C, so the debugpy will not be able to see it as python code.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Jan 12, 2022
@seishiroono
Copy link
Author

I'm sorry that I gave a bad exmaple.
I update the example which is a very simple version of my actual problem.
I want to use an external package, pyscf, and debug it.

Thank you for your help in advance.

@int19h
Copy link
Contributor

int19h commented Jan 12, 2022

Can you specify which line are you trying to perform the step on? Looking at pyscf repo, it also has some native code in it.

Note that if you want to debug the C code alongside Python, it is supported in Visual Studio proper (but not in VS for Mac or VSCode).

@seishiroono
Copy link
Author

@int19h Thank you for your comment. Actually, I set a breakpoint mol.build() in the above example.
Then, I expect that the debugger steps into mole.py (a python file of pyscf), but nothing happens.

@int19h
Copy link
Contributor

int19h commented Jan 13, 2022

Cannot repro this on Debian, and pyscf doesn't seem to have prebuilt wheels for macOS/ARM. I'll get my hands on an Intel mac and give it another try.

Meanwhile, if you have access to a Linux environment, can you check if it repros for you there as well?

@seishiroono
Copy link
Author

seishiroono commented Jan 13, 2022

I'll get my hands on an Intel mac and give it another try.

Thank you for your help. Actually, my laptop is also Intel Mac.

if you have access to a Linux environment, can you check if it repros for you there as well?

I'm sorry that I don't have a Linux environment.

@seishiroono
Copy link
Author

@int19h Could you reproduce the problem with your mac?
Thank you very much for your time in advance.

@fabioz
Copy link
Collaborator

fabioz commented Jan 18, 2022

@seishiroono can you provide the logging from running in your machine?

i.e.:

  • Open VS Code
  • Select the command Extensions: Open Extensions Folder
  • Locate the Python extension directory, typically of the form ms-python.python-2021.*.****
  • In that directory ensure you do not have any debug*.log files, if you do, please delete them
  • Go back into VS Code and modify your launch.json to add the setting "logToFile": true, see below:
{
    "name": "Python: Current File (Integrated Terminal)",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal",
    "logToFile": true
}
  • Start debugging
  • When done, go back into the extension directory and upload the debug*.log files into this GitHub issue.

@seishiroono
Copy link
Author

seishiroono commented Jan 18, 2022

@fabioz Sorry, I didn't get what you meant. The following things are what I have to do?

  1. Install ms-python.python (Actually, I use version 2021.12.1559732655)
  2. Check if there does not exist debug(filename).log (Delete it if exists in the current opened folder)
  3. Add "logToFile": true to "launch.json."
  4. Perform debugging

If the above is correct, I actually did not get any log file...

Here is my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Debug Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "stopOnEntry": true,
            "justMyCode": false,
            "logToFile": true
        }
    ]
}

Also, I found that debug console in VScode said

Frame skipped from debugging during step-in.
Note: may have been skipped because of "justMyCode" option (default == true). Try setting "justMyCode": false in the debug configuration (e.g., launch.json).

However, as you can see, I add "justMyCode": false to my launch.json

@fabioz
Copy link
Collaborator

fabioz commented Jan 20, 2022

@seishiroono maybe the way you're launching is not really reading that launch.json (so, the justMyCode doesn't make any difference).

Can you provide a screenshot (or gif) showing how you're making the launch?

@seishiroono
Copy link
Author

seishiroono commented Jan 20, 2022

@fabioz Thank you for your message.
I see. Let me share my screenshots.

First, I put a file named "test.py", which is the same file as the above example.
Then, VScode told me that there are no json files in this folder (see the first screenshot).
So, I made it and add some lines to "launch.json", which results in the above json file.
"launch.json" was created in ./.vscode, as shown in the second screenshot.

(first screenshot)
screen1

(second screenshot)
screen2

Next, I performed debug, but I got the same result...

What should I do?
Thank you for your help!

@seishiroono
Copy link
Author

@fabioz Are there any mistakes?
If so, please let me know.

I appreciate your help.

@fabioz
Copy link
Collaborator

fabioz commented Jan 26, 2022

But for launching are you clicking the launch config or are you using some other shortcut?

i.e.: if you click here it should work (but if you use some other shortcut it may need to be defined differently...).

image

@seishiroono
Copy link
Author

@fabioz Oh, I see. I used another shortcut (see upper right in the attached figure).
debug

If I use the shortcut, the debugging is fine.
I really thank you for your help!

@fabioz
Copy link
Collaborator

fabioz commented Jan 27, 2022

Depending on how you run you really need to configure the launch.json differently (if you want to use that dropdown, I think you need to specify a different purpose to customize it -- see: https://code.visualstudio.com/docs/python/debugging#_purpose).

@fabioz fabioz closed this as completed Jan 27, 2022
@chopeen
Copy link

chopeen commented Jan 20, 2023

Only tangentially related, but let me post it here - in my case, I could not enter a certain function while debugging a unit test, because that function was patched to return {}, so it wasn't called at all.

@vpozdnyakov
Copy link

@chopeen justMyCode does not work in unit test debugging, am I right? I have the same issue.
Any options to fix that?

@chopeen
Copy link

chopeen commented Feb 23, 2023

@vpozdnyakov I am able to step into 3rd party library code while debugging unit tests with the following configuration added to launch.json:

{
    "name": "Debug Unit Test",
    "type": "python",
    "request": "test",
    "justMyCode": false,
}

Source: microsoft/vscode-python#7131 (comment)

@Aaron-WengXu
Copy link

@chopeen justMyCode does not work in unit test debugging, am I right? I have the same issue.
Any options to fix that?

I agree with you. If I use Jupyter notebook and debug code segments individually, I can not step into the std library. If I put all code segments in a single python file, however, I can do it.

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

7 participants