forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsizeof.py
55 lines (40 loc) · 1.43 KB
/
sizeof.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
"""
GDB command for printing the sizes of various containers.
"""
from compatibility import *
import gdb
from gdbutils import *
#------------------------------------------------------------------------------
# Size accessor.
def sizeof(container):
container = deref(container)
t = template_type(rawtype(container.type))
if t == 'std::vector' or t == 'HPHP::req::vector':
impl = container['_M_impl']
return impl['_M_finish'] - impl['_M_start']
elif t == 'std::priority_queue':
return sizeof(container['c'])
elif t == 'std::unordered_map' or t == 'HPHP::hphp_hash_map':
return container['_M_h']['_M_element_count']
elif t == 'HPHP::FixedStringMap':
return container['m_extra']
elif t == 'HPHP::IndexedStringMap':
return container['m_map']['m_extra']
#------------------------------------------------------------------------------
# `sizeof' command.
class SizeOfCommand(gdb.Command):
"""Print the semantic size of a container."""
def __init__(self):
super(SizeOfCommand, self).__init__('sizeof', gdb.COMMAND_DATA)
@errorwrap
def invoke(self, args, from_tty):
argv = parse_argv(args)
if len(argv) != 1:
print('Usage: sizeof <container>')
return
size = sizeof(argv[0])
if size is not None:
gdbprint(size)
else:
print('sizeof: Unrecognized container.')
SizeOfCommand()