Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB: Breakpoint that breaks only after a different breakpoint is hit

Tags:

gdb

Say I create two breakpoints, 2 and 3. Breakpoint 3 is on line 10, which is executed frequently through the program. How can I configure 3 to break only after 2 has been hit once?

like image 956
user1299784 Avatar asked May 02 '16 06:05

user1299784


People also ask

How do I break a specific line in GDB?

Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.

How do I delete a specific breakpoint in GDB?

With the clear command you can delete breakpoints according to where they are in your program. With the delete command you can delete individual breakpoints, watchpoints, or catchpoints by specifying their breakpoint numbers.

What is watchpoint in GDB?

You can use a watchpoint to stop execution whenever the value of an expression changes, without having to predict a particular place where this may happen. Depending on your system, watchpoints may be implemented in software or hardware.

Why is GDB not stopping at breakpoint?

GDB normally ignores breakpoints when it resumes execution, until at least one instruction has been executed. If it did not do this, you would be unable to proceed past a breakpoint without first disabling the breakpoint. This rule applies whether or not the breakpoint already existed when your program stopped.


1 Answers

with a simple example:

void bp2() { };
void bp1() { bp2(); }

int main()
{
  bp2();
  bp1();
  return 0;
}

we can create a breakpoint which only triggers when bp2 is called through bp1 with something like the following:

break bp1
break bp2

commands 1
silent
enable 2
c
end

commands 2
disable 2
end

disable 2
like image 88
matt Avatar answered Sep 26 '22 07:09

matt