<commit_before>require 'uri'
require 'timeout'

DEBUGGER_STEP_TYPE = ['STEP','STOVER','STRET','SUSP']
DEBUGGER_STEP_COMMENT = ['Stepped into','Stepped over','Stepped return','Suspended']

def debug_read_cmd(io,wait)
  begin
    if wait
      cmd = io.readpartial(4096)
      $_cmd << cmd if cmd !~ /^\s*$/
    else
      cmd = io.read_nonblock(4096)
      $_cmd << cmd if cmd !~ /^\s*$/
    end

    #$_s.write("get data from front end" + $_cmd.to_s + "\n")
  rescue
    # puts $!.inspect
  end
end

def execute_cmd(cmd, advanced)
  cmd = URI.unescape(cmd.gsub(/\+/,' ')) if advanced
  puts "[Debugger] Executing: #{cmd.inspect}"
  result = ""
  error = '0';
  begin
    result = eval(cmd, $_binding).inspect
  rescue Exception => exc
    error = '1';
    result = "#{$!}".inspect
  end
  
  cmd = URI.escape(cmd.sub(/[\n\r]+$/, ''), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) if advanced
  $_s.write("EV" + (advanced ? "L:#{error}:#{cmd}:" : ':'+(error.to_i != 0 ? 'ERROR: ':'')) + result + "\n")
end

def get_variables(scope)
  #$_s.write("get_variables start\n")

  if (scope =~ /^GVARS/)
   cmd = "global_variables"
   prefix = ""
   vartype = "G"
  elsif (scope =~ /^LVARS/)
   cmd = "local_variables"
   prefix = ""
   vartype = "L"
  elsif (scope =~ /^CVARS/)
   if $_classname =~ /^\s*$/
     return
   end
   cmd = "class_variables"
   prefix = "#{$_classname}."
   vartype = "C"
  elsif (scope =~ /^IVARS/)
   if ($_classname =~ /^\s*$/) or ($_methodname =~ /^\s*$/)
     return
   end
   cmd = "instance_variables"
   prefix = "self."
   vartype = "I"
  end
  begin
    vars = eval(prefix + cmd, $_binding)
    $_s.write("VSTART:#{vartype}\n")
    vars.each do |v|
      if v !~ /^\$(=|KCODE)$/
        begin
          result = eval(v,$_binding).inspect
        rescue Exception => exc
          #$_s.write("get var exception\n")
          result = "#{$!}".inspect
        end
        $_s.write("V:#{vartype}:#{v}:#{result}\n")
      end
    end
    $_s.write("VEND:#{vartype}\n")
  rescue
  end
end

def log_command(cmd)
  # puts "[Debugger] Received command: #{cmd}"
end

def debug_handle_cmd(inline)
  #$_s.write("start of debug_handle_cmd wait=" + inline.to_s + "\n")

  cmd = $_cmd.match(/^([^\n\r]*)([\n\r]+|$)/)[0]
  processed = false
  wait = inline

  if cmd != ""
    if cmd =~/^CONNECTED/
      log_command(cmd)
      puts "[Debugger] Connected to debugger"
      processed = true
    elsif cmd =~/^(BP|RM):/<commit_msg>fix move to ruby 1.9.2<commit_after>require 'uri'
require 'timeout'

DEBUGGER_STEP_TYPE = ['STEP','STOVER','STRET','SUSP']
DEBUGGER_STEP_COMMENT = ['Stepped into','Stepped over','Stepped return','Suspended']

def debug_read_cmd(io,wait)
  begin
    if wait
      cmd = io.readpartial(4096)
      $_cmd << cmd if cmd !~ /^\s*$/
    else
      cmd = io.read_nonblock(4096)
      $_cmd << cmd if cmd !~ /^\s*$/
    end

    #$_s.write("get data from front end" + $_cmd.to_s + "\n")
  rescue
    # puts $!.inspect
  end
end

def execute_cmd(cmd, advanced)
  #$_s.write("execute_cmd start\n")
  cmd = URI.unescape(cmd.gsub(/\+/,' ')) if advanced
  puts "[Debugger] Executing: #{cmd.inspect}"
  result = ""
  error = '0';
  begin
    result = eval(cmd.to_s, $_binding).inspect
  rescue Exception => exc
    error = '1';
    result = "#{$!}".inspect
  end
  
  cmd = URI.escape(cmd.sub(/[\n\r]+$/, ''), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) if advanced
  $_s.write("EV" + (advanced ? "L:#{error}:#{cmd}:" : ':'+(error.to_i != 0 ? 'ERROR: ':'')) + result + "\n")
  #$_s.write("execute_cmd end\n")
end

def get_variables(scope)
  #$_s.write("get_variables start\n")

  if (scope =~ /^GVARS/)
   cmd = "global_variables"
   prefix = ""
   vartype = "G"
  elsif (scope =~ /^LVARS/)
   cmd = "local_variables"
   prefix = ""
   vartype = "L"
  elsif (scope =~ /^CVARS/)
   if $_classname =~ /^\s*$/
     return
   end
   cmd = "class_variables"
   prefix = "#{$_classname}."
   vartype = "C"
  elsif (scope =~ /^IVARS/)
   if ($_classname =~ /^\s*$/) or ($_methodname =~ /^\s*$/)
     return
   end
   cmd = "instance_variables"
   prefix = "self."
   vartype = "I"
  end
  begin
    vars = eval(prefix + cmd, $_binding)
    $_s.write("VSTART:#{vartype}\n")
    vars.each do |v|
      if v !~ /^\$(=|KCODE)$/
        begin
          result = eval(v.to_s, $_binding).inspect
        rescue Exception => exc
          $_s.write("get var exception\n")
          result = "#{$!}".inspect
        end
        $_s.write("V:#{vartype}:#{v}:#{result}\n")
      end
    end
    $_s.write("VEND:#{vartype}\n")
  rescue
  end
end

def log_command(cmd)
  # puts "[Debugger] Received command: #{cmd}"
end

def debug_handle_cmd(inline)
  #$_s.write("start of debug_handle_cmd wait=" + inline.to_s + "\n")

  cmd = $_cmd.match(/^([^\n\r]*)([\n\r]+|$)/)[0]
  processed = false
  wait = inline

  if cmd != ""
    if cmd =~/^CONNECTED/
      log_command(cmd)
      puts "[Debugger] Connected to debugger"
      processed = true
    elsif cmd =~/^(BP|RM):/
{'fraction_non_alphanumeric': 0.20305282185177748, 'fraction_numerical': 0.0054227756577626025, 'mean_word_length': 2.767019667170953, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2869578', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1925, 'n_words': 418}