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

創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站制作、成都做網(wǎng)站、萊山網(wǎng)絡(luò)推廣、小程序開(kāi)發(fā)、萊山網(wǎng)絡(luò)營(yíng)銷、萊山企業(yè)策劃、萊山品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)建站為所有大學(xué)生創(chuàng)業(yè)者提供萊山建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:www.cdcxhl.com
bdb 模塊處理基本的調(diào)試器函數(shù),例如設(shè)置中斷點(diǎn)或通過(guò)調(diào)試器來(lái)管理執(zhí)行。
定義了以下異常:
exception bdb.BdbQuit
由 Bdb 類引發(fā)用于退出調(diào)試器的異常。
bdb 模塊還定義了兩個(gè)類:
class bdb.Breakpoint(self, file, line, temporary=False, cond=None, funcname=None)
這個(gè)類實(shí)現(xiàn)了臨時(shí)性中斷點(diǎn)、忽略計(jì)數(shù)、禁用與(重新)啟用,以及條件設(shè)置等。
中斷點(diǎn)通過(guò)一個(gè)名為 bpbynumber 的列表基于數(shù)字并通過(guò) bplist 基于 (file, line) 對(duì)進(jìn)行索引。 前者指向一個(gè) Breakpoint 類的單獨(dú)實(shí)例。 后者指向一個(gè)由這種實(shí)例組成的列表,因?yàn)樵诿恳恍兄锌赡艽嬖诙鄠€(gè)中斷點(diǎn)。
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 的實(shí)例具有下列方法:
-
deleteMe()
從關(guān)聯(lián)到文件/行的列表中刪除此中斷點(diǎn)。 如果它是該位置上的最后一個(gè)中斷點(diǎn),還將刪除相應(yīng)的文件/行條目。
-
enable()
將此中斷點(diǎn)標(biāo)記為啟用。
-
disable()
將此中斷點(diǎn)標(biāo)記為禁用。
-
bpformat()
返回一個(gè)帶有關(guān)于此中斷點(diǎn)的所有信息的,格式良好的字符串:
-
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則打印到標(biāo)準(zhǔn)輸出。, 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)試器基類。
這個(gè)類負(fù)責(zé)追蹤工具的細(xì)節(jié);所派生的類應(yīng)當(dāng)實(shí)現(xiàn)用戶交互。 標(biāo)準(zhǔn)調(diào)試器類 (pdb.Pdb) 就是一個(gè)例子。
如果給出了 skip 參數(shù),它必須是一個(gè)包含 glob 風(fēng)格的模塊名稱模式的可迭代對(duì)象。 調(diào)試器將不會(huì)步進(jìn)到來(lái)自與這些模式相匹配的模塊的幀。 一個(gè)幀是否會(huì)被視為來(lái)自特定的模塊是由幀的 __name__ 全局變量來(lái)確定的。
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屬性設(shè)置為準(zhǔn)備開(kāi)始調(diào)試的值。 -
trace_dispatch(frame, event, arg)
此函數(shù)被安裝為被調(diào)試幀的追蹤函數(shù)。 它的返回值是新的追蹤函數(shù)(在大多數(shù)情況下就是它自身)。
默認(rèn)實(shí)現(xiàn)會(huì)決定如何分派幀,這取決于即將被執(zhí)行的事件的類型(作為字符串傳入)。 event 可以是下列值之一:
-
"line": 一個(gè)新的代碼行即將被執(zhí)行。 -
"call": 一個(gè)函數(shù)即將被調(diào)用,或者進(jìn)入了另一個(gè)代碼塊。 -
"return": 一個(gè)函數(shù)或其他代碼塊即將返回。 -
"exception": 一個(gè)異常已發(fā)生。 -
"c_call": 一個(gè) C 函數(shù)即將被調(diào)用。 -
"c_return": 一個(gè) C 函數(shù)已返回。 -
"c_exception": 一個(gè) C 函數(shù)引發(fā)了異常。
對(duì)于 Python 事件,調(diào)用了專門(mén)的函數(shù)(見(jiàn)下文)。 對(duì)于 C 事件,不執(zhí)行任何操作。
arg 形參取決于之前的事件。
請(qǐng)參閱 sys.settrace() 的文檔了解追蹤函數(shù)的更多信息。 對(duì)于代碼和幀對(duì)象的詳情,請(qǐng)參考 標(biāo)準(zhǔn)類型層級(jí)結(jié)構(gòu)。
-
-
dispatch_line(frame)
如果調(diào)試器應(yīng)當(dāng)在當(dāng)前行上停止,則發(fā)起調(diào)用 user_line() 方法(該方法應(yīng)當(dāng)在子類中被重載)。 如果設(shè)置了
Bdb.quitting旗標(biāo)(可以通過(guò) user_line() 設(shè)置)則將引發(fā) BdbQuit 異常。 返回一個(gè)對(duì) trace_dispatch() 方法的引用以便在該作用域內(nèi)進(jìn)一步地追蹤。 -
dispatch_call(frame, arg)
如果調(diào)試器應(yīng)當(dāng)在此函數(shù)調(diào)用上停止,則發(fā)起調(diào)用 user_call() 方法(該方法應(yīng)當(dāng)在子類中被重載)。 如果設(shè)置了
Bdb.quitting旗標(biāo)(可以通過(guò) user_call() 設(shè)置)則將引發(fā) BdbQuit 異常。 返回一個(gè)對(duì) trace_dispatch() 方法的引用以便在該作用域內(nèi)進(jìn)一步地追蹤。 -
dispatch_return(frame, arg)
如果調(diào)試器應(yīng)當(dāng)在此函數(shù)返回時(shí)停止,則發(fā)起調(diào)用 user_return() 方法(該方法應(yīng)當(dāng)在子類中被重載)。 如果設(shè)置了
Bdb.quitting旗標(biāo)(可以通過(guò) user_return() 設(shè)置)則將引發(fā) BdbQuit 異常。 返回一個(gè)對(duì) trace_dispatch() 方法的引用以便在該作用域內(nèi)進(jìn)一步地追蹤。 -
dispatch_exception(frame, arg)
如果調(diào)試器應(yīng)當(dāng)在此異常上停止,則發(fā)起調(diào)用 user_exception() 方法(該方法應(yīng)當(dāng)在子類中被重載)。 如果設(shè)置了
Bdb.quitting旗標(biāo)(可以通過(guò) user_exception() 設(shè)置)則將引發(fā) BdbQuit 異常。 返回一個(gè)對(duì) trace_dispatch() 方法的引用以便在該作用域內(nèi)進(jìn)一步地追蹤。
通常情況下派生的類不會(huì)重載下列方法,但是如果想要重新定義停止和中斷點(diǎn)的定義則可能會(huì)重載它們。
-
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.
派生的類應(yīng)當(dāng)重載這些方法以獲取調(diào)試器操作的控制權(quán)。
-
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)
處理當(dāng)一個(gè)中斷點(diǎn)屬于臨時(shí)性中斷點(diǎn)時(shí)是否必須要移除它。
此方法必須由派生類來(lái)實(shí)現(xiàn)。
派生類與客戶端可以調(diào)用以下方法來(lái)影響步進(jìn)狀態(tài)。
-
set_step()
在一行代碼之后停止。
-
set_next(frame)
在給定的幀以內(nèi)或以下的下一行停止。
-
set_return(frame)
當(dāng)從給定的幀返回時(shí)停止。
-
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 開(kāi)始調(diào)試。 如果未指定 frame,則從調(diào)用者的幀開(kāi)始調(diào)試。
-
set_continue()
僅在中斷點(diǎn)上或是當(dāng)結(jié)束時(shí)停止。 如果不存在中斷點(diǎn),則將系統(tǒng)追蹤函數(shù)設(shè)為
None。 -
set_quit()
將
quitting屬性設(shè)為True。 這將在對(duì)某個(gè)dispatch_*()方法的下一次調(diào)用中引發(fā) BdbQuit。
派生的類和客戶端可以調(diào)用下列方法來(lái)操縱中斷點(diǎn)。 如果出現(xiàn)錯(cuò)誤則這些方法將返回一個(gè)包含錯(cuò)誤消息的字符串,或者如果一切正常則返回 None。
-
set_break(filename, lineno, temporary=False, cond=None, funcname=None)
設(shè)置一個(gè)新的中斷點(diǎn)。 如果對(duì)于作為參數(shù)傳入的 filename 不存在 lineno,則返回一條錯(cuò)誤消息。 filename 應(yīng)為規(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 中索引號(hào)為 arg 的中斷點(diǎn)。 如果 arg 不是數(shù)字或超出范圍,則返回一條錯(cuò)誤消息。
-
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ù)字所指明的中斷點(diǎn)。 如果 arg 是一個(gè)字符串,它將被轉(zhuǎn)換為一個(gè)數(shù)字。 如果 arg 不是一個(gè)表示數(shù)字的字符串,如果給定的中斷點(diǎn)不存在或者已被刪除,則會(huì)引發(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 上的所有中斷點(diǎn),或者如果未設(shè)置任何中斷點(diǎn)則返回一個(gè)空列表。
-
get_file_breaks(filename)
返回 filename 中的所有中斷點(diǎn),或者如果未設(shè)置任何中斷點(diǎn)則返回一個(gè)空列表。
-
get_all_breaks()
返回已設(shè)置的所有中斷點(diǎn)。
派生類與客戶端可以調(diào)用以下方法來(lái)獲取一個(gè)代表?xiàng);厮菪畔⒌臄?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ù)。
-
返回值。
-
代碼的行(如果存在)。
-
以下兩個(gè)方法可由客戶端調(diào)用以使用一個(gè)調(diào)試器來(lái)調(diào)試一條以字符串形式給出的 statement。
-
run(cmd, globals=None, locals=None)
調(diào)試一條通過(guò) exec() 函數(shù)執(zhí)行的語(yǔ)句。 globals 默認(rèn)為
__main__.__dict__,locals 默認(rèn)為 globals。 -
runeval(expr, globals=None, locals=None)
調(diào)試一條通過(guò) eval() 函數(shù)執(zhí)行的表達(dá)式。 globals 和 locals 的含義與在 run() 中的相同。
-
runctx(cmd, globals, locals)
為了保證向下兼容性。 調(diào)用 run() 方法。
-
runcall(func, /, \args, **kwds*)
調(diào)試一個(gè)單獨(dú)的函數(shù)調(diào)用,并返回其結(jié)果。
最后,這個(gè)模塊定義了以下函數(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()
使用一個(gè)來(lái)自調(diào)用方的幀的 Bdb 實(shí)例開(kāi)始調(diào)試。
新聞名稱:創(chuàng)新互聯(lián)Python教程:bdb—-調(diào)試器框架
新聞來(lái)源:http://www.5511xx.com/article/dpoispo.html


咨詢
建站咨詢
