Debugging sitl with GDB and No Optimization

Is the Compiler optimization section of the user guide still accurate?

It does accurately say that the NO_OPTIMIZATION environment variable will be ignored when the configuration isn’t posix_sitl_* because I need tried with px4_sitl and still got -O2 (see terminal output below).

How does one create a posix_sitl_* config? make list_config_targets |grep posix is empty.

dgeorge@danduril:~/projects/community-px4$ echo $PX4_NO_OPTIMIZATION
px4;^modules__uORB;^modules__vtol_att_control$
dgeorge@danduril:~/projects/community-px4$ make clean
dgeorge@danduril:~/projects/community-px4$ make px4_sitl
-- PX4 version: v1.11.0-rc3-914-g7861377e20
-- PX4 config file: /home/dgeorge/projects/community-px4/boards/px4/sitl/default.cmake
-- PX4 config: px4_sitl_default
-- PX4 platform: posix
-- PX4 lockstep: enabled
-- cmake build type: RelWithDebInfo
-- The CXX compiler identification is GNU 9.3.0
-- The C compiler identification is GNU 9.3.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Building for code coverage
-- ccache enabled (export CCACHE_DISABLE=1 to disable)
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.5", minimum required is "3")
-- build type is RelWithDebInfo
-- PX4 ECL: Very lightweight Estimation & Control Library v1.9.0-rc1-492-gdf7f261
-- ROMFS: px4fmu_common
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dgeorge/projects/community-px4/build/px4_sitl_default
[0/763] git submodule src/drivers/gps/devices
[13/763] git submodule src/lib/ecl
[14/763] git submodule mavlink/include/mavlink/v2.0
[763/763] Linking CXX shared library src/examples/dyn_hello/examples__dyn_hello.px4mod
dgeorge@danduril:~/projects/community-px4$ touch src/modules/vtol_att_control/
CMakeLists.txt             tailsitter.cpp             tiltrotor.h                vtol_att_control_params.c
standard.cpp               tailsitter.h               tiltrotor_params.c         vtol_type.cpp
standard.h                 tailsitter_params.c        vtol_att_control_main.cpp  vtol_type.h
standard_params.c          tiltrotor.cpp              vtol_att_control_main.h
dgeorge@danduril:~/projects/community-px4$ touch src/modules/vtol_att_control/vtol_att_control_main.cpp
dgeorge@danduril:~/projects/community-px4$ VERBOSE=1 make px4_sitl
[1/4] /usr/bin/ccache /usr/bin/c++  -DCONFIG_ARCH_BOARD_PX4_SITL -DENABLE_LOCKSTEP_SCHEDULER -DMODULE_NAME=\"vtol_att_control\" -DPX4_MAIN=vtol_att_control_app_main -D__CUSTOM_FILE_IO__ -D__PX4_LINUX -D__PX4_POSIX -D__STDC_FORMAT_MACROS -Dnoreturn_function="__attribute__((noreturn))" -I../../boards/px4/sitl/src -I../../platforms/posix/src/px4/common/include -I. -Isrc/lib -I../../platforms/posix/src/px4/generic/generic/include -I../../platforms/common/include -I../../src -I../../src/include -I../../src/lib -I../../src/lib/matrix -I../../src/modules -I../../platforms/posix/include -Iexternal/Install/include -O2 -g -DNDEBUG -fPIC   -g -fdata-sections -ffunction-sections -fomit-frame-pointer -fmerge-all-constants -fno-signed-zeros -fno-trapping-math -freciprocal-math -fno-math-errno -fno-strict-aliasing -fvisibility=hidden -include visibility.h -Wall -Wextra -Werror -Warray-bounds -Wcast-align -Wdisabled-optimization -Wdouble-promotion -Wfatal-errors -Wfloat-equal -Wformat-security -Winit-self -Wlogical-op -Wpointer-arith -Wshadow -Wuninitialized -Wunknown-pragmas -Wunused-variable -Wno-missing-field-initializers -Wno-missing-include-dirs -Wno-unused-parameter -fdiagnostics-color=always -fno-builtin-printf -fno-strength-reduce -Wformat=1 -Wunused-but-set-variable -Wno-format-truncation -fcheck-new -fno-exceptions -fno-rtti -fno-threadsafe-statics -Wreorder -Wno-overloaded-virtual -std=gnu++14 -MD -MT src/modules/vtol_att_control/CMakeFiles/modules__vtol_att_control.dir/vtol_att_control_main.cpp.o -MF src/modules/vtol_att_control/CMakeFiles/modules__vtol_att_control.dir/vtol_att_control_main.cpp.o.d -o src/modules/vtol_att_control/CMakeFiles/modules__vtol_att_control.dir/vtol_att_control_main.cpp.o -c ../../src/modules/vtol_att_control/vtol_att_control_main.cpp

Although I was unable to use the instructions in the user guide, I was able to use gdb on the px4_sitl after updating CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG, in platforms/posix/CMakeLists.txt, where CMAKE_RUNTIME_OUTPUT_DIRECTORY already gets updated. Now, PX4_CMAKE_BUILD_TYPE=Debug make px4_sitl creates a debug-able system.

Update: See PR16446 for fix to platforms/posix/CMakeLists.txt.