# -*- coding: utf-8 -*- # Copyright (C) 2010 Rocky Bernstein require_relative '../base/subcmd' class Trepan::Subcommand::InfoBreakpoints < Trepan::Subcommand unless defined?(HELP) HELP = < 0 msg("\tignore next %d hits" % bp.ignore) end if bp.hits > 0 ss = (bp.hits > 1) ? 's' : '' msg("\tbreakpoint already hit %d time%s" % [bp.hits, ss]) end end def save_command bpmgr = @proc.brkpts bpmgr.list.inject([]) do |res, bp| iseq = bp.iseq next unless 'file' == iseq.source_container[0] loc = iseq.source_container[1] + ':' loc += # if 'line' == bp.type iseq.offset2lines(bp.offset)[0].to_s # else # 'O' + bp.offset.to_s # end res << "break #{loc}" end end def run(args) verbose = false unless args.empty? if 'verbose' == args[-1] verbose = true args.pop end end show_all = if args.size > 2 opts = { :msg_on_error => "An '#{PREFIX.join(' ')}' argument must eval to a breakpoint between 1..#{@proc.brkpts.max}.", :min_value => 1, :max_value => @proc.brkpts.max } bp_nums = @proc.get_int_list(args[2..-1]) false else true end bpmgr = @proc.brkpts if bpmgr.empty? msg('No breakpoints.') else # There's at least one msg("Num Type Disp Enb Where") if show_all bpmgr.list.each do |bp| bpprint(bp, verbose) end else notfound = [] bp_nums.each do |bp_num| bp = @proc.brkpts[bp_num] if bp bpprint(bp, verbose) else notfound << bp_num end end errmsg "No breakpoint number(s) #{not_found.join(' ')}." unless notfound.empty? end end end end if __FILE__ == $0 # Demo it. require_relative '../../mock' name = File.basename(__FILE__, '.rb') dbgr, cmd = MockDebugger::setup('info') subcommand = Trepan::Subcommand::InfoBreak.new(cmd) puts '-' * 20 subcommand.run(%w(info break)) puts '-' * 20 subcommand.summary_help(name) puts puts '-' * 20 require 'thread_frame' tf = RubyVM::ThreadFrame.current pc_offset = tf.pc_offset def foo 5 end brk_cmd = dbgr.core.processor.commands['break'] brk_cmd.run(['break', "O#{pc_offset}"]) cmd.run(%w(info break)) puts '-' * 20 brk_cmd.run(['break', 'foo']) subcommand.run(%w(info break)) puts '-' * 20 p subcommand.save_command end