Add support of source code scroll
See original GitHub issuerecently started to use gdb and found this awesome tool however, i have to switch between this and tui when need to read code around
so i tried to add this feature myself, and finally made it (although just a walkaround solution) problem of my try is that it requires more config in .inputrc and .gdbinit.d/init can anyone help me improve it and make config as less as possible?
below is my changes: .gdbinit
246a247
Dashboard.SrcScrollCommand(self)
510a512,532
@staticmethod def source_scroll_up(dashboard): for module in dashboard.modules: if module.name == 'source': module.instance.scrl_up() dashboard.redisplay() @staticmethod def source_scroll_down(dashboard): for module in dashboard.modules: if module.name == 'source': module.instance.scrl_down() dashboard.redisplay() @staticmethod def source_scroll_reset(dashboard): for module in dashboard.modules: if module.name == 'source': module.instance.scrl_rst() dashboard.redisplay()
684a707,730
class SrcScrollCommand(gdb.Command): def __init__(self, dashboard): gdb.Command.__init__(self, 'dashboard -srcscroll', gdb.COMMAND_USER) self.dashboard = dashboard def invoke(self, arg, from_tty): arg = Dashboard.parse_arg(arg) if arg == 'rst': self.dashboard.source_scroll_reset(self.dashboard) elif arg == 'up': self.dashboard.source_scroll_up(self.dashboard) #self.dashboard.redisplay() elif arg == 'down': self.dashboard.source_scroll_down(self.dashboard) else: msg = 'Wrong argument "{}"; expecting "up" or "down"' Dashboard.err(msg.format(arg)) def complete(self, text, word): return Dashboard.complete(word, ['up', 'down'])
869a916
self.src_offset = 0
894a942
self.src_offset = 0
905,906c953,954
start = max(current_line - 1 - self.context + self.src_offset, 0) end = min(current_line - 1 + self.context + 1 + self.src_offset, len(self.source_lines))
928a977,985
def scrl_up(self): self.src_offset = self.src_offset - 1 def scrl_down(self): self.src_offset = self.src_offset + 1 def scrl_rst(self): self.src_offset = 0
=========================== .gdbinit.d/init
define scrollup
dashboard -srcscroll up
end
define scrolldown
dashboard -srcscroll down
end
define scrollreset
dashboard -srcscroll rst
end
define hookpost-next
scrollreset
end
==================
.inputrc
$if gdb "\C-p": "scrollup\n" "\C-n": "scrolldown\n" $endif
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top GitHub Comments
Implemented in c671fddb455d85f23631742159084aae2bed991d. To implement the
readline
trick do something like this:@yankee14 yes, see
help dashboard source scroll
.