檢視原始碼 int (除錯器 v5.5)

直譯器介面。

Erlang 直譯器提供中斷點和程式碼逐步執行的機制。它主要供除錯器使用;請參閱除錯器使用者指南和模組debugger

可以從 shell 執行以下操作

  • 指定要直譯的模組。
  • 指定中斷點。
  • 監控所有在已直譯模組中執行程式碼的程序,也包含其他 Erlang 節點的程序。

藉由附加到正在執行已直譯程式碼的程序,可以檢查變數綁定並逐步執行程式碼。這是透過第三個稱為元程序 (meta process) 的程序來回傳送資訊來完成的。您可以實作自己的附加程序。有關可用的函式,請參閱 int.erl,有關可能的訊息,請參閱 dbg_wx_trace.erl

直譯器依賴 Kernel、STDLIB 和 WX 應用程式。這表示不允許直譯屬於這些應用程式的模組,因為這可能會導致死鎖或模擬器崩潰。這也適用於屬於除錯器應用程式的模組。

中斷點

中斷點是以行為基礎指定的。當在已直譯模組中執行程式碼的程序到達中斷點時,它會停止。這表示必須在可執行行上設定中斷點,也就是包含可執行表達式的程式碼行。

中斷點具有以下特性

  • 一個狀態,活動非活動。非活動的中斷點會被忽略。
  • 一個觸發動作。當到達中斷點時,觸發動作會指定中斷點是否要繼續保持活動狀態(啟用)、變為非活動狀態(停用),或被移除(刪除)。
  • 可選的相關條件。條件是 {Module,Name} 的元組。當到達中斷點時,會呼叫 Module:Name(Bindings)。如果評估結果為 true,則執行會停止。如果評估結果為 false,則會忽略中斷點。Bindings 包含目前的變數綁定。若要檢索指定變數的值,請使用 get_binding/2

預設情況下,中斷點是活動的,具有觸發動作 enable,且沒有相關的條件。有關中斷點的詳細資訊,請參閱除錯器使用者指南中的中斷點和中斷對話視窗

摘要

函式

ModuleLine 的中斷點的觸發動作設定為 Action

取得所有中斷點。

取得模組 Module 中的所有中斷點。

取得如何自動附加到正在已直譯模組中執行程式碼的程序。

停用自動附加。

設定何時以及如何自動附加到正在已直譯模組中執行程式碼的程序。

Module 中的 Line 建立中斷點。

在函式 Module:Name/Arity 的每個子句的第一行建立中斷點。

清除執行已直譯程式碼的程序資訊,方法是移除所有關於已終止程序的資訊。

繼續 Pid 的程序執行。

繼續 c:pid(X, Y, Z) 的程序執行。

刪除函式 Module:Name/Arity 的每個子句的第一行的中斷點。

刪除 ModuleLine 的中斷點。

使 ModuleLine 的中斷點變為非活動狀態。

使 ModuleLine 的中斷點變為活動狀態。

傳回已直譯模組 Module 的原始碼檔案名稱 File

Bindings 檢索 Var 的綁定。

在本地節點上直譯指定的模組。

檢查是否可以直譯模組。

傳回所有已直譯模組的清單。

停止在本地節點上直譯指定的模組。

在所有已知節點上直譯指定的模組。

停止在所有已知節點上直譯指定的模組。

刪除所有中斷點。

刪除 Module 中的所有中斷點。

取得所有執行已直譯程式碼的程序的相關資訊。

取得如何在堆疊中儲存呼叫框架。

設定如何在堆疊中儲存呼叫框架。

ModuleLine 的中斷點的條件測試設定為 Function

函式

連結至此函式

action_at_break(Module, Line, Action)

檢視原始碼
-spec action_at_break(Module, Line, Action) -> ok
                         when Module :: module(), Line :: integer(), Action :: enable | disable | delete.

ModuleLine 的中斷點的觸發動作設定為 Action

-spec all_breaks() -> [Break]
                    when
                        Break :: {Point, Options},
                        Point :: {Module, Line},
                        Module :: module(),
                        Line :: integer(),
                        Options :: [Status | Trigger | null | Cond],
                        Status :: active | inactive,
                        Trigger :: enable | disable | delete,
                        Cond :: null | Function,
                        Function :: {Module, Name},
                        Name :: atom().

