moduleByebug# Mix-in module to assist in command parsing.moduleEnableDisableFunctionsdefenable_disable_breakpoints(is_enable,args)returnerrmsg"No breakpoints have been set."ifByebug.breakpoints.empty?all_breakpoints=Byebug.breakpoints.sort_by{|b|b.id}if!argsselected_breakpoints=all_breakpointselseselected_ids=[]args.eachdo|pos|pos=get_int(pos,"#{is_enable} breakpoints",1,all_breakpoints.last.id)returnnilunlessposselected_ids<<posendselected_breakpoints=all_breakpoints.select{|b|selected_ids.include?(b.id)}endselected_breakpoints.eachdo|b|enabled=('enable'==is_enable)ifenabled&&!syntax_valid?(b.expr)errmsg"Expression \"#{b.expr}\" syntactically incorrect; "\"breakpoint remains disabled.\n"elseb.enabled=enabledendendenddefenable_disable_display(is_enable,args)if0==@state.display.sizeerrmsg"No display expressions have been set.\n"returnendargs.eachdo|pos|pos=get_int(pos,"#{is_enable} display",1,@state.display.size)returnnilunlesspos@state.display[pos-1][0]=('enable'==is_enable)endendendclassEnableCommand<CommandSubcommands=[['breakpoints',2,'Enable breakpoints','This is used to cancel the effect of the "disable" command. Give '\'breakpoint numbers (separated by spaces) as arguments or no '\'argument at all if you want to reenable every breakpoint'],['display',2,'Enable some expressions to be displayed when program stops','Arguments are the code numbers of the expressions to resume '\'displaying. Do "info display" to see the current list of code '\'numbers.'],].mapdo|name,min,short_help,long_help|Subcmd.new(name,min,short_help,long_help)endunlessdefined?(Subcommands)defregexp/^\s* en(?:able)? (?:\s+(.+))? \s*$/xenddefexecutereturnerrmsg"\"enable\" must be followed by \"display\", "\"\"breakpoints\" or breakpoint numbers.\n"unless@match[1]args=@match[1].split(/[ \t]+/)param=args.shiftsubcmd=Command.find(Subcommands,param)ifsubcmdsend("enable_#{subcmd.name}",args)elsesend('enable_breakpoints',args.unshift(param))endenddefenable_breakpoints(args)enable_disable_breakpoints('enable',args)enddefenable_display(args)enable_disable_display('enable',args)endclass<<selfdefnames%w(enable)enddefdescription%{Enable breakpoints or displays.
This is used to cancel the effect of the "disable" command.}endendendclassDisableCommand<CommandSubcommands=[['breakpoints',1,'Disable breakpoints','A disabled breakpoint is not forgotten, but has no effect until '\'reenabled. Give breakpoint numbers (separated by spaces) as '\'arguments or no argument at all if you want to disable every '\'breakpoint'],['display',1,'Disable some display expressions when program stops','Arguments are the code numbers of the expressions to stop '\'displaying. Do "info display" to see the current list of code '\'numbers.'],].mapdo|name,min,short_help,long_help|Subcmd.new(name,min,short_help,long_help)endunlessdefined?(Subcommands)defregexp/^\s* dis(?:able)? (?:\s+(.+))? \s*$/xenddefexecutereturnerrmsg"\"disable\" must be followed by \"display\", "\"\"breakpoints\" or breakpoint numbers.\n"unless@match[1]args=@match[1].split(/[ \t]+/)param=args.shiftsubcmd=Command.find(Subcommands,param)ifsubcmdsend("disable_#{subcmd.name}",args)elsesend('disable_breakpoints',args.unshift(param))endenddefdisable_breakpoints(args)enable_disable_breakpoints('disable',args)enddefdisable_display(args)enable_disable_display('disable',args)endclass<<selfdefnames%w(disable)enddefdescription%{Disable breakpoints or displays.
A disabled item is not forgotten, but has no effect until reenabled.
Use the "enable" command to have it take effect again.}endendendend