-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathdump-class-layout
More file actions
executable file
·121 lines (96 loc) · 4.8 KB
/
Copy pathdump-class-layout
File metadata and controls
executable file
·121 lines (96 loc) · 4.8 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
# Copyright (C) 2011-2026 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
import re
import sys
import getopt
import argparse
import os
import subprocess
up = os.path.dirname
tools_directory = up(up(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(tools_directory, "lldb"))
from lldb_dump_class_layout import LLDBDebuggerInstance, ClassLayout
framework = "WebCore"
build_directory = ""
target_path = ""
config = "Release"
arch = None
def webkit_build_dir():
scriptpath = os.path.dirname(os.path.realpath(__file__))
return subprocess.check_output([os.path.join(scriptpath, "webkit-build-directory"), "--top-level"]).decode().strip()
def find_binary(build_dir, config, name):
if os.path.isfile(name):
return name
candidates = [
os.path.join(name + ".framework", name), # Framework.
"lib" + name + ".a", # Static library, named as the build system names it.
name + ".a",
"lib" + name + ".dylib",
name + ".dylib",
name, # Executable.
]
configuration_dir = os.path.join(build_dir, config)
for candidate in candidates:
path = os.path.join(configuration_dir, candidate)
if os.path.isfile(path):
return path
print('error: found no framework, library or executable named "%s" in "%s"' % (name, configuration_dir))
sys.exit(1)
def main(argv=None):
parser = argparse.ArgumentParser(description='Dumps the in-memory layout of the given class or classes, showing padding holes.')
parser.add_argument('binary', metavar='binary',
help='name of the framework, static library or executable containing the class (e.g. "WebCore", "JavaScriptCoreTools"), or a path to one')
parser.add_argument('classname', metavar='classname', nargs='+',
help='name of the class or struct to dump (may specify multiple classes)')
parser.add_argument('-b', '--build-directory', dest='build_directory', action='store',
help='Path to the directory under which build files are kept (should not include configuration)')
parser.add_argument('-c', '--configuration', dest='config', action='store',
help='Configuration (Debug or Release)')
parser.add_argument('-a', '--architecture', dest='arch', action='store',
help='Architecture (i386, x86_64, armv7, armv7s, arm64). Uses the first architecture listed by \'file\' by default')
parser.add_argument('-t', '--target-path', dest='target_path', action='store',
help='Path to the target')
parser.add_argument('-s', '--skip-nested', dest='skip_nested', default=False, action='store_true',
help='Do not traverse nested classes and structs')
args = parser.parse_args(argv)
build_dir = webkit_build_dir()
if args.config is None:
args.config = "Release"
if args.build_directory is not None:
build_dir = args.build_directory
if args.target_path is not None:
target_path = args.target_path
else:
target_path = find_binary(build_dir, args.config, args.binary)
lldb_instance = LLDBDebuggerInstance(target_path, args.arch)
# Check if stdout is a TTY to determine if we should use colors
use_colors = sys.stdout.isatty()
for i, classname in enumerate(args.classname):
if i > 0:
print() # Add blank line between multiple class dumps
class_layout = lldb_instance.layout_for_classname(classname, args.skip_nested)
if class_layout is not None:
class_layout.dump(colorize=use_colors)
if __name__ == "__main__":
main()