gdb不能在macOS catalina上与Visual Studio一起运行

问题描述

我在macOS catalina上有一个小的hello-world c ++代码,并且brew附带安装了g ++ / gdb。 我正在尝试使用visual-studio-code调试此程序,但无法运行它。

当我在vs代码中“运行>开始调试”时,出现错误

ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run".
Unable to find Mach task port for process-id 2400: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))

然后,要解决此问题,我已完成以下步骤:

最初,我尝试从命令行运行gdb,以检查其是否正常工作:

$g++ -g hello.cpp
$./a.out # this prints hello message as expected
$gdb -v --> this is 9.2
$ls -ls a.out
    96 -rwxr-xr-x  1 ... a.out --> so executable permissions are correct
$gdb ./a.out
    Reading symbols from ./a.out...
    Reading symbols from .../a.out...
  > run
    Starting program: .../a.out 
    Unable to find Mach task port for process-id 2003: (os/kern) failure (0x5).
        (please check gdb is codesigned - see taskgated(8))

搜索一个解决方案,并执行了以下操作:

  1. 按照link的说明对调试器进行代码签名。我还对原始可执行文件和符号链接进行了代码签名。
  2. 还遵循了link上的修改说明,
  3. 重新启动Mac

仍然,我遇到了同样的错误,但问题仍未得到解决

我还尝试了将gdb版本降级为8.01解决方案, 但是后来我遇到了另一个错误-可执行文件未被识别, 那是一个已知的gdb错误,已在9.2中修复,因此我回到了较新的版本。

然后按照解决方62563627运行:

$sudo gdb ./a.out --> this command worked
    Reading symbols from ./a.out...
    Reading symbols from .../a.out...
  > run
    Starting program: .../a.out 
    [New Thread 0xe03 of process 2528]
    [New Thread 0x1703 of process 2528]
    warning: unhandled dyld version (16)
    Hello C++ World from VS Code and the C++ extension! 
    [Inferior 1 (process 2528) exited normally]

因此,现在gdb可从命令行运行,但仅适用于sudo。

但是,我不能使用sudo,因为我的目标是从vs代码内部运行gdb。 所以我检查了gdb的权限,它们具有管理员权限:

$ls -ls /usr/local/bin/gdb
0 lrwxr-xr-x  1 rog  admin  27 Aug 29 16:05 /usr/local/bin/gdb -> ../Cellar/gdb/9.2_1/bin/gdb
$ls -ls /usr/local/Cellar/gdb/9.2_1/bin/gdb
50368 -rwxr-xr-x   1 rog  admin  25786928 Aug 29 16:09 gdb

那么,不使用sudo就能使gdb工作的解决方案是什么,希望可以使其在vs代码中工作?或者,还有其他方法可以使其与vs代码一起使用吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)