Closed maelvls closed 4 years ago
I reproduced the Auto-attach feature not working by running
code --disable-extensions
run example in https://github.com/Microsoft/vscode/issues/55918#issuecomment-411016230:
- turn on auto-attach via the "Toggle Auto Attach" action
- use a long-running node.js program "hello.js":
var i = 0; setInterval(() => { console.log('hello world ' + i++); }, 1000);
- set a breakpoint in line 3
- open integrated terminal
- enter node --inspect hello.js
Debugger should hit breakpoint
But no breakpoint is hit 🤔
Auto attach works fine for me on Ubuntu 18.10:
What linux are you using? Are you running tmux in your integrated terminal?
I use /usr/bin/zsh
as my default shell (chsh -s /usr/bin/zsh
).
Running from vscode-1.29.1:
Is VSCODE_PID
set in the integrated terminal on your side? Or is the debug-auto-attach
extension working even though it is not set?
The only variable that is related to vscode (and allows me to detect I am inside the integrated terminal) is TERM_PROGRAM
:
> env | grep -i vscode
TERM_PROGRAM=vscode
VS Code sets VSCODE_PID and that env var is inherited to the extension host where it is picked up by the node-debug or auto-attach extensions. It could be that the env var VSCODE_PID is removed before the integrated terminal is started. So that would explain why you are not seeing it. In addition the auto attach code should work even if VSCODE_PID not found. In this case the processes tree starts at the process with the PID === 0 (which is more inefficient because the tree is larger).
Got it! Thank you so much for the time spent on this issue by the way!!! ❤️
I also tested on 1.30.0-insider (c348be6) but same issue.
I'll try to switch back to plain bash with no fancy bashrc. 🙄
But does it make a difference if you use "plain bash"?
I guess it shouldn't make a difference 😁 As I pretty much have no clue on what is preventing the auto-attach feature to work on my machine, I am trying every possibility 🙂
In VS Code could you please open the Chrome "Developer Tools" via the Windows menu. Then switch to the "Console" tab . In the REPL enter "process.env" Expanding the array should show a "VSCODE_PID" variable.
No sign of VSCODE_PID
:disappointed:
Strange.
VSCODE_PID is set here: https://github.com/Microsoft/vscode/blob/b36ee32fe7ca1da5285f1392be22c8bd14355315/src/vs/code/electron-main/main.ts#L161 and I do not see a reason why that piece of code is not executed in your version.
How are you running VS Code? An official build? Or are you building it yourself?
I tried all vscode version I know of:
apt install code
(1.29.1)apt install code-insiders
(1.30.0-insider)./scripts/code-cli.sh
When trying the oss dev version of vscode, I couldn't find a way to debug the builtin extension ms-vscode.node-debug
(in order to debug the logic behind auto-attach).
I tried ./scripts/code-cli.sh --builtin
with 'local' (I cloned ms-vscode.node-debug
and ran yarn
inside). But I keep having issues (from vscode
at 0d3a14402d88f0):
./scripts/code-cli.sh
[16:52:39] Syncronizing built-in extensions...
[16:52:39] You can manage built-in extensions with the --builtin flag
[16:52:39] [local] ms-vscode.node-debug: /home/mvalais/.vscode-oss-dev/vscode-node-debug ✔︎
[16:52:39] [marketplace] ms-vscode.node-debug2@1.30.1 ✔︎
[16:52:39] [disabled] ms-vscode.references-view
Debugger listening on ws://127.0.0.1:5874/ab468708-05f6-4855-b31a-6c63493cce5f
For help see https://nodejs.org/en/docs/inspector
It says
Activating extension 'ms-vscode.node-debug' failed: Cannot find module '/home/mvalais/.vscode-oss-dev/vscode-node-debug/dist/extension.js'.
The thing is vscode-node-debug
does not contain any dist/
folder after yarn
has been run (only a out/
)
Anyway... :weary:
I wonder why we have no other reports of Auto Attach failing on linux...
I've even installed "zsh" but still I cannot reproduce the problem:
Interesting: when launching VS Code from the command line (instead of from the dock), I do not have the VSCODE_PID env var:
But Auto Attach still works!
Are you using a special version of the "/bin/ps" command?
Auto Attach relies on this command /bin/ps -ax -o pid,ppid,comm:20,command
.
And the output should like this:
I noticed the exact same thing about VSCODE_PID
: when opened from the command-line, vscode won't have it; when opened from the (ubuntu) dock, it is set!
About /bin/ps
, here is what it looks like when I launch a debug with break-right-now:
> /bin/ps --version
ps from procps-ng 3.3.12
> /bin/ps -ax -o pid,ppid,comm:20,command | grep 'node '
10928 7978 node node --inspect-brk hello.js
10944 5167 grep grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn node
Here is a screencast of me trying to figure things out (I use the Peek app for Linux):
I'm also experiencing this issue, process.env['VSCODE_PID']
is not set in my VS code and auto-attach doesn't work.
➜ ~ hostnamectl
Machine ID: 1754e7222fb841289f9bb39e61a8e6cc
Boot ID: 7c06867a3a5147a5958220e2ef09a5ac
Operating System: Ubuntu 18.04.1 LTS
Kernel: Linux 4.15.0-43-generic
Architecture: x86-64
➜ ~ code --version
1.30.2
61122f88f0bf01e2ac16bdb9e1bc4571755f5bd8
x64
The same on macOS
❯ code --version
1.35.1
c7d83e57cd18f18026a8162d042843bda1bcf21f
x64
❯ archey -o
Distro: OS X 10.14.5
Kernel: Darwin
Shell: /usr/local/bin/zsh
Terminal: screen vscode
We are currently working on a new version of the JavaScript (node.js) debug extension.
It will implement the "Auto attach" feature with a new approach not relying on VSCODE_PID
.
Please give it a try.
For details see https://code.visualstudio.com/updates/v1_43#_new-javascript-debugger
Issue Type: Bug
I was investigating the Auto Attach feature not working on my Ubuntu box. I noticed that VSCODE_PID was used:
https://github.com/Microsoft/vscode/blob/bc24f98b5f70467bc689abf41cc5550ca637088e/extensions/debug-auto-launch/src/extension.ts#L120-L128
If I understand correctly, the
extension.node-debug.startAutoAttach
is created there:https://github.com/Microsoft/vscode-node-debug/blob/dd8fca03672e05eca5d1e8e36f99c3a7f835459d/src/node/extension/autoAttach.ts#L57-L67
Thing is I don't think
VSCODE_PID
is set on Linux (not set in integrated terminal shells; in dev toolsprocess.env.VSCODE_PID
doesn't exist). TherootPid
given is set by default to 0.Sorry for not having investigating further. 🙄 I'll try to clone vscode and debug from there.
cc @weinand
VS Code version: Code 1.29.1 (bc24f98b5f70467bc689abf41cc5550ca637088e, 2018-11-15T19:07:43.495Z) OS version: Linux x64 4.15.0-39-generic
System Info
|Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz (4 x 3392)| |GPU Status|2d_canvas: enabledchecker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
video_decode: unavailable_software
video_encode: unavailable_software
webgl: enabled
webgl2: enabled| |Load (avg)|1, 1, 1| |Memory (System)|7.77GB (0.89GB free)| |Process Argv|--proxy-server=localhost:3128 .| |Screen Reader|no| |VM|100%|
Extensions (27)
Extension|Author (truncated)|Version ---|---|--- project-manager|ale|9.1.0 insertnumbers|Asu|0.9.1 vscode-gpm|axe|1.0.0 solargraph|cas|0.17.6 npm-intellisense|chr|1.3.0 vscode-markdownlint|Dav|0.21.0 xml|Dot|2.3.2 EditorConfig|Edi|0.12.5 tslint|eg2|1.0.40 vscode-npm-script|eg2|0.3.5 prettier-vscode|esb|1.7.2 shell-format|fox|1.1.3 randomeverything|hel|0.0.3 Go|ms-|0.7.0 vscode-jest|Ort|2.9.2 vscode-docker|Pet|0.4.0 ruby|reb|0.20.0 java|red|0.34.0 rewrap|stk|1.9.1 shellcheck|tim|0.6.0 vscode-input-sequence|tom|0.2.0 vscode-java-debug|vsc|0.15.0 vscode-java-pack|vsc|0.4.0 vscode-java-test|vsc|0.10.0 vscode-maven|vsc|0.11.1 change-case|wma|1.0.0 markdown-all-in-one|yzh|1.7.0