Conditionalizing Command Execution

if command

The debugger provides the if command , whose behavior depends on the value of an expression.

 

if_command

: if expression braced_command_list [ else_clause ]

else_clause

:else braced_command_list

 

In this command, the first braced_command_list is executed if expression evaluates to a non-zero value; otherwise, the braced_command_list in the else_clause is executed, if specified.

For example:

 

(idb) set $c = 1

(idb) assign pid = 0

(idb) if (pid < $c) { print "Greater" } else { print "Lesser" }

Greater

while command

In addition to the if command, the debugger also provides the while command.

 

while_command

: while expression braced_command_list

 

The commands in the braced_command_list will execute as long as expression evaluates to a non-zero value.

For example:

 

(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):167 0x0804c632]

    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):167 0x0804c632]

    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):167 0x0804c632]

    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):167 0x0804c632]

    167         cout << "Node " << i ;

currentNode->_data is  3

Node 4 type is integer, value is 3

[1] stopped at [void List<Node>::print(void):167 0x0804c632]

    167         cout << "Node " << i ;

currentNode->_data is  4

Node 5 type is integer, value is 4

[1] stopped at [void List<Node>::print(void):167 0x0804c632]

    167         cout << "Node " << i ;

(idb)

(idb) print currentNode->_data

5

 

In this example we use the while command to continue the execution of the debuggee until the _data field in currentNode is 5.

Note that if the commands in the braced_command_list do not change the state of the debuggee process, such as the value of a variable or the PC register, then the while command can go into an infinite loop. In this case, press Ctrl+C to interrupt the loop, or type 'n' when you see the "More (n if no)?" prompt if your while command generates output and the paging is turned on.