微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

msys2 中的 gdb 无法正常工作点击“运行”后,“ModuleNotFoundError”和“无法插入断点”

如何解决msys2 中的 gdb 无法正常工作点击“运行”后,“ModuleNotFoundError”和“无法插入断点”

使用 Mingw-w64 编译一个简单的程序之后:

#include <stdio.h>

int main(int argc,char** argv) {

        printf("hello world");
        return 0;
}

通过运行:

gcc -g test.c

如果我尝试通过运行以下命令对生成的可执行文件执行 gdb:

gdb ./a

我得到这个输出

GNU gdb (GDB) 9.2
copyright (C) 2020 Free Software Foundation,Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY,to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-msys".
Type "show configuration" for configuration details.
For bug reporting instructions,please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help,type "help".
Type "apropos word" to search for commands related to "word"...
Traceback (most recent call last):
  File "<string>",line 3,in <module>
ModuleNotFoundError: No module named 'libstdcxx'
/etc/gdbinit:6: Error in sourced command file:
Error while executing Python code.
Reading symbols from ./a...

此外,如果我尝试设置断点然后运行程序,我会收到几个警告,然后进程被中止。

(gdb) break main
Breakpoint 1 at 0x1400015a8: file main.c,line 5.
(gdb) run
Starting program: /c/Users/gianm/Desktop/a
[New Thread 17704.0x2d54]
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x1400015a3

Command aborted.

这在一个月前还可以正常工作,但现在它表现出这种奇怪的行为,我似乎无法找到解决方案。

如果有帮助,这是我的配置:

(gdb) show configuration
This GDB was configured as follows:
   configure --host=x86_64-pc-msys --target=x86_64-pc-msys
             --with-auto-load-dir=$debugdir:$datadir/auto-load
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load
             --with-expat
             --with-gdb-datadir=/usr/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/lib/gdb (relocatable)
             --without-libunwind-ia64
             --with-lzma
             --without-babeltrace
                             --without-intel-pt
             --with-mpfr
             --without-xxhash
             --with-python=/usr (relocatable)
             --without-guile
             --disable-source-highlight
             --with-separate-debug-dir=/usr/lib/debug (relocatable)
             --with-system-gdbinit=/etc/gdbinit

("Relocatable" means the directory can be moved with the GDB installation
tree,and GDB will still find it.)

不确定它是否相关,但我正在从 Windows Powershell 运行 msys2 的 gcc 和 gdb 实现(我已将 C:\msys64\usr\binC:\msys64\mingw64\bin 添加到我的路径系统变量中)。

编辑:这是 etc/gdbinit 的内容

python
import sys
sys.path.insert(0,sys.path[0] + '/../../gcc-9.3.0/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。