注意是gdb通过python脚本来调试程序,不是调试python代码,和pdb不是一回事
理解为gdb进程里实现了python虚拟机就可以了
参考
https://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html#Python-API
错误方式1:
点击(此处)折叠或打开
- [root@second ~]# python
- Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
- [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import gdb
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- ImportError: No module named gdb
- >>>
错误方式2:
点击(此处)折叠或打开
- [root@second ~]# cd /usr/share/gdb/python/
- gdb/ libstdcxx/
- [root@second ~]# cd /usr/share/gdb/python/
- [root@second python]# python
- Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
- [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import gdb
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "gdb/__init__.py", line 19, in <module>
- import gdb.command.require
- File "gdb/command/require.py", line 21, in <module>
- class RequireCommand (gdb.Command):
- AttributeError: 'module' object has no attribute 'Command'
正确方式
1.py内容
点击(此处)折叠或打开
-
import gdb
- help(gdb)
点击(此处)折叠或打开
- [root@second ~]# gdb -q -x 1.py
- Help on package gdb:
- NAME
- gdb
- FILE
- (built-in)
- PACKAGE CONTENTS
- FrameIterator
- FrameWrapper
- backtrace
- command (package)
- function (package)
- CLASSES
- __builtin__.object
- Block
- BlockIterator
- Breakpoint
- Command
- Field
- Frame
- Function
- Inferior
- InferiorThread
- Membuf
- Objfile
- Parameter
- Progspace
- Symbol
- Symtab
- Symtab_and_line
- Type
- Value
- exceptions.Exception(exceptions.BaseException)
- GdbError
- class Block(__builtin__.object)
待续