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	结束调试,退出当前程序

b lineNo/funcName  设置断点
b 列出所有断点
没有删除断点的命令,可以启动/禁用断点
enable / disable 无缩写

参考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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值