Cannot debug ckks_bootstrap.cpp when set -O3 to -O0

Hi,

I would like to report something weird.
I git the latest main branch.
I first set -O3 to -O0 in the global CmakeLists.txt, and then i set debug point at ckks-bootstrap.cpp at line 99, and it reports: ! Debugger was unable to disassemble function containing address 0x0000000000000000: Cannot access memory at address 0x0.

It was fine when using -Og.

@yhh You should use both flags “-O0” and “-g” in order to debug the code. “-O0” doesn’t enable debug information

Firstly, you have not specified explicitly where you set the optimization level in OpenFHE’s cmake file.
Secondly, @dsuponitskiy-duality is right, setting the optimization level to -O0 is insufficient to enable debugging.

Here is my favorite way to enable debugging through the OpenFHE code base.

  1. Change the following two lines in OpenFHE main cmake file
set(C_COMPILE_FLAGS "-Wall -Werror -O3 ${NATIVE_OPT} -DOPENFHE_VERSION=${OPENFHE_VERSION}")
set(CXX_COMPILE_FLAGS "-Wall -Werror -O3 ${NATIVE_OPT} -DOPENFHE_VERSION=${OPENFHE_VERSION} ${IGNORE_WARNINGS}")

to

set(C_COMPILE_FLAGS "-Wall -O0 ${NATIVE_OPT} -DOPENFHE_VERSION=${OPENFHE_VERSION}")
set(CXX_COMPILE_FLAGS "-Wall -O0 ${NATIVE_OPT} -DOPENFHE_VERSION=${OPENFHE_VERSION} ${IGNORE_WARNINGS}")
  1. invoke the cmake command as follows:
cd openfhe-development # assuming you already cloned OpenFHE locally
mkdir build_debug
cd build_debug
cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_OPENMP=OFF ..
make -j<num_threads>

Note that, turning OpenMP off is optional but it makes debugging multi-threaded code much easier.