- Rexx 教程
- Rexx - 首頁
- Rexx - 概述
- Rexx - 環境
- Rexx - 安裝
- Rexx - 外掛安裝
- Rexx - 基本語法
- Rexx - 資料型別
- Rexx - 變數
- Rexx - 運算子
- Rexx - 陣列
- Rexx - 迴圈
- Rexx - 決策
- Rexx - 數字
- Rexx - 字串
- Rexx - 函式
- Rexx - 堆疊
- Rexx - 檔案I/O
- Rexx - 檔案函式
- Rexx - 子程式
- Rexx - 內建函式
- Rexx - 系統命令
- Rexx - XML
- Rexx - Regina
- Rexx - 解析
- Rexx - 訊號
- Rexx - 除錯
- Rexx - 錯誤處理
- Rexx - 面向物件
- Rexx - 可移植性
- Rexx - 擴充套件函式
- Rexx - 指令
- Rexx - 實現
- Rexx - Netrexx
- Rexx - Brexx
- Rexx - 資料庫
- 手持式和嵌入式
- Rexx - 效能
- Rexx - 最佳程式設計實踐
- Rexx - 圖形使用者介面
- Rexx - Reginald
- Rexx - Web程式設計
- Rexx 有用資源
- Rexx - 快速指南
- Rexx - 有用資源
- Rexx - 討論
Rexx - 除錯
除錯是任何程式語言中的重要功能。它幫助開發人員診斷錯誤,找到根本原因,然後相應地解決問題。在 Rexx 中,trace 實用程式用於除錯。trace 指令可以透過兩種方式實現,一種是批處理模式,另一種是互動模式。讓我們看看如何實現這兩個選項。
批處理模式下的 Trace
trace 命令用於詳細顯示每個執行的 Rexx 命令。
trace 語句的一般語法如下所示:
語法
trace [setting]
其中設定可以是以下任何一個選項:
A - 追蹤所有命令。
C - 只追蹤傳送到作業系統的宿主命令。
E - 只追蹤導致錯誤的傳送到作業系統的宿主命令。
F - 只追蹤導致失敗的傳送到作業系統的宿主命令。
I - 這提供了一箇中間級別的 Rexx 命令追蹤。
L - 如果你想在追蹤發生時進行標記,則使用此選項。
N - 這是預設選項,不進行任何追蹤。
讓我們來看一個 trace 命令的例子。
示例
/* Main program */ trace A /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say 'This is a whole number' return 0 msg : say ' This is an incorrect number '
上述程式的輸出如下:
5 *-* n = 100.45 if datatype( n, wholenumber ) then signal msg 7 *-* say 'This is a whole number This is a whole number 8 *-* return 0
從輸出中,您可以看到程式輸出中添加了額外的追蹤資訊。關於輸出,可以注意到以下幾點:
執行語句的行號被新增到追蹤輸出中。
追蹤輸出中顯示了每行執行的程式碼。
Trace 函式
也可以透過 trace 函式啟用 Trace。下面顯示了一般語法和示例。
語法
trace()
上述函式返回當前的追蹤級別。
引數
無
返回值
上述函式給出當前的追蹤級別。
示例
/* Main program */ say trace() /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say 'This is a whole number' return 0 msg : say 'This is an incorrect number '
上述程式的輸出如下所示。
N This is an incorrect number
第一行的 N 表示追蹤設定為正常。
設定 Trace 值
可以使用 trace 函式設定追蹤級別。下面顯示了一般語法和示例。
語法
trace(travel_level)
引數
trace_level - 這與設定追蹤級別可用的選項類似。
返回值
上述函式給出當前的追蹤級別。
示例
/* Main program */
say trace()
current_trace = trace('A')
say current_trace
/* Main program */
n = 100.45 if datatype( n, wholenumber ) then
signal msg say 'This is a whole number'
return 0
msg :
say ' This is an incorrect number '
上述程式的輸出如下:
N 4 *-* say current_trace N 6 *-* n = 100.45 7 *-* if \ datatype( n, wholenumber ) then 8 *-* signal msg 12 *-* say 'This is an incorrect number' 'This is an incorrect number'
互動式追蹤
互動式追蹤是指在程式執行時進行追蹤。就像在 .Net 的 Visual Studio 等 IDE 中,您可以新增斷點並檢視每個語句是如何執行的,同樣在這裡您也可以看到程式的每一行程式碼是如何執行的。
一般語法如下:
語法
trace ?options
其中,選項與 trace 命令相同,如下所示。
A - 追蹤所有命令
C - 只追蹤傳送到作業系統的宿主命令。
E - 只追蹤導致錯誤的傳送到作業系統的宿主命令。
F - 只追蹤導致失敗的傳送到作業系統的宿主命令。
I - 這提供了一箇中間級別的 Rexx 命令追蹤。
L - 如果你想在追蹤發生時進行標記,則使用此選項。
N - 這是預設選項,不進行任何追蹤。
讓我們來看一個實現互動式追蹤的例子。
示例
/* Main program */ trace ?A /* Main program */ n = 100.45 if datatype( n, wholenumber ) then signal msg say 'This is a whole number' return 0 msg : say 'This is an incorrect number'
上述程式的輸出將如以下程式所示。追蹤將停止在每一行程式碼;然後您需要按 Enter 鍵才能移動到下一行程式碼。
This is an incorrect number
+++ "LINUX COMMAND /home/cg/root/5798511/main.rex"
5 *-* n = 100.45 if datatype( n, wholenumber ) then
+++ Interactive trace. "Trace Off" to end debug, ENTER to Continue. +++
6 *-* signal msg
10 *-* msg :
10 *-* say 'This is an incorrect number'