From nobody at rubyforge.org Fri Jan 23 12:20:29 2009 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Fri, 23 Jan 2009 12:20:29 -0500 (EST) Subject: [Ruby-debug-commits] [906] trunk/cli/ruby-debug: Add a kill command Message-ID: <20090123172029.BB745185810F@rubyforge.org> Revision: 906 Author: rockyb Date: 2009-01-23 12:20:29 -0500 (Fri, 23 Jan 2009) Log Message: ----------- Add a kill command Modified Paths: -------------- trunk/cli/ruby-debug/processor.rb Added Paths: ----------- trunk/cli/ruby-debug/commands/kill.rb Added: trunk/cli/ruby-debug/commands/kill.rb =================================================================== --- trunk/cli/ruby-debug/commands/kill.rb (rev 0) +++ trunk/cli/ruby-debug/commands/kill.rb 2009-01-23 17:20:29 UTC (rev 906) @@ -0,0 +1,51 @@ +module Debugger + + # Implements debugger "kill" command + class KillCommand < Command + self.allow_in_control = true + + def regexp + / ^\s* + (?:kill) \s* + (?:\s+(\S+))?\s* + $ + /ix + end + + def execute + puts @match[1] + if @match[1] + signame = @match[1] + unless Signal.list.member?(signame) + errmsg("signal name #{signame} is not a signal I know about\n") + return false + end + if 'KILL' == signame: + @state.interface.finalize + end + else + if not confirm("Really kill? (y/n) ") + return + else + signame = 'KILL' + end + end + Process.kill(signame, Process.pid) + end + + class << self + def help_command + %w[kill] + end + + def help(cmd) + %{ + kill [SIGNAL] + + Send [signal] to Process.pid +Equivalent of Process.kill(Process.pid) + } + end + end + end +end Property changes on: trunk/cli/ruby-debug/commands/kill.rb ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/cli/ruby-debug/processor.rb =================================================================== --- trunk/cli/ruby-debug/processor.rb 2008-12-24 03:32:42 UTC (rev 905) +++ trunk/cli/ruby-debug/processor.rb 2009-01-23 17:20:29 UTC (rev 906) @@ -116,6 +116,8 @@ end rescue IOError, Errno::EPIPE self.interface = nil + rescue SignalException + raise rescue Exception print "INTERNAL ERROR!!! #\{$!\}\n" rescue nil print $!.backtrace.map{|l| "\t#\{l\}"}.join("\n") rescue nil From nobody at rubyforge.org Fri Jan 23 15:51:57 2009 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Fri, 23 Jan 2009 15:51:57 -0500 (EST) Subject: [Ruby-debug-commits] [907] trunk/doc/ruby-debug.texi: Show how to add a new command Message-ID: <20090123205157.DF2111858101@rubyforge.org> Revision: 907 Author: rockyb Date: 2009-01-23 15:51:57 -0500 (Fri, 23 Jan 2009) Log Message: ----------- Show how to add a new command Modified Paths: -------------- trunk/doc/ruby-debug.texi Modified: trunk/doc/ruby-debug.texi =================================================================== --- trunk/doc/ruby-debug.texi 2009-01-23 17:20:29 UTC (rev 906) +++ trunk/doc/ruby-debug.texi 2009-01-23 20:51:57 UTC (rev 907) @@ -3472,6 +3472,7 @@ @menu * Debugger.Breakpoint:: Debugger::Breakpoint * Debugger.Context:: Debugger::Context +* Debugger.Command:: Debugger::Command @end menu @table @code @@ -3585,6 +3586,86 @@ the debugged program, you may want to set this @code{false}. @end table + at node Debugger.Command + at subsection The @code{Debugger::Command} Class + +Each command you run is in fact its own class. Should you want to extend +ruby-debug, it's pretty easy to do since after all ruby-debug is Ruby. + +Each @code{Debugger#Command} class should have the a @code{regexp} +method. This method returns regular expression for command-line +strings that match your command. It's up to you to make sure this +regular expression doesn't conflict with another one. If it does, it's +undefined which one will get matched and run + +In addition the instance needs these methods: + at table @code + at item execute +Code which gets run when you type a command (string) that matches the +commands regular expression. + at item help +A string which gets displayed when folks as for help on that command + at item help_command +A name used the help system uses to show what commands are available. + at end table + +Here's a small example of a new command: + at smallexample +module Debugger + class MyCommand < Command + def regexp + /^\s*me$/ # Regexp that will match your command + end + + def execute + puts "hi" # What you want to happen when your command runs + end + class << self + def help_command + 'me' # String name of command + end + def help(cmd) + # Some sort of help text. + %@{This does whatever it is I want to do@} + end + end +end + at end smallexample + +Now here's an example of how you can load/use it: + at smallexample + require 'rubygems' + require 'ruby-debug' + require '/tmp/mycmd.rb' # or wherever + Debugger.start + x=1 + debugger + y=2 + at end smallexample + +And now an example of invoking it: + at smallexample +ruby /tmp/testit.rb: +/tmp/testit.rb:7 +y=2 +(rdb:1) help +ruby-debug help v0.10.3 +Type 'help ' for help on a specific command +Available commands: +backtrace delete enable help method putl set trace +break disable eval info next quit show undisplay +catch display exit irb p reload source up +condition down finish list pp restart step var +continue edit frame me ps save thread where + ^^ This is you + +(rdb:1) help me +This does whatever it is I want to do +(rdb:1) me +hi +(rdb:1) + at end smallexample + @node Kernel routines @section Additions to @code{Kernel} @@ -3660,7 +3741,6 @@ @end table - @node Using from Subversion @appendix Building and Installing from rubyforge's Subversion Repository