gdb: Visualize register positions on the left
This commit is contained in:
parent
9e678cdbd0
commit
a9b6b25de5
15
misc/gdb.py
15
misc/gdb.py
@ -1,3 +1,5 @@
|
|||||||
|
import textwrap
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
# cfp: Dump the current cfp
|
# cfp: Dump the current cfp
|
||||||
# cfp + 1: Dump the caller cfp
|
# cfp + 1: Dump the caller cfp
|
||||||
@ -66,13 +68,24 @@ class CFP(gdb.Command):
|
|||||||
print(f'Stack (size={stack_size}):')
|
print(f'Stack (size={stack_size}):')
|
||||||
for i in range(0, stack_size):
|
for i in range(0, stack_size):
|
||||||
self.print_stack(cfp, i, self.rp(cfp, i))
|
self.print_stack(cfp, i, self.rp(cfp, i))
|
||||||
|
print(self.regs(cfp, stack_size))
|
||||||
|
|
||||||
def print_stack(self, cfp, bp_index, content):
|
def print_stack(self, cfp, bp_index, content):
|
||||||
address = self.get_int(f'{cfp}->__bp__ + {bp_index}')
|
address = self.get_int(f'{cfp}->__bp__ + {bp_index}')
|
||||||
value = self.get_value(cfp, bp_index)
|
value = self.get_value(cfp, bp_index)
|
||||||
|
regs = self.regs(cfp, bp_index)
|
||||||
if content:
|
if content:
|
||||||
|
content = textwrap.indent(content, ' ' * 3).lstrip() # Leave the regs column empty
|
||||||
content = f'{content} '
|
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):
|
def rp(self, cfp, bp_index):
|
||||||
value = self.get_value(cfp, bp_index)
|
value = self.get_value(cfp, bp_index)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user