Module: PryByebug
- Extended by:
- PryByebug
- Included in:
- PryByebug
- Defined in:
- lib/pry-byebug/base.rb,
lib/pry-byebug/version.rb,
lib/pry-byebug/commands.rb,
lib/pry-byebug/processor.rb,
lib/pry-byebug/breakpoints.rb
Defined Under Namespace
Modules: Breakpoints Classes: Processor
Constant Summary collapse
- VERSION =
'1.3.1'- Commands =
Pry::CommandSet.new do create_command 'step' do description 'Step execution into the next line or method.' " Usage: step [TIMES]\n Aliases: s\n\n Step execution forward. By default, moves a single step.\n\n Examples:\n\n step Move a single step forward.\n step 5 Execute the next 5 steps.\n BANNER\n\n def process\n check_file_context\n breakout_navigation :step, args.first\n end\n end\n alias_command 's', 'step'\n\n create_command 'next' do\n description 'Execute the next line within the current stack frame.'\n\n banner <<-BANNER\n Usage: next [LINES]\n Aliases: n\n\n Step over within the same frame. By default, moves forward a single\n line.\n\n Examples:\n\n next Move a single line forward.\n next 4 Execute the next 4 lines.\n BANNER\n\n def process\n check_file_context\n breakout_navigation :next, args.first\n end\n end\n alias_command 'n', 'next'\n\n create_command 'finish' do\n description 'Execute until current stack frame returns.'\n\n banner <<-BANNER\n Usage: finish\n Aliases: f\n BANNER\n\n def process\n check_file_context\n breakout_navigation :finish\n end\n end\n alias_command 'f', 'finish'\n\n create_command 'continue' do\n description 'Continue program execution and end the Pry session.'\n\n banner <<-BANNER\n Usage: continue\n Aliases: c\n BANNER\n\n def process\n check_file_context\n run 'exit-all'\n end\n end\n alias_command 'c', 'continue'\n\n create_command 'break' do\n description 'Set or edit a breakpoint.'\n\n banner <<-BANNER\n Usage: break <METHOD | FILE:LINE | LINE> [if CONDITION]\n break --condition N [CONDITION]\n break [--show | --delete | --enable | --disable] N\n break [--delete-all | --disable-all]\n Aliases: breakpoint\n\n Set a breakpoint. Accepts a line number in the current file, a file and\n line number, or a method, and an optional condition.\n\n Pass appropriate flags to manipulate existing breakpoints.\n\n Examples:\n\n break SomeClass#run Break at the start of `SomeClass#run`.\n break Foo#bar if baz? Break at `Foo#bar` only if `baz?`.\n break app/models/user.rb:15 Break at line 15 in user.rb.\n break 14 Break at line 14 in the current file.\n\n break --condition 4 x > 2 Add/change condition on breakpoint #4.\n break --condition 3 Remove the condition on breakpoint #3.\n\n break --delete 5 Delete breakpoint #5.\n break --disable-all Disable all breakpoints.\n\n break List all breakpoints. (Same as `breakpoints`)\n break --show 2 Show details about breakpoint #2.\n BANNER\n\n def options(opt)\n opt.on :c, :condition, 'Change the condition of a breakpoint.', :argument => true, :as => Integer\n opt.on :s, :show, 'Show breakpoint details and source.', :argument => true, :as => Integer\n opt.on :D, :delete, 'Delete a breakpoint.', :argument => true, :as => Integer\n opt.on :d, :disable, 'Disable a breakpoint.', :argument => true, :as => Integer\n opt.on :e, :enable, 'Enable a disabled breakpoint.', :argument => true, :as => Integer\n opt.on :'disable-all', 'Disable all breakpoints.'\n opt.on :'delete-all', 'Delete all breakpoints.'\n method_options(opt)\n end\n\n def process\n Pry.processor.pry = _pry_\n\n { :delete => :delete,\n :disable => :disable,\n :enable => :enable,\n :'disable-all' => :disable_all,\n :'delete-all' => :clear\n }.each do |action, method|\n if opts.present?(action)\n Breakpoints.__send__ method, *(method == action ? [opts[action]] : [])\n return run 'breakpoints'\n end\n end\n\n if opts.present?(:condition)\n Breakpoints.change(opts[:condition], args.empty? ? nil : args.join(' '))\n run 'breakpoints'\n elsif opts.present?(:show)\n print_full_breakpoint Breakpoints.find_by_id(opts[:show])\n elsif args.empty?\n run 'breakpoints'\n else\n new_breakpoint\n end\n end\n\n def new_breakpoint\n place = args.shift\n condition = args.join(' ') if 'if' == args.shift\n\n bp =\n case place\n when /^(\\d+)$/ # Line number only\n line = $1\n unless PryByebug.check_file_context(target)\n raise ArgumentError, 'Line number declaration valid only in a file context.'\n end\n Breakpoints.add_file(target.eval('__FILE__'), line.to_i, condition)\n when /^(.+):(\\d+)$/ # File and line number\n Breakpoints.add_file($1, $2.to_i, condition)\n when /^(.*)[.#].+$/ # Method or class name\n if $1.strip.empty?\n unless PryByebug.check_file_context(target)\n raise ArgumentError, 'Method name declaration valid only in a file context.'\n end\n place = target.eval('self.class.to_s') + place\n end\n Breakpoints.add_method(place,condition)\n else\n raise ArgumentError, 'Cannot identify arguments as breakpoint'\n end\n\n print_full_breakpoint bp\n end\n end\n alias_command 'breakpoint', 'break'\n\n\n create_command 'breakpoints' do\n description 'List defined breakpoints.'\n\n banner <<-BANNER\n Usage: breakpoints [OPTIONS]\n Aliases: breaks\n\n List registered breakpoints and their current status.\n BANNER\n\n def options(opt)\n opt.on :v, :verbose, 'Print source around each breakpoint.'\n end\n\n def process\n if Breakpoints.count > 0\n if opts.verbose? # Long-form with source output\n Breakpoints.each { |b| print_full_breakpoint(b) }\n else # Simple table output\n max_width = [Math.log10(Breakpoints.count).ceil, 1].max\n header = \"\#{' ' * (max_width - 1)}# Enabled At \"\n\n output.puts\n output.puts text.bold(header)\n output.puts text.bold('-' * header.size)\n Breakpoints.each do |breakpoint|\n output.printf \"%\#{max_width}d \", breakpoint.id\n output.print breakpoint.enabled? ? 'Yes ' : 'No '\n output.print breakpoint.to_s\n output.print \" (if \#{breakpoint.expr})\" if breakpoint.expr\n output.puts\n end\n output.puts\n end\n else\n output.puts text.bold('No breakpoints defined.')\n end\n end\n end\n alias_command 'breaks', 'breakpoints'\n\n helpers do\n def breakout_navigation(action, times = nil)\n _pry_.binding_stack.clear # Clear the binding stack.\n throw :breakout_nav, { # Break out of the REPL loop and signal tracer\n :action => action,\n :times => times,\n :pry => _pry_\n }\n end\n\n # Ensures that a command is executed in a local file context.\n def check_file_context\n unless PryByebug.check_file_context(target)\n raise Pry::CommandError, 'Cannot find local context. Did you use `binding.pry`?'\n end\n end\n\n # Print out full information about a breakpoint including surrounding code\n # at that point.\n def print_full_breakpoint(breakpoint)\n line = breakpoint.pos\n output.print text.bold(\"Breakpoint \#{breakpoint.id}: \")\n output.print \"\#{breakpoint.to_s} \"\n output.print breakpoint.enabled? ? '(Enabled)' : '(Disabled)'\n output.puts ' :'\n if (expr = breakpoint.expr)\n output.puts \"\#{text.bold('Condition:')} \#{expr}\"\n end\n output.puts\n output.puts breakpoint.source_code.with_line_numbers.to_s\n output.puts\n end\n end\nend\n"
Instance Attribute Summary collapse
-
#current_remote_server ⇒ Object
Reference to currently running pry-remote server.
Instance Method Summary collapse
-
#check_file_context(target) ⇒ Object
Checks that a binding is in a local file context.
Instance Attribute Details
#current_remote_server ⇒ Object
Reference to currently running pry-remote server. Used by the processor.
12 13 14 |
# File 'lib/pry-byebug/base.rb', line 12 def current_remote_server @current_remote_server end |
Instance Method Details
#check_file_context(target) ⇒ Object
Checks that a binding is in a local file context. Extracted from github.com/pry/pry/blob/master/lib/pry/default_commands/context.rb
6 7 8 9 |
# File 'lib/pry-byebug/base.rb', line 6 def check_file_context(target) file = target.eval('__FILE__') file == Pry.eval_path || (file !~ /(\(.*\))|<.*>/ && file != '' && file != '-e') end |