3

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. But gcc -m32 helloworld.c gave errors like this. The comment here explains it with -m32 option. It asks to add i686-w64-mingw32/x86_64-w64-mingw32 flags while compiling. But gcc -x86_64-w64-mingw32 helloworld.c gives language not recognized error, gcc -i686-w64-mingw32 helloworld.c gives unrecognized 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?
4
  • You need to set the path for the debug symbols. symbolSearchPath=C:\\path_1;D:\\path_2;etc... Mar 10, 2017 at 17:28
  • Nice little GitHub VSCode write up for configuring launch.json. Hopefully it helps a bit. github.com/Microsoft/vscode-cpptools/blob/master/launch.md Mar 10, 2017 at 17:37
  • @Ingenioushax but where are those debug symbols? As I said in my case gcc -g helloworld.c isnt generating any debug symbols.
    – Mahesha999
    Mar 10, 2017 at 19:42
  • Note Mahesh, you have Mingw installed in "Program Files" <-- a folder with a space in it. This can cause mysterious problems; it should be installed to C:\mingw.
    – rdtsc
    Apr 10, 2017 at 12:17

3 Answers 3

1

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:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "C++ Launch",
        "type": "cppdbg",
        "request": "launch",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "externalConsole": true,

        "linux": {
            "program": "${workspaceRoot}/a.out",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        "osx": {
            "MIMode": "lldb"
        },
        "windows": {
            "miDebuggerPath": "C:\\TDM-GCC-64\\bin\\gdb.exe",
            "program": "${workspaceRoot}\\a.exe",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    },
    {
        "name": "C++ Attach",
        "miDebuggerPath": "C:\\TDM-GCC-64\\bin\\gdb.exe",
        "type": "cppdbg",
        "request": "attach",
        "program": "${workspaceRoot}/a.exe",
        "processId": "${command:pickProcess}",
        "linux": {
            "MIMode": "gdb",
            "program": "${workspaceRoot}/a.out",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        "osx": {
            "MIMode": "lldb"
        },
        "windows": {
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\TDM-GCC-64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    }
    ]
}
1

If you want command.PickProcess to work..

It should be a ':' not a '.' - therefore:

{
    "name": ".NET Core Attach",
    "type": "coreclr",
    "request": "attach",
    "processId": "${command:pickProcess}"
}

Should sort you out :)

0

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!

1
  • What is this supposed to mean?
    – ifconfig
    Sep 6, 2017 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.