I was following instructions from here. Installed cpptools. Created tasks.json
with following contents:
{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"showOutput": "always",
"args": ["-g", "helloworld.c"]
}
And launch.json
with following content:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch (Windows)",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"windows": {
"MIMode" : "gdb",
"miDebuggerPath": "C:\\Mahesh\\Program Files\\mingw\\MinGW\\bin\\gdb.exe"
}
},
{
"name": "C++ Attach (Windows)",
"program": "${workspaceRoot}/a.exe",
"type": "cppvsdbg",
"request": "attach",
"processId": "${command.pickProcess}",
"windows": {
"MIMode" : "gdb",
"miDebuggerPath": "C:\\Mahesh\\Program Files\\mingw\\MinGW\\bin\\gdb.exe"
}
}
]
}
When I do Ctrl+Shift+B
, the code builds, generating a.exe
. When I run debug, it gives following output:
--------------------------------------------------------------------------------
You may only use the C/C++ Extension for Visual Studio Code with Visual Studio
Code, Visual Studio or Xamarin Studio software to help you develop and test your
applications.
--------------------------------------------------------------------------------
Loaded 'C:\Mahesh\repos\VSCodeC\polyaddition\a.exe'. Symbols are not loaded.
Loaded 'C:\Windows\System32\ntdll.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\kernel32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\sysfer.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\msvcr100.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\QIPCAP64.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\oleaut32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\ole32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\msvcrt.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\gdi32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\user32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\lpk.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\usp10.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\rpcrt4.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\imm32.dll'. Symbols are not loaded.
Loaded 'C:\Windows\System32\msctf.dll'. Symbols are not loaded.
The thread 9524 has exited with code 0 (0x0).
Hello World!!!
The program '[7876] a.exe' has exited with code 0 (0x0).
But the code is not hitting the debug point I set up in the code. You can see, it is printing "Hello World!!!". How can I configure so that it will allow me to step through the code while debugging?
Environment:
- The program '[7876] a.exe' has exited with code 0 (0x0), configured as "i686-pc-mingw32".
- gcc.exe (x86_64-win32-seh-rev201506, mingwpy build) 4.9.2
- g++.exe (x86_64-win32-seh-rev201506, mingwpy build) 4.9.2
Update
- In the discussion in the comments, I have been asked to run gcc with
m32
flag as my compiler is 64-bit, it may be generating 64-bit binaries. Butgcc -m32 helloworld.c
gave errors like this. The comment here explains it with-m32
option. It asks to addi686-w64-mingw32/x86_64-w64-mingw32
flags while compiling. Butgcc -x86_64-w64-mingw32 helloworld.c
giveslanguage not recognized
error,gcc -i686-w64-mingw32 helloworld.c
givesunrecognized command line option
. What I am doing wrong? - Also this article says that debugging is currently possible only with linux but not with Windows. Is it so?
I believe you are trying to use the VS Code debugger (cppvsdbg) instead of gdb (cppdbg.) This modified
launch.json
works for me with TDM-GCC and gdb as the debugger:If you want command.PickProcess to work..
It should be a ':' not a '.' - therefore:
Should sort you out :)
I have faced this issue before. In my case, the compiler generated a release application as default. It has no symbols for debugging.
So, please make sure that you are generated a debug app for debugging.
good luck!