-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclang_prettyprinter.py
46 lines (38 loc) · 1.79 KB
/
clang_prettyprinter.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
#!/usr/bin/env python3
from __future__ import print_function
import struct
import sys
import gdb.printing
import gdb.types
class SourceLocationPrinter:
"""Print an clang::SourceLocation object."""
def __init__(self, val):
self.val = val
def to_string(self):
# https://stackoverflow.com/questions/22774067/gdb-python-api-is-it-possible-to-make-a-call-to-a-class-struct-method
eval_string = "(*("+str(self.val.type)+"*)("+str(self.val.address)+")).dump(this->getSourceManager())"
return gdb.parse_and_eval(eval_string);
class MultiLevelTemplateArgumentListPrinter:
"MultiLevelTemplateArgumentList"
def __init__(self, val):
self.val = val
def to_string(self):
eval_string = "(*("+str(self.val.type)+"*)("+str(self.val.address)+")).TemplateArgumentLists.size()"
depth = int(gdb.parse_and_eval(eval_string))
strstr = ""
for i in range(depth):
eval_string = "(*("+str(self.val.type)+"*)("+str(self.val.address)+")).TemplateArgumentLists[{}].size()".format(i)
sz = int(gdb.parse_and_eval(eval_string))
strstr += "\nlevel {}: args {}".format(i, sz)
for j in range(sz):
eval_string = "p (*("+str(self.val.type)+"*)("+str(self.val.address)+")).TemplateArgumentLists[{}][{}].dump()".format(i,j)
gdb.execute(eval_string,True,True)
return strstr
pp = gdb.printing.RegexpCollectionPrettyPrinter("CLANGSupport")
pp.add_printer('SourceLocationPrinter',
'^clang::SourceLocation$',
SourceLocationPrinter)
pp.add_printer('MultiLevelTemplateArgumentListPrinter',
'^clang::MultiLevelTemplateArgumentList$',
MultiLevelTemplateArgumentListPrinter)
gdb.printing.register_pretty_printer(gdb.current_objfile(), pp, True)