Skip to content

C++ Debug breakpoint doesn't work with linked libraries built with the application in VSCode #14357

@khteh

Description

@khteh

Environment

  • OS and version: Ubuntu 25.10
  • VS Code: 1.114.0
  • C/C++ extension: 1.5.1
  • OS and version of remote machine (if applicable):
  • GDB / LLDB version: 16.3

Bug Summary and Steps to Reproduce

Bug Summary:
Breakpoints set inside a statically linked library built with the same C++ application in the same source tree are greyed out and not hit.

Steps to reproduce:
Console.cpp CMakeLists.txt:

target_link_libraries(${PROJECT_NAME} PRIVATE
MyLibrary.Core
)

top-level CMakeLists.txt:

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_BUILD_TYPE "Debug")

# ###############################################################################
# Global compiler options
# https://stackoverflow.com/questions/79444534/vscode-cmake-configure-does-not-generate-cmakecache-txt-from-cmakelists-txt
# CMAKE_CXX_COMPILER_ID is set only at the project() call, when CMake actually detect compilers.
# ###############################################################################
if(MSVC)
    # remove default flags provided with CMake for MSVC
    set(CMAKE_CXX_FLAGS "")
    set(CMAKE_CXX_FLAGS_DEBUG "")
    set(CMAKE_CXX_FLAGS_RELEASE "")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
    message("-- Setting GNU options from CMakeLists.txt")
    set(CMAKE_CXX_FLAGS "-std=gnu++26 -fdiagnostics-color=always" CACHE STRING "CXX build flags" FORCE)
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -ggdb3 -Og -g3" CACHE STRING "Debug build flags" FORCE)
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG" CACHE STRING "Release build flags" FORCE)
endif()

Debugger Configurations

launch.json:

        {
            "name": "C++ Launch (Console)",
            "type": "cppdbg",
            "request": "launch",
            "preLaunchTask": "CMake: build all",
            "postDebugTask": "",
            "program": "${workspaceFolder}/Debug/Console",
            "cwd": "${workspaceFolder}/build",
            "stopAtEntry": false,
            "externalConsole": false,
            "launchCompleteCommand": "exec-run",
            "linux": {
              "MIMode": "gdb",
              "miDebuggerPath": "/usr/bin/gdb"
            },
            "osx": {
              "MIMode": "lldb"
            },
            "windows": {
              "MIMode": "gdb",
              "miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"
            },
            "args": [],
            "setupCommands": [
                {
                    "description": "Disable MI-async",
                    "text": "set mi-async off",
                    "ignoreFailures": true
                },
                {
                    "description": "Enable auto-load for all paths. Considered a security risk. See link for details: https://sourceware.org/gdb/current/onlinedocs/gdb.html/Auto_002dloading-safe-path.html",
                    "text": "set auto-load safe-path /",
                    "ignoreFailures": true
                },
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                },                
                {
                    "description": "Do not display function arguments when printing a stack frame",
                    "text": "set print frame-arguments none",
                    "ignoreFailures": true
                }
            ]
        },          

tasks.json:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cmake",
			"label": "CMake: build all",
			"command": "build",
			"targets": [
				"all"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"problemMatcher": ["$gcc"],
			"detail": "CMake build all"
		},
		{
			"type": "cmake",
			"label": "CMake: build Console",
			"command": "build",
			"targets": [
				"Console"
			],
			"group": {
				"kind": "build",
				"isDefault": false
			},
			"problemMatcher": ["$gcc"],
			"detail": "CMake build Console"
		},
		{
			"type": "cmake",
			"label": "CMake: build Core",
			"command": "build",
			"targets": [
				"DataStructuresAlgorithms.Core"
			],
			"group": {
				"kind": "build",
				"isDefault": false
			},
			"problemMatcher": ["$gcc"],
			"detail": "CMake build Core"
		},
		{
			"type": "cmake",
			"label": "CMake: build Tests",
			"command": "build",
			"targets": [
				"DataStructuresAlgorithms.Tests"
			],
			"group": {
				"kind": "build",
				"isDefault": false
			},
			"problemMatcher": ["$gcc"],
			"detail": "CMake build Tests"
		},
	]
}

Debugger Logs

--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (590) DebuggerPid=583206\n"},"seq":185}
1: (590) DebuggerPid=583206
<--   C (setBreakpoints-4): {"command":"setBreakpoints","arguments":{"source":{"name":"Arithmetic.cpp","path":"/usr/src/DataStructuresAlgorithms/src/Arithmetic.cpp"},"lines":[299,323],"breakpoints":[{"line":299},{"line":323}],"sourceModified":false},"type":"request","seq":4}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (604) <-1016-break-insert -f Arithmetic.cpp:299\n"},"seq":188}
1: (604) <-1016-break-insert -f Arithmetic.cpp:299
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (701) ->&\"No compiled code for line 299 in file \\\"Arithmetic.cpp\\\".\\n\"\n"},"seq":190}
1: (701) ->&"No compiled code for line 299 in file \"Arithmetic.cpp\".\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (702) ->1016^done,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"<PENDING>\",pending=\"Arithmetic.cpp:299\",times=\"0\",original-location=\"Arithmetic.cpp:299\"}\n"},"seq":192}
1: (702) ->1016^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="Arithmetic.cpp:299",times="0",original-location="Arithmetic.cpp:299"}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (702) ->(gdb)\n"},"seq":194}

Other Extensions

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions