10

Googleで検索した後、nodejsアプリケーションでgdbを実行し、./configure --debugオプションでノードを構築してから実行する以下の方法を見つけました

  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-

4

2 に答える 2

14

gdbbcdC++ ソースから生成されたデバッグ情報でシンボルを検索しようとします。実際には、c++ ではなく JavaScript をデバッグしたいようです。

V8にはデバッガーが組み込まれており、node.jsにはデバッガープロトコル用のクライアントがあります

プログラムにアタッチされたデバッガークライアントで node.js を開始するには:

node inspect test.js

デバッガーコマンドを使用してブレークポイントを設定できます。

sh-3.2$ node inspect 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 inspect 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など

于 2013-05-13T12:50:17.727 に答える