Search code examples
c++visual-studiogccvisual-c++clang

windows visual studio, how to debug c++ program like gdb or lldb (no GUI, only command line)?


In linux, you compile a bunch of cpp files and then debug it

gcc -g *.cpp
gdb main.o

or

clang -g *.cpp
lldb main.o

That's it.

What's the equivalent of this easy thing in Windows?

In Windows SDK, you can use clang too,

clang -g *.cpp

But there is no lldb. There is a lldb.exe, but it seems it's fake. enter image description here

I also heard cdb.exe, but no document about how to use it.


Solution

  • cdb.exe is the command line version of WinDbg (or rather WinDbg is the GUI version for cdb). For i guess historical reasons, there's also ntsd.exe, which is the same thing as cdb.exe. These are all part of the Debugging Tools for Windows toolkit from Microsoft.
    More info here: https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugging-using-cdb-and-ntsd

    The Visual Studio Debugger can at least be started from the command line if you so desire: devenv /debugexe MyApplication.exe
    As this is not its intended use, i would expect mixed results here.
    https://learn.microsoft.com/en-us/visualstudio/ide/reference/debugexe-devenv-exe?view=vs-2022

    Lastly, there is a windows version of gdb available as part of MinGW, which it turn is the windows port of the GCC compiler.