VS Code cannot breakpoint or step through 3rd party Python code from Jupyter Notebook - visual-studio-code

One of my main uses for a debugger is to step through parts of new libraries to better understand how they work and how to use them. But, my current install of VS Code refuses to let me set breakpoints or step through 3rd party libraries when I start debugging in Jupyter Notebook. I get a 'Breakpoint in file excluded by filters' error.
I've looked through everything I could find online about this problem, and nothing I've tried has worked. I have:
In File > Preferences > Settings > Debug turned on 'Allow breakpoints everywhere' for both User and Workspace
In ... Settings > Extensions > Jupyter turned off 'Debug Just My Code' for both
In launch.json changed ' "justMyCode": true ' to ' "justMyCode": false '
After suggestions in How to disable "just my code" setting in VSCode debugger?, I tried to add a separate debug configuration to launch.json. This used to do the trick, but ' "request": "test" ' can no longer be used. Various alternatives I've tried here also do not work (e.g. "request": "attach" or "purpose": "debug-test").
The problem does not exist when I use a python file with the same code. So whatever is applying filters is only doing so when I seek to debug a cell in Jupyter Notebook.

For others, the issue has been resolved, see release notes: "Just My Code" for notebook cell debugging.
"Just My Code" for notebook cell debugging
The "Just My Code" debug feature allows the user to determine whether
the debugger will step through code from Python libraries, or will
only step through user code. This has been enabled by default when
debugging a notebook cell, and you can now set
"jupyter.debugJustMyCode": false to disable it and allow stepping
through library code. For the best experience, upgrade debugpy in
your environment to >=1.6.3. Previously, this setting was only
respected for debugging using the Interactive Window. Now it is
respected in notebook editors as well.

Evidently, the problem I'm encountering is a known bug: https://github.com/microsoft/vscode-jupyter/issues/8146 . I've heard from a VS Code developer that they've (tried) to implement fixes and I should try the latest Insiders vscode build, with the latest pre-release Jupyter extension. I'm not sure I'm ready for bleeding edge, so may live with the bug until these fixes end up in a standard release.

Related

Should debugger be launched always in VScode when only running a file (not debugging) using code-runner?

In a VScode C/C++ programming setup on Windows 10 system, the "C/C++ Extension Pack", "Code Runner", "WSL" extensions are installed, which use Alpine Linux target on WSL on this PC. Alpine Linux WSL instance has the gcc dev environment, build-tools, gdb etc. installed, apart from the necessary VScode extensions needed inside WSL.
In this environment I am able to write C/C++ programs, build them, execute them, interact with them through the built-in terminal. I use the "Code Runner" "Run C/C++ file" shortcut button to build(if necessary) and run individual C/C++ program files (there is no Makefile and these are simple programs all thrown in a single folder, not in a project structure).
Recently however, I noticed that whenever I try to "Run C/C++ file", debugger is also launched and I get a screen like this (notice the 2 yellow/orange arrows indicating what I am trying to draw attention to):
I do not remember this being the case earlier, but I think this started after I tried to debug a program by setting a breakpoint, which I later cleared. I've also ensured that "Run > Remove All Breakpoints" is done, to make sure that there are absolutely no breakpoints. Therefore wondering if:
it is normal for debugger to get launched in this manner ?
if not, what exactly might have caused it ?
finally, what can I do to make sure that the debugger is not launched, when all I want to do is "Run" ?
In "Code Runner" settings file, I did not find anything that might control this behaviour, but then I am quite new to VScode so not sure if I am missing anything obvious.

VS Code - can I disable the 'No Python interpreter' warning?

I use VS Code for multiple languages and don't always need an interpreter. I also use multiple Python versions, usually managed via Pipenv. I find the constant nagging to select an interpreter really annoying; can I disable it?
After all, I'll soon quickly find out I don't have one selected when I try and run the code.
Yes. You can go into settings, extensions, Python ( which is generating the popup) , and there you can check the box next to "Python: Disable Installation Check"
Is you open the settings.json file instead, you are going to add/check the setting to this.
"python.disableInstallationCheck": true
For reference, I'm on VS Code for Mac v1.6, Python extension is v2021.12.1559732655.

NIOS II IDE unsuably slow

