gpt4 book ai didi

c++ - gdbinit、 pretty-print 和相关目录?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:48:19 26 4
gpt4 key购买 nike

在我的 ~/.gdbinit 中,我希望能够通过相对路径引用安装在我的主目录中的 GDB python pretty-print :

python
import sys
# 1, works
sys.path.insert(0, '/home/<username>/.gdb_viz')
# 2, doesn't work
# sys.path.insert(0, '~/.gdb_viz')
# 3, doesn't work
# sys.path.insert(0, '.gdb_viz')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

~/.gdb_viz 包含 libstdcxx 目录和关联的 python 文件。

我怎样才能使#2 或#3 之类的东西起作用?

编辑: 除了始终从我的主目录启动 gdb :)

通用 GDB 信息/输出:

GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 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-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...

“有效”输出:

Reading symbols from <executable>...done.

“不起作用”输出:

Traceback (most recent call last):
File "<string>", line 3, in <module>
ImportError: No module named libstdcxx.v6.printers
/home/<username>/.gdbinit:6: Error in sourced command file:
Error while executing Python code.
Reading symbols from <executable>...done.

最佳答案

未测试,但应该可以:

python
import sys, os

sys.path.insert(0, os.getenv('HOME') + '/.gdb_viz')

关于c++ - gdbinit、 pretty-print 和相关目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6922093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com