Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1104282
  • 博文数量: 170
  • 博客积分: 1603
  • 博客等级: 上尉
  • 技术积分: 1897
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-09 15:54
文章分类

全部博文(170)

文章存档

2016年(27)

2015年(21)

2014年(27)

2013年(21)

2012年(7)

2011年(67)

我的朋友

分类: Python/Ruby

2015-08-04 23:28:29

注意是gdb通过python脚本来调试程序,不是调试python代码,和pdb不是一回事

理解为gdb进程里实现了python虚拟机就可以了
 
 
参考

https://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html#Python-API


错误方式1:
 

点击(此处)折叠或打开

  1. [root@second ~]# python
  2. Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
  3. [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import gdb
  6. Traceback (most recent call last):
  7. File "<stdin>", line 1, in <module>
  8. ImportError: No module named gdb
  9. >>>

错误方式2:

点击(此处)折叠或打开

  1. [root@second ~]# cd /usr/share/gdb/python/
  2. gdb/ libstdcxx/
  3. [root@second ~]# cd /usr/share/gdb/python/
  4. [root@second python]# python
  5. Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
  6. [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
  7. Type "help", "copyright", "credits" or "license" for more information.
  8. >>> import gdb
  9. Traceback (most recent call last):
  10. File "<stdin>", line 1, in <module>
  11. File "gdb/__init__.py", line 19, in <module>
  12. import gdb.command.require
  13. File "gdb/command/require.py", line 21, in <module>
  14. class RequireCommand (gdb.Command):
  15. AttributeError: 'module' object has no attribute 'Command'


正确方式


 1.py内容

点击(此处)折叠或打开

  1. import gdb
  2. help(gdb)


点击(此处)折叠或打开

  1. [root@second ~]# gdb -q -x 1.py
  2. Help on package gdb:
  3. NAME
  4. gdb
  5. FILE
  6. (built-in)
  7. PACKAGE CONTENTS
  8. FrameIterator
  9. FrameWrapper
  10. backtrace
  11. command (package)
  12. function (package)
  13. CLASSES
  14. __builtin__.object
  15. Block
  16. BlockIterator
  17. Breakpoint
  18. Command
  19. Field
  20. Frame
  21. Function
  22. Inferior
  23. InferiorThread
  24. Membuf
  25. Objfile
  26. Parameter
  27. Progspace
  28. Symbol
  29. Symtab
  30. Symtab_and_line
  31. Type
  32. Value
  33. exceptions.Exception(exceptions.BaseException)
  34. GdbError
  35. class Block(__builtin__.object)

待续
阅读(3638) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~