Conditionalizing Command Execution

To conditionalize command execution, use the if [else] and while commands.

The following example demonstrates using the if command.

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

The following example demonstrates using the while command to continue the execution of the debuggee until the _data field in currentNode is 5.

Notice 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 enter n when you see the More (n if no)? prompt if your while command generates output and the paging is turned on.

(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

See Also


Submit feedback on this help topic

Copyright © 2001-2011, Intel Corporation. All rights reserved.