Linux命令行pdb调试python脚本

Linux命令行pdb调试python脚本

shell脚本与py混合编程,因此无法在windows上使用pycharm调试py脚本,虽然也可以通过pycharm远程调试的方法,但是感觉不太方便。

task.sh如下

#!/bin/sh

'''
shell代码块
'''

python task1.py
python task2.py

这时调试py方便快捷就是pdb命令行了, 改写sh中py调用python -m pdb task1.py 然后执行到py就会自动停在py的第一行。pdb支持的调试命令简单有限。比较全面中文介绍

pdb常用命令:
命令	缩写	说明
break	b	设置断点
continue	cont/c	继续执行至下一个断点
next	n	执行下一行,如果下一行是子程序,不会进入子程序
step	s	执行下一行,如果下一行是子程序,会进如子程序
where	bt/w	打印堆栈轨迹
enable	-	启用禁用的断点
disable	-	禁用启用的断点
pp/p	-	打印变量或表达式
list	l	根据参数值打印源码
up	u	移动到上一层堆栈
down	d	移动到下一层堆栈
restart	run	重新开始调试
args	a	打印函数参数
clear	cl	清楚所有断点
return	r	执行到当前函数结束
quit	q	结束调试,退出当前程序

参考Python官方文档:
https://docs.python.org/3/library/pdb.html

pdb-cheatsheet

(Pdb) h

Documented commands (type help <topic>):
========================================
EOF    c          d        h         list      q        rv       undisplay
a      cl         debug    help      ll        quit     s        unt
alias  clear      disable  ignore    longlist  r        source   until
args   commands   display  interact  n         restart  step     up
b      condition  down     j         next      return   tbreak   w
break  cont       enable   jump      p         retval   u        whatis
bt     continue   exit     l         pp        run      unalias  where

Miscellaneous help topics:
==========================
exec  pdb

(Pdb) j n
*** The 'jump' command requires a line number
(Pdb) h n
n(ext)
        Continue execution until the next line in the current function
        is reached or it returns.
(Pdb)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章