What is it

pdbx: A remote pdb debugger base on pdb. It's:
  1. be compatible with pdb
  2. remote debug supported
  3. xq/xquit commands supported
    • quit safely from debugger, the program being executed is continued(not abored)
  4. redebug supported
  5. suspend mode supported

软件介绍

pdbx: 一款基于pdb的远程pdb调试工具,主要特性有:
  1. 和pdb完全兼容
  2. 支持远程调试功能
  3. 支持xq/xquit命令
    • 安全退出命令: 使用xq/xquit退出调试,执行的Python脚本会继续执行,而不中断退出(对q/quit命令的改善)
  4. 支持重复调试
  5. 支持suspend模式
    • 强制或者非强制进入断点

Installing pdbx

  1. Download pdbx from https://code.google.com/p/stonelab/downloads/list or https://pypi.python.org/pypi
  2. Unpack the archive
    • tar xvf pdbx-x.x.x.tar.gz
  3. Install pdbx
    • sudo python setup.py install

安装pdbx

  1. 从https://code.google.com/p/stonelab/downloads/list 或者 https://pypi.python.org/pypi下载pdbx
  2. 解压压缩包
    • tar xvf pdbx-x.x.x.tar.gz
  3. 安装pdbx
    • sudo python setup.py install

How to use pdbx

  1. Add pbdx in python scripts
  2. from pdbx import Rpdb
    rpdb = Rpdb()                # Debugger started. Port is 8787(Default Value),   Suspend is True(Default Value)
    rpdb = Rpdb(9898)            # Debugger started. Port is 9898(Specified Value), Suspend is True(Default Value)
    rpdb = Rpdb(suspend=False)   # Debugger started. Port is 8787(Default Value),   Suspend is False(Specified Value) 
    rpdb = Rpdb(9898, False)     # Debugger started. Port is 9898(Specified Value), Suspend is False(Specified Value) 
    rpdb.set_trace()
  3. Remote debug with telnet
  4. telnet xxx.xxx.xxx.xxx 8787
  5. Interact with pdb commands
  6. Documented commands (type help <topic>):
    ========================================
    EOF    bt         cont      enable  jump  pp       run      unt     xq   
    a      c          continue  exit    l     q        s        until   xquit
    alias  cl         d         h       list  quit     step     up    
    args   clear      debug     help    n     r        tbreak   w     
    b      commands   disable   ignore  next  restart  u        whatis
    break  condition  down      j       p     return   unalias  where
    
    xq/xquit are new commands in pdbx
    it's used to quit safely from debugger, the program being executed is continued(not abored)
  7. Re-Remote debug with telnet
    • telnet again.

如何使用pdbx

  1. 在python脚本中添加pdbx代码,设置断点
  2. from pdbx import Rpdb
    rpdb = Rpdb()                # 启动调试,默认端口8787,强制断点
    rpdb = Rpdb(9898)            # 启动调试,指定端口9898,强制断点
    rpdb = Rpdb(suspend=False)   # 启动调试,默认端口8787,非强制断点
    rpdb = Rpdb(9898, False)     # 启动调试,指定端口9898, 非强制断点
    rpdb.set_trace()
  3. 通过telnet,进入远程调试
  4. telnet xxx.xxx.xxx.xxx 8787
  5. 使用pdb命令,进入调试交互状态
  6. Documented commands (type help <topic>):
    ========================================
    EOF    bt         cont      enable  jump  pp       run      unt     xq   
    a      c          continue  exit    l     q        s        until   xquit
    alias  cl         d         h       list  quit     step     up    
    args   clear      debug     help    n     r        tbreak   w     
    b      commands   disable   ignore  next  restart  u        whatis
    break  condition  down      j       p     return   unalias  where
    
    xq/xquit是pdbx新加的命令
    使用安全退出模式,执行xq/xquit,远程python脚本自动运行,而非被强制中断退出,是对pdb q/quit命令的改善。
  7. 重复调试
    • 使用telnet再次进入调试状态

Release Notes

发布说明

Author Info

sample(演示)

telnet 127.0.0.1 8787
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
--Return--
> /Library/Python/2.7/site-packages/pdbx/pdbx.py(133)set_trace()->None
-> Pdb.set_trace(self, frame=frame)
(Pdb) n
> /Users/stone/Tmp/sample.py(25)main()
-> rpdb.set_trace()
(Pdb) n
> /Users/stone/Tmp/sample.py(26)main()
-> i = random.randint(1, 10)
(Pdb) l  
 21         # rpdb = Rpdb(9898)          # Debugger started. Port is 9898(Specified Value), Suspend is True(Default Value)
 22         # rpdb = Rpdb(suspend=False) # Debugger started. Port is 8787(Default Value),   Suspend is False(Specified Value) 
 23         # rpdb = Rpdb(9898, False)   # Debugger started. Port is 9898(Specified Value), Suspend is False(Specified Value) 
 24         while True:
 25             rpdb.set_trace()
 26  ->          i = random.randint(1, 10)
 27             j = random.randint(1, 10)
 28             r = add(i, j)
 29             print r
 30             time.sleep(1)
 31     
(Pdb) b 29
Breakpoint 2 at /Users/stone/Tmp/sample.py:29
(Pdb) c
> /Users/stone/Tmp/sample.py(29)main()
-> print r
(Pdb) p r
9
(Pdb) help xq
xq(uit) - Quit safely from the debugger.
The program being executed is continued(not abored).
(Pdb) xq
Connection closed by foreign host.