Skip to content

Attaching debugger to cpptools or cpptools‐srv

Michelle Matias edited this page Feb 10, 2021 · 5 revisions

Attaching a debugger to cpptools or cpptools-srv processes, allows VS Code to provide stacks when reproducing 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 reproduce 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 reproducing is a crash, attach first, then reproduce 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. If the issue is an IntelliSense crash with cpptools-srv, you should be able to comment out (or #if 0) the code, attach to cpptools-srv, and then uncomment the code to reproduce the crash.

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
  • If the program exits out after attaching you're hitting issue https://github.com/microsoft/vscode-cpptools/issues/6151, which we're working on fixing.
  • Reports may also be generated at the following path as crashes occur: ~/Library/Logs/DiagnosticReports