Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight Variables that have changed since the last render. #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions .gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -1484,12 +1484,15 @@ A value of 0 uses the whole height.''',
class Variables(Dashboard.Module):
'''Show arguments and locals of the selected frame.'''

def __init__(self):
self.previous_values = {}

def label(self):
return 'Variables'

def lines(self, term_width, term_height, style_changed):
return Variables.format_frame(
gdb.selected_frame(), self.show_arguments, self.show_locals, self.compact, self.align)
gdb.selected_frame(), self.show_arguments, self.show_locals, self.compact, self.align, self)

def attributes(self):
return {
Expand Down Expand Up @@ -1518,7 +1521,7 @@ class Variables(Dashboard.Module):
}

@staticmethod
def format_frame(frame, show_arguments, show_locals, compact, align):
def format_frame(frame, show_arguments, show_locals, compact, align, myself):
out = []
# fetch frame arguments and locals
decorator = gdb.FrameDecorator.FrameDecorator(frame)
Expand All @@ -1527,7 +1530,7 @@ class Variables(Dashboard.Module):
def prefix(line):
return Stack.format_line('arg', line)
frame_args = decorator.frame_args()
args_lines = Variables.fetch(frame, frame_args, compact, align)
args_lines = Variables.fetch(frame, frame_args, compact, align, myself)
if args_lines:
if compact:
args_line = separator.join(args_lines)
Expand All @@ -1539,7 +1542,7 @@ class Variables(Dashboard.Module):
def prefix(line):
return Stack.format_line('loc', line)
frame_locals = decorator.frame_locals()
locals_lines = Variables.fetch(frame, frame_locals, compact, align)
locals_lines = Variables.fetch(frame, frame_locals, compact, align, myself)
if locals_lines:
if compact:
locals_line = separator.join(locals_lines)
Expand All @@ -1550,16 +1553,21 @@ class Variables(Dashboard.Module):
return out

@staticmethod
def fetch(frame, data, compact, align):
def fetch(frame, data, compact, align, myself):
lines = []
name_width = 0
if align and not compact:
name_width = max(len(str(elem.sym)) for elem in data) if data else 0
for elem in data or []:
name = ansi(elem.sym, R.style_high) + ' ' * (name_width - len(str(elem.sym)))
raw_name = str(elem.sym)
name = ansi(elem.sym, R.style_high) + ' ' * (name_width - len(raw_name))
equal = ansi('=', R.style_low)
value = format_value(elem.sym.value(frame), compact)
lines.append('{} {} {}'.format(name, equal, value))
changed = myself and (myself.previous_values.get(raw_name, '') != value)
if myself:
myself.previous_values[raw_name] = value
style = R.style_selected_1 if changed else ''
lines.append('{} {} {}'.format(name, equal, ansi(value, style)))
return lines

class Stack(Dashboard.Module):
Expand Down Expand Up @@ -1596,7 +1604,7 @@ Optionally list the frame arguments and locals too.'''
frame_lines = []
frame_lines.append('[{}] {}'.format(frame_id, info))
# add frame arguments and locals
variables = Variables.format_frame(frame, self.show_arguments, self.show_locals, self.compact, self.align)
variables = Variables.format_frame(frame, self.show_arguments, self.show_locals, self.compact, self.align, False)
frame_lines.extend(variables)
# add frame
frames.append(frame_lines)
Expand Down