新聞中心
bdb —- 調(diào)試器框架
源代碼: Lib/bdb.py

創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于網(wǎng)站制作、成都做網(wǎng)站、萊山網(wǎng)絡推廣、小程序開發(fā)、萊山網(wǎng)絡營銷、萊山企業(yè)策劃、萊山品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)建站為所有大學生創(chuàng)業(yè)者提供萊山建站搭建服務,24小時服務熱線:18982081108,官方網(wǎng)址:www.cdcxhl.com
bdb 模塊處理基本的調(diào)試器函數(shù),例如設置中斷點或通過調(diào)試器來管理執(zhí)行。
定義了以下異常:
exception bdb.BdbQuit
由 Bdb 類引發(fā)用于退出調(diào)試器的異常。
bdb 模塊還定義了兩個類:
class bdb.Breakpoint(self, file, line, temporary=False, cond=None, funcname=None)
這個類實現(xiàn)了臨時性中斷點、忽略計數(shù)、禁用與(重新)啟用,以及條件設置等。
中斷點通過一個名為 bpbynumber 的列表基于數(shù)字并通過 bplist 基于 (file, line) 對進行索引。 前者指向一個 Breakpoint 類的單獨實例。 后者指向一個由這種實例組成的列表,因為在每一行中可能存在多個中斷點。
When creating a breakpoint, its associated file name should be in canonical form. If a funcname is defined, a breakpoint hit will be counted when the first line of that function is executed. A conditional breakpoint always counts a hit.
Breakpoint 的實例具有下列方法:
-
deleteMe()
從關聯(lián)到文件/行的列表中刪除此中斷點。 如果它是該位置上的最后一個中斷點,還將刪除相應的文件/行條目。
-
enable()
將此中斷點標記為啟用。
-
disable()
將此中斷點標記為禁用。
-
bpformat()
返回一個帶有關于此中斷點的所有信息的,格式良好的字符串:
-
Breakpoint number.
-
Temporary status (del or keep).
-
File/line position.
-
Break condition.
-
Number of times to ignore.
-
Number of times hit.
3.2 新版功能.
-
-
bpprint(out=None)
將 bpformat() 的輸出打印到文件 out,或者如果為
None則打印到標準輸出。, to standard output.
Breakpoint instances have the following attributes:
-
file
File name of the Breakpoint.
-
line
Line number of the Breakpoint within file.
-
temporary
True if a Breakpoint at (file, line) is temporary.
-
cond
Condition for evaluating a Breakpoint at (file, line).
-
funcname
Function name that defines whether a Breakpoint is hit upon entering the function.
-
enabled
True if Breakpoint is enabled.
-
bpbynumber
Numeric index for a single instance of a Breakpoint.
-
bplist
Dictionary of Breakpoint instances indexed by (file, line) tuples.
-
ignore
Number of times to ignore a Breakpoint.
-
hits
Count of the number of times a Breakpoint has been hit.
class bdb.Bdb(skip=None)
Bdb 類是作為通用的 python 調(diào)試器基類。
這個類負責追蹤工具的細節(jié);所派生的類應當實現(xiàn)用戶交互。 標準調(diào)試器類 (pdb.Pdb) 就是一個例子。
如果給出了 skip 參數(shù),它必須是一個包含 glob 風格的模塊名稱模式的可迭代對象。 調(diào)試器將不會步進到來自與這些模式相匹配的模塊的幀。 一個幀是否會被視為來自特定的模塊是由幀的 __name__ 全局變量來確定的。
3.1 新版功能: skip 參數(shù)。
Bdb 的以下方法通常不需要被重載。
-
canonic(filename)
Return canonical form of filename.
For real file names, the canonical form is an operating-system-dependent, case-normalized absolute path. A filename with angle brackets, such as
"generated in interactive mode, is returned unchanged." -
reset()
將
botframe,stopframe,returnframe和quitting屬性設置為準備開始調(diào)試的值。 -
trace_dispatch(frame, event, arg)
此函數(shù)被安裝為被調(diào)試幀的追蹤函數(shù)。 它的返回值是新的追蹤函數(shù)(在大多數(shù)情況下就是它自身)。
默認實現(xiàn)會決定如何分派幀,這取決于即將被執(zhí)行的事件的類型(作為字符串傳入)。 event 可以是下列值之一:
-
"line": 一個新的代碼行即將被執(zhí)行。 -
"call": 一個函數(shù)即將被調(diào)用,或者進入了另一個代碼塊。 -
"return": 一個函數(shù)或其他代碼塊即將返回。 -
"exception": 一個異常已發(fā)生。 -
"c_call": 一個 C 函數(shù)即將被調(diào)用。 -
"c_return": 一個 C 函數(shù)已返回。 -
"c_exception": 一個 C 函數(shù)引發(fā)了異常。
對于 Python 事件,調(diào)用了專門的函數(shù)(見下文)。 對于 C 事件,不執(zhí)行任何操作。
arg 形參取決于之前的事件。
請參閱 sys.settrace() 的文檔了解追蹤函數(shù)的更多信息。 對于代碼和幀對象的詳情,請參考 標準類型層級結(jié)構(gòu)。
-
-
dispatch_line(frame)
如果調(diào)試器應當在當前行上停止,則發(fā)起調(diào)用 user_line() 方法(該方法應當在子類中被重載)。 如果設置了
Bdb.quitting旗標(可以通過 user_line() 設置)則將引發(fā) BdbQuit 異常。 返回一個對 trace_dispatch() 方法的引用以便在該作用域內(nèi)進一步地追蹤。 -
dispatch_call(frame, arg)
如果調(diào)試器應當在此函數(shù)調(diào)用上停止,則發(fā)起調(diào)用 user_call() 方法(該方法應當在子類中被重載)。 如果設置了
Bdb.quitting旗標(可以通過 user_call() 設置)則將引發(fā) BdbQuit 異常。 返回一個對 trace_dispatch() 方法的引用以便在該作用域內(nèi)進一步地追蹤。 -
dispatch_return(frame, arg)
如果調(diào)試器應當在此函數(shù)返回時停止,則發(fā)起調(diào)用 user_return() 方法(該方法應當在子類中被重載)。 如果設置了
Bdb.quitting旗標(可以通過 user_return() 設置)則將引發(fā) BdbQuit 異常。 返回一個對 trace_dispatch() 方法的引用以便在該作用域內(nèi)進一步地追蹤。 -
dispatch_exception(frame, arg)
如果調(diào)試器應當在此異常上停止,則發(fā)起調(diào)用 user_exception() 方法(該方法應當在子類中被重載)。 如果設置了
Bdb.quitting旗標(可以通過 user_exception() 設置)則將引發(fā) BdbQuit 異常。 返回一個對 trace_dispatch() 方法的引用以便在該作用域內(nèi)進一步地追蹤。
通常情況下派生的類不會重載下列方法,但是如果想要重新定義停止和中斷點的定義則可能會重載它們。
-
is_skipped_line(module_name)
Return True if module_name matches any skip pattern.
-
stop_here(frame)
Return True if frame is below the starting frame in the stack.
-
break_here(frame)
Return True if there is an effective breakpoint for this line.
Check whether a line or function breakpoint exists and is in effect. Delete temporary breakpoints based on information from effective().
-
break_anywhere(frame)
Return True if any breakpoint exists for frame‘s filename.
派生的類應當重載這些方法以獲取調(diào)試器操作的控制權。
-
user_call(frame, argument_list)
Called from dispatch_call() if a break might stop inside the called function.
-
user_line(frame)
Called from dispatch_line() when either stop_here() or break_here() returns
True. -
user_return(frame, return_value)
Called from dispatch_return() when stop_here() returns
True. -
user_exception(frame, exc_info)
Called from dispatch_exception() when stop_here() returns
True. -
do_clear(arg)
處理當一個中斷點屬于臨時性中斷點時是否必須要移除它。
此方法必須由派生類來實現(xiàn)。
派生類與客戶端可以調(diào)用以下方法來影響步進狀態(tài)。
-
set_step()
在一行代碼之后停止。
-
set_next(frame)
在給定的幀以內(nèi)或以下的下一行停止。
-
set_return(frame)
當從給定的幀返回時停止。
-
set_until(frame, lineno=None)
Stop when the line with the lineno greater than the current one is reached or when returning from current frame.
-
set_trace([frame])
從 frame 開始調(diào)試。 如果未指定 frame,則從調(diào)用者的幀開始調(diào)試。
-
set_continue()
僅在中斷點上或是當結(jié)束時停止。 如果不存在中斷點,則將系統(tǒng)追蹤函數(shù)設為
None。 -
set_quit()
將
quitting屬性設為True。 這將在對某個dispatch_*()方法的下一次調(diào)用中引發(fā) BdbQuit。
派生的類和客戶端可以調(diào)用下列方法來操縱中斷點。 如果出現(xiàn)錯誤則這些方法將返回一個包含錯誤消息的字符串,或者如果一切正常則返回 None。
-
set_break(filename, lineno, temporary=False, cond=None, funcname=None)
設置一個新的中斷點。 如果對于作為參數(shù)傳入的 filename 不存在 lineno,則返回一條錯誤消息。 filename 應為規(guī)范的形式,如在 canonic() 方法中描述的。
-
clear_break(filename, lineno)
Delete the breakpoints in filename and lineno. If none were set, return an error message.
-
clear_bpbynumber(arg)
刪除 Breakpoint.bpbynumber 中索引號為 arg 的中斷點。 如果 arg 不是數(shù)字或超出范圍,則返回一條錯誤消息。
-
clear_all_file_breaks(filename)
Delete all breakpoints in filename. If none were set, return an error message.
-
clear_all_breaks()
Delete all existing breakpoints. If none were set, return an error message.
-
get_bpbynumber(arg)
返回由指定數(shù)字所指明的中斷點。 如果 arg 是一個字符串,它將被轉(zhuǎn)換為一個數(shù)字。 如果 arg 不是一個表示數(shù)字的字符串,如果給定的中斷點不存在或者已被刪除,則會引發(fā) ValueError。
3.2 新版功能.
-
get_break(filename, lineno)
Return True if there is a breakpoint for lineno in filename.
-
get_breaks(filename, lineno)
返回 filename 中在 lineno 上的所有中斷點,或者如果未設置任何中斷點則返回一個空列表。
-
get_file_breaks(filename)
返回 filename 中的所有中斷點,或者如果未設置任何中斷點則返回一個空列表。
-
get_all_breaks()
返回已設置的所有中斷點。
派生類與客戶端可以調(diào)用以下方法來獲取一個代表?;厮菪畔⒌臄?shù)組結(jié)構(gòu)。
-
get_stack(f, t)
Return a list of (frame, lineno) tuples in a stack trace, and a size.
The most recently called frame is last in the list. The size is the number of frames below the frame where the debugger was invoked.
-
format_stack_entry(frame_lineno, lprefix=’: ‘)
Return a string with information about a stack entry, which is a
(frame, lineno)tuple. The return string contains:-
The canonical filename which contains the frame.
-
The function name or
"." -
輸入?yún)?shù)。
-
返回值。
-
代碼的行(如果存在)。
-
以下兩個方法可由客戶端調(diào)用以使用一個調(diào)試器來調(diào)試一條以字符串形式給出的 statement。
-
run(cmd, globals=None, locals=None)
調(diào)試一條通過 exec() 函數(shù)執(zhí)行的語句。 globals 默認為
__main__.__dict__,locals 默認為 globals。 -
runeval(expr, globals=None, locals=None)
調(diào)試一條通過 eval() 函數(shù)執(zhí)行的表達式。 globals 和 locals 的含義與在 run() 中的相同。
-
runctx(cmd, globals, locals)
為了保證向下兼容性。 調(diào)用 run() 方法。
-
runcall(func, /, \args, **kwds*)
調(diào)試一個單獨的函數(shù)調(diào)用,并返回其結(jié)果。
最后,這個模塊定義了以下函數(shù):
bdb.checkfuncname(b, frame)
Return True if we should break here, depending on the way the Breakpoint b was set.
If it was set via line number, it checks if b.line is the same as the one in frame. If the breakpoint was set via function name, we have to check we are in the right frame (the right function) and if we are on its first executable line.
bdb.effective(file, line, frame)
Return (active breakpoint, delete temporary flag) or (None, None) as the breakpoint to act upon.
The active breakpoint is the first entry in bplist for the (file, line) (which must exist) that is enabled, for which checkfuncname() is True, and that has neither a False condition nor positive ignore count. The flag, meaning that a temporary breakpoint should be deleted, is False only when the cond cannot be evaluated (in which case, ignore count is ignored).
If no such entry exists, then (None, None) is returned.
bdb.set_trace()
使用一個來自調(diào)用方的幀的 Bdb 實例開始調(diào)試。
分享名稱:創(chuàng)新互聯(lián)Python教程:bdb—-調(diào)試器框架
新聞來源:http://m.fisionsoft.com.cn/article/dpoispo.html


咨詢
建站咨詢
