vscode Nodejs 調試 相關總結


 Launch

和 attach的區別

 

 

Launch的話是直接以debug模式運行一個js文件,遇到debugger后會停止

 

 

 

 

Attach需要先開啟一個運行在調試模式開啟了debug端口的nodejs項目

 

 

資料:

https://code.visualstudio.com/docs/nodejs/nodejs-debugging

 

 

 

 

Debugger是如何工作的:

 

有系統調用叫ptrace,可以用一個進程去監視控制另一個進程的執行,甚至讓他暫停。獲取另一個進程執行的調用棧.. 然后就可以構造出一個debugger。

https://www.cnblogs.com/moonz-wu/archive/2012/01/15/2322120.html

https://i5ting.github.io/node-debug-tutorial/

https://stackoverflow.com/questions/42563900/how-does-the-visual-studio-attach-to-process-work

 

 

 

 

 

根據nodejs文檔描述,

Node.js includes an out-of-process debugging utility accessible via a V8Inspector and built-in debugging client. To use it, start Node.js with the inspect argument followed by the path to the script to debug; a prompt will be displayed indicating successful launch of the debugger:

 

nodejs集成了V8 inspector(可以和Chrome devltools protocol的debug客戶端來交互)

還內置了一個內建debug客戶端。

 

 

1.Nodejs內置了一個簡易的debugger客戶端 

使用node inspect xxx.js 開始進行調試

 

2.如果想使用功能更全的debugger客戶端

先使用—inspect標記 開啟V8 inspector,

此時就可以和一個實現了Chrome DevTools Protocol的debugger客戶端來交互

(例如VsCode中的 attach 調試方式)

或直接打開的Chrome瀏覽器客戶端

 

 

 

資料:

1.https://nodejs.org/en/docs/guides/debugging-getting-started/

Enable Inspector

When started with the --inspect switch, a Node.js process listens for a debugging client. By default, it will listen at host and port 127.0.0.1:9229. Each process is also assigned a unique UUID.

Inspector clients must know and specify host address, port, and UUID to connect. A full URL will look something like ws://127.0.0.1:9229/0f2c936f-b1cd-4ac9-aab3-f63b0f33d55e.

Node.js will also start listening for debugging messages if it receives a SIGUSR1 signal. (SIGUSR1 is not available on Windows.) In Node.js 7 and earlier, this activates the legacy Debugger API. In Node.js 8 and later, it will activate the Inspector API.

2.https://nodejs.org/api/debugger.html

3.https://juejin.im/post/5e042967e51d45584d239e86 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM