forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnameof.py
59 lines (42 loc) · 1.24 KB
/
nameof.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
"""
GDB command for printing the names of various objects.
"""
from compatibility import *
import gdb
from gdbutils import *
#------------------------------------------------------------------------------
# Name accessor.
def nameof(val):
val = deref(val)
try:
t = val.type.name
except:
return None
sd = None
if t == 'HPHP::Func':
sd = val['m_fullName']
elif t == 'HPHP::Class':
sd = deref(val['m_preClass'])['m_name']
elif t == 'HPHP::ObjectData':
cls = deref(val['m_cls'])
sd = deref(cls['m_preClass'])['m_name']
if sd is None:
return None
return string_data_val(deref(sd))
#------------------------------------------------------------------------------
# `nameof' command.
class NameOfCommand(gdb.Command):
"""Print the name of an HHVM object."""
def __init__(self):
super(NameOfCommand, self).__init__('nameof', gdb.COMMAND_DATA)
@errorwrap
def invoke(self, args, from_tty):
try:
obj = gdb.parse_and_eval(args)
except gdb.error:
print('Usage: nameof <object>')
return
name = nameof(obj)
if name is not None:
print('"' + name + '"')
NameOfCommand()