c++ - Is there any way to set a breakpoint in gdb that is conditional on the call stack? -


I want to debug C ++ in Linux on GDB 7.1.

I have a function called a () in many places in the code. I want to set a breakpoint in it, but only if it was told to b () is there any way to do this?

Is there any way to do this if the b () is called from c () , and there is nothing about advertising ?

You often need to describe the need, typically Some_utility_fn is very It is said, but you are only interested in the call that comes from some_other_fn .

It's possible that you may have the new embedded Python support from CDS trunk in GDB.

Without Python, what you can do is limited, but breakpoints a () on normal technology disabled Enabled by command, is connected to a breakpoint at b () .

Here's an example:

  int A (int x) {return x + 1; } Int b () {back one (1); } Int call_a_lots () {int i, sum = 0; For (i = 0; i <100; i ++) Yoga + = A (i); } Int main () {call_a_lots (); Return b (); } Reading symbols from GCC-GTC GDB-C ./a.out/tmp/a.out..done (GDB) break a breakpoint 1 on 0x4004cb: Disable the file TC, Line 3 (GDB) Break 1 (GDB) Breakpoint 2 0x4004 on D7: File TC, Line 8. (GDB) Command2> Silent & gt; 1 Enable & gt; Continue; End (GDB), Breakpoint 1, A (X = 1) TC: 3 Returns 3 Returns X + 1; TC: 8 # 2 0x000000000040052 T In C: 21 (GDB) Q   

Voila: (GDB) BT # 0A (X = 1) TC: 3 # 1 0x000000004004e1b () We have called a () with b () , ignored the previous 100 calls for <100> a () is.

Comments