Remove unused @lint-avoid-pyflakes* and others
[hiphop-php.git] / hphp / tools / gdb / nameof.py
blob8bc0d9dd1deec35f025d194840fb64fa60921a55
1 """
2 GDB command for printing the names of various objects.
3 """
5 from compatibility import *
7 import gdb
8 from gdbutils import *
11 #------------------------------------------------------------------------------
12 # Name accessor.
14 def nameof(val):
15 val = deref(val)
16 t = val.type.name
18 sd = None
20 if t == 'HPHP::Func':
21 sd = val['m_fullName']
22 elif t == 'HPHP::Class':
23 sd = deref(val['m_preClass'])['m_name']
24 elif t == 'HPHP::ObjectData':
25 cls = deref(val['m_cls'])
26 sd = deref(cls['m_preClass'])['m_name']
28 if sd is None:
29 return None
31 return string_data_val(deref(sd))
34 #------------------------------------------------------------------------------
35 # `nameof' command.
37 class NameOfCommand(gdb.Command):
38 """Print the name of an HHVM object."""
40 def __init__(self):
41 super(NameOfCommand, self).__init__('nameof', gdb.COMMAND_DATA)
43 @errorwrap
44 def invoke(self, args, from_tty):
45 try:
46 obj = gdb.parse_and_eval(args)
47 except gdb.error:
48 print('Usage: nameof <object>')
49 return
51 name = nameof(obj)
53 if name is not None:
54 print('"' + name + '"')
56 NameOfCommand()