Stack overflow when adding CONFIG_DEBUG_OPTIMIZATIONS and CONFIG_DEBUG_THREAD_INFO to prj.conf

I am using a nRF5340 DK with nRF Connect for VS Code, and wanted to debug a problem so I enabled debugging with:

CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_DEBUG_THREAD_INFO=y

Now I'm getting Stack Overflow errors. I was following this video on nRF Connect for VS Code, part 5: Debugging

  • Hi Leo, 

    You receive stack overflow most likely because when you do CONFIG_DEBUG_OPTIMIZATIONS and CONFIG_DEBUG_THREAD_INFO the memory optimization was turned off to allow debugging. 
    When memory optimization turned off there is a risk that the stack configuration you have is not sufficient for the operation. You would need to increase stack sizes. 
    To know which stack causing the problem you can set CONFIG_THREAD_NAME=y, the stack overflow error message should show the thread that causing the problem that can give you an idea on which stack need to be increased. 

    You can also enable Thread Analyzer to know which thread has higher usage and higher chance of being overflow. You can find how it should be used by looking at the tip from prj_minimal.conf in peripheral_lbs project: 

    # In order to correctly tune the stack sizes for the threads the following
    # Configurations can enabled to print the current use:
    # CONFIG_THREAD_NAME=y
    # CONFIG_THREAD_ANALYZER=y
    # CONFIG_THREAD_ANALYZER_AUTO=y
    # CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y
    # CONFIG_THREAD_ANALYZER_USE_PRINTK=y
    # CONFIG_CONSOLE=y
    # CONFIG_UART_CONSOLE=y
    # CONFIG_SERIAL=y
    # CONFIG_PRINTK=y
    
    # Example output of thread analyzer
    # SDC RX              : unused 816 usage 208 / 1024 (20 %)
    # BT RX               : unused 1784 usage 416 / 2200 (18 %)
    # BT TX               : unused 992 usage 544 / 1536 (35 %)
    # thread_analyzer     : unused 136 usage 376 / 512 (73 %)
    # sysworkq            : unused 1824 usage 224 / 2048 (10 %)
    # MPSL signal         : unused 520 usage 504 / 1024 (49 %)
    # idle 00             : unused 192 usage 64 / 256 (25 %)
    # main                : unused 136 usage 888 / 1024 (86 %)
    # Configurations set based on thread analyzer output.
    CONFIG_BT_RX_STACK_SIZE=1024
    CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y
    CONFIG_BT_HCI_TX_STACK_SIZE=640
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
    CONFIG_MPSL_WORK_STACK_SIZE=640
    CONFIG_MAIN_STACK_SIZE=1024
    CONFIG_IDLE_STACK_SIZE=128
    CONFIG_ISR_STACK_SIZE=1024


Related