summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-31 09:13:33 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-31 09:13:37 -0700
commita9b6b25de53b6cb324666f0114789c5f48f877db (patch)
treeddcb930f6d54d3468e84eb9ea99c9c8fea338c33 /misc
parent9e678cdbd054f78576a8f21b3f97cccc395ade22 (diff)
gdb: Visualize register positions on the left
Diffstat (limited to 'misc')
-rw-r--r--misc/gdb.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/misc/gdb.py b/misc/gdb.py
index caf07f0457..2c2b94f5dc 100644
--- a/misc/gdb.py
+++ b/misc/gdb.py
@@ -1,3 +1,5 @@
+import textwrap
+
# Usage:
# cfp: Dump the current cfp
# cfp + 1: Dump the caller cfp
@@ -66,13 +68,24 @@ class CFP(gdb.Command):
print(f'Stack (size={stack_size}):')
for i in range(0, stack_size):
self.print_stack(cfp, i, self.rp(cfp, i))
+ print(self.regs(cfp, stack_size))
def print_stack(self, cfp, bp_index, content):
address = self.get_int(f'{cfp}->__bp__ + {bp_index}')
value = self.get_value(cfp, bp_index)
+ regs = self.regs(cfp, bp_index)
if content:
+ content = textwrap.indent(content, ' ' * 3).lstrip() # Leave the regs column empty
content = f'{content} '
- print('0x{:x} [{}] {}(0x{:x})'.format(address, bp_index, content, value))
+ print('{:2} 0x{:x} [{}] {}(0x{:x})'.format(regs, address, bp_index, content, value))
+
+ def regs(self, cfp, bp_index):
+ address = self.get_int(f'{cfp}->__bp__ + {bp_index}')
+ regs = []
+ for reg, field in { 'EP': 'ep', 'BP': '__bp__', 'SP': 'sp' }.items():
+ if address == self.get_int(f'{cfp}->{field}'):
+ regs.append(reg)
+ return ' '.join(regs)
def rp(self, cfp, bp_index):
value = self.get_value(cfp, bp_index)