Class: ZenDebugger
- Inherits:
-
Object
- Object
- ZenDebugger
- Defined in:
- lib/zendebug.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
- .start_debugging ⇒ Object
- .stdout ⇒ Object
- .stdout=(s) ⇒ Object
- .stop_debugging ⇒ Object
- .suspend ⇒ Object
- .thread_list(num) ⇒ Object
- .thread_list_all ⇒ Object
- .waiting ⇒ Object
Class Method Details
.break_points ⇒ Object
775 776 777 |
# File 'lib/zendebug.rb', line 775 def break_points @break_points end |
.context(thread = Thread.current) ⇒ Object
828 829 830 831 832 833 834 |
# File 'lib/zendebug.rb', line 828 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
884 885 886 887 888 889 890 891 892 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 |
# File 'lib/zendebug.rb', line 884 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
771 772 773 |
# File 'lib/zendebug.rb', line 771 def display @display end |
.get_thread(num) ⇒ Object
840 841 842 843 844 845 846 847 |
# File 'lib/zendebug.rb', line 840 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
836 837 838 |
# File 'lib/zendebug.rb', line 836 def interrupt context(@last_thread).stop_next end |
.make_thread_list ⇒ Object
871 872 873 874 875 876 877 878 879 880 881 882 |
# File 'lib/zendebug.rb', line 871 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
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 |
# File 'lib/zendebug.rb', line 811 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
794 795 796 |
# File 'lib/zendebug.rb', line 794 def set_last_thread(th) @last_thread = th end |
.set_trace(arg) ⇒ Object
783 784 785 786 787 788 789 790 791 792 |
# File 'lib/zendebug.rb', line 783 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 |
.start_debugging ⇒ Object
932 933 934 |
# File 'lib/zendebug.rb', line 932 def start_debugging self.context.add_event_hook end |
.stdout ⇒ Object
763 764 765 |
# File 'lib/zendebug.rb', line 763 def stdout @stdout end |
.stdout=(s) ⇒ Object
767 768 769 |
# File 'lib/zendebug.rb', line 767 def stdout=(s) @stdout = s end |
.stop_debugging ⇒ Object
936 937 938 |
# File 'lib/zendebug.rb', line 936 def stop_debugging self.context.remove_event_hook end |
.suspend ⇒ Object
798 799 800 801 802 803 804 805 806 807 808 809 |
# File 'lib/zendebug.rb', line 798 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
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 |
# File 'lib/zendebug.rb', line 849 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
865 866 867 868 869 |
# File 'lib/zendebug.rb', line 865 def thread_list_all for th in @thread_list.values.sort thread_list(th) end end |
.waiting ⇒ Object
779 780 781 |
# File 'lib/zendebug.rb', line 779 def waiting @waiting end |