Vscode-cpptools: cppdbg attach issues

Created on 12 Apr 2020  Â·  5Comments  Â·  Source: microsoft/vscode-cpptools

  • OS and Version: Linux Mint 19.3 x64
  • VS Code Version: 1.44.0
  • C/C++ Extension Version: 0.27.0

Issue 1:
When attaching to a program using cppdbg with processId as ${command:pickProcess}, the command pick does not wait for the preLaunchTask initialization/finalization, processId command pick should start just after the preLaunchTask finalization.

Issue 2:
Not able to pass environment variables values to cppdbg when attaching to a program, but is possible when launching. Why? Let's say I have a PID stored inside an environment variable and I would like to use this variable for the attach processId property, how I would do that?

Launch/Tasks examples:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "/mnt/ssd/Steam/steamapps/common/Half-Life/hl_linux",
            "processId": "${command:pickProcess}",
            "preLaunchTask": "attach",
            "MIMode": "gdb",
            //"additionalSOLibSearchPath": "/lib/i386-linux-gnu;/usr/lib/i386-linux-gnu/",
            "setupCommands": [
                /*                 {
                    "description": "Command-line arguments",
                    "text": "-exec set args ",
                }, */
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Auto load symbols when loading an .so file",
                    "text": "set auto-solib-add",
                    "ignoreFailures": false
                }
            ]
        },
    ]
}

{
    "version": "2.0.0",
    "options": {
        "env": {
            "GAME_ID": "xxxxxxxxxxxxx",
            "HL_PATH": "/mnt/ssd/Steam/steamapps/common/Half-Life",
            "HL_PID": ""
        }
    },
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "./linux/build.sh",
            "args": [],
            "group": "build",
            "isBackground": false,
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "presentation": {
                "reveal": "always",
                "panel": "shared"
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "attach",
            "type": "shell",
            "command": "./linux/attach.sh",
            "args": [],
            "group": "build",
            "isBackground": false,
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "presentation": {
                "reveal": "always",
                "panel": "shared"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "dependsOn": [
                "build"
            ]
        }
    ]
}

build/attach scripts:

#!/bin/bash

export AG_PATH=${HL_PATH}/ag
echo "HL_PATH: ${HL_PATH}"
echo "AG_PATH: ${AG_PATH}"
echo "GAME_ID: ${GAME_ID}"

dir=$(pwd)
echo "Starting build.."
git submodule update --init
mkdir -p build
cd build
cmake -DCMAKE_RULE_MESSAGES:BOOL=OFF -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=Debug ..
make --no-print-directory
#!/bin/bash

echo "GAME_ID: ${GAME_ID}"

dir=$(pwd)
echo "Killing olds hl_linux instances.."
killall hl_linux
/usr/bin/steam steam://rungameid/${GAME_ID} && sleep 5
#PID=$(pgrep -f "hl_linux" | xargs)
PID=$(pidof hl_linux)
export HL_PID=$PID
echo "hl_linux PID: ${HL_PID}"
debugger fixed (release pending)

All 5 comments

Issue 1:
When attaching to a program using cppdbg with processId as ${command:pickProcess}, the command pick does not wait for the preLaunchTask initialization/finalization, processId command pick should start just after the preLaunchTask finalization.

Unfortunately. preLaunchTask is handled by VSCode, they only guarantee that it will be completed before debug session starts. ${command:pickProcess} runs when VS Code calls resolveDebugConfiguration which is done also before the debug session starts. You will want to file an issue on the VS Code issues page to have a way to have the preLaunchTask complete before sending it to resolveDebugConfiguration.

Issue 2:
Not able to pass environment variables values to cppdbg when attaching to a program, but is possible when launching. Why? Let's say I have a PID stored inside an environment variable and I would like to use this variable for the attach processId property, how I would do that?

The environment configuration in launch is to set the debuggee processes' environment variables before starting up the debuggee process. During attach, there is no way for us to inject the environment variables into the debuggee process before attaching to the process.

Also setting up environment variables in tasks.json would require that VS Code uses the same terminal session for launching the debug adapter for the debugger to get the setup environment variables.

@WardenGnaw I will open an issue on the vscode issues page. Regarding the issue 2, vscode should provide a way to read the processId, reading an environment variable/file or something else, like process name or pidof... I will make a point about it on the issue.

VS Code has a way to provide custom inputs. I haven't tried this out myself, but this may possible with command inputs.

However, this may require a change on the extension side to use resolveDebugConfigurationWithSubstitutedVariables

VS Code has a way to provide custom inputs. I haven't tried this out myself, but this may possible with command inputs.

However, this may require a change on the extension side to use resolveDebugConfigurationWithSubstitutedVariables

I could help you with the changes.

Superuser access is required to attach to a process. Attaching as superuser can potentially harm your computer. Do you want to continue? [y/N]

Also, an option to pass y/n to the superuser confirmation directly from the launch.json would be nice. Something like "allowSuperuser": true

Was this page helpful?
0 / 5 - 0 ratings