Mister Tusk
Mister Tusk

Reputation: 325

Run a while() function n times in gdb

How would I go about running a while loop in C to say N number of times? For example, I reach this function and then I want to run the while() block 5 times.

// while there are customers
while (customers_length)
{
        // check if there are customers waiting
        if (index == initial_customers_length)
                customers_are_waiting = 0;

        // increment one hour
        sum++;

        // for every cashier subtract one hour
        for (i = 0; i < n; i++)
        {
                cashiers[i].how_many_hours--;
                // if cashier has no customers and no customers waiting reset to 0;
                if (cashiers[i].how_many_hours < 0)
                        cashiers[i].how_many_hours = 0;
        }

        // if a cashier is free and there are no customers waiting, allocate next customer
        for (i = 0; i < n; i++)
        {
                if (!cashiers[i].how_many_hours && customers_are_waiting)
                {
                        cashiers[i].how_many_hours = customers[index];
                        customers_length--;
                        // queue next customer in line
                        index++;
                }
                if (!cashiers[i].how_many_hours)
                        customers_length--;
        }
}

What's the command for that in gdb?

Upvotes: 2

Views: 157

Answers (1)

Employed Russian
Employed Russian

Reputation: 213799

I want to run the while() block 5 times.

Set a break point on the first if statement inside the loop. Then use ignore $bpnum 5 and continue.

GDB will stop on the if statement breakpoint on 6th iteration through the loop.

Upvotes: 1

Related Questions