When you have finished examining the current state of the process, you can move the process forward and see what happens. The following table shows the aliases and commands you can use to do this.
Desired Behavior |
Command |
Alias |
Can Take Repeat Cont |
---|---|---|---|
Continue until another interesting thing happens | cont | c | Yes* |
Single step by line, but step over calls | next | n | Yes |
Single step to a new line, stepping into calls | step | s | Yes |
Continue until control returns to the caller | return (dbx), finish (gdb) | None | No |
Single step by instruction, over calls | nexti | ni | Yes |
Single step by instruction, into calls | stepi | si | Yes |
* For the cont command, in GDB mode repeat count specifies the number of times to ignore a breakpoint. For the other commands repeat count has the same meaning in both modes.
The following examples demonstrate stepping through lines of source code (dbx) (gdb) and stepping at the instruction level (dbx) (gdb).
Stepping through lines of source code:
(idb) list $curline - 10:20
172
173 if (i == 1) cout << "The list is empty ";
174 cout << endl << endl;
175 }
176
177
178 // The driver for this test
179 //
180 main()
181 {
> 182 List<Node> nodeList;
183
184 // add entries to list
185 //
186 IntNode* newNode = new IntNode(1);
187 nodeList.append(newNode); {static int somethingToReturnTo; somethingToReturnTo++; }
188
189 CompoundNode* cNode = new CompoundNode(12.345, 2);
190 nodeList.append(cNode); {static int somethingToReturnTo; somethingToReturnTo++; }
191
(idb) next
stopped at [int main(void):186 0x08052ea1]
186 IntNode* newNode = new IntNode(1);
(idb) next 3
stopped at [int main(void):190 0x0805301a]
190 nodeList.append(cNode); {static int somethingToReturnTo; somethingToReturnTo++; }
(idb) step
stopped at [void List<Node>::append(class Node* const):148 0x0804c5de]
148 if (!_firstNode)
(idb) list $curline - 2:6
146 {
147
> 148 if (!_firstNode)
149 _firstNode = node;
150 else {
151 Node* currentNode = _firstNode;
(idb) next
stopped at [void List<Node>::append(class Node* const):151 0x0804c5f1]
151 Node* currentNode = _firstNode;
(idb) list $curline - 2:5
149 _firstNode = node;
150 else {
> 151 Node* currentNode = _firstNode;
152 while (currentNode->getNextNode())
153 currentNode = currentNode->getNextNode();
(idb) return
stopped at [int main(void):190 0x08053032]
190 nodeList.append(cNode); {static int somethingToReturnTo; somethingToReturnTo++; }
(idb) next 2
stopped at [int main(void):193 0x080530ed]
193 nodeList.append(cNode1); {static int somethingToReturnTo; somethingToReturnTo++; }
Stepping at the instruction level:
(idb) $pc/2i
int main(void): src/x_list.cxx
*[line 193, 0x08053100] main+0x28c: call append(class Node* const)
[line 193, 0x08053105] main+0x291: addl $0x8, %esp
(idb) nexti
stopped at [int main(void):193 0x08053105] main+0x291: addl $0x8, %esp
(idb) $pc/1i
int main(void): src/x_list.cxx
*[line 193, 0x08053105] main+0x291: addl $0x8, %esp
(idb) rerun
Process has exited
[3] stopped at [int main(void):193 0x08053100]
193 nodeList.append(cNode1); {static int somethingToReturnTo; somethingToReturnTo++; }
(idb) $pc/2i
int main(void): src/x_list.cxx
*[line 193, 0x08053100] main+0x28c: call append(class Node* const)
[line 193, 0x08053105] main+0x291: addl $0x8, %esp
(idb) stepi
stopped at [void List<Node>::append(class Node* const):146 0x0804c5d8] append(class Node* const): pushl %ebp
(idb) $pc/1i
void List<Node>::append(class Node* const): src/x_list.cxx
*[line 146, 0x0804c5d8] append(class Node* const): pushl %ebp
Stepping through lines of source code:
(idb) list
172
173 if (i == 1) cout << "The list is empty ";
174 cout << endl << endl;
175 }
176
177
178 // The driver for this test
179 //
180 main()
181 {
182 List<Node> nodeList;
183
184 // add entries to list
185 //
186 IntNode* newNode = new IntNode(1);
187 nodeList.append(newNode); {static int somethingToReturnTo; somethingToReturnTo++; }
188
189 CompoundNode* cNode = new CompoundNode(12.345, 2);
190 nodeList.append(cNode); {static int somethingToReturnTo; somethingToReturnTo++; }
191
(idb) next
186 IntNode* newNode = new IntNode(1);
(idb) next 3
190 nodeList.append(cNode); {static int somethingToReturnTo; somethingToReturnTo++; }
(idb) step
List<Node>::append (node=(Node *) 0x805e610) at src/x_list.cxx:148
148 if (!_firstNode)
(idb) list -2,+6
146 {
147
148 if (!_firstNode)
149 _firstNode = node;
150 else {
151 Node* currentNode = _firstNode;
(idb) step
151 Node* currentNode = _firstNode;
(idb) list -2,+5
149 _firstNode = node;
150 else {
151 Node* currentNode = _firstNode;
152 while (currentNode->getNextNode())
153 currentNode = currentNode->getNextNode();
(idb) finish
main () at src/x_list.cxx:190
190 nodeList.append(cNode); {static int somethingToReturnTo; somethingToReturnTo++; }
(idb) next 2
193 nodeList.append(cNode1); {static int somethingToReturnTo; somethingToReturnTo++; }
Stepping at the instruction level:
(idb) x /2i $pc
0x0804c5d8 <append>: pushl %ebp
0x0804c5d9 <append+1>: movl %esp, %ebp
(idb) nexti
146 {
(idb) x /1i $pc
0x0804c5d9 <append+1>: movl %esp, %ebp
(idb) run
Program exited normally.
Starting program: /home/user/examples/x_list
Breakpoint 3, main () at src/x_list.cxx:193
193 nodeList.append(cNode1); {static int somethingToReturnTo; somethingToReturnTo++; }
(idb) x /2i $pc
0x08053100 <main+652>: call 0x0804c5d8 <append>
0x08053105 <main+657>: addl $0x8, %esp
(idb) stepi
List<Node>::append (node=(Node *) 0xbfffc864) at src/x_list.cxx:146
146 {
(idb) x /1i $pc
0x0804c5d8 <append>: pushl %ebp