3. PDB 常用指令介紹
1. break
2. clear
3. step
4. next
5. return
6. continue
7. jump
8. list
9. p
*可惜 pdb 無法做到監看變數改變的功能
4. What is frame?
● 儲存 function 執行時的相關資訊,如區域變
數、函數位址等資訊。
● 作用像 C 的 call stack( run-time stack )。
5. PyFrameObject
f_back next outer frame object (this frame’s caller)
f_code code object being executed in this frame
f_exc_traceback traceback if raised in this frame, or None
f_exc_type exception type if raised in this frame, or None
f_exc_value exception value if raised in this frame, or None
f_globals global namespace seen by this frame
f_lineno current line number in Python source code
f_locals local namespace seen by this frame
f_trace tracing function for this frame, or None
REF: http://docs.python.org/2/library/inspect.html
7. More Details
f_trace, if not None, is a function called at the start of each source code line
(this is used by the debugger)
f_lineno is the current line number of the frame — writing to this from within a
trace function jumps to the given line (only for the bottom-most frame).
8. sys._getframe([depth])¶
Return a frame object from the call stack. If optional integer depth is given,
return the frame object that many calls below the top of the stack. If that is
deeper than the call stack, ValueError is raised. The default for depthis zero,
returning the frame at the top of the call stack.
sys.settrace(tracefunc)
Set the system’s trace function, which allows you to implement a Python source
code debugger in Python. The function is thread-specific; for a debugger to
support multiple threads, it must be registered using settrace() for each thread
being debugged.
9. why?
it must be registered using settrace() for each thread being debugged.
Because: each thread have their own starck. In the python, the stack means
the frame.
process
thread
process
thread thread thread
16. recoverable_pdb
● github: https://github.com/ya790206/recoverable_pdb
● Like time machine, you can recover the runtime to the
point you save.
● addition command:
○ save point_name: save the current frame to the point.
○ restore point_name: restore frame from the frame you
saved.
○ diff point_name: compare the current frame and the
another you saved.
● limit:
○ same as jump command.
○ it can't recover file or database.
18. Thanks all
thanks for all listener, taipei.py, and the
manx.
Taipe pyi: http://www.meetup.
com/Taipei-py/
The manx:
http://www.themanxgroup.tw/
The manx production:
http://lucky-lane.com/