Vs code debug linux

Debugging

You can debug C# applications in Visual Studio Code using the Microsoft C# extension.

Run and Debug

The C# extension along with C# Dev Kit provides multiple ways to run and debug your C# application.

To run and debug without C# Dev Kit, see Microsoft C# extension’s GitHub page for documentation.

Debug with F5

With the C# Dev Kit extension installed and no debug configurations available to select in the Debug view, you can start debugging your project by having a .cs file opened and then pressing F5 . The debugger will automatically find your project and start debugging. If you have multiple projects, it will prompt for which project you would like to start debugging.

You can also start a debugging session from the Run and Debug view from the side bar of VS Code. See more at Debugging in VS Code.

Debug with Solution Explorer

With the C# Dev Kit extension installed, there is a Debug context menu when you right-click on your project in the Solution Explorer.

  • Start New Instance — This starts your project with a debugger attached.
  • Start without Debugging — This runs your project without a debugger attached.
  • Step into New Instance — This starts your project with a debugger attached but stops at the entrypoint of your code.

Debug with Command Palette

With the C# Dev Kit extension installed, you can also start debugging from the Command Palette ⇧⌘P (Windows, Linux Ctrl+Shift+P ) by using the Debug: Select and Start Debugging command.

Читайте также:  Linux sstp vpn client

Note: This adds a launch configuration entry to your debug dropdown list.

Debug with dynamic (in-memory) launch configurations

With the C# Dev Kit extension installed, you can create dynamic launch configurations. How you create them depends if your project has an existing launch.json file.

Existing launch.json

If you have an existing launch.json , you can go to the Debug view, select the dropdown, and select the C# option. This should give you a selection of launch targets that you can add to your dropdown list. After selecting, you can hit F5 or Start Debugging with the newly generated configuration.

No launch.json

If you do not have a launch.json in your project, you can add and access these dynamic configurations in the Show all automatic debug configurations in the Debug view.

Removing dynamic (in-memory) launch configurations

You can remove the generated configurations with Command Palette ⇧⌘P (Windows, Linux Ctrl+Shift+P ) and using the command Debug: Select and Start Debugging.

In the dropdown, it lists all your existing debug configurations. If you hover over the dynamic configurations, a clickable trashcan icon appears on the right. You can select that icon to remove the dynamic configuration.

Debug with launch.json

If you are using the C# Dev Kit, we recommend not using this option. However, if you have the need to modify the debug configuration directly, see Configuring launch.json for C# debugging.

Attaching to a process

You can attach to a C# process using with the Command Palette ⇧⌘P (Windows, Linux Ctrl+Shift+P ) and running the Debug: Attach to a .NET 5+ or .NET Core process command.

Attach to a C# process

Configuration options

There are many options and settings available to configure the debugger. You can use launchSettings.json , VS Code User Settings to modify your debug options, or directly modify your launch.json .

Читайте также:  Сколько человек пользуется линуксом

launchSettings.json

If you have launchSettings.json from Visual Studio, you should see your profiles listed using Run from F5 or Run from Command Palette.

Refer to Configuring C# debugging for more details.

User settings

