Skip to content

Attaching debugger to cpptools or cpptools‐srv

Sean McManus edited this page Sep 25, 2020 · 5 revisions

Attaching a debugger to cpptools or cpptools-srv processes, allows Vs Code to provide stacks when repro'ing a crash, or to report excessive memory usage or excessive CPU usage.

How-To

  • In VS Code, open the folder or workspace to use to repro the issue.
  • Create or edit .vscode/launch.json.
  • Add the following ‘attach’ configuration to launch.json.
    • Note that full paths to cpptools and cpptools-srv will be different on your machine and should be edited before attempting to attach to the process.

On Windows (full launch.json file):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Attach",
            "type": "cppvsdbg",
            "request": "attach",
            "processId": "${command:pickProcess}",
            "symbolSearchPath": "https://msdl.microsoft.com/download/symbols",
            "logging": {
                "engineLogging": true,
                "trace": true
            },
        }
    ]
}

On Linux (full launch.json file):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "processId": "${command:pickProcess}",
            "program": "/home/MyName/.vscode/extensions/ms-vscode.cpptools-1.0.0/bin/cpptools",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

On Mac (full launch.json file):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "processId": "${command:pickProcess}",
            "program": "/Users/MyName/.vscode/extensions/ms-vscode.cpptools-1.0.0/bin/cpptools",
            "MIMode": "lldb"
        }
    ]
}
  • Click on the "Run" icon in the left panel of the VS Code window.
  • Select this launch config in the drop-down on the Run panel.

image

  • Clicking on the “Start Debugging” button should cause a process picker to be displayed.
  • Select cpptools (or cpptools-srv, if attempting to attach to the IntelliSense process)

2

  • If the issue you are repro’ing is a crash, attach first, then repro the crash. The debugger should break in when the crash occurs. Right-click on a function within the call stack and select "Copy Call Stack". Provide this stack when reporting the issue in the cpptools Github repo.

3

  • If the issue is excessive memory usage or CPU usage, you can attach the debugger while cpptools is already in this state. Then, click on the pause button to halt the execution. Capture all call stacks.

On Linux, if using gdb, all stacks can be output by executing the following in the Debug Console panel: -exec thread apply all bt

On Mac, if these instructions do not work to attach to a process to collect info on excessive memory or CPU use:

  • run the following in a terminal window to attach lldb: lldb -p <PID of process to debug>
  • Then run the following command in lldb to output all stacks: bt all
  • Reports should be generated at the following path as crashes occur: ~/Library/Logs/DiagnosticReports