Skip to content

Commit

Permalink
Follow gdb for enable, disable, delete...
Browse files Browse the repository at this point in the history
No args enables, disables or deletes all of them.

Delete has an alias delete! to not prompt
  • Loading branch information
rocky committed Aug 31, 2017
1 parent 69f7083 commit a038837
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
31 changes: 25 additions & 6 deletions trepan/lib/breakpoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Rocky Bernstein <rocky@gnu.org>
# Copyright (C) 2015, 2017 Rocky Bernstein <rocky@gnu.org>
"""Breakpoints as used in a debugger.
This code is a rewrite of the stock python bdb.Breakpoint"""
Expand Down Expand Up @@ -68,14 +68,16 @@ def add_breakpoint(self, filename, lineno, temporary=False, condition=None,
return brkpt

def delete_all_breakpoints(self):
count = 0
bp_list = []
for bp in self.bpbynumber:
count += 1
if bp: self.delete_breakpoint(bp)
if 0 == count:
if bp:
bp_list.append(str(bp.number))
self.delete_breakpoint(bp)
pass
if not bp_list:
return 'There are no breakpoints'
else:
return '%d breakpoints deleted' % count
return 'Deleted breakpoints %s' % ', '.join(bp_list)
return

def delete_breakpoint(self, bp):
Expand All @@ -98,6 +100,23 @@ def delete_breakpoint_by_number(self, bpnum):
self.delete_breakpoint(bp)
return (True, '')

def en_disable_all_breakpoints(self, do_enable=True):
"Enable or disable all breakpoints."
bp_list = [bp for bp in self.bpbynumber if bp]
bp_nums = []
if do_enable:
endis = 'en'
else:
endis = 'dis'
pass
if not bp_list:
return "No breakpoints to %sable" % endis
for bp in bp_list:
bp.enabled = do_enable
bp_nums.append(str(bp.number))
pass
return ("Breakpoints %sabled: %s" % (endis, ", ".join(bp_nums)))

def en_disable_breakpoint_by_number(self, bpnum, do_enable=True):
"Enable or disable a breakpoint given its breakpoint number."
success, msg, bp = self.get_breakpoint(bpnum)
Expand Down
12 changes: 9 additions & 3 deletions trepan/processor/command/delete.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2009, 2013, 2015 Rocky Bernstein
# Copyright (C) 2009, 2013, 2015, 2017 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -35,6 +35,7 @@ class DeleteCommand(Mbase_cmd.DebuggerCommand):
`clear`
"""
category = 'breakpoints'
aliases = ('delete!',)
min_args = 0
max_args = None
name = os.path.basename(__file__).split('.')[0]
Expand All @@ -45,8 +46,13 @@ class DeleteCommand(Mbase_cmd.DebuggerCommand):

def run(self, args):
if len(args) <= 1:
if self.confirm('Delete all breakpoints', False):
self.core.bpmgr.delete_all_breakpoints()
if '!' != args[0][-1]:
confirmed = self.confirm('Delete all breakpoints', False)
else:
confirmed = True

if confirmed:
self.msg(self.core.bpmgr.delete_all_breakpoints())
return

for arg in args[1:]:
Expand Down
6 changes: 3 additions & 3 deletions trepan/processor/command/disable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2009, 2013-2015 Rocky Bernstein
# Copyright (C) 2009, 2013-2015, 2017 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -24,7 +24,7 @@ class DisableCommand(Mbase_cmd.DebuggerCommand):
"""**disable** *bpnumber* [*bpnumber* ...]
Disables the breakpoints given as a space separated list of breakpoint
numbers. See also `info break` to get a list.
numbers. To disable all breakpoints, give no argument. See also `info break` to get a list.
See also:
---------
Expand All @@ -42,7 +42,7 @@ class DisableCommand(Mbase_cmd.DebuggerCommand):

def run(self, args):
if len(args) == 1:
self.errmsg('No breakpoint number given.')
self.msg(self.core.bpmgr.en_disable_all_breakpoints(do_enable=False))
return
# if args[1] == 'display':
# self.display_enable(args[2:], 0)
Expand Down
8 changes: 4 additions & 4 deletions trepan/processor/command/enable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2009, 2013, 2015 Rocky Bernstein
# Copyright (C) 2009, 2013, 2015, 2017 Rocky Bernstein
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -27,7 +27,7 @@ class EnableCommand(Mbase_cmd.DebuggerCommand):
"""**enable** *bpnumber* [*bpnumber* ...]
Enables the breakpoints given as a space separated list of breakpoint
numbers. See also `info break` to get a list.
numbers. To enable all breakpoints, give no argument. See also `info break` to get a list.
See also:
---------
Expand All @@ -46,14 +46,14 @@ class EnableCommand(Mbase_cmd.DebuggerCommand):

def run(self, args):
if len(args) == 1:
self.errmsg('No breakpoint number given.')
self.msg(self.core.bpmgr.en_disable_all_breakpoints(do_enable=True))
return
# if args[1] == 'display':
# self.display_enable(args[2:], 0)
# return
for i in args[1:]:
success, msg = \
self.core.bpmgr.en_disable_breakpoint_by_number(i, True)
self.core.bpmgr.en_disable_breakpoint_by_number(i, do_enable=True)
if not success:
self.errmsg(msg)
else:
Expand Down

0 comments on commit a038837

Please sign in to comment.