取得所有中斷點。

-spec all_breaks(Module) -> [Break]
                    when
                        Break :: {Point, Options},
                        Point :: {Module, Line},
                        Module :: module(),
                        Line :: integer(),
                        Options :: [Status | Trigger | null | Cond],
                        Status :: active | inactive,
                        Trigger :: enable | disable | delete,
                        Cond :: null | Function,
                        Function :: {Module, Name},
                        Name :: atom().

取得模組 Module 中的所有中斷點。

-spec auto_attach() -> false | {Flags, Function}
                     when
                         Flags :: [init | break | exit],
                         Function :: {Module, Name, Args},
                         Module :: module(),
                         Name :: atom(),
                         Args :: [term()].

取得如何自動附加到正在已直譯模組中執行程式碼的程序。

有關 Flags 中可能值的含義,請參閱 auto_attach/2

-spec auto_attach(false) -> term().

停用自動附加。

連結至此函式

auto_attach(Flags, Function)

檢視原始碼
-spec auto_attach(Flags, Function) -> term()
                     when
                         Flags :: [init | break | exit],
                         Function :: {Module, Name, Args},
                         Module :: module(),
                         Name :: atom(),
                         Args :: [term()].

設定何時以及如何自動附加到正在已直譯模組中執行程式碼的程序。

預設情況下,當啟動直譯器時,會停用自動附加。

如果 Flags 是空清單,則會停用自動附加。

否則,Flags 應為包含下列至少一個旗標的清單

  • init - 當程序第一次呼叫已直譯函式時附加。
  • break - 每當程序到達中斷點時附加。
  • exit - 當程序終止時附加。

當指定的事件發生時,函式 Function 會以下列方式呼叫

spawn(Module, Name, [Pid | Args])

Pid 是執行已直譯程式碼的程序的 pid。

-spec break(Module, Line) -> ok | {error, break_exists} when Module :: module(), Line :: integer().

Module 中的 Line 建立中斷點。

連結至此函式

break_in(Module, Name, Arity)

檢視原始碼
-spec break_in(Module, Name, Arity) -> ok | {error, function_not_found}
                  when Module :: module(), Name :: atom(), Arity :: integer().

在函式 Module:Name/Arity 的每個子句的第一行建立中斷點。

-spec clear() -> ok.

清除執行已直譯程式碼的程序資訊,方法是移除所有關於已終止程序的資訊。

-spec continue(Pid :: pid()) -> ok | {error, not_interpreted}.

繼續 Pid 的程序執行。

-spec continue(X, Y, Z) -> ok | {error, not_interpreted}
                  when X :: integer(), Y :: integer(), Z :: integer().

繼續 c:pid(X, Y, Z) 的程序執行。

連結至此函式

del_break_in(Module, Name, Arity)

檢視原始碼
-spec del_break_in(Module, Name, Arity) -> ok | {error, function_not_found}
                      when Module :: module(), Name :: atom(), Arity :: integer().

刪除函式 Module:Name/Arity 的每個子句的第一行的中斷點。

連結至此函式

delete_break(Module, Line)

檢視原始碼
-spec delete_break(Module, Line) -> ok when Module :: module(), Line :: integer().

刪除 ModuleLine 的中斷點。

連結至此函式

disable_break(Module, Line)

檢視原始碼
-spec disable_break(Module, Line) -> ok when Module :: module(), Line :: integer().

使 ModuleLine 的中斷點變為非活動狀態。

連結至此函式

enable_break(Module, Line)

檢視原始碼
-spec enable_break(Module, Line) -> ok when Module :: module(), Line :: integer().

使 ModuleLine 的中斷點變為活動狀態。

-spec file(Module) -> File | {error, not_loaded} when Module :: module(), File :: file:filename_all().

傳回已直譯模組 Module 的原始碼檔案名稱 File

連結至此函式

get_binding(Var, Bindings)

