thesofproject / sof

Sound Open Firmware
Other
561 stars 318 forks source link

[BUG]Testbench build for debug does not produce debug friendly code #1835

Open singalsu opened 5 years ago

singalsu commented 5 years ago

Is your feature request related to a problem? Please describe. The cmake build of testbench does not generate an executable without optimization. When run in debugger (gdb + graphical front end) the optimized executable has variables optimized out and code stepping is not linear. The hand editing of makefiles manually to remove code optimization is cumbersome due to complexity of cmake generates makefiles.

Describe the solution you'd like When running command "cmake -DCMAKE_BUILD_TYPE=Debug .." there should be no -O3 optimizations left anywhere in makefiles (testbench, pipeline & components code). Just "-O" might be sufficient but to be safe just leave "-g".

Describe alternatives you've considered No alternates besides hand editing of makefiles.

Additional context N/A

singalsu commented 3 years ago

This is tricky, need a cmake expert here.

ShriramShastry commented 3 years ago

Tested with below command for all -O3 replacement in all files

grep -rl "-O3" . | xargs sed -i 's/-O3/-O/g'

Tested with below command for all -O3 replacement for CMakeLists.txt files

find . -name "CMakeLists.txt" | xargs grep -rl "-O3" | xargs sed -i 's/-O3/-O/g'

Note : Editor is NOT accepting/displaying the escape character \ please add \ before-O3 and -O

lgirdwood commented 3 years ago

@juimonen can you help here, cmake support conditional logic so you can pass in -DEBUG or similar on the cmd line to select different CFLAGS.

marc-hb commented 2 years ago

This happens simply because we have -O3 hardcoded in various CMakeLists.txt files, for the testbench this was done in commit 56228b0221dc. The first step is this, try it and see what happens:

--- a/tools/testbench/CMakeLists.txt
+++ b/tools/testbench/CMakeLists.txt
@@ -30,7 +30,7 @@ target_include_directories(testbench PRIVATE
 )
 endif()

-target_compile_options(testbench PRIVATE -g -O3 -Wall -Werror -Wl,-EL -Wmissing-prototypes
+target_compile_options(testbench PRIVATE -g -Wall -Werror -Wl,-EL -Wmissing-prototypes
   -Wimplicit-fallthrough -DCONFIG_LIBRARY -imacros${config_h})

 target_link_libraries(testbench PRIVATE -ldl -lm)

@ShriramShastry : https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax

marc-hb commented 2 years ago

To see which flags are used without being flooded by the build logs:

$ touch tools/testbench/testbench.c 
make -C tools/testbench/build_testbench/ testbench.o VERBOSE=1
marc-hb commented 2 years ago

PS: debugging -O code is madness. Don't do it. Ever.

marc-hb commented 2 years ago

Also try this:

$ grep OPT tools/testbench/build_testbench/sof_ep/build/generated/.config 
CONFIG_OPTIMIZE_FOR_PERFORMANCE=y
# CONFIG_OPTIMIZE_FOR_SIZE is not set
# CONFIG_OPTIMIZE_FOR_DEBUG is not set
# CONFIG_OPTIMIZE_FOR_NONE is not set

$ make -C tools/testbench/build_testbench/sof_ep/build/ menuconfig
lgirdwood commented 2 years ago

@marc-hb are you able to take care of a global -g and -pg setting for building all code. The latter is for building on host. I'm assuming this would be done in Zephyr Kconfig ?

lgirdwood commented 2 years ago

@marc-hb are you able to take care of a global -g and -pg setting for building all code. The latter is for building on host. I'm assuming this would be done in Zephyr Kconfig ?

Sorry, reason I ask as its not propagated through all tools/code and I've no idea if we inherit from Zephyr.

marc-hb commented 2 years ago

@lgirdwood this feels like significant CMake surgery and I have no idea how long it would take, sorry. My untested, testbench-specific advice above was just off the top of my head and after looking at it for 5 minutes.

lgirdwood commented 2 years ago

@marc-hb ok, how about if we make it consistent when we invoke cmake or make e.g. make DEBUG=1 just something quick and easy for the tools developers.