'VScode debugger is not stopping at breakpoint when executing aliased names for node scripts
When I launch a script using
node examples/js/cli alias1 arg2in the VSCode terminal, my debugger stops at breakpoints that I have set in VSCodeI have some aliases that I have defined in my
~/.zshrcwhich look like
alias alias1="node /path/to/examples/js/cli alias1 arg2"
alias alias2="node /path/to/examples/js/cli alias2 arg2"
- When I run
alias1 arg1, the program runs, but the VSCode debugger does not stop at the breakpoints I have set
How can I get the VSCode debugger to stop at the breakpoints I have set when using my aliases?
My launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/examples/js/cli.js"
}
]
}
Solution 1:[1]
Disclaimer: This is not a solution, this is just me trying to answer the question the best I can because it tickled my curiosity and I found it very interesting. The following are facts, and the reasons why it is not working are just my assumptions.
What are breakpoints, and how do they work?
I'm sure you know about debuggers since you already use one, or at least, how they work globally, on the surface.
I won't go into details about software and hardware breakpoints, how do they work in details etc. since others already have and in a way better manner that I could ever achieve.
However, in short, breakpoints (debuggers, in fact, breakpoints are just a functionality of a debugger) rely on code injection in order to work.
The INT 3 instruction, as its name implies, interrupts the execution of the program where it has been injected.
We now know that breakpoints, in our case, will be injected in our code so that Node, our interpreter, will transform that to an INT 3 instruction that can be caught by our debugger.
Aliases on shells
Aliases are usually just strings to, well, alias, a long command line.
Normally, according to Bash manual (and I believe that's the case for other shells), all aliases are replaced before executing any of the compound command-line:
Bash always reads at least one complete line of input, and all lines that make up a compound command, before executing any of the commands on that line or the compound command. Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read
I cannot guarantee that this is the case with zsh though, since they are not as extensive regarding how it works in the background.
So, under normal circumstances, nothing should impair the injection.
VSCode and its terminal
Now, you mentioned launching these under the VSCode terminal. I can't tell for sure because I use JetBrains IDEs, but you must be using this feature to automatically attach the debugger to any node-related project, right?
If that's the case, my assumption is that the VSCode terminal supersedes, or enhances, the shell it is using in the background, in the sense that it is acting before zsh parses your command-line.
VSCode terminal handler parses your command-line first, acknowledges that there is no node in your command-line and so, delegates the execution to the shell its using, zsh in this case. If you work with JavaScript, think of this instance of the VSCode terminal as a middleware.
The sentence that made me think this way is the following:
If the Auto Attach feature is enabled, the Node debugger automatically attaches to certain Node.js processes that have been launched from VS Code's Integrated Terminal
... implying only NodeJS processes would be affected.
But that's only my assumption and I could be completely wrong.
Now, is there a way to solve this, keeping the same features (auto-attach, aliases)? If it works like I think it does, I'm afraid not..
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
