Setting up gdb (breakpoint at wrong line)


I’m trying to walk through the codebase step by step using gdb. However I’m having some troubles…
I can’t put breakpoints in every line… many times when I put in some line It puts in the last line, where the return of the main function is.

I thinks that this is for some optimization or something when I compile, but I can’t figure it out.

Things I did:

  • I compile OpenFHE using cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_OPENMP=OFF ...
  • I copy the CMakeList.User.txt from there to my project directory.
  • I add only one file like the example add_executable( enc encrypt.cpp )
  • In that directory i make cmake -DCMAKE_BUILD_TYPE=Debug . (i don’t know it this flags is needed but I try with and without it)
  1. gdb encrypt.cpp
  2. file enc
  3. Example b 20
  4. Output: Breakpoint 1 at hexa..: filepath/encrypt.cpp, line 28.......

What I’m missing?

PD: Maybe it has no sense but I also try adding this to the CMakeList.txt


Hi, from Debugging Options (Using the GNU Compiler Collection (GCC))
" If you are not using some other optimization option, consider using -Og (see Options That Control Optimization) with -g. With no -O option at all, some compiler passes that collect information useful for debugging do not run at all, so that -Og may result in a better debugging experience."

You are setting the right debug flag.
I debug using gdb not gdb
and if there are command line parameters,I run like this:

gdb --args executablename arg1 arg2 arg3 ETC.... 

and that works for me. if you have problems finding the openfhe sources you may need to google that specifically but if the shared libraries were compiled with -g support that info should be available.