檢視原始碼
-spec get_binding(Var, Bindings) -> {value, Value} | unbound
                     when Var :: atom(), Bindings :: term(), Value :: term().

Bindings 檢索 Var 的綁定。

此函式旨在由中斷點的條件函式使用。

-spec i(AbsModules | AbsModule) -> Result
           when
               AbsModules :: [AbsModule, ...],
               AbsModule :: Module | File,
               Module :: module(),
               File :: file:name_all(),
               Result :: AbsModuleResult | AbsModulesResult,
               AbsModuleResult :: {module, Module} | error,
               AbsModulesResult :: ok.

在本地節點上直譯指定的模組。

模組可以使用其模組名稱 (atom) 或檔案名稱來指定。

如果使用其模組名稱指定,則會在目前路徑中搜尋物件程式碼 Module.beam。首先會在與物件程式碼相同的目錄中搜尋原始碼 Module.erl,然後在旁邊的 src 目錄中搜尋。

如果使用其檔案名稱指定,則檔案名稱可以包含路徑,並且可以省略 .erl 副檔名。首先會在與原始碼相同的目錄中搜尋物件程式碼 Module.beam,然後在旁邊的 ebin 目錄中搜尋,最後在目前路徑中搜尋。

注意

直譯器需要原始碼和物件程式碼。物件程式碼必須包含除錯資訊,也就是說,只有使用選項 debug_info 編譯的模組才能被直譯。

如果模組已直譯,則函式會傳回 {module,Module},否則會傳回 error

參數也可以是模組或檔案名稱的清單,在這種情況下,函式會嘗試如先前指定的方式直譯每個模組。然後,函式始終傳回 ok,但如果無法直譯模組,則會將一些資訊列印到 stdout

連結至此函式

interpretable(AbsModule)

檢視原始碼
-spec interpretable(AbsModule) -> true | {error, Reason}
                       when
                           AbsModule :: Module | File,
                           Module :: module(),
                           File :: file:name_all(),
                           Reason :: no_src | no_beam | no_debug_info | badarg | {app, App},
                           App :: atom().

檢查是否可以直譯模組。

可以使用其模組名稱 Module 或其原始碼檔案名稱 File 來指定模組。如果使用模組名稱指定,則會在程式碼路徑中搜尋模組。

如果滿足以下所有條件,則函式會傳回 true

  • 找到模組的原始碼和物件程式碼。
  • 模組已使用設定的選項 debug_info 編譯。
  • 模組不屬於 Kernel、STDLIB、WX 或 Debugger 的任何應用程式。

如果無法直譯模組,則函式會傳回 {error,Reason}Reason 可以具有以下值

  • no_src - 找不到原始碼。假設原始碼和物件程式碼位於相同的目錄中,或位於彼此相鄰的 srcebin 目錄中。

  • no_beam - 找不到物件程式碼。假設原始碼和物件程式碼位於相同的目錄中,或位於彼此相鄰的 srcebin 目錄中。

  • no_debug_info - 模組尚未使用設定的選項 debug_info 編譯。

  • badarg - 找不到 AbsModule。這可能是因為指定的檔案不存在,或者因為 code:which/1 沒有傳回 BEAM 檔案名稱,這不僅適用於不存在的模組,也適用於預先載入或涵蓋編譯的模組。

  • {app,App} - 如果 AbsModule 屬於這些應用程式之一,則 Appkernelstdlibgsdebugger

請注意,即使模組不可解釋,函式仍可能回傳 true,如果該模組被標記為 sticky,或位於標記為 sticky 的目錄中。原因在於,必須等到直譯器嘗試載入模組時才會發現這一點。

-spec interpreted() -> [Module] when Module :: module().

傳回所有已直譯模組的清單。

-spec n(AbsModule) -> ok
           when
               AbsModule :: Module | File | [Module | File], Module :: module(), File :: file:name_all().

停止在本地節點上直譯指定的模組。

i/1ni/1 類似,模組可以透過模組名稱或檔案名稱指定。

-spec ni(AbsModules | AbsModule) -> Result
            when
                AbsModules :: [AbsModule],
                AbsModule :: Module | File,
                Module :: module(),
                File :: file:name_all(),
                Result :: AbsModuleResult | AbsModulesResult,
                AbsModuleResult :: {module, Module} | error,
                AbsModulesResult :: ok.

