Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ debugger crashes on M2 Mac when using SDL and std::map #10965

Open
Rojetto opened this issue May 17, 2023 · 2 comments
Open

C++ debugger crashes on M2 Mac when using SDL and std::map #10965

Rojetto opened this issue May 17, 2023 · 2 comments

Comments

@Rojetto
Copy link

Rojetto commented May 17, 2023

Type: Bug

While working on a project using SDL, I ran into a weird issue where after setting a breakpoint, the VS Code debugger (using lldb) would stop at the breakpoint and show the stack trace, but couldn't load variables or step. The program then also froze, even after stopping the debugger and had to be force quit. I reduced it to the following minimal example:

main.cpp

#include <SDL.h>
#include <map>

int main() {
    if (SDL_Init(SDL_INIT_VIDEO) != 0)
    {
        return -1;
    }

    std::map<int, int> badMap;

    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(LLDB Repro)

# Set the C++ standard to be used for compilation
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Define the source files to be compiled
file(GLOB_RECURSE SOURCE_FILES 
    main.cpp
)

# Create an executable from the source files
add_executable(${PROJECT_NAME} ${SOURCE_FILES})

# Find the SDL2 package
find_package(SDL2 REQUIRED)

# Add the SDL2 include directories and link the SDL2 libraries
target_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${command:cmake.launchTargetPath}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ],
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "macos-clang-arm64",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}

If I set a breakpoint in the main function, VS Code will break there, but then something crashes internally. If you remove either the map or SDL_Init, the problem disappears. I also tried debugging manually from the command line with LLDB, but there the issue doesn't appear.

robert@RMBA LLDB Repro % lldb --version
lldb-1403.0.17.64
Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
robert@RMBA LLDB Repro % brew list --versions sdl2
sdl2 2.26.5

Extension version: 1.15.4
VS Code version: Code 1.78.2 (Universal) (b3e4e68a0bc097f0ae7907b217c1119af9e03435, 2023-05-10T14:44:45.204Z)
OS version: Darwin arm64 22.4.0
Modes:
Sandboxed: Yes

System Info
Item Value
CPUs Apple M2 (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 2, 2, 2
Memory (System) 8.00GB (0.08GB free)
Process Argv --crash-reporter-id 87b0c4e4-4f3b-445b-9f36-34444426ed13
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vstes627:30244334
vslsvsres303:30308271
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
vscccc:30610679
3biah626:30602489
pyind779:30671433
89544117:30613380
pythonsymbol12:30671437
a9j8j154:30646983
showlangstatbar:30737416
vsctsb:30705553
azdwalk:30721579
pythonms35:30701012
pythonfmttext:30731395
fixhidewlkth:30730051
pythongtdpathcf:30739705

@H-G-Hristov
Copy link

H-G-Hristov commented May 17, 2023

There are multiple reports on that. You can find them and link them here.

Just install CodeLLDB.

#10816
#7240
#5805
#9831
lldb-tools/lldb-mi#101

@Rojetto
Copy link
Author

Rojetto commented May 18, 2023

Thanks, CodeLLDB seems to work much better even in normal operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants