-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathutils.py
More file actions
57 lines (39 loc) · 1.33 KB
/
utils.py
File metadata and controls
57 lines (39 loc) · 1.33 KB
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
import gdb
import os
import re
import shutil
import texttable
def cast(value, typename):
return value.cast(gdb.lookup_type(typename))
def cast_ptr(value, typename):
return value.cast(gdb.lookup_type(typename).pointer())
def local_var(name):
return gdb.newest_frame().read_var(name)
def global_var(name):
return gdb.parse_and_eval(name)
def relpath(path):
return path.rsplit('sys/')[-1]
def get_arch():
for arch in ['mips', 'aarch64', 'riscv']:
if arch in gdb.architecture_names():
return arch
print('Current architecture is not supported')
raise KeyError
# calculates address of ret instruction within function body (MIPS specific)
def func_ret_addr(name):
s = gdb.execute('disass thread_create', to_string=True)
for line in s.split('\n'):
m = re.match(r'\s+(0x[0-9a-f]{8})\s+<\+\d+>:\tjr\tra', line)
if m:
return int(m.groups()[0], 16)
class TextTable(texttable.Texttable):
termsize = shutil.get_terminal_size(fallback=(80, 25))
def __init__(self, types=None, align=None):
super().__init__(self.termsize[0])
self.set_deco(self.HEADER | self.VLINES | self.BORDER)
if types:
self.set_cols_dtype(types)
if align:
self.set_cols_align(align)
def __str__(self):
return self.draw()