In Gdb, how to set a conditional breakpoint on a 3rd line function

How to set a conditional breakpoint on the 3rd line function in GDB?

I know that I can specify the file name + line number, but this does not work for me.
I need to save the gdb commands as a script in order to repeat it later, and I do not want to change the script every time the source file changes.

+3
source share
2 answers

How to define your own command file for gdb and then just find it during debugging? This would help reduce fair typing. Try the following:

Create a file, name it mydef and here its contents:

define cmd
  b function-where-you-want-to-break
  r
  b +2
  c
end

After loading the executable into gdb, type gdb source mydefat the prompt, and thencmd

.:) , !

+3


,
,

(gdb) break <function-name>

GDB 1 0xaddr: _, linenumber.


( 1)


( )

(gdb) condition 1 <condition>

( ) next

(gdb) next
(gdb) next

.. 3- !

UPDATE:

, , , :

(gdb) watch variable==value

:
- GDB:
- GDB

+3

Source: https://habr.com/ru/post/1749369/


All Articles