microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

gdb debugging - step controls, breakpoints, etc. not working #1685

Closed unf0rce closed 6 years ago

unf0rce commented 6 years ago

Hello everyone, I'm having issues with the debugger in vs code that is it isn't really working. When i start the debugger, the program executes fine, but the debugging controls, variables, watch, breakpoints, etc. will not work. I am guessing the issue is on my end, but after 2 evenings of googling and testing i'm kinda at my wits end, so i'm glad for any help i can get.

My System:

* Operating System and version
Fedora 27
* VS Code version and if you are using the Insiders build
VS Code 1.21.0; No Insiders build
* C/C++ extension version
C/C++ for Visual Studio Code v0.15.0
* Other extensions you installed and if the issue persists after disabling them
C++ Intellisense v0.2.2; C/C++ Clang Command Adapter v0.2.2

int main(){

std::cout << "Hello World" << " ";
std::cout << std::endl;

/*this is just so the terminal window 
* doesn't close after completion*/
std::cin.clear();
std::cin.ignore(32767, '\n');
std::cin.get();

return 0;

}

2. build with ```g++ -g -o hello hello.cpp```
3. launch debug
4. program gets executed, debugging tools are unusable: [screenshot](https://i.imgur.com/gKod1UL.png)

* Relevant settings from your settings.json, c_cpp_properties.json, and/or launch.json files

settings.json (user settings):

{ "workbench.startupEditor": "newUntitledFile", "editor.detectIndentation": false, "editor.insertSpaces": false, "window.zoomLevel": 0, "C_Cpp.loggingLevel": "Information" }

c_cpp_properties.json:

{ "name": "Linux", "includePath": [ "/usr/include", "${workspaceRoot}", "/usr/include/c++/7", "/usr/include/c++/7/x86_64-redhat-linux", "/usr/include/linux" ], "defines": [], "intelliSenseMode": "clang-x64", "browse": { "path": [ "/usr/include", "${workspaceRoot}" ], "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } },

launch.json:
"version": "0.2.0",
"configurations": [
    {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/hello",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    },
* Any log messages present in the Output window (use "C_Cpp.loggingLevel": "Information" in settings.json)
debug console output:

=thread-group-added,id="i1" GNU gdb (GDB) Fedora 8.0.1-36.fc27 Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/. For help, type "help". Type "apropos word" to search for commands related to "word". =cmd-param-changed,param="pagination",value="off" Stopped due to shared library event (no libraries added or removed) Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.

Breakpoint 1, main () at hello.cpp:5 5 std::cout << "Hello World" << " "; [Inferior 1 (process 16921) exited normally] The program '/home/unas/Documents/Code/hello' has exited with code 0 (0x00000000).



Thank you for any assistance!
pieandcakes commented 6 years ago

@un4s what do you mean when you say the debugging tools are unusable? Are you saying your terminal window blocks your use of VS Code? the screenshot doesn't provide enough info. What occurs when you try and set a breakpoint?

unf0rce commented 6 years ago

hi @pieandcakes and thank you for your assistance - like i said, i guessed right in that the issue was on my end. It is working now. I did not realize, that i have to compile with an active breakpoint to get the result i wanted... I come from a background of scripting/interpreter languages, so this compiling is still a bit new to me. Thank you and sorry for the wasted time ;)

pieandcakes commented 6 years ago

@un4s No problem! Glad it is working for you now.

voyage19941119 commented 6 years ago

@un4s Hi, I have met the same problem, and it's still not working after I rebuild the project . suppose you have some idea about that

pieandcakes commented 6 years ago

@voyage19941119 are you compiling with -g ? This usually is the case if you don't compile with Debug symbols enabled.

nathanzh commented 5 years ago

Hi, facing the same problem here: VScode just won't hit the breakpoints. OS: win10 Home ver: 1803 VsCode: 1.32.1 Extension installed C/C++ for Visual Studio Code Version 0.21.0

task.json:

{
    "version": "2.0.0",
    "command": "g++",
    "args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe","-v"], 
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,  //this will call a dos prompt window for cin and cout
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGWx64\\gcc\\bin\\gdb.exe",
            "preLaunchTask": "g++", //this must same as command in task.json
            "logging": {"trace": true, "traceResponse": true,
                        "engineLogging": true,
                        "exceptions": true,
                        "moduleLoad": true,
                        "programOutput": true},
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "MinGw",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceRoot}",
                "C:\\MinGWx64\\gcc\\include\\c++\\8.2.0",
                "C:\\MinGWx64\\gcc\\x86_64-w64-mingw32\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\MinGWx64\\gcc\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

debug logs:

--> E (output): {"event":"output","body":{"category":"console","output":"1: (128) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'\r\n"},"seq":2,"type":"event"}
1: (128) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (134) LaunchOptions  ExePath='C:\\Users\\natha\\Seafile\\CDmyCompany\\cpp_study\\myCode\\c_primer.exe'\r\n"},"seq":4,"type":"event"}
1: (134) LaunchOptions  ExePath='C:\Users\natha\Seafile\CDmyCompany\cpp_study\myCode\c_primer.exe'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (135) LaunchOptions  WorkingDirectory='C:\\Users\\natha\\Seafile\\CDmyCompany\\cpp_study\\myCode'\r\n"},"seq":6,"type":"event"}
1: (135) LaunchOptions  WorkingDirectory='C:\Users\natha\Seafile\CDmyCompany\cpp_study\myCode'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (135) LaunchOptions  ExeArguments=''\r\n"},"seq":8,"type":"event"}
1: (135) LaunchOptions  ExeArguments=''
--> E (output): {"event":"output","body":{"category":"console","output":"1: (135) LaunchOptions  MIMode='gdb'\r\n"},"seq":10,"type":"event"}
1: (135) LaunchOptions  MIMode='gdb'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (136) LaunchOptions  MIDebuggerPath='C:\\MinGWx64\\gcc\\bin\\gdb.exe'\r\n"},"seq":12,"type":"event"}
1: (136) LaunchOptions  MIDebuggerPath='C:\MinGWx64\gcc\bin\gdb.exe'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (136) LaunchOptions  WaitDynamicLibLoad='false'\r\n"},"seq":14,"type":"event"}
1: (136) LaunchOptions  WaitDynamicLibLoad='false'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (136) LaunchOptions  ExternalConsole='true'\r\n"},"seq":16,"type":"event"}
1: (136) LaunchOptions  ExternalConsole='true'
--> E (output): {"event":"output","body":{"category":"console","output":"1: (137) LaunchOptions>\r\n"},"seq":18,"type":"event"}
1: (137) LaunchOptions>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (137) LaunchOptions    <SetupCommands>\r\n"},"seq":20,"type":"event"}
1: (137) LaunchOptions    <SetupCommands>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (137) LaunchOptions        <Command IgnoreFailures='true' Description='Enable pretty-printing for gdb'>-enable-pretty-printing</Command>\r\n"},"seq":22,"type":"event"}
1: (137) LaunchOptions        <Command IgnoreFailures='true' Description='Enable pretty-printing for gdb'>-enable-pretty-printing</Command>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (137) LaunchOptions    </SetupCommands>\r\n"},"seq":24,"type":"event"}
1: (137) LaunchOptions    </SetupCommands>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (137) LaunchOptions</LocalLaunchOptions>\r\n"},"seq":26,"type":"event"}
1: (137) LaunchOptions</LocalLaunchOptions>
--> E (output): {"event":"output","body":{"category":"console","output":"1: (201) Starting: \"C:\\MinGWx64\\gcc\\bin\\gdb.exe\" --interpreter=mi\r\n"},"seq":28,"type":"event"}
1: (201) Starting: "C:\MinGWx64\gcc\bin\gdb.exe" --interpreter=mi
--> E (output): {"event":"output","body":{"category":"console","output":"1: (690) DebuggerPid=8268\r\n"},"seq":30,"type":"event"}
1: (690) DebuggerPid=8268
--> E (output): {"event":"output","body":{"category":"console","output":"1: (761) ->=thread-group-added,id=\"i1\"\r\n"},"seq":32,"type":"event"}
1: (761) ->=thread-group-added,id="i1"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (763) ->~\"This binary was built by Equation Solution <http://www.Equation.com>.\\n\"\r\n"},"seq":34,"type":"event"}
1: (763) ->~"This binary was built by Equation Solution <http://www.Equation.com>.\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (763) ->~\"GNU gdb (GDB) 7.12\\n\"\r\n"},"seq":36,"type":"event"}
1: (763) ->~"GNU gdb (GDB) 7.12\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (763) ->~\"Copyright (C) 2016 Free Software Foundation, Inc.\\n\"\r\n"},"seq":38,"type":"event"}
1: (763) ->~"Copyright (C) 2016 Free Software Foundation, Inc.\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (763) ->~\"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\\nThis is free software: you are free to change and redistribute it.\\nThere is NO WARRANTY, to the extent permitted by law.  Type \\\"show copying\\\"\\nand \\\"show warranty\\\" for details.\\n\"\r\n"},"seq":40,"type":"event"}
1: (763) ->~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (764) ->~\"This GDB was configured as \\\"x86_64-w64-mingw32\\\".\\nType \\\"show configuration\\\" for configuration details.\"\r\n"},"seq":42,"type":"event"}
1: (764) ->~"This GDB was configured as \"x86_64-w64-mingw32\".\nType \"show configuration\" for configuration details."
--> E (output): {"event":"output","body":{"category":"console","output":"1: (764) ->~\"\\nFor bug reporting instructions, please see:\\n\"\r\n"},"seq":44,"type":"event"}
1: (764) ->~"\nFor bug reporting instructions, please see:\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (764) ->~\"<http://www.gnu.org/software/gdb/bugs/>.\\n\"\r\n"},"seq":46,"type":"event"}
1: (764) ->~"<http://www.gnu.org/software/gdb/bugs/>.\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (765) ->~\"Find the GDB manual and other documentation resources online at:\\n<http://www.gnu.org/software/gdb/documentation/>.\\n\"\r\n"},"seq":48,"type":"event"}
1: (765) ->~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (765) ->~\"For help, type \\\"help\\\".\\n\"\r\n"},"seq":50,"type":"event"}
1: (765) ->~"For help, type \"help\".\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (765) ->~\"Type \\\"apropos word\\\" to search for commands related to \\\"word\\\".\\n\"\r\n"},"seq":52,"type":"event"}
1: (765) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (766) ->(gdb)\r\n"},"seq":54,"type":"event"}
1: (766) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (772) <-1001-gdb-set target-async on\r\n"},"seq":56,"type":"event"}
1: (772) <-1001-gdb-set target-async on
--> E (output): {"event":"output","body":{"category":"console","output":"1: (773) ->&\"\\357\\273\\2771001-gdb-set target-async on\\n\"\r\n"},"seq":58,"type":"event"}
1: (773) ->&"\357\273\2771001-gdb-set target-async on\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (775) ->&\"Undefined command: \\\"\\357\\\".  Try \\\"help\\\".\\n\"\r\n"},"seq":60,"type":"event"}
1: (775) ->&"Undefined command: \"\357\".  Try \"help\".\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (776) ->^error,msg=\"Undefined command: \\\"\\357\\\".  Try \\\"help\\\".\"\r\n"},"seq":62,"type":"event"}
1: (776) ->^error,msg="Undefined command: \"\357\".  Try \"help\"."
--> E (output): {"event":"output","body":{"category":"console","output":"1: (776) ->(gdb)\r\n"},"seq":64,"type":"event"}
1: (776) ->(gdb)
--> E (output): {"event":"output","body":{"category":"console","output":"1: (776) ->&\"\\n\"\r\n"},"seq":66,"type":"event"}
1: (776) ->&"\n"
--> E (output): {"event":"output","body":{"category":"console","output":"1: (777) ->^done\r\n"},"seq":68,"type":"event"}
1: (777) ->^done
--> E (output): {"event":"output","body":{"category":"console","output":"1: (777) ->(gdb)\r\n"},"seq":70,"type":"event"}
1: (777) ->(gdb)

the same program and config files running fine in another laptop.

pieandcakes commented 5 years ago

@nathanzh your issue looks like the #1527

MaiMeng1204 commented 1 year ago

@voyage19941119 are you compiling with -g ? This usually is the case if you don't compile with Debug symbols enabled.

useful