I've installed Quartus and NIOS II IDE on my Linux machine. Originally I tried importing an existing NIOS II Project into Eclipse, but it just sits there spinning away and eventually tells me it can't import the project because it already exists.
I tried installing everything on a Win10 machine and the project imported OK. I did notice that some of the paths in the orignal project have backslashes. So, for example:
#include "..\subfolder\include_file.h"
Kind of thing. I wonder whether maybe it was that was causing issues.
So, I then tried creating an hello world NIOS Processor in Quartus and making a NIOS II project from scratch. Every step along the way with Eclipse was grindingly slow, but eventually worked up until the point I was able to hit Finish at which point it's just hanging with the little circle with red and blue arrows spinning round and round.
I also have a pop up window with a long list of:
Remote System Explorer Opertion
lines, and at the top it says:
The user operation is waiting for background work to complete
It seems like everything is installed correctly, I can open the NIOS II Eclipse IDE from Quartus for example. Quartus itself works nicely.
I used these instructions to installed Eclipse:
Is anyone able to give me any pointers as to why this is so incredibly slow please? My Linux machine is pretty high spec and flies. Nothing else whatsoever even vaguely struggles on it.
If there's anything I can try to give diagnostic info, am more than happy to supply. Thanks!
I found a solution here
https://askubuntu.com/questions/761604/eclipse-not-working-in-16-04
To test if this fix works, try opening a terminal, and doing
$export SWT_GTK3=0
then run eclipse-nios2. That is, do something like
$ ~/intelFPGA_lite/20.1/nios2eds/bin/eclipse-nios2
If that fixes the problem then to make the fix permanent edit eclipse.ini which for me is in intelFPGA_lite/20.1/nios2eds/bin/eclipse_nios2
In that file, between the lines openFile and --launcher.appendVmargs
insert
--launcher.GTK_version
2
So it reads:
openFile
--launcher.GTK_version
2
--launcher.appendVmargs
and save.
Worked for me!
Try using Visual Studio Code instead. It can do (almost) everything that Eclipse can do, with the added benefit that you can debug remote. E.g. in my setup, I develop exclusively using macOS. I have Quartus installed in a Ubuntu 20.04 VM and VSCODE allows me to develop and debug as if I'm running Quartus natively in macOS.
I'll provide a rough 'how-to' below.
I strongly suggest using a Ubuntu environment for Quartus (other linux environments should work too: I've tested Arch and Manjaro). The Windows install is a royal pain to get working, regardless of IDE choice. I haven't tried the Windows version since 20.1 but nothing worked out of the box and it took many hours or messing with config files to fix it. Also, the Windows version isn't native anyway - it's actually running in Ubuntu via WSL.
Make sure you have installed your required version of Quartus - this should work for Pro, Standard and Lite editions. You can skip the manual installation of NiosII Build Tools for Eclipse if you'd like but I would actually recommend installing it. It can still be useful, if only for creating a new project, BSP etc.
Install VSCODE along with the C/C++ Extension provided by Microsoft (and the Visual Studio Code Remote - SSH extension if you intend to use that feature)
Create a new project using Eclipse (or skip, if you already have a project)
Open VSCODE, select open and navigate to the software directory of your project.
VSCODE will open your project and you should see your application directory and BSP directory.
From here, you can work on your code with full linting, auto completion etc.
If you need to regenerate your BSP, you can either do that using Eclipse or just run the command-line tool instead.
Compiling
If you allowed Eclipse to create your project for you, it will have produced a makefile in your application directory. Compiling is as simple as running 'make' from the application directory. I like to keep a terminal window open within VSCODE so I can run various tools as I work so this is usually how I can compile code. If, instead, you'd like to integrate this into VSCODE, you can define a task (https://code.visualstudio.com/docs/editor/tasks).
Eclipse automatically adds new sources that you create to the makefile. VSCODE won't do this - however, I personally don't think this is a bad thing. I don't like IDEs messing with my makefiles, I want fully control over them myself. So when you create a new source file, just remember to add it to the makefile. There is probably a way to get VSCODE to add sources files automatically (you can run commands on save etc) - but I have no motivation to try to figure this out.
Debugging
It is also possible to debug Nios2 software live on the target via the USB-Blaster using VSCODE. To do this, open the launch.json file in the .vscode folder of your project. If this file does not exist, just create it. The path should be:
<project root dir>/.vscode/launch.json
Copy the following into the launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "app",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/app/app.elf",
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"MIMode": "gdb",
"miDebuggerServerAddress": "localhost:2334",
"miDebuggerPath": "/PATH/TO/intelFPGA/20.1/nios2eds/bin/gnu/H-x86_64-pc-linux-gnu/bin/nios2-elf-gdb",
"debugServerPath": "/PATH/TO/intelFPGA/20.1/quartus/bin/nios2-gdb-server",
"debugServerArgs": "--tcpport 2334 --reset-target --tcppersist",
}
]
}
This file is a list of debug targets and settings. You can add any number of configurations here, but easiest to just start with one for now. The configuration above is called 'app', you can change this to suit your own project if you wish.
Update the "program" entry with the path to your applications elf
file
Update the "miDebuggerPath" path with the path the nios2-elf-gdb on
your system. This is the gdb client for Nios2
Update the "debugServerPath" path with the path the nios2-gdb-server.
This is the gdb server for Nios2
Save the file and now click on the "run and debug" button on the left
side control panel in VSCODE
You'll see play button at the top of the screen next to the configuration you just defined in launch.json. Hit the play button - this will start an instance of the gdb server, followed by the gdb client and connect the two. If all goes well, your target will run and stop in main.
VSCODE will provide you with a set of debug tools for stepping, watching variables, call stack - all that good stuff. On the right hand side, you can view the debug console which will allow you to enter commands directly into the gdb console. Note, you have to prepend your commands with -exec. E.g. to print the value of a variable x, you would type:
-exec print x
Caveat
There is a problem with this debugging method: nios2-gdb-server doesn't always exit cleanly and as a result the port doesn't close. If you try to start another debug session, the server won't start because the port is in use. Eclipse solves this problem by randomizing the port everytime it launches the gdb. I have not found a way to do that VSCODE yet.
I find easiest way around this is to run the gdb server manually when I need it. Comment out the two 'debugServer' lines above. Open a second terminal in VSCODE and run:
nios2-gdb-server --tcpport 2334 --reset-target --tcppersist
This will keep the server running even when you stop debugging. If you start another debug session, it will reconnect to the same server instance.
Update: rioV8 provided a helpful solution to this problem which involves using a vscode extension to generate a random environment variable which can used be used in place of the port numbers. The solution is here.

