cassepipe
cassepipe

Reputation: 653

lldb : Step out of loop?

I have looked around but I can't seem to find that information anywhere so I guess this is not possible but I would like to be sure.

Is there a way to break out of a loop when using lldb ?

(And if not why has it not been implemented ?)

Upvotes: 1

Views: 1984

Answers (2)

Aleynikov Mikhail
Aleynikov Mikhail

Reputation: 11

If you know line, where loop ends, you can step out of loop with thread until <line>.

This is the same as setting temporary breakpoint in <line> but only one time.

Upvotes: 1

Jim Ingham
Jim Ingham

Reputation: 27118

Debug information doesn't encode source constructs like loops, if branches, etc. That's been true of all the debug formats I've had to do with. So there's really no way that lldb could implement step out of loop - it has no way to know that loops are a thing.

The cleanest way to do this, when it's possible, is to set whatever condition the loop is checking to the "stop looping" value. Then set a breakpoint outside the loop and continue and the iteration you are in will be the last iteration.

You can also use the thread jump command to move the PC out of the loop, continuing from that point. Be very careful using this, however, as it's easy skip over some code you probably should have run. For instance if there were objects scoped to the loop, they won't get destroyed if you jump the PC to some line outside the loop.

Upvotes: 3

Related Questions