Module: TraceLineNumbers

Defined in:
lib/tracelines.rb,
ext/trace_nums.c

Overview

require ‘ruby-debug’ ; Debugger.start

Constant Summary collapse

@@SRC_DIR =
File.expand_path(File.dirname(__FILE__))

Class Method Summary collapse

Class Method Details

.lnums_for_file(file) ⇒ Object

Return an array of lines numbers that could be stopped at given a file name of a Ruby program.



12
13
14
# File 'lib/tracelines.rb', line 12

def lnums_for_file(file)
  lnums_for_str(File.read(file))
end

.lnums_for_str(src) ⇒ Object

Return a list of trace hook line numbers for the string in Ruby source src



676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'ext/trace_nums.c', line 676

static VALUE 
lnums_for_str(VALUE self, VALUE src) {
  VALUE result = rb_ary_new(); /* The returned array of line numbers. */
  NODE *node = NULL;
  int critical;

  ruby_nerrs = 0;
  StringValue(src); /* Check that src is a string. */

  critical = rb_thread_critical;
  rb_thread_critical = Qtrue;

  /* Making ruby_in_eval nonzero signals rb_compile_string not to save
     source in SCRIPT_LINES__. */
  ruby_in_eval++; 
  node = rb_compile_string("(numbers_for_str)", src, 1);
  ruby_in_eval--;

  rb_thread_critical = critical;

  if (ruby_nerrs > 0) {
    ruby_nerrs = 0;
#if RUBY_VERSION_CODE < 190
    ruby_eval_tree_begin = 0;
#endif
    rb_exc_raise(ruby_errinfo);
  }

  if (RTEST(ruby_debug)) {
    indent_level = 0;
  }
  ln_eval(self, node, result);
  return result;
}

.lnums_for_str_array(string_array, newline = '') ⇒ Object

Return an array of lines numbers that could be stopped at given a file name of a Ruby program. We assume the each line has n at the end. If not set the newline parameters to n.



21
22
23
# File 'lib/tracelines.rb', line 21

def lnums_for_str_array(string_array, newline='')
  lnums_for_str(string_array.join(newline))
end