Totalview® for HPC Reference Guide : PART I Using the CLI : Chapter 4 Batch Debugging Using tvscript : tvscript External Script Files : Example tvscript Script File
Example tvscript Script File
The following example tvscript file registers several action point handlers when an action point (breakpoint) is hit. When the handlers are called, they display information about the action point event. The script also installs an error handler, which is called if an error occurs during execution of the program. Run the script as follows:
tvscript -script_file script_file program
Where program is the name of the program to run under the control of tvscript. This tvscript example, tvscript_example.tvd, is available in the TotalView examples directory.
This script installs an error handler and an action point handler. When an error is encountered during execution, tvscript passes an array of information to the error handler and prints information to the log. Similarly, when an action point is hit, it passes an array of information to the action point handler and prints information to the log. These arrays are described in "Event API".
# Get the process so we have some information about it
tvscript_log "PID: \
             [tvscript_get_process_property 1 "syspid"]";
tvscript_log "Status: \
             [tvscript_get_process_property 1 "state"]";
tvscript_log "Executable: \
             [tvscript_get_process_property 1 "executable"]";
 
#############################################################
proc error_handler {error_data} {
tvscript_log "Inside error_handle: $error_data"
 
# Change the incoming list into an array.
# It contains the following indices:
# process_id
# thread_id
# error_message
array set error_data_array $error_data
 
# Get the process so we have some information about it
set temp [tvscript_get_process_property \
$error_data_array(process_id) "syspid"];
tvscript_log " Process ID: $temp";
 
set temp [tvscript_get_thread_property \
$error_data_array(thread_id) "systid"];
tvscript_log " Thread ID: $temp";
 
set temp $error_data_array(error_message);
tvscript_log " Error Message: $temp";
 
}
 
#############################################################
# Action point handlers
 
proc actionpoint_handler {event_data} {
tvscript_log "Inside actionpnt_handler: $event_data"
tvscript_slog "Inside actionpnt_handler: $event_data"
 
# Change the incoming list into an array.
# It contains the following indices:
# actionpoint_id
# actionpoint_source_loc_expr
# event
# process_id
# thread_id
array set event_data_array $event_data
 
# Get the process so we have some information about it
set temp [tvscript_get_process_property \
$event_data_array(process_id) "syspid"];
tvscript_log " Process ID: $temp";
 
set temp [tvscript_get_thread_property \
$event_data_array(thread_id) "systid"];
tvscript_log " Thread ID: $temp";
 
set temp [tvscript_get_process_property \
$event_data_array(process_id) "state"];
tvscript_log " Status: $temp";
 
set temp [tvscript_get_process_property \
$event_data_array(process_id) "executable"]
tvscript_log " Executable: $temp";
 
set temp $event_data_array(actionpoint_source_loc_expr)
tvscript_log "Action point Expression: $temp"
 
tvscript_log "Value of i:"
set output [capture "dprint i"]
tvscript_log $output
}
 
#######################################################
# Event handlers
 
proc generic_actionpoint_event_handler {actionpoint_data} {
tvscript_log "Inside generic_actionpoint_event_handler: "
tvscript_log $actionpoint_data
tvscript_slog "Inside generic_actionpoint_event_handler: "
tvscript_slog $actionpoint_data
 
# Change the incoming list into an array.
# It contains the following indices:
# actionpoint_id
# actionpoint_source_loc_expr
# event
# process_id
# thread_id
array set actionpnt_data_array $actionpoint_data
 
set temp $actionpnt_data_array(process_id)
tvscript_log " Process ID: $temp"
 
set temp $actionpnt_data_array(thread_id)
tvscript_log " Thread ID: $temp"
 
set temp $actionpnt_data_array(actionpoint_id)
tvscript_log " Action Point ID: $temp"
 
set temp $actionpnt_data_array(actionpoint_source_loc_expr)
tvscript_log "Action Point Expression: "
}
 
#############################################################
# Add event handlers
 
# Create a breakpoint on function main and register
# procedure "actionpoint_handler" to be called if the
# breakpoint is hit.
set actionpoint_id [tvscript_create_actionpoint "main"]
tvscript_add_actionpoint_handler $actionpoint_id \ "actionpoint_handler"
 
# Set up a generic actionpoint handler that is called
# whenever any action point is hit.
tvscript_add_event_handler "actionpoint" \ "generic_actionpoint_event_handler"
 
#######################################################
# Add error handler that is called if an error
# occurs while running the program.
tvscript_add_event_handler "error" "error_handler"