'vscode how to supply gdb with the processId automatically

I've been building a C++ dll which then gets loaded into another process that loads it. I've been trying to find a solution so that whenever I hit F5, it will automatically attach itself to that external process without me having to provide the processId from the list, but I haven't found any solutions specific to my language. Do anyone have a solution?

This is my current launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attatch to process",
            "type": "cppdbg",
            "request": "attach",
            "program": "D:\\myapp.exe",
            "processId": "${command:pickProcess}",
            "stopAtEntry": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ]
        }
    ]
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source