-
Notifications
You must be signed in to change notification settings - Fork 9
/
gdb-regview.py
56 lines (43 loc) · 1.4 KB
/
gdb-regview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gdb
import struct
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import RegisterView
rv = RegisterView.RegisterView()
class RegviewPrefixCommand (gdb.Command):
"Prefix command for viewing special function registers."
def __init__(self):
super (RegviewPrefixCommand, self).__init__("regview",
gdb.COMMAND_SUPPORT,
gdb.COMPLETE_NONE, True)
class RegviewLoadCommand(gdb.Command):
"Load register definitions from XML file."
def __init__(self):
super (RegviewLoadCommand, self).__init__ ("regview load",
gdb.COMMAND_SUPPORT,
gdb.COMPLETE_FILENAME)
def invoke(self, arg, from_tty):
rv.load_definitions(arg)
class RegviewShowCommand(gdb.Command):
"Show the value of a register."
def __init__(self):
super (RegviewShowCommand, self).__init__ ("regview show",
gdb.COMMAND_SUPPORT)
def invoke(self, arg, from_tty):
e = rv.get_reg_element(arg)
if e is None:
print "Unknown register %s" % arg
return
addr = rv.get_reg_address(arg)
buff = gdb.inferiors()[0].read_memory(addr, 4)
val = struct.unpack("I", buff)[0]
rv.print_reg(arg, val)
def complete(self, arg, from_tty):
return rv.find_registers(arg)
RegviewPrefixCommand()
RegviewLoadCommand()
RegviewShowCommand()
if __name__ == '__main__':
print 'Loaded', __file__
print 'Type "regview <tab>" to see available commands.'