Class: DEBUGGER__

Inherits:
Object
  • Object
show all
Defined in:
ext/ae-debug/debug1.57.rb

Defined Under Namespace

Classes: Context, Mutex

Constant Summary collapse

MUTEX =
Mutex.new

Class Method Summary collapse

Class Method Details

.break_pointsObject



835
836
837
# File 'ext/ae-debug/debug1.57.rb', line 835

def break_points
  @break_points
end

.context(thread = Thread.current) ⇒ Object



888
889
890
891
892
893
894
# File 'ext/ae-debug/debug1.57.rb', line 888

def context(thread=Thread.current)
  c = thread[:__debugger_data__]
  unless c
    thread[:__debugger_data__] = c = Context.new
  end
  c
end

.debug_thread_info(input, binding) ⇒ Object



944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
# File 'ext/ae-debug/debug1.57.rb', line 944

def debug_thread_info(input, binding)
  case input
  when /^l(?:ist)?/
    make_thread_list
    thread_list_all

  when /^c(?:ur(?:rent)?)?$/
    make_thread_list
    thread_list(@thread_list[Thread.current])

  when /^(?:sw(?:itch)?\s+)?(\d+)/
    make_thread_list
    th = get_thread($1.to_i)
    if th == Thread.current
      @stdout.print "It's the current thread.\n"
    else
      thread_list(@thread_list[th])
      context(th).stop_next
      th.run
      return :cont
    end

  when /^stop\s+(\d+)/
    make_thread_list
    th = get_thread($1.to_i)
    if th == Thread.current
      @stdout.print "It's the current thread.\n"
    elsif th.stop?
      @stdout.print "Already stopped.\n"
    else
      thread_list(@thread_list[th])
      context(th).suspend
    end

  when /^resume\s+(\d+)/
    make_thread_list
    th = get_thread($1.to_i)
    if th == Thread.current
      @stdout.print "It's the current thread.\n"
    elsif !th.stop?
      @stdout.print "Already running."
    else
      thread_list(@thread_list[th])
      th.run
    end
  end
end

.displayObject



831
832
833
# File 'ext/ae-debug/debug1.57.rb', line 831

def display
  @display
end

.get_thread(num) ⇒ Object



900
901
902
903
904
905
906
907
# File 'ext/ae-debug/debug1.57.rb', line 900

def get_thread(num)
  th = @thread_list.index(num)
  unless th
    @stdout.print "No thread ##{num}\n"
    throw :debug_error
  end
  th
end

.interruptObject



896
897
898
# File 'ext/ae-debug/debug1.57.rb', line 896

def interrupt
  context(@last_thread).stop_next
end

.make_thread_listObject



931
932
933
934
935
936
937
938
939
940
941
942
# File 'ext/ae-debug/debug1.57.rb', line 931

def make_thread_list
  hash = {}
  for th in Thread::list
    if @thread_list.key? th
      hash[th] = @thread_list[th]
    else
      @max_thread += 1
      hash[th] = @max_thread
    end
  end
  @thread_list = hash
end

.resumeObject



871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
# File 'ext/ae-debug/debug1.57.rb', line 871

def resume
  saved_crit = Thread.critical
  Thread.critical = true
  make_thread_list
  for th, in @thread_list
    next if th == Thread.current
    context(th).clear_suspend
  end
  waiting.each do |th|
    th.run
  end
  waiting.clear
  Thread.critical = saved_crit
  # Schedule other threads to restart as soon as possible.
  Thread.pass
end

.set_last_thread(th) ⇒ Object



854
855
856
# File 'ext/ae-debug/debug1.57.rb', line 854

def set_last_thread(th)
  @last_thread = th
end

.set_trace(arg) ⇒ Object



843
844
845
846
847
848
849
850
851
852
# File 'ext/ae-debug/debug1.57.rb', line 843

def set_trace( arg )
  saved_crit = Thread.critical
  Thread.critical = true
  make_thread_list
  for th, in @thread_list
    context(th).set_trace arg
  end
  Thread.critical = saved_crit
  arg
end

.stdoutObject



823
824
825
# File 'ext/ae-debug/debug1.57.rb', line 823

def stdout
  @stdout
end

.stdout=(s) ⇒ Object



827
828
829
# File 'ext/ae-debug/debug1.57.rb', line 827

def stdout=(s)
  @stdout = s
end

.suspendObject



858
859
860
861
862
863
864
865
866
867
868
869
# File 'ext/ae-debug/debug1.57.rb', line 858

def suspend
  saved_crit = Thread.critical
  Thread.critical = true
  make_thread_list
  for th, in @thread_list
    next if th == Thread.current
    context(th).set_suspend
  end
  Thread.critical = saved_crit
  # Schedule other threads to suspend as soon as possible.
  Thread.pass unless Thread.critical
end

.thread_list(num) ⇒ Object



909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
# File 'ext/ae-debug/debug1.57.rb', line 909

def thread_list(num)
  th = get_thread(num)
  if th == Thread.current
    @stdout.print "+"
  else
    @stdout.print " "
  end
  @stdout.printf "%d ", num
  @stdout.print th.inspect, "\t"
  file = context(th).instance_eval{@file}
  if file
    @stdout.print file,":",context(th).instance_eval{@line}
  end
  @stdout.print "\n"
end

.thread_list_allObject



925
926
927
928
929
# File 'ext/ae-debug/debug1.57.rb', line 925

def thread_list_all
  for th in @thread_list.values.sort
    thread_list(th)
  end
end

.waitingObject



839
840
841
# File 'ext/ae-debug/debug1.57.rb', line 839

def waiting
  @waiting
end