Python Learning note 012--pdb debugging

Source: Internet
Author: User

1 description

The PDB is a Python-brought package that provides an interactive source code debugging function for Python programs.

Key features include setting breakpoints, stepping through debugging, entering function debugging, viewing current code, viewing stack fragments, dynamically changing the values of variables, etc.

Debug function:

Allows the program to step through, observing intermediate results

Specify breakpoints can be set for specific position observation

2 Debugging commands

Full command Shorthand command Describe
Args A Print the parameters of the current function
Break B Set breakpoints
Clear Cl Clear breakpoints
Condition No Set conditional breakpoints
Continue C or cont Continue running, knowing that a breakpoint was encountered or the script ended
Disable No disabling breakpoints
Enable No Enable breakpoints
Help H View PDB Help
Ignore No Ignore Breakpoint
Jump J Jump to a specified number of rows run
List L List script lists
Next N Executes the next statement, encountering a function that does not enter its interior
P P Print variable values, or you can
Quit Q Exit PDB
Return R Run until function returns
Tbreak No Set a temporary breakpoint, break only once
Step S Executes the next statement, encounters a function into its internal
where W See where you are
! No Executing statements in the PDB

Attention:

1: Enter enter directly, will execute the previous command;

2: Enter a command that the PDB does not know, and the PDB will execute it as a Python statement in the current environment;

3 Example 3.1 Example 1 (test code)
1 Import PDB 2 " AAA " 3 pdb.set_trace () 4 " BBB " 5 " CCC " 6 final = a + B + c7print(final)
Run
>/home/tarena/Desktop/t.py (4) <module>()b ="BBB"(PDB) n>/home/tarena/Desktop/t.py (5) <module>()c ="CCC"(PDB)>/home/tarena/Desktop/t.py (6) <module>()Final = a + B +C (Pdb)>/home/tarena/Desktop/t.py (7) <module>()-Print(Final) (PDB) AAABBBCCC--return-->/home/tarena/Desktop/t.py (7) <module> ()None-Print(Final) (PDB)

To start Debugging:

Run the script directly, will stay at Pdb.set_trace () , pdb.set_trace () function : From the pdb.set_trace () position to enter the debug state, The code that follows the statement is stepping .

Select N+enter to perform the current statement. After you press N+enter for the first time, you can press ENTER directly to repeat the previous debug command.

Importpdbpdb.set_trace ()defA (n):Print(n + 1)    Print(n + 2)    Print(n + 3)    Print(n + 4)    Print(n + 5)    Print(n + 6)defb (n):Print('b', N) A (n+ 1)    Print("B End")defC (): X= 100B (x+ 100) C ()

Run

>/home/tarena/Desktop/t.py (4) <module>()def  A (n):(Pdb) n>/home/tarena/Desktop/t.py ( <module>()def>/home/tarena/Desktop/t.py (+) <module>()def >/home/tarena/Desktop/t.py (+) <module>()200202203204205206207 b   End --return-->/home/tarena/Desktop/t.py (<module>),None,
3.2 Example 2 (code debugging)

Detailed code

https://www.ibm.com/developerworks/cn/linux/l-cn-pythondebugger/

Https://docs.python.org/3.6/library/pdb.html

Python Learning note 012--pdb debugging

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.