home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-27 | 32.6 KB | 1,387 lines |
- # $Header: P:/source/ppee/macros/debug.pev 1.46 13 Aug 1990 12:54:38 ericj $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: debug.pel $: sageedit debugger entry points
- #
-
- global debug_color_border = 0x02
- global debug_color_text = 0x07
- global debug_color_highlight = 0x1F
- global debug_color_title = 0x02
-
- global debug_flip = 1;
- local debug_window;
- local debug_empty_name = "Debug Window: no function active"
- local debug_keymap;
- local debug_buffer;
- local debug_filename = "";
- local command_mode;
- local debug_enabled # True if debug has been called
- local original_window; # Saved when function is debugged.
- local original_buffer;
- local win_top = 3
- local command_win_height = 7
- local display_win_height = 15
- local win_left, win_width;
- local debug_id;
- local debug_tabs = default_buffer_tabs;
- local debug_view_file = "???"
- local debug_num_steps = 0;
-
- #
- # debug_fun_breakpoints is an array of function gids to break on.
- # The index is the gid as a string. The value is the gid itself.
- # The distinction is important because function_name requires the gid itself.
- # debug_fun_lineno are the line numbers of the start of the function,
- # determined when we hit it.
- #
- local debug_fun_breakpoints;
- local debug_fun_breakpoint_names;
- local debug_fun_bp_types; # 0 = disabled, 1 = enabled, 2 = goto point
- local debug_bp_linenos;
- local breakpoints_visible = 0;
- local ctrl_break_attached = 0;
-
-
- local BP_ENABLED = 0x01;
- local BP_GOTO_POINT = 0x02;
-
- local debug_gid, debug_lineno = 0; # GID and lineno of current debugged function
- local debug_step_gid; # GID of function during debug_step
- local debug_go_mode;
-
- local debug_command_keymap
- local debug_command_window
- local debug_command_buffer
-
- local CTRL_G = 8711
- local CTRL_T = 5140
-
- global debugger_running = 0;
-
-
-
- global function debug_reset(){
- debug_gid = 0;
- debug_filename = "";
- }
-
-
- local function debug_init()
- {
- local cw;
- local cb;
- local insert_id = function_id( "debug_insert_key" );
- local i;
- local win_height
-
- if (!current_window) {
- current_window = create_window( 0, 0, display_width, display_height);
- attach_window_buffer( current_window, current_buffer );
- }
-
- cw = current_window
- cb = current_buffer
-
- if (debug_enabled) { return; }
- debug_enabled = 1
-
- debug_go_mode = 0;
- debug_id = function_id( "debug_fun" );
-
- # determine the size of the debug window
- win_left = display_width / 4;
- win_width = win_left * 3 - 1;
- win_height = display_height - win_top - 2 - command_win_height;
-
- current_window =
- debug_window = create_factory_window( win_left, win_top, win_width, display_win_height,
- WINDOW_SYSTEM + \
- WINDOW_SB_RIGHT + \
- WINDOW_TITLE )
- linenumber_format = "%5d: "
- color_text = color_linenumbers = debug_color_text;
- color_border = debug_color_border;
- color_title = debug_color_title;
-
- debug_buffer = create_buffer( \
- debug_empty_name, \
- "", \
- BUFFER_SYSTEM + BUFFER_NO_UNDO + BUFFER_READ_ONLY )
- attach_window_buffer( debug_window, debug_buffer );
-
- debug_keymap = create_keymap(empty_keymap)
- push_keymap(debug_keymap)
-
- #
- # define command keymap bindings for the debug window and
- # the command window.
- #
- for (i = 32; i < 127; i++)
- assign_key( "\\" chr(i), insert_id );
- assign_key( "\\#", insert_id );
- assign_key( "\\\\", insert_id );
-
- assign_key( "<Up>", "debug_up" );
- assign_key( "<Down>", "debug_down" );
- assign_key( "<Left>", "debug_left" );
- assign_key( "<Right>", "right" );
- assign_key( "<PgUp>", "debug_page_up");
- assign_key( "<PgDn>", "debug_page_dn");
- assign_key( "<Ctrl-PgUp>", "debug_home");
- assign_key( "<Ctrl-PgDn>", "debug_end" );
- assign_key( "<Ctrl-T>", "debug_resize_window" );
- assign_key( "<Ctrl-G>", "debug_resize_window" );
- assign_key( "<Enter>", "debug_enter" );
- assign_key( "<Bksp>", "debug_backspace" );
- assign_key( "<Del>", "debug_delete_chars" );
- assign_key( "<F1>", "debug_help" );
- assign_key( "<F4>", "debug_prev_screen" );
- assign_key( "<F5>", "debug_go" );
- assign_key( "<F6>", "debug_toggle_windows" );
- assign_key( "<F8>", "debug_trace" );
- assign_key( "<F10>", "debug_step" );
- assign_key( "#61440", "debug_left_press" )
- assign_key( "<End>", "goto_eol" );
- assign_key( "<Alt-H>", "debug_help" );
- assign_key( "<Ctrl-C>", "debug_break" );
- assign_key( "<Alt-C>", "debug_callstack" );
-
- debug_command_keymap = create_keymap( debug_keymap )
-
-
- # now the keys specific to the debug_window
- #
- assign_key( "<Home>", "goto_bol" );
- assign_key( "<F9>", "bp_line" );
-
- pop_keymap()
-
- #
- # create a command line window, buffer, and keymap
- #
- current_window =
- debug_command_window = create_factory_window( win_left, win_top + display_win_height - 1,
- win_width, command_win_height,
- WINDOW_SYSTEM + \
- WINDOW_SB_RIGHT )
- scroll_context_top = 0;
- scroll_context_bottom = 0;
- color_text = debug_color_text;
- color_border = debug_color_border;
- color_title = debug_color_title;
-
-
- current_buffer =
- debug_command_buffer = create_buffer( \
- "", \
- "", \
- BUFFER_SYSTEM )
- insert_key( ord(">") );
- attach_window_buffer( debug_command_window, debug_command_buffer );
-
- push_keymap(debug_command_keymap)
-
- # now the keys specific to the debug_command_window
- #
- assign_key( "<Home>", "debug_bol" );
-
- pop_keymap()
-
- assign_current_window( cw );
- current_buffer = cb;
-
- command_mode = 1;
- }
-
-
- # Invoke this to start debugging.
- #
- function debug()
- {
- local gid;
-
- attach_break_handler()
-
- debug_function( 0 );
- debug_init()
-
- # Put debugger in trace mode.
- debug_step_gid = 0
- debug_go_mode = 0
- debug_num_steps = 0;
-
- for (gid in debug_fun_breakpoints)
- if ( and(debug_fun_bp_types[gid], BP_GOTO_POINT))
- debug_remove_goto_point( gid );
-
- if (debugger_running)
- debugger_running = 0;
-
- debug_fun( 0, 1 );
-
- }
-
-
- # Contents is an array of strings to go in the popup window
- # This is a message() function that works
- # Used for debugging.
- # local function mymessage(msg)
- # {
- # local x
- # x[1] = msg
- # popup("Here is a message",x)
- # }
- #
- local function popup(winname,contents)
- {
- local i
- local width = length(winname)
- local height
- local curbuf = current_buffer
- local curwin = current_window
- for (i in contents) {
- if (length(contents[i]) > width) { width = length(contents[i]); }
- height++
- }
- width += 3; # Add 2 for borders and 1 for a pleasing space
- height += 2; # Add 2 for borders.
- if (width > display_width) { width = display_width; }
- if (height < 4) { height = 4; } # Minimum height
- current_window = create_factory_window( (display_width - width) / 2,
- 3,
- width,
- height )
- current_buffer = create_buffer( \
- "DEBUG", \
- "",
- BUFFER_SYSTEM + BUFFER_NO_UNDO )
- attach_window_buffer(current_window,current_buffer)
- window_name = winname
-
- for (i in contents) {
- insert_string(contents[i])
- insert_newline()
- }
-
- goto_buffer_top()
- display_update()
- getkey()
- delete_buffer(current_buffer)
- delete_window(current_window)
- current_buffer = curbuf
- assign_current_window( curwin );
- }
-
-
-
-
- # Print the call stack
- function debug_callstack()
- {
- local i, n, x, argc, arglist = ""
- local popbuf
-
- if (!debug_gid)
- return;
-
- for (n=1; (x = debug_get_frame(n)); n++) {
- # x[1] is gid, x[2] is lineno, x[3] is argc, x[4] is param list
- # Create the list of function arguments
- argc = x[3]
- for (i = 1; i <= argc; i++) {
- arglist = arglist debug_get_stack_var(n,i)
- if (i != argc) arglist = arglist ","
- }
- popbuf[n*2] = substr(function_name(x[1]) "(" arglist ")", 1, 60)
- popbuf[n*2+1] = sprintf(" at %s:%d",
- get_source_file_name(x[1]),x[2]);
- }
- popup("Call Stack",popbuf)
- }
-
-
- function debug_prev_screen(){
- if (debugger_running) {
- assign_current_window( original_window );
- current_buffer = original_buffer;
- display_update();
-
- getkey();
-
- current_window = debug_window;
- current_window = debug_command_window;
- current_window = (command_mode) ? debug_command_window : debug_window;
- display_update();
- }
- }
-
- function debug_break(){
- debug_go_mode = 0
- debug_step_gid = 0
- }
-
-
-
- # Step over function call.
- # This will not work if the function is called recursively.
- function debug_step()
- {
- debug_go_mode = 0
- debug_step_gid = debug_gid
- process_end(1) # Run function some more.
- }
-
-
- function debug_trace() {
- debug_go_mode = 0
- debug_step_gid = 0
- process_end(1)
- }
-
-
- function debug_esc() {
- debug_go_mode = 0
- debug_step_gid = 0
- debug_view_file = "???";
- debug_filename = ""
- delete_buffer( debug_buffer )
- process_end(0)
- remove_break_handler()
- }
-
-
- # Print the value of a variable in the message box.
- local function print_val(varname,val)
- {
- local typo
-
- current_window = debug_command_window;
- current_buffer = debug_command_buffer;
-
- typo = typeof( val )
-
- if ( typo == "array" ) {
- display_array( val )
- return;
- } else if( 0 + val ) {
- val = sprintf( "%s (hex 0x%04X)", val, val )
- } else if( typo == "string" ){
- val = "\"" val "\""
- }
-
- debug_message( sprintf("%s == %s, type: %s", varname, val, typo ))
- debug_newline();
- }
-
-
- # If name is a function parameter or local variable of the current
- # function being debugged, then return the index of that variable.
- # stframe is the frame number of the function desired.
- local function debug_find_stvar(varname,stframe)
- {
- local x, list,list1,n,i
- if ((x = debug_get_frame(stframe))) {
- split(x[4],list1,";") # x[4] is the parameter;local list
- n = split(list1[1],list) # list1[1] is the parameters
- for (i = 1; i <= n; i++) {
- if (list[i] == varname) return(i)
- }
- n = split(list1[2],list) # list1[2] is the locals
- for (i = 1; i <= n; i++) {
- if (list[i] == varname) return(- i)
- }
- }
- return(0)
- }
-
-
- #
- # List Breakpoints
- #
- function bl()
- {
- local i,j = 0;
- local gid = 0;
- local cw;
- local top, bottom;
-
- for (i in debug_fun_breakpoint_names) {
- if (!j) debug_message( "Breakpoints" );
- debug_newline( 1 );
- debug_message( sprintf( "%4d %s %s", j++,
- and(debug_fun_bp_types[i],BP_ENABLED) ? "e" : "d", \
- debug_fun_breakpoint_names[i] ));
- }
-
- if (debug_filename &&
- (current_window == debug_window) ||
- (current_window == debug_command_window)) {
- cw = current_window;
- current_window = debug_window;
- top = window_first;
- bottom = current_line + distance_to_window_bottom();
- while (top <= bottom) {
- if ((top != current_line) &&
- ((debug_filename ":" top) in debug_fun_breakpoint_names)) {
- highlight_window( 0, top - window_first,
- window_text_width, 1, 0x000F,
- debug_window );
- }
- top++;
- }
- breakpoints_visible = 1;
- assign_current_window( cw );
- }
-
- if (!j)
- debug_message( "No Breakpoints Set" );
-
- debug_newline();
- }
-
-
- #
- # Clear Breakpoint
- #
- function bc( str )
- {
- local gid,i;
-
- i = (str == "*" ? -1 : atoi( str ));
- if ((i == 0) && (str != "0"))
- return;
-
- if (i >= 0) {
- gid = bpindex_to_gid( i );
- if ((gid) && (gid in debug_fun_breakpoints)) {
- delete debug_fun_breakpoints[gid]
- delete debug_fun_breakpoint_names[gid]
- delete debug_fun_bp_types[gid];
- } else {
- debug_message("Breakpoint " i " not set.")
- debug_newline();
- }
- } else {
- # Clear all breakpoints
- delete debug_fun_breakpoints
- delete debug_fun_breakpoint_names;
- delete debug_fun_bp_types;
- }
- }
-
-
- #
- # Disable Breakpoint
- #
- function bd( str ){
- local gid,i;
-
- i = (str == "*" ? -1 : atoi( str ));
- if ((i == 0) && (str != "0"))
- return;
-
- if (i >= 0) {
- gid = bpindex_to_gid( i );
- if ((gid) && (gid in debug_fun_breakpoints))
- debug_fun_bp_types[gid] = and( debug_fun_bp_types[gid], not(BP_ENABLED));
- } else {
- for (gid in debug_fun_bp_types)
- debug_fun_bp_types[gid] = and( debug_fun_bp_types[gid], not(BP_ENABLED));
- }
- }
-
- #
- # Enable Breakpoint
- #
- function be( str ){
- local gid,i;
-
- i = (str == "*" ? -1 : atoi( str ));
- if ((i == 0) && (str != "0"))
- return;
-
- if (i >= 0) {
- gid = bpindex_to_gid( i );
- if (gid)
- debug_fun_bp_types[gid] = or( debug_fun_bp_types[gid], BP_ENABLED);
- } else {
- for (gid in debug_fun_bp_types)
- debug_fun_bp_types[gid] = or( debug_fun_bp_types[gid], BP_ENABLED);
- }
- }
-
-
-
- #
- # Set Breakpoints
- #
- function bp(funname)
- {
- local gid;
- local i = 0;
- local msglvl = message_level;
-
- debug_init()
-
- message_level = 2;
- gid = function_id(funname)
- message_level = msglvl;
-
- # This is magic: acceptable gids lie in the range 1000 to 8000
- if (!gid || (gid < 1000 || gid >= 8000)) {
- debug_message("Invalid break address: " funname)
- debug_newline();
- return 0
- }
-
- debug_fun_breakpoints[gid] = 0
- debug_fun_breakpoint_names[gid] = function_name( gid );
- debug_fun_bp_types[gid] = debug_go_mode ? BP_ENABLED + BP_GOTO_POINT : BP_ENABLED;
-
- if (!debugger_running) {
- #
- # don't make the windows visible unless the breakpoints
- # were set from within the debugger.
- #
- hide_window( debug_window );
- hide_window( debug_command_window );
-
- debug_go_mode = 1;
- debug_step_gid = 0;
- debug_function(debug_id)
- }
- return gid;
- }
-
-
- function bp_line(){
- local fn;
-
- if (debug_view_file) {
- fn = buildpath( debug_view_file ) ":" current_line;
-
- if (debug_lineno && (current_line != debug_lineno))
- highlight_window( 0, current_line - window_first,
- window_text_width, 1, debug_color_text,
- debug_window );
- if (fn in debug_fun_breakpoints) {
- delete( debug_fun_breakpoints[fn] );
- delete( debug_fun_bp_types[fn] );
- delete( debug_fun_breakpoint_names[fn] );
- } else {
- debug_bp_linenos[ current_line ] = 0;
- debug_fun_breakpoints[ fn ] = current_line;
- debug_fun_bp_types[ fn ] = BP_ENABLED;
- debug_fun_breakpoint_names[ fn ] = fn;
- highlight_window( 0, current_line - window_first,
- window_text_width, 1, 0x000F,
- debug_window );
- breakpoints_visible = 1;
- }
- }
- }
-
-
-
- function debug_go()
- {
- debug_step_gid = 0;
- debug_go_mode = 1
- process_end(1)
- }
-
-
- # Function to perform ? debug command.
- # Prompt for variable, then print it out.
- #
- function debug_query( varname )
- {
- local msglev = message_level
- local fid,n
- local val
-
- if (!varname)
- return;
-
- assign_current_window( original_window );
- current_buffer = original_buffer;
-
- # Look for local or parameter, then module local var, then global.
- # Turn off error messages while we are doing this.
- message_level = 2
- if (debug_gid && (n = debug_find_stvar(varname,1))) {
- print_val(varname,debug_get_stack_var(1,n))
- }
- else if ((fid = quoted_function_id(path_fname(debug_filename) ":" varname)) ||
- (fid = quoted_function_id(varname))) {
- print_val(varname,execute_function(fid))
- }
- else {
- current_window = debug_command_window;
- current_buffer = debug_command_buffer;
- debug_message("Variable \"" varname "\" not found.");
- debug_newline();
- }
- message_level = msglev
-
- current_window = debug_command_window;
- current_window = debug_window;
- current_window = debug_command_window;
- }
-
-
- # Call this with the gid and line number of function being debugged,
- # or with gid == 0 to just bring up the debugger on nothing.
- # debug_session returns 1 to continue debugging, 0 to quit
- local function debug_session(){
- local filename = debug_filename;
- local cb;
-
- attach_break_handler()
-
- original_window = current_window
- original_buffer = current_buffer
-
- if (!debugger_running) {
- restore_window( debug_window );
- restore_window( debug_command_window );
- debugger_running = 1;
- }
-
- unhighlight_line();
-
- current_window = debug_command_window;
-
- debug_at()
-
- if (command_mode)
- current_window = debug_command_window;
-
- push_keymap( command_mode ? debug_command_keymap : debug_keymap );
-
- debugger_running = process_begin()+0
-
- pop_keymap()
-
- if (!debugger_running) {
- hide_window( debug_command_window );
- hide_window( debug_window );
- }
-
- assign_current_window( original_window);
- current_buffer = original_buffer;
-
- if ( !( debugger_running && !debug_flip) )
- display_update()
-
- return(debugger_running)
- }
-
-
-
- local function debug_file_display( filename ){
- local def_buf_eol = default_buffer_eol_string;
-
- debug_view_file = filename;
- delete_buffer( debug_buffer )
-
-
- default_buffer_eol_string = "\r\n"
- current_buffer =
- debug_buffer = create_buffer( debug_gid \
- ? "FILE: " debug_filename " FUNCTION: " function_name(debug_gid) \
- : debug_empty_name,
- debug_filename,
- BUFFER_SYSTEM + BUFFER_NO_UNDO + BUFFER_READ_ONLY)
- default_buffer_eol_string = def_buf_eol;
-
- buffer_tabs = debug_tabs;
- attach_window_buffer( current_window, current_buffer );
- }
-
- function debug_at()
- {
- current_window = debug_window;
-
-
- #
- # if the current file displayed doesn't equal the one that's
- # suppose to be displayed, find the one to display
- #
- if (debug_filename != debug_view_file) {
- debug_filename = debug_gid ? get_source_file_name(debug_gid) : "";
- debug_file_display( debug_filename );
- }
-
- if (debug_gid) {
- current_line = debug_lineno;
- center_cursor();
- highlight_line( debug_color_highlight );
- }
-
- }
-
-
- local currentFrame = 1;
-
- # Gid is the function_id of the function being executed.
- # lineno is the line number in that function.
- #
- function debug_fun(gid,lineno)
- {
- local fn;
- local i,ln;
- local x;
-
- # If we are performing a debug_step function,
- # keep going until we get back to the function
- # we did the step in or stepping out of.
- #
- if (debug_step_gid && (gid != debug_step_gid)) {
- if ( debug_get_frame(currentFrame) ) {
- debug_function(debug_id)
- return;
- }
- }
-
- if (debug_num_steps) {
- if (debug_num_steps != -1)
- --debug_num_steps;
- if (debug_num_steps) {
- if (!keyboard_input_pending || debug_step_gid) {
- original_window = current_window
- original_buffer = current_buffer
-
- if (debug_gid != gid) {
- debug_filename = gid ? get_source_file_name(gid) : "";
- debug_gid = gid;
- }
-
- debug_lineno = lineno;
- unhighlight_line();
- debug_at();
- if (!debug_gid)
- highlight_line( debug_color_highlight );
- display_update();
-
- assign_current_window( original_window );
- current_buffer = original_buffer;
-
- debug_function(debug_id)
-
- return;
- }
- if (!debug_step_gid)
- getkey();
- debug_num_steps = 0;
- }
- debug_step_gid = 0;
- }
-
- # If we are performing a debug_go function, keep going
- # until a breakpoint is reached.
- # We remember the first line number of each function.
- if (debug_go_mode) {
- if ( (gid in debug_fun_breakpoints) &&
- and(debug_fun_bp_types[gid], BP_ENABLED) &&
- (!debug_fun_breakpoints[gid] ||
- (debug_fun_breakpoints[gid] == lineno))){
- if (!debug_fun_breakpoints[gid])
- debug_fun_breakpoints[gid] = lineno;
- if (and(debug_fun_bp_types[gid], BP_GOTO_POINT))
- debug_remove_goto_point( gid );
- } else if (lineno in debug_bp_linenos) {
- fn = gid ? get_source_file_name( gid ) ":" lineno : ""
- if ( !((fn in debug_fun_breakpoints) &&
- (and(debug_fun_bp_types[fn], BP_ENABLED))) ) {
- debug_function(debug_id)
- return;
- }
- delete( debug_bp_linenos );
- for (i in debug_fun_breakpoints)
- if ( (ln = debug_fun_breakpoints[i]) )
- debug_bp_linenos[ ln ] = ln;
- } else {
- debug_function(debug_id)
- return;
- }
- debug_go_mode = 0;
- debug_num_steps = 0;
- }
-
- if (debug_gid != gid) {
- debug_filename = gid ? get_source_file_name(gid) : "";
- debug_gid = gid;
- }
-
- debug_lineno = lineno;
-
- for (currentFrame=0; debug_get_frame(currentFrame+1); currentFrame++)
- continue;
-
- remove_break_handler()
- if ( debug_session() ) {
- debug_function(debug_id)
- attach_break_handler()
- }
- }
-
- local function debug_remove_goto_point( gid ){
- delete( debug_fun_breakpoints[gid] )
- delete( debug_fun_bp_types[gid] )
- delete( debug_fun_breakpoint_names[gid] )
- }
-
- local function bpindex_to_gid( index ){
- local gid;
-
- for( gid in debug_fun_bp_types) {
- if (!index) return gid;
- index--;
- }
- return 0;
- }
-
-
- #-------------------------------------------------------------------
- #
- # Keymap bound functions
- #
- #-------------------------------------------------------------------
-
-
- function debug_left(){
- left();
- if (current_column < command_mode+1) {
- scroll_horizontal( -display_width );
- right();
- }
- }
- function debug_up(){
- if (command_mode)
- up();
- else {
- up();
- highlight_line( debug_color_highlight );
- }
- }
- function debug_down(){
- if (command_mode)
- down();
- else {
- down();
- highlight_line( debug_color_highlight );
- }
- }
- function debug_bol(){
- goto_bol();
- scroll_horizontal( -display_width );
- right();
- }
- function debug_page_up(){
- if (command_mode) {
- page_up(); current_column = 2;
- } else {
- page_up();
- highlight_line( debug_color_highlight );
- }
- }
- function debug_page_dn(){
- if (command_mode) {
- page_down(); current_column = 2;
- } else {
- page_down();
- highlight_line( debug_color_highlight );
- }
- }
- function debug_home(){
- goto_buffer_top();
- scroll_window_top();
- current_column = command_mode+1;
- highlight_line( debug_color_highlight );
- }
- function debug_end(){
- goto_buffer_bottom();
- scroll_window_bottom();
- current_column = command_mode+1;
- highlight_line( debug_color_highlight );
- }
- function debug_backspace(){
- if (!command_mode)
- current_window = debug_command_window;
-
- if (current_column > 2) {
- backspace();
- }
-
- if (!command_mode)
- current_window = debug_window;
- }
- function debug_delete_chars(){
- if (!command_mode)
- current_window = debug_command_window;
- if (current_column <= current_line_width) {
- delete_chars(1);
- }
- if (!command_mode)
- current_window = debug_window;
- }
- function debug_insert_key(){
- if (!command_mode)
- current_window = debug_command_window;
- insert_key( current_key );
- if (!command_mode)
- current_window = debug_window;
- }
- function debug_resize_window(){
- local cw = current_window;
-
- if (((current_key == CTRL_G) && command_mode) ||
- ((current_key == CTRL_T) && !command_mode)) {
- current_window = debug_window;
- if (window_height > 3 ) {
- # make the command window larger
- frame_window( window_x0, window_y0, \
- window_width, window_height - 1 );
- current_window = debug_command_window;
- frame_window( window_x0, window_y0 - 1, \
- window_width, window_height + 1);
- }
- } else {
- current_window = debug_command_window;
- if (window_height > 3 ) {
- # make the debug window larger
- frame_window( window_x0, window_y0 + 1, \
- window_width, window_height - 1);
- current_window = debug_window;
- frame_window( window_x0, window_y0, \
- window_width, window_height + 1 );
- }
- }
- assign_current_window( cw );
- }
- function debug_toggle_windows(){
- if ( (command_mode = !command_mode) ) {
- current_window = debug_command_window;
- pop_keymap();
- push_keymap( debug_command_keymap );
- } else {
- current_window = debug_window;
- pop_keymap();
- push_keymap( debug_keymap );
- }
- }
- function debug_message( str ){
- if (current_window == debug_command_window)
- insert_string( str );
- else
- notify( str );
- }
-
- function debug_newline( no_prmpt ){
- if (current_window == debug_command_window) {
- insert_newline();
- insert_key( ord(no_prmpt ? " " : ">") );
- delete_to_eol();
- }
- }
-
- function debug_help()
- {
- display_help_item( "debug" );
- }
-
- function debug_enter(){
- local cmnd;
- local cw = current_window;
- local cb = current_buffer;
- local ch;
- local str;
- local orig_cmnd;
- local upper_cmnd;
- local nch;
- local id;
-
- current_window = debug_command_window;
- current_buffer = debug_command_buffer;
-
- # read the command from the current line
- #
- current_column = 2;
- cmnd = read_buffer();
- goto_buffer_bottom();
-
- debug_newline();
-
- if (distance_to_window_bottom() < 0)
- scroll_window_bottom();
- else if (distance_to_window_top() < 0)
- scroll_window_top();
-
- orig_cmnd = cmnd;
- cmnd = compress( ltrim( trim( cmnd, " \t" ), " \t" ), " \t" );
- upper_cmnd = toupper( cmnd );
- ch = substr(upper_cmnd,1,1);
-
- if (cmnd) {
- ch == toupper( substr(cmnd,1,1) );
- if (ch == "B") {
- # Breakpoints
- #
- cmnd = substr( cmnd, 2 );
- ch = toupper( substr( cmnd,1,1 ));
- if (upper_cmnd == "BL") {
- bl();
- } else if (ch == "P") {
- bp( substr( cmnd,2 ) );
- } else {
- str = ltrim( substr( cmnd,2 ));
- if (ch == "C")
- bc( str );
- else if (ch == "E")
- be( str );
- else if (ch == "D")
- bd( str );
- else
- debug_bad_command( orig_cmnd );
- }
- } else if ( (id = function_id( cmnd )) ) {
- assign_current_window( original_window );
- current_buffer = original_buffer;
- execute_function( id );
- } else {
- if (cmnd == ".") {
- # Restore position
- #
- debug_at();
- } else if (ch == "?") {
- # Query
- #
- debug_query( ltrim(trim(substr( cmnd,2 ))));
- } else if (upper_cmnd == "E") {
- # Execute
- #
- debug_num_steps = -1;
- debug_trace();
- } else if (ch == "G") {
- # Go
- #
- cmnd = ltrim( substr( cmnd,2 ));
- if (cmnd != "") {
- debug_go_mode = 1
- if (bp( cmnd ))
- debug_go();
- } else
- debug_go();
- } else if (upper_cmnd == "H") {
- # Help
- #
- debug_help();
- } else if (ch == "P") {
- # Step over
- #
- cmnd = ltrim( substr( cmnd,2 ));
- if (cmnd != "") {
- if ( (debug_num_steps = atoi( cmnd )) > 0 );
- debug_step();
- } else
- debug_step();
- } else if ((upper_cmnd == "Q") || (upper_cmnd == "EXIT")) {
- # Quit
- #
- debug_esc();
- } else if (cmnd== "@") {
- # redraw display
- #
- display_redraw();
- } else if (cmnd == "K" || cmnd == "k") {
- # Stack Trace
- #
- debug_callstack();
- } else if (ch == "#") {
- # Tabs
- #
- current_window = debug_window;
- current_buffer = debug_buffer;
- debug_tabs =
- buffer_tabs = substr( cmnd,2 );
- display_update();
- current_window = debug_command_window;
- current_buffer = debug_command_buffer;
- } else if (ch == "T") {
- # Trace
- #
- cmnd = ltrim( substr( cmnd,2 ));
- if (cmnd != "") {
- if ( (debug_num_steps = atoi( cmnd )) > 0);
- debug_trace();
- } else
- debug_trace();
- } else if (ch == "V") {
- # View new file
- #
- current_window = debug_window;
- current_buffer = debug_buffer;
-
- debug_view( substr( cmnd,2 ) );
- current_window = debug_command_window;
- current_buffer = debug_command_buffer;
- } else if (ch == "/") {
- # Search
- #
- current_window = debug_window;
- current_buffer = debug_buffer;
- debug_search( orig_cmnd );
- current_window = debug_command_window;
- current_buffer = debug_command_buffer;
- } else if (ch == "O") {
- cmnd = substr( cmnd, 2 );
- ch = toupper( substr( cmnd,1,1 ));
- nch = toupper( ltrim(substr( cmnd, 2 )));
- if (ch == "R") {
- # regex searching option
- if (nch == "+")
- debug_search_flags = or( debug_search_flags, SEARCH_REGEX )
- else if (nch == "-")
- debug_search_flags = and( debug_search_flags, not(SEARCH_REGEX) )
- else
- debug_bad_command( orig_cmnd );
- debug_show_options( OR_OPTION );
- } else if (ch == "F") {
- # flipping screen
- if (nch == "+")
- debug_flip = 1;
- else if (nch == "-")
- debug_flip = 0;
- else debug_bad_command( orig_cmnd );
- debug_show_options( OF_OPTION );
- } else if (ch == "C") {
- # case sensitive searching option
- if (nch == "+")
- debug_search_flags = and( debug_search_flags, not(SEARCH_IGNORE_CASE) )
- else if (nch == "-")
- debug_search_flags = or( debug_search_flags, SEARCH_IGNORE_CASE )
- else
- debug_bad_command( orig_cmnd );
- debug_show_options( OC_OPTION );
- } else if (ch == "") {
- debug_show_options( O_OPTION );
- } else {
- debug_bad_command( orig_cmnd );
- }
- } else {
- debug_bad_command( orig_cmnd );
- }
- }
- }
-
-
- if (distance_to_window_bottom() < 0)
- scroll_window_bottom();
- else if (distance_to_window_top() < 0)
- scroll_window_top();
-
-
- assign_current_window( cw );
- current_buffer = cb;
- }
-
- function debug_bad_command( cmnd ){
- debug_message( "Unknown command: " cmnd );
- debug_newline();
- }
-
-
- function debug_left_press(){
- local mp;
- local wc = window_containing( mouse_event_x, mouse_event_y );
-
- if (wc == debug_window) {
- current_window = debug_window;
- command_mode = 0;
- } else if (wc == debug_command_window) {
- current_window = debug_command_window;
- command_mode = 1;
- } else
- return;
-
- if (window_border_contains( mouse_event_x, mouse_event_y, debug_window ) ||
- window_border_contains( mouse_event_x, mouse_event_y, debug_command_window )) {
- mp = mouse_position( 1 );
- if ( and(mp, MOUSE_N + MOUSE_E ) && !and(mp, MOUSE_W) ) {
- if (!command_mode)
- unhighlight_line();
- left_press( 1 );
- if (!command_mode)
- highlight_line( debug_color_highlight );
- }
- }
- }
-
-
- local last_search = "";
- local debug_search_flags = 0;
-
- function debug_search( cmnd ){
- if (!debug_search_flags)
- debug_search_flags = SEARCH_FORWARD + \
- SEARCH_IGNORE_CASE + \
- SEARCH_ADVANCE + \
- SEARCH_WRAPS + \
- SEARCH_MAXIMAL_MATCH;
-
- if ( length( cmnd ) > index( cmnd, "/") )
- last_search = substr( cmnd, index( cmnd, "/" )+1 );
-
- if (search( last_search, debug_search_flags ))
- center_cursor();
- highlight_line( debug_color_highlight );
- }
-
- function debug_view( fname ){
- local cb = current_buffer;
- local def_buf_eol = default_buffer_eol_string;
-
-
- fname = ltrim( trim( fname ) )
-
- default_buffer_eol_string = "\r\n"
- current_buffer = create_buffer( \
- "FILE: " path_fname(fname) path_ext(fname),
- fname,
- BUFFER_SYSTEM + BUFFER_NO_UNDO + BUFFER_READ_ONLY)
- default_buffer_eol_string = def_buf_eol;
-
- if (buffer_size) {
- buffer_tabs = debug_tabs;
-
- delete_buffer( debug_buffer )
- debug_buffer = current_buffer;
-
- debug_view_file = fname;
- attach_window_buffer( debug_window, debug_buffer)
- }
-
- current_buffer = cb;
- }
-
-
- #
- # options settings to be shown
- #
- local OR_OPTION = 0x01
- local OF_OPTION = 0x02
- local OC_OPTION = 0x04
- local O_OPTION = 0x07
-
- local function debug_show_options( option ){
- if ( and(option, OR_OPTION) ) {
- if (and(debug_search_flags, SEARCH_REGEX))
- debug_message( "Regular Expression Searching On.")
- else
- debug_message( "Regular Expression Searching Off.")
- debug_newline();
- }
- if ( and(option, OF_OPTION) ) {
- if (debug_flip)
- debug_message( "Window Flipping On.")
- else
- debug_message( "Window Flipping Off.")
- debug_newline();
- }
- if ( and(option, OC_OPTION) ) {
- if (and(debug_search_flags, SEARCH_IGNORE_CASE))
- debug_message( "Case Searching Off.")
- else
- debug_message( "Case Searching On.")
- debug_newline();
- }
- }
-
-
-
- local y_highlight = -1;
- local y_ext = -1;
- local x_ext = -1;
-
- local function highlight_line( attr ){
-
-
- display_update(); # this will set window_first appropriately
- unhighlight_line();
-
- y_highlight = debug_lineno - window_first;
-
- y_ext = window_text_height;
- x_ext = window_text_width;
-
- if ((y_highlight < 0) || (y_highlight >= y_ext))
- return;
-
- highlight_window( 0, y_highlight, x_ext, 1, attr, debug_window );
- }
-
- local function unhighlight_line(){
-
- if (breakpoints_visible) {
- breakpoints_visible = 0;
- display_redraw();
- } else {
- # use the last highlighted line setting to unhighlight
- #
- if ((y_highlight >= 0) && (y_highlight < y_ext))
- highlight_window( 0, y_highlight, x_ext, 1, debug_color_text,
- debug_window );
- }
- y_highlight = -1;
- }
-
-
-
- local function get_source_file_name( gid ){
- local fn = source_file_name( gid );
- local src_name;
-
- if (findfirst( fn ) == "")
- return buildpath( path_fname( fn ) path_ext( fn ) );
- return fn;
- }
-
- global function debug_ctrl_break(){
- debug_num_steps = 0;
- debug_go_mode = 0;
- }
-
-
- function attach_break_handler(){
- if (!ctrl_break_attached) {
- attach_event_handler( EVENT_CTRL_BREAK, function_id( "debug_ctrl_break" ));
- ctrl_break_attached = 1;
- }
- }
-
-
- function remove_break_handler(){
- if (ctrl_break_attached) {
- delete_event( EVENT_CTRL_BREAK, function_id( "debug_ctrl_break" ));
- ctrl_break_attached = 0;
- }
- }
-
-