2013-05-13 86 views
6

在谷歌搜索後調試,我發現下面的方法做對應用的NodeJS GDB, 構建節點在./configure時--debug選項,然後執行的NodeJS,怎麼辦使用GDB

gdb --args ~/node_g start.js 

使用這個我想調試一個小程序,但設置了斷點後,我沒能看到它是在功能突破,

我簡單的程序gdb_node.js看起來是這樣的:

function abc() { 
    console.log("In abc"); 
} 

function bcd() { 
    abc(); 
    console.log("Done abc"); 
} 

bcd(); 

現在我發放gdb:

(gdb) b bcd 
Function "bcd" not defined. 
Make breakpoint pending on future shared library load? (y or [n]) y 
Breakpoint 1 (bcd) pending. 
(gdb) run 
Starting program: /Users/mayukh/node_g gdb_node.js 
Reading symbols for shared libraries 

++++ ............................... .................................................. .................................................. ......完成

In abc 
Done abc 

Program exited normally. 
(gdb) 

有人可以讓我知道我在這裏失蹤了嗎?

問候, -M-

回答

8

gdb試圖查找bcd符號調試從C++源生成的信息。看來你真的想調試JavaScript而不是C++。

V8已建成調試,和node.js中有client用於調試protocol

要開始使用調試器客戶端的node.js連接到程序:

node debug test.js 

您可以設置使用調試器commands斷點:

sh-3.2$ node debug test.js 
< debugger listening on port 5858 
connecting... ok 
break in test.js:10 
    8 } 
    9 
10 bcd(); 
11 
12 }); 
debug> sb(6) 
    5 function bcd() { 
* 6 abc(); 
    7 console.log("Done abc"); 
    8 } 
    9 
10 bcd(); 
11 
12 }); 
debug> 

或者使用debugger關鍵字:

function abc() { 
    console.log("In abc"); 
} 

function bcd() { 
    debugger; 
    abc(); 
    console.log("Done abc"); 
} 

bcd(); 

=

sh-3.2$ node debug test.js 
< debugger listening on port 5858 
connecting... ok 
break in test.js:11 
    9 } 
10 
11 bcd(); 
12 
13 }); 
debug> c 
break in test.js:6 
    4 
    5 function bcd() { 
    6 debugger; 
    7 abc(); 
    8 console.log("Done abc"); 
debug> 

存在用於V8調試程序的GUI客戶端,以及:node-webkit-agentnode-inspectoreclipse和其他

+0

節點V8建議使用'節點inspect'代替'節點debug' – morhook 2017-11-01 13:26:34