在所有已知節點上直譯指定的模組。

模組可以使用其模組名稱 (atom) 或檔案名稱來指定。

如果使用其模組名稱指定,則會在目前路徑中搜尋物件程式碼 Module.beam。首先會在與物件程式碼相同的目錄中搜尋原始碼 Module.erl,然後在旁邊的 src 目錄中搜尋。

如果使用其檔案名稱指定,則檔案名稱可以包含路徑,並且可以省略 .erl 副檔名。首先會在與原始碼相同的目錄中搜尋物件程式碼 Module.beam,然後在旁邊的 ebin 目錄中搜尋,最後在目前路徑中搜尋。

注意

直譯器需要原始碼和物件程式碼。物件程式碼必須包含除錯資訊,也就是說,只有使用選項 debug_info 編譯的模組才能被直譯。

如果模組已直譯,則函式會傳回 {module,Module},否則會傳回 error

參數也可以是模組或檔案名稱的清單,在這種情況下,函式會嘗試如先前指定的方式直譯每個模組。然後,函式始終傳回 ok,但如果無法直譯模組,則會將一些資訊列印到 stdout

-spec nn(AbsModule) -> ok
            when
                AbsModule :: Module | File | [Module | File],
                Module :: module(),
                File :: file:name_all().

停止在所有已知節點上直譯指定的模組。

i/1ni/1 類似,模組可以透過模組名稱或檔案名稱指定。

-spec no_break() -> ok.

刪除所有中斷點。

-spec no_break(Module :: term()) -> ok.

刪除 Module 中的所有中斷點。

-spec snapshot() -> [Snapshot]
                  when
                      Snapshot :: {Pid, Function, Status, Info},
                      Pid :: pid(),
                      Function :: {Module, Name, Args},
                      Module :: module(),
                      Name :: atom(),
                      Args :: [term()],
                      Status :: idle | running | waiting | break | exit | no_conn,
                      Info :: {} | {Module, Line} | ExitReason,
                      Line :: integer(),
                      ExitReason :: term().

取得所有執行已直譯程式碼的程序的相關資訊。

  • Pid - 程序識別碼。
  • Function - 程序呼叫的第一個直譯函式。
  • Status - 程序目前的狀態。
  • Info - 更多資訊。

Status 是下列其中一種:

  • idle - 程序不再執行直譯程式碼。Info{}
  • running - 程序正在執行。Info{}
  • waiting - 程序正在 receive 處等待。Info{}
  • break - 程序執行已停止,通常在斷點處停止。Info{Module,Line}
  • exit - 程序已終止。InfoExitReason
  • no_conn - 與執行程序的節點的連線已中斷。Info{}
-spec stack_trace() -> Flag when Flag :: all | no_tail | false.

取得如何在堆疊中儲存呼叫框架。

關於 Flag 的含義,請參閱 stack_trace/1

-spec stack_trace(Flag) -> term() when Flag :: all | no_tail | false.

設定如何在堆疊中儲存呼叫框架。

儲存呼叫框架可以檢查程序的呼叫鏈,並在發生錯誤(屬於 error 類別的例外)時模擬堆疊追蹤。可以指定下列旗標:

  • all - 儲存所有目前呼叫的相關資訊,也就是尚未回傳值的函式呼叫。

  • no_tail - 儲存目前呼叫的相關資訊,但在進行尾遞迴呼叫時捨棄先前的資訊。此選項消耗較少的記憶體,對於具有較長生命週期和多次尾遞迴呼叫的程序來說,可能必須使用此選項。這是預設值。

  • false - 不儲存目前呼叫的相關資訊。

連結至此函式

test_at_break(Module, Line, Function)

檢視原始碼
-spec test_at_break(Module, Line, Function) -> ok
                       when
                           Module :: module(),
                           Line :: integer(),
                           Function :: {Module, Name},
                           Name :: atom().

ModuleLine 的中斷點的條件測試設定為 Function

函式 Function 必須符合斷點章節中指定的條件。