Skip to content

Commit 396ac41

Browse files
committed
Allow to unwatch expressions by index
Close #291
1 parent 4cc7793 commit 396ac41

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

.gdbinit

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,7 +2142,7 @@ class Expressions(Dashboard.Module):
21422142
'''Watch user expressions.'''
21432143

21442144
def __init__(self):
2145-
self.table = set()
2145+
self.table = []
21462146

21472147
def label(self):
21482148
return 'Expressions'
@@ -2153,7 +2153,7 @@ class Expressions(Dashboard.Module):
21532153
if self.align:
21542154
label_width = max(len(expression) for expression in self.table) if self.table else 0
21552155
default_radix = Expressions.get_default_radix()
2156-
for expression in self.table:
2156+
for number, expression in enumerate(self.table, start=1):
21572157
label = expression
21582158
match = re.match('^/(\d+) +(.+)$', expression)
21592159
try:
@@ -2166,9 +2166,10 @@ class Expressions(Dashboard.Module):
21662166
finally:
21672167
if match:
21682168
run('set output-radix {}'.format(default_radix))
2169+
number = ansi(str(number), R.style_selected_2)
21692170
label = ansi(expression, R.style_high) + ' ' * (label_width - len(expression))
21702171
equal = ansi('=', R.style_low)
2171-
out.append('{} {} {}'.format(label, equal, value))
2172+
out.append('[{}] {} {} {}'.format(number, label, equal, value))
21722173
return out
21732174

21742175
def commands(self):
@@ -2180,8 +2181,7 @@ class Expressions(Dashboard.Module):
21802181
},
21812182
'unwatch': {
21822183
'action': self.unwatch,
2183-
'doc': 'Stop watching an expression.',
2184-
'complete': gdb.COMPLETE_EXPRESSION
2184+
'doc': 'Stop watching an expression by index.'
21852185
},
21862186
'clear': {
21872187
'action': self.clear,
@@ -2200,15 +2200,22 @@ class Expressions(Dashboard.Module):
22002200

22012201
def watch(self, arg):
22022202
if arg:
2203-
self.table.add(arg)
2203+
if arg not in self.table:
2204+
self.table.append(arg)
2205+
else:
2206+
raise Exception('Expression already watched')
22042207
else:
22052208
raise Exception('Specify an expression')
22062209

22072210
def unwatch(self, arg):
22082211
if arg:
22092212
try:
2210-
self.table.remove(arg)
2213+
number = int(arg) - 1
22112214
except:
2215+
number = -1
2216+
if 0 <= number < len(self.table):
2217+
self.table.pop(number)
2218+
else:
22122219
raise Exception('Expression not watched')
22132220
else:
22142221
raise Exception('Specify an expression')

0 commit comments

Comments
 (0)