how to fix the debugger in visual studio code

Bhavya Jain 20 Reputation points
2024-07-29T13:50:02.1566667+00:00

My debugger is not working. I guess there is some problem with the configuration but it is not working. Everytime i try to debug it show 'Configuration 'C/C++: gcc.exe build and debug active file' is missing in 'launch.json'. Please help me configure the debugger

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,143 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
999 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 30,821 Reputation points Microsoft Vendor
    2024-07-30T07:41:34.1966667+00:00

    Hello @Bhavya Jain,

    Thank you for taking time to post this issue in Microsoft Q&A forum.

    As Visual Studio Code(different from VS IDE) is currently not supported in the Microsoft Q&A forums, please first check and try @Amanulla Asfak Ahamed ’s suggestions above. If the error persists, please kindly post your question here: Github – vscode for better help.

    Thanks for your understanding, have a nice day:)

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Amanulla Asfak Ahamed 155 Reputation points
    2024-07-29T13:52:09.3166667+00:00
    1. Open Your Project in VS Code:
      • Ensure that your project files are open in Visual Studio Code.
    2. Install the C/C++ Extension:
      • If not already installed, you need to install the C/C++ extension from Microsoft. Go to the Extensions view by clicking on the square icon on the sidebar or pressing Ctrl+Shift+X, and search for "C/C++". Install the one made by Microsoft.
    3. Configure the launch.json File:
      • Go to the Run and Debug view by clicking the play icon on the sidebar or pressing Ctrl+Shift+D.
      • Click on "create a launch.json file", then select C++ (GDB/LLDB). If prompted, select the environment, e.g., C/C++: gcc.exe build and debug active file.
      • If you don't get the prompt to create the file, you can manually create a launch.json file by clicking on the "Add Configuration..." button and then selecting "C/C++: (gdb) Launch".
    4. Modify the launch.json File:
      • Here’s an example configuration for using gcc:
        
             {
        
                 "version": "0.2.0",
        
                 "configurations": [
        
                     {
        
                         "name": "gcc.exe build and debug active file",
        
                         "type": "cppdbg",
        
                         "request": "launch",
        
                         "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        
                         "args": [],
        
                         "stopAtEntry": false,
        
                         "cwd": "${workspaceFolder}",
        
                         "environment": [],
        
                         "externalConsole": false,
        
                         "MIMode": "gdb",
        
                         "miDebuggerPath": "path\\to\\your\\gdb.exe",
        
                         "preLaunchTask": "C/C++: gcc.exe build active file",
        
                         "setupCommands": [
        
                             {
        
                                 "description": "Enable pretty-printing for gdb",
        
                                 "text": "-enable-pretty-printing",
        
                                 "ignoreFailures": true
        
                             }
        
                         ]
        
                     }
        
                 ]
        
             }
        
        
      • Make sure to replace "miDebuggerPath": "path\\to\\your\\gdb.exe" with the actual path to your gdb.exe file if it's not in your system path.
    5. Configure a Build Task:
      • You might also need to set up a build task if it’s not already configured. This can be done by going to Terminal > Configure Default Build Task > C/C++: gcc.exe build active file.
    6. Start Debugging:
      • Set a breakpoint by clicking on the left of the line number in your code editor.
      • Press F5 to start debugging.

    If you follow these steps and still face issues, make sure your gcc and gdb are correctly installed and accessible from your command line or terminal. Also, check for any typos or path errors in the configuration files.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.