If you install according to https://code.visualstudio.com/docs/cpp/config-mingw, MSYS2.exe direct install.
check if your path: \msys64\mingw64\bin is empty? if it is empty, it shows the gdb is missing. Follow my step 2
open this website, https://packages.msys2.org/packages/mingw-w64-x86_64-gdb, copy the installation comman: pacman -S mingw-w64-x86_64-gdb
open the MSYS2 installed in your computer, past: pacman -S mingw-w64-x86_64-gdb, the comman you copied in step 2.
if you see the path: \msys64\mingw64\bin is filled with files. You're successeful. Open a cmd window, and input: gbd --version.