在gdb中运行while()函数n次
我如何在C中运行while循环,比如说N次? 例如,我到达这个函数,然后我想运行while()块5次在gdb中运行while()函数n次,gdb,Gdb,我如何在C中运行while循环,比如说N次? 例如,我到达这个函数,然后我想运行while()块5次 // while there are customers while (customers_length) { // check if there are customers waiting if (index == initial_customers_length) customers_are_waiting = 0;
// 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--;
}
}
//有客户时
while(客户长度)
{
//检查是否有客户在等待
if(索引==初始长度)
客户正在等待=0;
//增加一小时
sum++;
//每个出纳减去一小时
对于(i=0;i
gdb中的命令是什么
我想运行while()块5次
// 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--;
}
}
在循环中的第一个if
语句上设置断点。然后使用ignore$bpnum 5
和continue
在循环的第6次迭代中,GDB将在if
语句断点处停止
我想运行while()块5次
// 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--;
}
}
在循环中的第一个if
语句上设置断点。然后使用ignore$bpnum 5
和continue
GDB将在循环的第6次迭代中在
if
语句断点处停止。@MisterTusk您应该用刚刚创建的断点编号替换$bp\u number
。@看起来上次设置的断点编号可以作为$bpnum
方便变量使用。我已经更新了答案。@MisterTusk您应该用刚才创建的断点编号替换$bp\u number
。@看起来上次设置的断点编号可以作为$bpnum
方便变量使用。我已经更新了答案。