vscode automatically "source activate" everytime launches new terminal

Recently when I'm using vscode, everytime I launches the built-in terminal, it automatically uses "source activate base" to launch a anaconda python virtual environment. You can see the screenshot
I don't think I changed anything but it just came up randomly. Can someone help me out?
To prevent automatic activation of a selected environment, add
"python.terminal.activateEnvironment": false
to your settings.json file (it can be placed anywhere as a sibling to the existing settings). However, debugging or running Python code without any activated environment won't work.

Debugging Python Code, Visual Studio Code, Virtual Enviroments

I have been trying to configure the debugger on vscode for debugging python code. Below is the launch.json config and following are the settings.json and externalTerminal (launch.json) config, respectively.
I have read through the documentation but I am afraid I am not able to understand it. From what I read on there, I need to set up my external terminal configuration as the integrated terminal isn't capable of accepting inputs(yet).
I am using virtualenvs for my project and I have them in the path: usr/Projects/VirtualEnvs. All my venvs reside in there. I tried to set "python.pythonPath": "/usr/Projects/VirtualEnvs/myVenv/bin/python3.6" which doesn't seem to work. Could anyone help me out or at least point me in the right direction (would be a good learning experience)? Please let me know if my question isn't clear enough.
I figured it out!
My mistake: The python interpreter was not set for the script I was debugging, and since I was using a venv with different Python version, I was thinking that maybe I'd have to somehow set it to that version of the Python interpreter!
How I came to the solution?: Today, while studying and getting stuck with a problem, I noticed that near my shebang was line that said 'Set as interpreter'. I clicked that and VSCode told me that it was now using Python 3.6.1 as the interpreter, that kind of got me excited. Just to be sure I did a google search and found this video. That, very quickly, helped me understand my problem that firstly the interpreter wasn't set and secondly, I was running the debugger from the wrong file!
"program": "${file}",
"cwd": "${workspaceFolder}"
This setting takes care of which folder and what file for you!
For the External Terminal configuration, a new terminal window pops up and you can supply args to your input statement and watch as the debugger goes step by step!