Share via


.scriptdebug (偵錯 JavaScript)

使用 .scriptdebug 命令來偵錯 JavaScript 腳本。

.scriptdebug FileName

參數

FileName

指定要偵錯的調試程式 JavaScript 腳本名稱。

Environment

模式

全部

目標

全部

平台

全部

其他資訊

如需 JavaScript 偵錯的概觀,請參閱 JavaScript 調試程式腳本 - JavaScript 偵錯。

注意

若要搭配 WinDbg 使用 JavaScript 偵錯,請以 管理員 istrator 身分執行調試程式。

備註

偵錯 JavaScript 之前,請先完成下列步驟。

  1. 載入範例腳本。

    0:000> .scriptload C:\MyScripts\DebuggableSample.js
    

若要開始主動偵錯腳本,請使用 .scriptdebug 命令。

0:000> .scriptdebug C:\MyScripts\DebuggableSample.js
>>> ****** DEBUGGER ENTRY DebuggableSample ******
           No active debug event!

>>> Debug [DebuggableSample <No Position>] >

當您看到提示 >>> Debug [DebuggableSample <No Position>] > 和輸入要求之後,您就會在腳本調試程式內。

使用 .help 命令或 在 JavaScript 偵錯環境中顯示命令清單。

>>> Debug [DebuggableSample <No Position>] >.help
Script Debugger Commands (*NOTE* IDs are **PER SCRIPT**):
    ? .................................. Get help
    ? <expr>  .......................... Evaluate expression <expr> and display result
    ?? <expr>  ......................... Evaluate expression <expr> and display result
    |  ................................. List available scripts
    |<scriptid>s  ...................... Switch context to the given script
    bc \<bpid\>  ......................... Clear breakpoint by specified \<bpid\>
    bd \<bpid\>  ......................... Disable breakpoint by specified \<bpid\>
    be \<bpid\>  ......................... Enable breakpoint by specified \<bpid\>
    bl  ................................ List breakpoints
    bp <line>:<column>  ................ Set breakpoint at the specified line and column
    bp <function-name>  ................ Set breakpoint at the (global) function specified by the given name
    bpc  ............................... Set breakpoint at current location
    dv  ................................ Display local variables of current frame
    g  ................................. Continue script
    gu   ............................... Step out
    k  ................................. Get stack trace
    p  ................................. Step over
    q  ................................. Exit script debugger (resume execution)
    sx  ................................ Display available events/exceptions to break on
    sxe <event>  ....................... Enable break on <event>
    sxd <event>  ....................... Disable break on <event>
    t  ................................. Step in
    .attach <scriptId>  ................ Attach debugger to the script specified by <scriptId>
    .detach [<scriptId>]  .............. Detach debugger from the script specified by <scriptId>
    .frame <index>  .................... Switch to frame number <index>
    .f+  ............................... Switch to next stack frame
    .f-  ............................... Switch to previous stack frame
    .help  ............................. Get help

事件

使用 sx 文稿調試程式命令來查看可截獲的事件清單。

>>> Debug [DebuggableSample <No Position>] >sx              
sx                                                          
    ab  [   inactive] .... Break on script abort            
    eh  [   inactive] .... Break on any thrown exception    
    en  [   inactive] .... Break on entry to the script     
    uh  [     active] .... Break on unhandled exception     

使用 sxe 命令來啟用任何中斷行為。 例如,若要開啟中斷專案,讓腳本在腳本調試程式內執行任何程式代碼時立即進入腳本調試程式,請使用此命令。

>>> Debug [DebuggableSample <No Position>] >sxe en          
sxe en                                                      
Event filter 'en' is now active                             

使用 sxd 腳本調試程式命令來停用任何斷點行為。

>>> Debug [DebuggableSample 34:5] >sxd en                                                                              
sxd en                                                                                                                 
Event filter 'en' is now inactive                                                                                      

堆疊追蹤

使用 k 命令來顯示堆疊追蹤。

>>> Debug [DebuggableSample 34:5] >k                                                  
k                                                                                     
    ##  Function                         Pos    Source Snippet                        
-> [00] throwAndCatch                    034:05 (var curProc = host.currentProcess)   
   [01] outer                            066:05 (var foo = throwAndCatch())           
   [02] outermost                        074:05 (var result = outer())                

列舉變數

使用 ?? 列舉 JavaScript 變數的值。

>>> Debug [DebuggableSample 34:5] >??someObj                
??someObj                                                   
someObj          : {...}                                    
    __proto__        : {...}                                
    a                : 0x63                                 
    b                : {...}                                

中斷點

使用下列斷點命令來處理其他斷點。

bp <bpid>:設定斷點

bd <bpid>:停用斷點

be <bpid>:啟用斷點

bc <bpid>:清除斷點

bpc:在目前行上設定斷點

bl:列出斷點(s)

流程控制 - 流覽

使用下列命令在腳本中向前移動。

p:逐步執行

t:逐步執行

g:繼續腳本

gu: 跳出

框架

使用下列命令來處理框架。

.frame <index>:切換至框架編號 <索引>

.f+:切換至下一個堆棧框架

.f+:切換至上一個堆疊框架

結束

使用 .detach 命令卸離 JavaScript 調試程式。

>>> Debug [DebuggableSample 34:5] >.detach                  
.detach                                                     
Debugger has been detached from script!                     

使用 q 命令結束 JavaScript 調試程式。

>>> Debug [<NONE> ] >q                                      
q