diff --git a/CHANGELOG.md b/CHANGELOG.md index 11f8590..0c68b48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ ## 0.2.0 (2012-06-11) -# Breakpoints. -* **finish** command. -* Internal cleanup and bug fixes. +* Breakpoints +* **finish** command +* Internal cleanup and bug fixes ## 0.1.0 (2012-06-07) diff --git a/lib/pry-debugger/breakpoints.rb b/lib/pry-debugger/breakpoints.rb index 208f4c0..17d9235 100644 --- a/lib/pry-debugger/breakpoints.rb +++ b/lib/pry-debugger/breakpoints.rb @@ -10,13 +10,21 @@ module PryDebugger # Add a new breakpoint. def add(file, line, expression = nil) - raise ArgumentError, 'Invalid file!' unless File.exist?(file) + if !File.exist?(file) && file != Pry.eval_path + raise ArgumentError, 'Invalid file!' unless File.exist?(file) + end + validate_expression expression + Pry.processor.debugging = true - Debugger.add_breakpoint(File.expand_path(file), line, expression) + + path = file == Pry.eval_path ? file : File.expand_path(file) + Debugger.add_breakpoint(path, line, expression) end # Change the conditional expression for a breakpoint. def change(id, expression = nil) + validate_expression expression + breakpoint = find_by_id(id) breakpoint.expr = expression breakpoint @@ -79,5 +87,10 @@ module PryDebugger breakpoint.enabled = enabled breakpoint end + + def validate_expression(expression) + # `complete_expression?` throws a SyntaxError on invalid input. + expression && Pry::Code.complete_expression?(expression) + end end end diff --git a/lib/pry-debugger/commands.rb b/lib/pry-debugger/commands.rb index 379da00..05f3ebf 100644 --- a/lib/pry-debugger/commands.rb +++ b/lib/pry-debugger/commands.rb @@ -142,13 +142,13 @@ module PryDebugger file, line = case place - when /(\d+)/ # Line number only + when /^(\d+)$/ # Line number only line = $1 unless PryDebugger.check_file_context(target) raise ArgumentError, 'Line number declaration valid only in a file context.' end [target.eval('__FILE__'), line] - when /(.+):(\d+)/ # File and line number + when /^(.+):(\d+)$/ # File and line number [$1, $2] else # Method or class name self.args = [place] diff --git a/lib/pry-debugger/pry_ext.rb b/lib/pry-debugger/pry_ext.rb index 4ff9bd3..60ed4f7 100644 --- a/lib/pry-debugger/pry_ext.rb +++ b/lib/pry-debugger/pry_ext.rb @@ -2,21 +2,22 @@ require 'pry' require 'pry-debugger/processor' class << Pry - alias_method :start_existing, :start + alias_method :start_without_pry_debugger, :start attr_reader :processor - def start(target = TOPLEVEL_BINDING, options = {}) + def start_with_pry_debugger(target = TOPLEVEL_BINDING, options = {}) @processor ||= PryDebugger::Processor.new if target.is_a?(Binding) && PryDebugger.check_file_context(target) # Wrap the processer around the usual Pry.start to catch navigation # commands. @processor.run(true) do - start_existing(target, options) + start_without_pry_debugger(target, options) end else # No need for the tracer unless we have a file context to step through - start_existing(target, options) + start_without_pry_debugger(target, options) end end + alias_method :start, :start_with_pry_debugger end diff --git a/lib/pry-debugger/pry_remote_ext.rb b/lib/pry-debugger/pry_remote_ext.rb index 4dbb0f0..709c0af 100644 --- a/lib/pry-debugger/pry_remote_ext.rb +++ b/lib/pry-debugger/pry_remote_ext.rb @@ -19,14 +19,15 @@ module PryRemote end # Override to reset our saved global current server session. - alias_method :teardown_existing, :teardown - def teardown + alias_method :teardown_without_pry_debugger, :teardown + def teardown_with_pry_debugger return if @torn - teardown_existing + teardown_without_pry_debugger PryDebugger.current_remote_server = nil @torn = true end + alias_method :teardown, :teardown_with_pry_debugger end end diff --git a/pry-debugger.gemspec b/pry-debugger.gemspec index 4a9ec30..d9bfcd4 100644 --- a/pry-debugger.gemspec +++ b/pry-debugger.gemspec @@ -20,6 +20,6 @@ Gem::Specification.new do |gem| # Dependencies gem.required_ruby_version = '>= 1.9.2' gem.add_runtime_dependency 'pry', '~> 0.9.9' - gem.add_runtime_dependency 'debugger', '~> 1.1.3' + gem.add_runtime_dependency 'debugger', '~> 1.2.0' gem.add_development_dependency 'pry-remote', '~> 0.1.4' end