-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirmware-gdb.py
65 lines (45 loc) · 1.56 KB
/
firmware-gdb.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
57
58
59
60
61
62
63
64
65
import gdb.printing
import itertools
class Timeout(object):
def __init__(self, timeout):
self.timeout = timeout
def to_string(self):
options = []
if self.timeout['fired'] == True:
options.append("fired")
if self.timeout['repeat'] == True:
options.append("repeat")
if self.timeout['attached'] == True:
options.append("attached")
return "<%s %d/%d %s>" % (self.timeout.dynamic_type, self.timeout['remainingTime'], self.timeout['timeout'], " ".join(options))
class TimeoutIterator(object):
def __init__(self, timeout):
self.timeout = timeout
def __iter__(self):
return self
def next(self):
timeout = self.timeout
if timeout == 0:
raise StopIteration
self.timeout = self.timeout.dereference()['next']
return timeout.dereference()
class TimerPrinter(object):
def __init__(self, val):
self.val = val
def to_string(self):
return "Some timer %s" % str(self.val.dynamic_type)
def children(self):
counter = itertools.imap(lambda i: '[%d]' % i, itertools.count(1))
timeouts = TimeoutIterator(self.val['timeouts'])
return itertools.izip(counter, timeouts)
def display_hint (self):
return 'array'
def build_pretty_printer():
pp = gdb.printing.RegexpCollectionPrettyPrinter(
"TheFirmware")
pp.add_printer('timer', '^TheFirmware::Time::Timer$', TimerPrinter)
pp.add_printer('timeout', '^TheFirmware::Time::Timeout$', Timeout)
return pp
gdb.printing.register_pretty_printer(
gdb.current_objfile(),
build_pretty_printer(), replace=True)