If you have settings that you wish to change while using the C# debugger, you can find these options under File > Preferences > Settings ( ⌘, (Windows, Linux Ctrl+, ) ) and searching for these options.

  • csharp.debug.stopAtEntry — If true, the debugger should stop at the entry point of the target. This option defaults to false .
  • csharp.debug.console — When launching console projects, indicates which console the target program should be launched into. Note: This option is only used for the ‘dotnet’ debug configuration type.
    • internalConsole — Output to the VS Code Debug Console. This doesn’t support reading console input (ex:Console.ReadLine).
    • integratedTerminal — VS Code’s integrated terminal.
    • externalTerminal — External terminal that can be configured via user settings.
    • loadAllButExcluded — Load symbols for all modules unless the module is in the excludedModules array.
    • loadOnlyIncluded — Do not attempt to load symbols for ANY module unless it is in the includedModules array, or it is included through the includeSymbolsNextToModules setting.

    Breakpoints

    The C# Debugger supports various breakpoints, such as source line breakpoints, conditional breakpoints, and logpoints.

    Breakpoint — conditional breakpoint

    With the help of expression evaluation, the debugger also supports conditional breakpoint. You can set your breakpoint to break when expression evaluates to true.

    Breakpoint — Logpoints

    Logpoints (also known as Tracepoints in Visual Studio) allow you to send output to Debug Console without editing code. They’re different from breakpoints because they don’t stop the execution flow of your application.

    To add a Logpoint, right-click in the far-left margin next to a line of code. Select Add Logpoint and type the message you want to log. Any expression between curly braces (») will be evaluated when the Logpoint is hit.

    The following tokens are also supported in the log message:

    Token Description Example Output
    $FILEPOS Current source file location C:\sources\repos\Project\Program.cs:4
    $FUNCTION Current function name Program.$
    $ADDRESS Current instruction 0x00007FFF83A54001
    $TID Thread ID 20668
    $PID Process ID 10028
    $TNAME Thread name
    $PNAME Process name C:\sources\repos\Project\bin\Debug\net7.0\console.exe
    $CALLER Calling function name void console.dll!Program.Foo()
    $CALLSTACK Call stack void console.dll!Program.Bar()
    void console.dll!Program.Foo()
    void console.dll!Program.$(string[] args)
    [External Code]
    $TICK Tick count (from Windows GetTickCount) 28194046
    $HITCOUNT Number of times this breakpoint has been hit 5

    Expression evaluation

    The debugger also lets you evaluate expressions in the WATCH window as well as the Debug Console.

    Next steps

    Read on to find out about:

    Источник

    How to Debug C/C++ with VS Code

    With pipe transport, you’ll debug remote linux from macos.

    launch.json

     "version": "0.2.0", "configurations": [  "name": "(Mac to Linux)pipe transport", "type": "cppdbg", "request": "launch", "program": "/home/nnyn/Documents/vscode-debug-specs/cpp/main", "args": [ "4", "3", "2", "1" ], "stopAtEntry": false, "cwd": "/home/nnyn/Documents/vscode-debug-specs/cpp", "environment": [], "externalConsole": true, "pipeTransport":  "pipeCwd": "/usr/bin", "pipeProgram": "/usr/bin/ssh", "pipeArgs": [ "nnyn@192.168.56.101" ], "debuggerPath": "sudo /usr/bin/gdb" >, "sourceFileMap":  // "remote": "local" "/home/nnyn/Documents/vscode-debug-specs/cpp": "$" >, "MIMode": "gdb" >, > ] 

    how to

    cd /home/nnyn/Documents/vscode-debug-specs/cpp gcc -O0 -g -W -Wall -o main bubble_sort.c main.c 

    attach to remote process (Mac/Linux to Linux)

    With pipe transport, you’ll attach remote linux process from macos.

    launch.json

     "version": "0.2.0", "configurations": [  "name": "(Mac to Linux)pipe transport attach", "type": "cppdbg", "request": "attach", "program": "/home/nnyn/Documents/vscode-debug-specs/cpp/bubble_sort_cunit", "processId": "21073", "pipeTransport":  "pipeCwd": "", "pipeProgram": "/usr/bin/ssh", "pipeArgs": [ "nnyn@192.168.56.101" ], "debuggerPath": "sudo /usr/bin/gdb" >, "sourceFileMap":  // "remote": "local" "/home/nnyn/Documents/vscode-debug-specs/cpp": "$" >, "MIMode": "gdb" > > ] 

    how to

    1. build at remote machine
    2. launch program at remote machine
    3. check the process id of remote process
    4. set the process id to launch.json
    5. launch debug

    Источник

Оцените статью
Adblock
detector