Debugging Macros

The Slick-CŪ translator vstw.exe (UNIX: vstw) enables debug messages to be inserted into the code and compiled. Use the messageNwait function to display a message and wait until a key is pressed. The _message_box function can be used to display a dialog box with a message and wait until you press Enter to proceed. Useful defs tab .e extension aliases are listed in the table below.

Alias Name

Value

m

messageNwait(%\n: %\c);

mb

_message_box(%\n: %\c);

The following sections will help you debug and work on Slick-C macros:

Finding Procedures

The find_proc command (Macro → Go to Slick-C Definition) finds Slick-CŪ source code or Help for a Slick-C symbol name that you specify. Use this function if you are browsing a macro and you want to find out more about a function. You can find the procedure at the cursor by pressing Ctrl+Dot. The syntax of the find_proc command is:

       
    find_proc proc_name
    
    

Tip

Instead of find_proc, use the command fp, which is a shortcut. It functions exactly the same as find_proc.

The table below shows some examples of using find_proc on the command line.

Command

Description

find_proc find_proc

Finds the source code for find_proc.

find_proc cursor_up

Finds the source code for cursor_up.

find_proc substr

Displays Help on substr built-in.

Finding Run-Time Errors

When a Slick-CŪ error occurs, a dialog box with the title "Slick-C Error" is displayed. Usually the Slick-C Stack view is displayed listing the call stack at the time of the error. Double-click in this view to view source for a call stack entry. The find_error command (Macro → Find Slick-C Error) finds the last Slick-C interpreter run-time error. The module with the error is loaded and the cursor is placed on the line causing the error.

Performance Profiling

The Slick-CŪ interpreter supports performance profiling. This is useful to identify bottlenecks or other inefficiencies in Slick-C code. The profiler does not affect performance when it is inactive, and there is only a minimal effect on performance when it is collecting data.

To use this feature, invoke the profile command on the SlickEditŪ command line with the following options:

  • profile on - Starts profiling data collection (also resets counters).

  • profile off - Stops profiling data collection.

  • profile view - Displays profiling data (also stops collection).

  • profile command args - Executes the specified Slick-C command with the specified arguments, then displays the profiling data. For example, to profile a CVS update, type profile cvs-gui-mfupdate.

  • profile save - Saves the profiling data for loading/viewing at a later time.

  • profile load - Loads previously saved profiling data for viewing.

Prior to displaying the profiling data, the applicable Slick-C source files are scanned in order to resolve the names of static functions. Then the Slick-C Profiler dialog is displayed showing the data in multi-column, non-modal tree format. Each line represents one function, which is either a Slick-C function or an exported DLL function, depending on what was called when the profiling data was collected. All times are displayed in milliseconds.

The profiling data can be sorted by clicking any sortable column. Double-click on any function to open the associated file in SlickEdit, with the cursor at the function location.

The Slick-C Profiler displays the following columns:

  • Function - Name of the function called.

  • Module - Name of the module from which the function comes.

  • Offset - The P-code offset of the function within the module.

  • Calls - Number of calls to the function.

  • F+D Time - Total time spent in the function and its descendants.

  • Percent - Percentage of the total time spent in the function and its descendants.

  • Avg F+D - Average time spent in the function and its descendants.

  • Min F+D - Minimum time spent in the function and its descendants.

  • Max F+D - Maximum time spent in the function and its descendants.

  • Func Time - Total time spent in the function only.

  • Percent - Percentage of the total time spent in the function.

  • Avg Time - Average time spent in the function.

  • Min Time - Minimum time spent in the function.

  • Max Time - Maximum time spent in the function.

Slick-CŪ Debugger

The Slick-C Debugger helps you trace Slick-C code. The debugger has no effect on performance when it is inactive, and only a minimal effect on performance when it is running.

To activate the Slick-C Debugger, from the main menu, click Macro → Start Slick-CŪ Debugger, or use the slickc_debug_start command on the SlickEditŪ command line.

When you start the debugger, a separate instance of SlickEdit launches in debug mode (the "debugger instance") and attaches to the original instance of SlickEdit (the "debuggee"). In the debugger instance, you can set breakpoints, step through code, inspect globals and properties, and more.

Use the Debug menu items or key bindings to perform debug operations. See "debugging" in the Help system (Help → Index) for more information about how to use the debugger in SlickEdit and other options that are available.

You can also use the slickc_debug command on the SlickEdit command line to perform various actions:

  • Step into commands - Use slickc_debug command, where command is the SlickEdit command you want to step into. The debugger terminates when the command completes. For example, use slickc_debug list_tags to launch the debugger and step into the list_tags command, which scans the current buffer for tags and displays them in a selection list.

  • Debug batch macros - Use slickc_debug PathToBatchMacro to activate the debugger for the specified batch macro. For example, use slickc_debug C:TEMP\bm164.e to open the batch macro file bm164.e in the editor and start the debug session.

  • Enable remote attachment - Use slickc_debug on to enable debugging so that someone else can attach to your instance of SlickEdit remotely. Use the slickc_debug off to disable debugging.

To stop the debugging session, from the debug instance main menu, click Debug → Stop Debugging. This detaches the debugger instance and closes it.

The debugger instance connects to the debuggee using a lightly extended version of JDWP (Java Debug Wire Protocol), although there is no JVM (Java Virtual Machine) involved. By default, it attaches to port 8003.

In order to run in a safe, clean environment, the Slick-C Debugger creates and uses its own configuration directory, named SCDebug, located in the user config. Additionally, an empty workspace is created and stored in the debug config which is used thereafter each time the debugger is run. This workspace, SCDebug.vpw, is used to store breakpoints that you set in the debug instance. It also stores the list of open files and watch expressions.

The Loaded Classes view is a useful tool for examining the state of the debuggee with respect to Slick-C. It shows all the loaded modules and loaded classes, all global variables, all MISC_TYPE variables, and loaded event tables. Many of these items are found under the imaginary "sc.lang.*" namespaces. The Loaded Classes view is not active by default in debugging mode. To display it, from the main menu, click Debug → Windows → Loaded Classes. See "Loaded Classes view" in the Help system (Help → Index) for more information.