コマンド実行の条件付け

コマンド実行の条件を指定するには、if [else] コマンドおよび while コマンドを使用します。

次の例は、if コマンドの使用方法を示しています。

(idb) set $c = 1
(idb) assign pid = 0
(idb) if (pid < $c) { print "Greater" } else { print "Lesser" }
Greater

次の例は、while コマンドを使用して、currentNode_data フィールドが 5 になるまでデバッグ対象の実行を続けます。

波括弧 ({}) で囲まれたコマンドリスト中のコマンドが、変数や PC レジスターの値など、デバッグ対象処理の状態を変更しない場合、while コマンドは無限大ループとなります。この場合、Ctrl+C キーを押してループを中断できます。while コマンドが出力を生成し、ページングが有効な場合は、続行しますか (no の場合 n)? というメッセージが表示されたときに、n と入力して中断することもできます。

(idb) stop at 167
[#1: stop at "src/x_list.cxx":167]
(idb) run
The list is:
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
    167         cout << "Node " << i ;
(idb)
(idb) while (currentNode->_data != 5) { print "currentNode->_data is ", currentNode->_data; cont }
currentNode->_data is  1
Node 1 type is integer, value is 1
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
    167         cout << "Node " << i ;
currentNode->_data is  2
Node 2 type is compound, value is 12.345
       parent  type is integer, value is 2
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
    167         cout << "Node " << i ;
currentNode->_data is  7
Node 3 type is compound, value is 3.1415
       parent  type is integer, value is 7
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
    167         cout << "Node " << i ;
currentNode->_data is  3
Node 4 type is integer, value is 3
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
    167         cout << "Node " << i ;
currentNode->_data is  4
Node 5 type is integer, value is 4
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
    167         cout << "Node " << i ;
(idb)
(idb) print currentNode->_data
5

関連情報


このヘルプトピックについてのフィードバックを送信