Class: DEBUGGER__
- Inherits:
-
Object
- Object
- DEBUGGER__
- Defined in:
- lib/debug.rb
Defined Under Namespace
Constant Summary collapse
Class Method Summary collapse
- .break_points ⇒ Object
- .context(thread = Thread.current) ⇒ Object
- .debug_thread_info(input, binding) ⇒ Object
- .display ⇒ Object
- .get_thread(num) ⇒ Object
- .interrupt ⇒ Object
- .make_thread_list ⇒ Object
- .resume ⇒ Object
- .set_last_thread(th) ⇒ Object
- .set_trace(arg) ⇒ Object
- .stdout ⇒ Object
- .stdout=(s) ⇒ Object
- .suspend ⇒ Object
- .thread_list(num) ⇒ Object
- .thread_list_all ⇒ Object
- .waiting ⇒ Object
Class Method Details
.break_points ⇒ Object
784 785 786 |
# File 'lib/debug.rb', line 784 def break_points @break_points end |
.context(thread = Thread.current) ⇒ Object
837 838 839 840 841 842 843 |
# File 'lib/debug.rb', line 837 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
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 |
# File 'lib/debug.rb', line 893 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 |
.display ⇒ Object
780 781 782 |
# File 'lib/debug.rb', line 780 def display @display end |
.get_thread(num) ⇒ Object
849 850 851 852 853 854 855 856 |
# File 'lib/debug.rb', line 849 def get_thread(num) th = @thread_list.index(num) unless th @stdout.print "No thread ##{num}\n" throw :debug_error end th end |
.interrupt ⇒ Object
845 846 847 |
# File 'lib/debug.rb', line 845 def interrupt context(@last_thread).stop_next end |
.make_thread_list ⇒ Object
880 881 882 883 884 885 886 887 888 889 890 891 |
# File 'lib/debug.rb', line 880 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 |
.resume ⇒ Object
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
# File 'lib/debug.rb', line 820 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
803 804 805 |
# File 'lib/debug.rb', line 803 def set_last_thread(th) @last_thread = th end |
.set_trace(arg) ⇒ Object
792 793 794 795 796 797 798 799 800 801 |
# File 'lib/debug.rb', line 792 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 |
.stdout ⇒ Object
772 773 774 |
# File 'lib/debug.rb', line 772 def stdout @stdout end |
.stdout=(s) ⇒ Object
776 777 778 |
# File 'lib/debug.rb', line 776 def stdout=(s) @stdout = s end |
.suspend ⇒ Object
807 808 809 810 811 812 813 814 815 816 817 818 |
# File 'lib/debug.rb', line 807 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
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/debug.rb', line 858 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_all ⇒ Object
874 875 876 877 878 |
# File 'lib/debug.rb', line 874 def thread_list_all for th in @thread_list.values.sort thread_list(th) end end |
.waiting ⇒ Object
788 789 790 |
# File 'lib/debug.rb', line 788 def waiting @waiting end |