gdbinit,漂亮的打印机和相关目录?

时间:2011-08-03 05:35:20

标签: c++ python gdb

在我的~/.gdbinit中,我希望能够通过相对路径引用我主目录中安装的GDB python漂亮打印机:

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.

2 个答案:

答案 0 :(得分:3)

未经测试,但应该有效:

python
import sys, os

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

答案 1 :(得分:1)

我坚持使用path_setup.py 并运行source~ / .gdb_viz / path_setup.py 来自我的.gdbinit 没有测试3)。

# Add the path of this script to pythons search path. 
import os, sys

sys.path.append(os.path.expanduser(os.path.dirname(__file__)))