简体   繁体   中英

CLion debugger doesn't work with MinGW and GDB

I've been trying to debug a program of mine in CLion and couldn't figure out why none of the breakpoints that I set were hit. I was using MinGW as a toolchain. After I switched to the Visual Studio toolchain, the debugger mysteriously worked. Why is this and how can I fix this issue? I need the debugger to work with MinGW. Here are some more details of my set toolchains: I wrote this small program:

#include <stdio.h>

int main() {
    int a = 10;
    a += 1;
    printf("Hello, %d!\n", a);
    return 0;
}

And I set a breakpoint at every line after the main() declaration. Here is the default CMake file that was generated:

cmake_minimum_required(VERSION 3.17)
project(practice_1 C)

set(CMAKE_C_STANDARD 99)

add_executable(practice_1 main.c)

And here is the MinGW toolchain set:

在此处输入图像描述

When I run this in CLion in debug mode the debugger doesn't work. It just goes straight to the end, printing that message in the console.

If I set the toolchain with the Visual Studio setting it all works. So I do this:

在此处输入图像描述

And now I can use the Visual Studio debugger. It hits the breakpoints and I can debug my program. But I need to use the other setting. How can I solve this issue and use the GDB debugger? I tried adding this in the CMake file but it didn't work.

This is the build text I get in the console after rebuilding all:

====================[ Clean | Debug ]===========================================
"C:\Program Files\JetBrains\CLion 2020.3.3\bin\cmake\win\bin\cmake.exe" --build "D:\Practice\practice_1\cmake-build-debug" --target clean -- -j 9

Clean finished

====================[ Build | all | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2020.3.3\bin\cmake\win\bin\cmake.exe" --build "D:\Practice\practice_1\cmake-build-debug" --target all -- -j 9
[ 50%] Building C object CMakeFiles/practice_1.dir/main.c.obj
[100%] Linking C executable practice_1.exe
[100%] Built target practice_1

Build finished

I had the same problem, I changed the CMake configuration adding the flag -g as follows

在此处输入图像描述

It allowed the debugger to work fine

在此处输入图像描述

Hope it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM