Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gdb - difference beween step and next

10,624 views
Skip to first unread message

Basil El Masri

unread,
Aug 6, 2010, 12:18:06 AM8/6/10
to
Hello,

I'm not sure about the difference between next and step in gdb.
According to the notes, next will skip over routine calls to the
following cals, but step will step into the routine call. However, in
the notes, unless I'm misunderstanding the examples, they both go into
the routine anyways. So what's the differecne?

Thanks in advance.

Basil.

Caroline Kierstead

unread,
Aug 6, 2010, 10:11:11 AM8/6/10
to
In article <ce185887-ad79-4c49...@l20g2000yqm.googlegroups.com>,

next actually executes the entire routine, while step would move you to
the first executable line of the routine. So, if you had code like:

void foo() {
for ( int i = 0; i < v.size(); i++ ) {
...
}
}

int main() {
foo();
}

and were on the line in main() that invokes foo(), next would move you to
the next line (in this case, the closing brace of main()), while step would
put you on the for-loop in foo().

You could try it and see...
--
--
Caroline Kierstead, Undergraduate Operations Coordinator
David R. Cheriton School of Computer Science
University of Waterloo, DC3122 (519) 888-4567 x36226

Basil El Masri

unread,
Aug 6, 2010, 10:38:23 AM8/6/10
to
On Aug 6, 10:11 am, ctkie...@cpu102.cs.uwaterloo.ca (Caroline
Kierstead) wrote:
> In article <ce185887-ad79-4c49-b1ae-c0b72db36...@l20g2000yqm.googlegroups.com>,

Maybe I'm misunderstanding you, but it seems your example contradicts
the first thing you said.

At the top, you said next does the entire routine while step does the
first line, then at bottom you say
next would pass the routine call but step would go into it. Please
clarify. Thanks.

Justin Harris

unread,
Aug 6, 2010, 12:17:41 PM8/6/10
to
next executes the routine but you don't get to see the details of the
execution, you only see the next result. You can think of next as going
to the next line.
However on a line like foo(bar(set() ) ) this wont exactly be the case.

Caroline Kierstead

unread,
Aug 7, 2010, 10:09:18 AM8/7/10
to
In article <b08fd4c1-d588-47fc...@t2g2000yqe.googlegroups.com>,

Basil El Masri <basil...@gmail.com> wrote:
>> next actually executes the entire routine, while step would move you to
>> the first executable line of the routine. So, if you had code like:
>>
>> void foo() {
>> for ( int i = 0; i < v.size(); i++ ) {
>> ...
>> }
>>
>> }
>>
>> int main() {
>> foo();
>>
>> }
>>
>> and were on the line in main() that invokes foo(), next would move you to
>> the next line (in this case, the closing brace of main()), while step would
>> put you on the for-loop in foo().
>>
>> You could try it and see...
>Maybe I'm misunderstanding you, but it seems your example contradicts
>the first thing you said.
>
>At the top, you said next does the entire routine while step does the
>first line, then at bottom you say
>next would pass the routine call but step would go into it. Please
>clarify. Thanks.

If you had a breakpoint on the call to foo() in main(), next would run
foo() to completion and put you at the subsequence statement, which is the
closing brace to main. step, on the other hand, would have put you on
the for-loop in foo(). Could have been worded more clearly, I guess.

0 new messages