开发者

gdbinit, pretty-printers, and relative directories?

In my ~/.gdbinit I would like to be able to reference the GDB python pretty-printers installed in my home directory via relative path:

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_printer开发者_运维知识库s
register_libstdcxx_printers (None)
end 

~/.gdb_viz contains the libstdcxx directory and associated python files.

How can I get something like #2 or #3 to work?

EDIT: Other than starting gdb from my home directory all the time :)

Common GDB info/output:

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/>...

"works" output:

Reading symbols from <executable>...done.

"doesn't work" output:

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.


Not tested, but should work:

python
import sys, os

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


I stick this in path_setup.py and run source ~/.gdb_viz/path_setup.py from my .gdbinit hadn't tested 3).

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