Hi gotoken, It stopped raining in Tokyo. How is it in Hokkaido? > From: GOTO Kentaro [mailto:gotoken / math.sci.hokudai.ac.jp] > Sent: Sunday, July 11, 1999 4:12 AM > >> i(nfo) > > > >Gotoken-san, I couldn't find it in debug.rb in ruby/1.3.4-990625... > >Old spec? for example, in ruby-1.2 or younger? > > Sorry, I misunderstood; > There is `info break' only, now and then. I feel easy. Unlike many rubyist, I began to use ruby(1.2.3) from March of this year. I surely have many things to know about ruby. > >By the way, I made a patch since the action was more modeled on gdb. > >'list' command lists just 10 line. > >'list' command memorizes the line number listed before, for each target-file. > >'list -' for listing previous 10 lines. > >'list 0' does not cause error. > >'up' and 'down' puts the stack frame where you are. > > It seems helpful. Thanks! But I made several bugs... Once I had tried, I might understand it immediately... An 'up' command at the top of the stack frame caused to jump to the bottom... (;_;) This is a patch again, from /home/cvs/ruby/lib/debug.rb. / / / Index: debug.rb =================================================================== RCS file: /home/cvs/ruby/lib/debug.rb,v retrieving revision 1.1.1.2.2.3 diff -u -r1.1.1.2.2.3 debug.rb --- debug.rb 1999/06/24 04:24:08 1.1.1.2.2.3 +++ debug.rb 1999/07/11 05:36:17 @@ -6,7 +6,7 @@ @break_points = [] @stop_next = 1 @frames = [nil] - @frame_pos = nil + @frame_pos = nil # nil means not '0' but `unknown'. @last_file = nil @scripts = {} end @@ -23,19 +23,23 @@ val rescue at = caller(0) - printf "%s:%s\n", at.shift, $! + STDOUT.printf "%s:%s\n", at.shift, $! for i in at break if i =~ /`debug_(eval|command)'$/ #` - printf "\tfrom %s\n", i + STDOUT.printf "\tfrom %s\n", i end end end def debug_command(file, line, id, binding) + binding_file = file + binding_line = line + debug_line = {} if (ENV['EMACS'] == 't') - printf "\032\032%s:%d:\n", file, line + STDOUT.printf "\032\032%s:%d:\n", binding_file, binding_line else - printf "%s:%d:%s", file, line, line_at(file, line) + STDOUT.printf "%s:%d:%s", binding_file, binding_line, + line_at(binding_file, binding_line) end @frames[-1] = binding STDOUT.print "(rdb:-) " @@ -60,12 +64,13 @@ else pname = pos = pos.intern.id2name end - printf "Set breakpoint %d at %s:%s\n", @break_points.size, file, pname + STDOUT.printf "Set breakpoint %d at %s:%s\n", @break_points.size, file, + pname @break_points.push [file, pos] when /^b(reak)?$/, /^info b(reak)?$/ n = 0 for f, p in @break_points - printf "%d %s:%s\n", n, f, p + STDOUT.printf "%d %s:%s\n", n, f, p n += 1 end when /^del(ete)?(\s+(\d+))?$/ @@ -83,10 +88,10 @@ pos = Integer(pos) if @break_points[pos] bp = @break_points[pos] - printf "Clear breakpoint %d at %s:%s\n", pos, bp[0], bp[1] + STDOUT.printf "Clear breakpoint %d at %s:%s\n", pos, bp[0], bp[1] @break_points[pos] = nil else - printf "Breakpoint %d is not defined\n", pos + STDOUT.printf "Breakpoint %d is not defined\n", pos end end when /^c(ont)?$/ @@ -123,6 +128,10 @@ @frame_pos = 0 else binding = @frames[@frame_pos] + frame_info = caller(4)[-(@frame_pos+1)] + STDOUT.print "at #{frame_info}\n" + frame_info.sub( /:in `.*'$/, '' ) =~ /^(.*):(\d+)$/ + binding_file, binding_line = $1, $2.to_i end when /^down\s*(\d+)??$/ if $1 @@ -133,12 +142,16 @@ unless @frame_pos @frame_pos = @frames.size - 1 end - if lev >= @frames.size or @frame_pos and @frame_pos+lev >= @frames.size + @frame_pos += lev + if @frame_pos >= @frames.size STDOUT.print "at stack bottom\n" @frame_pos = nil else - @frame_pos += lev binding = @frames[@frame_pos] + frame_info = caller(4)[-(@frame_pos+1)] + STDOUT.print "at #{frame_info}\n" + frame_info.sub( /:in `.*'$/, '' ) =~ /^(.*):(\d+)$/ + binding_file, binding_line = $1, $2.to_i end when /^fin(ish)?$/ @finish_pos = @frames.size @@ -151,32 +164,39 @@ when /^where$/ at = caller(4) for i in at - printf " %s\n", i + STDOUT.printf " %s\n", i end when /^l(ist)?(\s+(.*))?$/ - if $3 + if !$3 + b = debug_line[binding_file]? debug_line[binding_file] + 10 : + binding_line - 5 + e = b + 9 + elsif $3 == '-' + b = debug_line[binding_file]? debug_line[binding_file] - 10 : + binding_line - 5 + e = b + 9 + else b, e = $3.split(/[-,]/) - b = Integer(b)-1 if e - e = Integer(e)-1 + b = Integer(b) + e = Integer(e) else - e = b + 10 + b = Integer(b)-5 + e = b + 9 end end - unless b - b = line - 1 - e = line + 9 - end - p [b,e] - line_at(file, line) - if lines = @scripts[file] and lines != TRUE - n = b+1 - for l in lines[b..e] - printf "%4d %s", n, l - n += 1 + debug_line[binding_file] = b + STDOUT.print "[#{b}, #{e}] in #{binding_file}\n" + line_at(binding_file, binding_line) + if lines = @scripts[binding_file] and lines != TRUE + n = 0 + b.upto(e) do |n| + if n > 0 && lines[n-1] + STDOUT.printf "%4d %s\n", n, lines[n-1].chomp + end end else - printf "no sourcefile available for %s\n", file + STDOUT.printf "no sourcefile available for %s\n", binding_file end when /^p\s+/ p debug_eval($', binding) #' @@ -224,7 +244,7 @@ file = File.basename(file) if @break_points.include? [file, pos] index = @break_points.index([file, pos]) - printf "Breakpoint %d, %s at %s:%s\n", + STDOUT.printf "Breakpoint %d, %s at %s:%s\n", index, debug_funcname(id), file, pos return TRUE end