summaryrefslogtreecommitdiff
path: root/lldb/scripts
diff options
context:
space:
mode:
authorDavid Spickett <david.spickett@linaro.org>2023-09-14 08:54:02 +0100
committerGitHub <noreply@github.com>2023-09-14 08:54:02 +0100
commit602e47c5f9fd2e14c7bfb6111e6558fa0d27c87f (patch)
tree6469bda9c2727dfa60a174b123edcc2918d9ad3a /lldb/scripts
parenta1ef5a9437fd027da6b479426e52dc0c8a713a3f (diff)
[lldb] Format Python files in scripts and utils (#66053)
Using: black --exclude "third_party/" ./lldb/
Diffstat (limited to 'lldb/scripts')
-rwxr-xr-xlldb/scripts/analyze-project-deps.py66
-rw-r--r--lldb/scripts/android/host_art_bt.py229
-rw-r--r--lldb/scripts/install_custom_python.py146
-rwxr-xr-xlldb/scripts/reproducer-replay.py98
-rw-r--r--lldb/scripts/use_lldb_suite.py4
-rwxr-xr-xlldb/scripts/verify_api.py99
6 files changed, 370 insertions, 272 deletions
diff --git a/lldb/scripts/analyze-project-deps.py b/lldb/scripts/analyze-project-deps.py
index 89da3dc9df7b..4724367e2e72 100755
--- a/lldb/scripts/analyze-project-deps.py
+++ b/lldb/scripts/analyze-project-deps.py
@@ -10,12 +10,21 @@ from collections import defaultdict
from use_lldb_suite import lldb_root
parser = argparse.ArgumentParser(
- description='Analyze LLDB project #include dependencies.')
-parser.add_argument('--show-counts', default=False, action='store_true',
- help='When true, show the number of dependencies from each subproject')
-parser.add_argument('--discover-cycles', default=False, action='store_true',
- help='When true, find and display all project dependency cycles. Note,'
- 'this option is very slow')
+ description="Analyze LLDB project #include dependencies."
+)
+parser.add_argument(
+ "--show-counts",
+ default=False,
+ action="store_true",
+ help="When true, show the number of dependencies from each subproject",
+)
+parser.add_argument(
+ "--discover-cycles",
+ default=False,
+ action="store_true",
+ help="When true, find and display all project dependency cycles. Note,"
+ "this option is very slow",
+)
args = parser.parse_args()
@@ -24,12 +33,14 @@ inc_dir = os.path.join(lldb_root, "include")
src_map = {}
-include_regex = re.compile('#include \"((lldb|Plugins|clang)(.*/)+).*\"')
+include_regex = re.compile('#include "((lldb|Plugins|clang)(.*/)+).*"')
+
def is_sublist(small, big):
it = iter(big)
return all(c in it for c in small)
+
def normalize_host(str):
if str.startswith("lldb/Host"):
return "lldb/Host"
@@ -39,6 +50,7 @@ def normalize_host(str):
return str.replace("lldb/../../source", "lldb")
return str
+
def scan_deps(this_dir, file):
global src_map
deps = {}
@@ -62,7 +74,8 @@ def scan_deps(this_dir, file):
if this_dir not in src_map and len(deps) > 0:
src_map[this_dir] = deps
-for (base, dirs, files) in os.walk(inc_dir):
+
+for base, dirs, files in os.walk(inc_dir):
dir = os.path.basename(base)
relative = os.path.relpath(base, inc_dir)
inc_files = [x for x in files if os.path.splitext(x)[1] in [".h"]]
@@ -71,7 +84,7 @@ for (base, dirs, files) in os.walk(inc_dir):
inc_path = os.path.join(base, inc)
scan_deps(relative, inc_path)
-for (base, dirs, files) in os.walk(src_dir):
+for base, dirs, files in os.walk(src_dir):
dir = os.path.basename(base)
relative = os.path.relpath(base, src_dir)
src_files = [x for x in files if os.path.splitext(x)[1] in [".cpp", ".h", ".mm"]]
@@ -82,6 +95,7 @@ for (base, dirs, files) in os.walk(src_dir):
scan_deps(norm_base_path, src_path)
pass
+
def is_existing_cycle(path, cycles):
# If we have a cycle like # A -> B -> C (with an implicit -> A at the end)
# then we don't just want to check for an occurrence of A -> B -> C in the
@@ -90,12 +104,13 @@ def is_existing_cycle(path, cycles):
# at the end), then A -> B -> C is also a cycle. This is an important
# optimization which reduces the search space by multiple orders of
# magnitude.
- for i in range(0,len(path)):
+ for i in range(0, len(path)):
if any(is_sublist(x, path) for x in cycles):
return True
path = [path[-1]] + path[0:-1]
return False
+
def expand(path_queue, path_lengths, cycles, src_map):
# We do a breadth first search, to make sure we visit all paths in order
# of ascending length. This is an important optimization to make sure that
@@ -127,54 +142,57 @@ def expand(path_queue, path_lengths, cycles, src_map):
path_queue.append(cur_path + [item])
pass
+
cycles = []
path_queue = [[x] for x in iter(src_map)]
path_lens = [1] * len(path_queue)
items = list(src_map.items())
-items.sort(key = lambda A : A[0])
+items.sort(key=lambda A: A[0])
-for (path, deps) in items:
+for path, deps in items:
print(path + ":")
sorted_deps = list(deps.items())
if args.show_counts:
- sorted_deps.sort(key = lambda A: (A[1], A[0]))
+ sorted_deps.sort(key=lambda A: (A[1], A[0]))
for dep in sorted_deps:
print("\t{} [{}]".format(dep[0], dep[1]))
else:
- sorted_deps.sort(key = lambda A: A[0])
+ sorted_deps.sort(key=lambda A: A[0])
for dep in sorted_deps:
print("\t{}".format(dep[0]))
+
def iter_cycles(cycles):
global src_map
for cycle in cycles:
cycle.append(cycle[0])
zipper = list(zip(cycle[0:-1], cycle[1:]))
- result = [(x, src_map[x][y], y) for (x,y) in zipper]
+ result = [(x, src_map[x][y], y) for (x, y) in zipper]
total = 0
smallest = result[0][1]
- for (first, value, last) in result:
+ for first, value, last in result:
total += value
smallest = min(smallest, value)
yield (total, smallest, result)
+
if args.discover_cycles:
print("Analyzing cycles...")
expand(path_queue, path_lens, cycles, src_map)
- average = sum([len(x)+1 for x in cycles]) / len(cycles)
+ average = sum([len(x) + 1 for x in cycles]) / len(cycles)
print("Found {} cycles. Average cycle length = {}.".format(len(cycles), average))
counted = list(iter_cycles(cycles))
if args.show_counts:
- counted.sort(key = lambda A: A[0])
- for (total, smallest, cycle) in counted:
+ counted.sort(key=lambda A: A[0])
+ for total, smallest, cycle in counted:
sys.stdout.write("{} deps to break: ".format(total))
sys.stdout.write(cycle[0][0])
- for (first, count, last) in cycle:
+ for first, count, last in cycle:
sys.stdout.write(" [{}->] {}".format(count, last))
sys.stdout.write("\n")
else:
@@ -186,8 +204,8 @@ if args.discover_cycles:
islands = []
outgoing_counts = defaultdict(int)
incoming_counts = defaultdict(int)
- for (total, smallest, cycle) in counted:
- for (first, count, last) in cycle:
+ for total, smallest, cycle in counted:
+ for first, count, last in cycle:
outgoing_counts[first] += count
incoming_counts[last] += count
for cycle in cycles:
@@ -201,8 +219,8 @@ if args.discover_cycles:
sorted = []
for node in island:
sorted.append((node, incoming_counts[node], outgoing_counts[node]))
- sorted.sort(key = lambda x: x[1]+x[2])
- for (node, inc, outg) in sorted:
+ sorted.sort(key=lambda x: x[1] + x[2])
+ for node, inc, outg in sorted:
print(" {} [{} in, {} out]".format(node, inc, outg))
sys.stdout.flush()
pass
diff --git a/lldb/scripts/android/host_art_bt.py b/lldb/scripts/android/host_art_bt.py
index 03797074aafd..d4c5af46d9e2 100644
--- a/lldb/scripts/android/host_art_bt.py
+++ b/lldb/scripts/android/host_art_bt.py
@@ -20,45 +20,59 @@ def host_art_bt(debugger, command, result, internal_dict):
thread = process.GetSelectedThread()
while lldb_frame_index < thread.GetNumFrames():
frame = thread.GetFrameAtIndex(lldb_frame_index)
- if frame.GetModule() and re.match(r'JIT\(.*?\)',
- frame.GetModule().GetFileSpec().GetFilename()):
+ if frame.GetModule() and re.match(
+ r"JIT\(.*?\)", frame.GetModule().GetFileSpec().GetFilename()
+ ):
# Compiled Java frame
# Get function/filename/lineno from symbol context
symbol = frame.GetSymbol()
if not symbol:
- print('No symbol info for compiled Java frame: ', frame)
+ print("No symbol info for compiled Java frame: ", frame)
sys.exit(1)
line_entry = frame.GetLineEntry()
- prettified_frames.append({
- 'function': symbol.GetName(),
- 'file': str(line_entry.GetFileSpec()) if line_entry else None,
- 'line': line_entry.GetLine() if line_entry else -1
- })
+ prettified_frames.append(
+ {
+ "function": symbol.GetName(),
+ "file": str(line_entry.GetFileSpec()) if line_entry else None,
+ "line": line_entry.GetLine() if line_entry else -1,
+ }
+ )
# Skip art frames
while True:
art_stack_visitor = frame.EvaluateExpression(
- """struct GetStackVisitor : public StackVisitor { GetStackVisitor(int depth_) : StackVisitor(Thread::Current(), NULL), depth(depth_) {} bool VisitFrame() { if (cur_depth_ == depth) { return false; } else { return true; } } int depth; }; GetStackVisitor visitor(""" +
- str(art_frame_index) +
- """); visitor.WalkStack(true); visitor""")
+ """struct GetStackVisitor : public StackVisitor { GetStackVisitor(int depth_) : StackVisitor(Thread::Current(), NULL), depth(depth_) {} bool VisitFrame() { if (cur_depth_ == depth) { return false; } else { return true; } } int depth; }; GetStackVisitor visitor("""
+ + str(art_frame_index)
+ + """); visitor.WalkStack(true); visitor"""
+ )
art_method = frame.EvaluateExpression(
- art_stack_visitor.GetName() + """.GetMethod()""")
+ art_stack_visitor.GetName() + """.GetMethod()"""
+ )
if art_method.GetValueAsUnsigned() != 0:
art_method_name = frame.EvaluateExpression(
- """art::PrettyMethod(""" + art_method.GetName() + """, true)""")
+ """art::PrettyMethod(""" + art_method.GetName() + """, true)"""
+ )
art_method_name_data = frame.EvaluateExpression(
- art_method_name.GetName() + """.c_str()""").GetValueAsUnsigned()
+ art_method_name.GetName() + """.c_str()"""
+ ).GetValueAsUnsigned()
art_method_name_size = frame.EvaluateExpression(
- art_method_name.GetName() + """.length()""").GetValueAsUnsigned()
+ art_method_name.GetName() + """.length()"""
+ ).GetValueAsUnsigned()
error = lldb.SBError()
art_method_name = process.ReadCStringFromMemory(
- art_method_name_data, art_method_name_size + 1, error)
+ art_method_name_data, art_method_name_size + 1, error
+ )
if not error.Success:
- print('Failed to read method name')
+ print("Failed to read method name")
sys.exit(1)
if art_method_name != symbol.GetName():
- print('Function names in native symbol and art runtime stack do not match: ', symbol.GetName(), ' != ', art_method_name)
+ print(
+ "Function names in native symbol and art runtime stack do not match: ",
+ symbol.GetName(),
+ " != ",
+ art_method_name,
+ )
art_frame_index = art_frame_index + 1
break
art_frame_index = art_frame_index + 1
@@ -68,53 +82,69 @@ def host_art_bt(debugger, command, result, internal_dict):
if lldb_frame_index < thread.GetNumFrames():
frame = thread.GetFrameAtIndex(lldb_frame_index)
if frame.GetModule() and re.match(
- r'JIT\(.*?\)', frame.GetModule().GetFileSpec().GetFilename()):
+ r"JIT\(.*?\)", frame.GetModule().GetFileSpec().GetFilename()
+ ):
# Another compile Java frame
# Don't skip; leave it to the next iteration
continue
- elif frame.GetSymbol() and (frame.GetSymbol().GetName() == 'art_quick_invoke_stub' or frame.GetSymbol().GetName() == 'art_quick_invoke_static_stub'):
+ elif frame.GetSymbol() and (
+ frame.GetSymbol().GetName() == "art_quick_invoke_stub"
+ or frame.GetSymbol().GetName() == "art_quick_invoke_static_stub"
+ ):
# art_quick_invoke_stub / art_quick_invoke_static_stub
# Skip until we get past the next ArtMethod::Invoke()
while True:
lldb_frame_index = lldb_frame_index + 1
if lldb_frame_index >= thread.GetNumFrames():
- print('ArtMethod::Invoke not found below art_quick_invoke_stub/art_quick_invoke_static_stub')
+ print(
+ "ArtMethod::Invoke not found below art_quick_invoke_stub/art_quick_invoke_static_stub"
+ )
sys.exit(1)
frame = thread.GetFrameAtIndex(lldb_frame_index)
- if frame.GetSymbol() and frame.GetSymbol().GetName(
- ) == 'art::mirror::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)':
+ if (
+ frame.GetSymbol()
+ and frame.GetSymbol().GetName()
+ == "art::mirror::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)"
+ ):
lldb_frame_index = lldb_frame_index + 1
break
else:
- print('Invalid frame below compiled Java frame: ', frame)
- elif frame.GetSymbol() and frame.GetSymbol().GetName() == 'art_quick_generic_jni_trampoline':
+ print("Invalid frame below compiled Java frame: ", frame)
+ elif (
+ frame.GetSymbol()
+ and frame.GetSymbol().GetName() == "art_quick_generic_jni_trampoline"
+ ):
# Interpreted JNI frame for x86_64
# Skip art frames
while True:
art_stack_visitor = frame.EvaluateExpression(
- """struct GetStackVisitor : public StackVisitor { GetStackVisitor(int depth_) : StackVisitor(Thread::Current(), NULL), depth(depth_) {} bool VisitFrame() { if (cur_depth_ == depth) { return false; } else { return true; } } int depth; }; GetStackVisitor visitor(""" +
- str(art_frame_index) +
- """); visitor.WalkStack(true); visitor""")
+ """struct GetStackVisitor : public StackVisitor { GetStackVisitor(int depth_) : StackVisitor(Thread::Current(), NULL), depth(depth_) {} bool VisitFrame() { if (cur_depth_ == depth) { return false; } else { return true; } } int depth; }; GetStackVisitor visitor("""
+ + str(art_frame_index)
+ + """); visitor.WalkStack(true); visitor"""
+ )
art_method = frame.EvaluateExpression(
- art_stack_visitor.GetName() + """.GetMethod()""")
+ art_stack_visitor.GetName() + """.GetMethod()"""
+ )
if art_method.GetValueAsUnsigned() != 0:
# Get function/filename/lineno from ART runtime
art_method_name = frame.EvaluateExpression(
- """art::PrettyMethod(""" + art_method.GetName() + """, true)""")
+ """art::PrettyMethod(""" + art_method.GetName() + """, true)"""
+ )
art_method_name_data = frame.EvaluateExpression(
- art_method_name.GetName() + """.c_str()""").GetValueAsUnsigned()
+ art_method_name.GetName() + """.c_str()"""
+ ).GetValueAsUnsigned()
art_method_name_size = frame.EvaluateExpression(
- art_method_name.GetName() + """.length()""").GetValueAsUnsigned()
+ art_method_name.GetName() + """.length()"""
+ ).GetValueAsUnsigned()
error = lldb.SBError()
function = process.ReadCStringFromMemory(
- art_method_name_data, art_method_name_size + 1, error)
+ art_method_name_data, art_method_name_size + 1, error
+ )
- prettified_frames.append({
- 'function': function,
- 'file': None,
- 'line': -1
- })
+ prettified_frames.append(
+ {"function": function, "file": None, "line": -1}
+ )
art_frame_index = art_frame_index + 1
break
@@ -124,78 +154,98 @@ def host_art_bt(debugger, command, result, internal_dict):
lldb_frame_index = lldb_frame_index + 1
if lldb_frame_index < thread.GetNumFrames():
frame = thread.GetFrameAtIndex(lldb_frame_index)
- if frame.GetSymbol() and (frame.GetSymbol().GetName() ==
- 'art_quick_invoke_stub' or frame.GetSymbol().GetName() == 'art_quick_invoke_static_stub'):
+ if frame.GetSymbol() and (
+ frame.GetSymbol().GetName() == "art_quick_invoke_stub"
+ or frame.GetSymbol().GetName() == "art_quick_invoke_static_stub"
+ ):
# art_quick_invoke_stub / art_quick_invoke_static_stub
# Skip until we get past the next ArtMethod::Invoke()
while True:
lldb_frame_index = lldb_frame_index + 1
if lldb_frame_index >= thread.GetNumFrames():
- print('ArtMethod::Invoke not found below art_quick_invoke_stub/art_quick_invoke_static_stub')
+ print(
+ "ArtMethod::Invoke not found below art_quick_invoke_stub/art_quick_invoke_static_stub"
+ )
sys.exit(1)
frame = thread.GetFrameAtIndex(lldb_frame_index)
- if frame.GetSymbol() and frame.GetSymbol().GetName(
- ) == 'art::mirror::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)':
+ if (
+ frame.GetSymbol()
+ and frame.GetSymbol().GetName()
+ == "art::mirror::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)"
+ ):
lldb_frame_index = lldb_frame_index + 1
break
else:
- print('Invalid frame below compiled Java frame: ', frame)
- elif frame.GetSymbol() and re.search(r'art::interpreter::', frame.GetSymbol().GetName()):
+ print("Invalid frame below compiled Java frame: ", frame)
+ elif frame.GetSymbol() and re.search(
+ r"art::interpreter::", frame.GetSymbol().GetName()
+ ):
# Interpreted Java frame
while True:
lldb_frame_index = lldb_frame_index + 1
if lldb_frame_index >= thread.GetNumFrames():
- print('art::interpreter::Execute not found in interpreter frame')
+ print("art::interpreter::Execute not found in interpreter frame")
sys.exit(1)
frame = thread.GetFrameAtIndex(lldb_frame_index)
- if frame.GetSymbol() and frame.GetSymbol().GetName(
- ) == 'art::interpreter::Execute(art::Thread*, art::MethodHelper&, art::DexFile::CodeItem const*, art::ShadowFrame&, art::JValue)':
+ if (
+ frame.GetSymbol()
+ and frame.GetSymbol().GetName()
+ == "art::interpreter::Execute(art::Thread*, art::MethodHelper&, art::DexFile::CodeItem const*, art::ShadowFrame&, art::JValue)"
+ ):
break
# Skip art frames
while True:
art_stack_visitor = frame.EvaluateExpression(
- """struct GetStackVisitor : public StackVisitor { GetStackVisitor(int depth_) : StackVisitor(Thread::Current(), NULL), depth(depth_) {} bool VisitFrame() { if (cur_depth_ == depth) { return false; } else { return true; } } int depth; }; GetStackVisitor visitor(""" +
- str(art_frame_index) +
- """); visitor.WalkStack(true); visitor""")
+ """struct GetStackVisitor : public StackVisitor { GetStackVisitor(int depth_) : StackVisitor(Thread::Current(), NULL), depth(depth_) {} bool VisitFrame() { if (cur_depth_ == depth) { return false; } else { return true; } } int depth; }; GetStackVisitor visitor("""
+ + str(art_frame_index)
+ + """); visitor.WalkStack(true); visitor"""
+ )
art_method = frame.EvaluateExpression(
- art_stack_visitor.GetName() + """.GetMethod()""")
+ art_stack_visitor.GetName() + """.GetMethod()"""
+ )
if art_method.GetValueAsUnsigned() != 0:
# Get function/filename/lineno from ART runtime
art_method_name = frame.EvaluateExpression(
- """art::PrettyMethod(""" + art_method.GetName() + """, true)""")
+ """art::PrettyMethod(""" + art_method.GetName() + """, true)"""
+ )
art_method_name_data = frame.EvaluateExpression(
- art_method_name.GetName() + """.c_str()""").GetValueAsUnsigned()
+ art_method_name.GetName() + """.c_str()"""
+ ).GetValueAsUnsigned()
art_method_name_size = frame.EvaluateExpression(
- art_method_name.GetName() + """.length()""").GetValueAsUnsigned()
+ art_method_name.GetName() + """.length()"""
+ ).GetValueAsUnsigned()
error = lldb.SBError()
function = process.ReadCStringFromMemory(
- art_method_name_data, art_method_name_size + 1, error)
+ art_method_name_data, art_method_name_size + 1, error
+ )
line = frame.EvaluateExpression(
- art_stack_visitor.GetName() +
- """.GetMethod()->GetLineNumFromDexPC(""" +
- art_stack_visitor.GetName() +
- """.GetDexPc(true))""").GetValueAsUnsigned()
+ art_stack_visitor.GetName()
+ + """.GetMethod()->GetLineNumFromDexPC("""
+ + art_stack_visitor.GetName()
+ + """.GetDexPc(true))"""
+ ).GetValueAsUnsigned()
file_name = frame.EvaluateExpression(
- art_method.GetName() + """->GetDeclaringClassSourceFile()""")
+ art_method.GetName() + """->GetDeclaringClassSourceFile()"""
+ )
file_name_data = file_name.GetValueAsUnsigned()
file_name_size = frame.EvaluateExpression(
- """(size_t)strlen(""" + file_name.GetName() + """)""").GetValueAsUnsigned()
+ """(size_t)strlen(""" + file_name.GetName() + """)"""
+ ).GetValueAsUnsigned()
error = lldb.SBError()
file_name = process.ReadCStringFromMemory(
- file_name_data, file_name_size + 1, error)
+ file_name_data, file_name_size + 1, error
+ )
if not error.Success():
- print('Failed to read source file name')
+ print("Failed to read source file name")
sys.exit(1)
- prettified_frames.append({
- 'function': function,
- 'file': file_name,
- 'line': line
- })
+ prettified_frames.append(
+ {"function": function, "file": file_name, "line": line}
+ )
art_frame_index = art_frame_index + 1
break
@@ -205,11 +255,12 @@ def host_art_bt(debugger, command, result, internal_dict):
while True:
lldb_frame_index = lldb_frame_index + 1
if lldb_frame_index >= thread.GetNumFrames():
- print('Can not get past interpreter native frames')
+ print("Can not get past interpreter native frames")
sys.exit(1)
frame = thread.GetFrameAtIndex(lldb_frame_index)
if frame.GetSymbol() and not re.search(
- r'art::interpreter::', frame.GetSymbol().GetName()):
+ r"art::interpreter::", frame.GetSymbol().GetName()
+ ):
break
else:
# Other frames. Add them as-is.
@@ -218,20 +269,32 @@ def host_art_bt(debugger, command, result, internal_dict):
if frame.GetModule():
module_name = frame.GetModule().GetFileSpec().GetFilename()
if not module_name in [
- 'libartd.so',
- 'dalvikvm32',
- 'dalvikvm64',
- 'libc.so.6']:
- prettified_frames.append({
- 'function': frame.GetSymbol().GetName() if frame.GetSymbol() else None,
- 'file': str(frame.GetLineEntry().GetFileSpec()) if frame.GetLineEntry() else None,
- 'line': frame.GetLineEntry().GetLine() if frame.GetLineEntry() else -1
- })
+ "libartd.so",
+ "dalvikvm32",
+ "dalvikvm64",
+ "libc.so.6",
+ ]:
+ prettified_frames.append(
+ {
+ "function": frame.GetSymbol().GetName()
+ if frame.GetSymbol()
+ else None,
+ "file": str(frame.GetLineEntry().GetFileSpec())
+ if frame.GetLineEntry()
+ else None,
+ "line": frame.GetLineEntry().GetLine()
+ if frame.GetLineEntry()
+ else -1,
+ }
+ )
for prettified_frame in prettified_frames:
- print(prettified_frame['function'], prettified_frame['file'], prettified_frame['line'])
+ print(
+ prettified_frame["function"],
+ prettified_frame["file"],
+ prettified_frame["line"],
+ )
def __lldb_init_module(debugger, internal_dict):
- debugger.HandleCommand(
- 'command script add -f host_art_bt.host_art_bt host_art_bt')
+ debugger.HandleCommand("command script add -f host_art_bt.host_art_bt host_art_bt")
diff --git a/lldb/scripts/install_custom_python.py b/lldb/scripts/install_custom_python.py
index 6e263fa714e0..04df6fbc3cea 100644
--- a/lldb/scripts/install_custom_python.py
+++ b/lldb/scripts/install_custom_python.py
@@ -30,122 +30,112 @@ import sys
def copy_one_file(dest_dir, source_dir, filename):
source_path = os.path.join(source_dir, filename)
dest_path = os.path.join(dest_dir, filename)
- print('Copying file %s ==> %s...' % (source_path, dest_path))
+ print("Copying file %s ==> %s..." % (source_path, dest_path))
shutil.copyfile(source_path, dest_path)
-def copy_named_files(
- dest_dir,
- source_dir,
- files,
- extensions,
- copy_debug_suffix_also):
- for (file, ext) in itertools.product(files, extensions):
- copy_one_file(dest_dir, source_dir, file + '.' + ext)
+def copy_named_files(dest_dir, source_dir, files, extensions, copy_debug_suffix_also):
+ for file, ext in itertools.product(files, extensions):
+ copy_one_file(dest_dir, source_dir, file + "." + ext)
if copy_debug_suffix_also:
- copy_one_file(dest_dir, source_dir, file + '_d.' + ext)
+ copy_one_file(dest_dir, source_dir, file + "_d." + ext)
def copy_subdirectory(dest_dir, source_dir, subdir):
dest_dir = os.path.join(dest_dir, subdir)
source_dir = os.path.join(source_dir, subdir)
- print('Copying directory %s ==> %s...' % (source_dir, dest_dir))
+ print("Copying directory %s ==> %s..." % (source_dir, dest_dir))
shutil.copytree(source_dir, dest_dir)
def copy_distro(dest_dir, dest_subdir, source_dir, source_prefix):
dest_dir = os.path.join(dest_dir, dest_subdir)
- print('Copying distribution %s ==> %s' % (source_dir, dest_dir))
+ print("Copying distribution %s ==> %s" % (source_dir, dest_dir))
os.mkdir(dest_dir)
- PCbuild_dir = os.path.join(source_dir, 'PCbuild')
+ PCbuild_dir = os.path.join(source_dir, "PCbuild")
if source_prefix:
PCbuild_dir = os.path.join(PCbuild_dir, source_prefix)
# First copy the files that go into the root of the new distribution. This
# includes the Python executables, python27(_d).dll, and relevant PDB
# files.
- print('Copying Python executables...')
+ print("Copying Python executables...")
+ copy_named_files(dest_dir, PCbuild_dir, ["w9xpopen"], ["exe", "pdb"], False)
+ copy_named_files(dest_dir, PCbuild_dir, ["python_d", "pythonw_d"], ["exe"], False)
copy_named_files(
- dest_dir, PCbuild_dir, ['w9xpopen'], [
- 'exe', 'pdb'], False)
- copy_named_files(
- dest_dir, PCbuild_dir, [
- 'python_d', 'pythonw_d'], ['exe'], False)
- copy_named_files(
- dest_dir, PCbuild_dir, [
- 'python', 'pythonw'], [
- 'exe', 'pdb'], False)
- copy_named_files(dest_dir, PCbuild_dir, ['python27'], ['dll', 'pdb'], True)
+ dest_dir, PCbuild_dir, ["python", "pythonw"], ["exe", "pdb"], False
+ )
+ copy_named_files(dest_dir, PCbuild_dir, ["python27"], ["dll", "pdb"], True)
# Next copy everything in the Include directory.
- print('Copying Python include directory')
- copy_subdirectory(dest_dir, source_dir, 'Include')
+ print("Copying Python include directory")
+ copy_subdirectory(dest_dir, source_dir, "Include")
# Copy Lib folder (builtin Python modules)
- print('Copying Python Lib directory')
- copy_subdirectory(dest_dir, source_dir, 'Lib')
+ print("Copying Python Lib directory")
+ copy_subdirectory(dest_dir, source_dir, "Lib")
# Copy tools folder. These are probably not necessary, but we copy them anyway to
# match an official distribution as closely as possible. Note that we don't just copy
# the subdirectory recursively. The source distribution ships with many more tools
# than what you get by installing python regularly. We only copy the tools that appear
# in an installed distribution.
- tools_dest_dir = os.path.join(dest_dir, 'Tools')
- tools_source_dir = os.path.join(source_dir, 'Tools')
+ tools_dest_dir = os.path.join(dest_dir, "Tools")
+ tools_source_dir = os.path.join(source_dir, "Tools")
os.mkdir(tools_dest_dir)
- copy_subdirectory(tools_dest_dir, tools_source_dir, 'i18n')
- copy_subdirectory(tools_dest_dir, tools_source_dir, 'pynche')
- copy_subdirectory(tools_dest_dir, tools_source_dir, 'scripts')
- copy_subdirectory(tools_dest_dir, tools_source_dir, 'versioncheck')
- copy_subdirectory(tools_dest_dir, tools_source_dir, 'webchecker')
+ copy_subdirectory(tools_dest_dir, tools_source_dir, "i18n")
+ copy_subdirectory(tools_dest_dir, tools_source_dir, "pynche")
+ copy_subdirectory(tools_dest_dir, tools_source_dir, "scripts")
+ copy_subdirectory(tools_dest_dir, tools_source_dir, "versioncheck")
+ copy_subdirectory(tools_dest_dir, tools_source_dir, "webchecker")
pyd_names = [
- '_ctypes',
- '_ctypes_test',
- '_elementtree',
- '_multiprocessing',
- '_socket',
- '_testcapi',
- 'pyexpat',
- 'select',
- 'unicodedata',
- 'winsound']
+ "_ctypes",
+ "_ctypes_test",
+ "_elementtree",
+ "_multiprocessing",
+ "_socket",
+ "_testcapi",
+ "pyexpat",
+ "select",
+ "unicodedata",
+ "winsound",
+ ]
# Copy builtin extension modules (pyd files)
- dlls_dir = os.path.join(dest_dir, 'DLLs')
+ dlls_dir = os.path.join(dest_dir, "DLLs")
os.mkdir(dlls_dir)
- print('Copying DLLs directory')
- copy_named_files(dlls_dir, PCbuild_dir, pyd_names, ['pyd', 'pdb'], True)
+ print("Copying DLLs directory")
+ copy_named_files(dlls_dir, PCbuild_dir, pyd_names, ["pyd", "pdb"], True)
# Copy libs folder (implibs for the pyd files)
- libs_dir = os.path.join(dest_dir, 'libs')
+ libs_dir = os.path.join(dest_dir, "libs")
os.mkdir(libs_dir)
- print('Copying libs directory')
- copy_named_files(libs_dir, PCbuild_dir, pyd_names, ['lib'], False)
- copy_named_files(libs_dir, PCbuild_dir, ['python27'], ['lib'], True)
+ print("Copying libs directory")
+ copy_named_files(libs_dir, PCbuild_dir, pyd_names, ["lib"], False)
+ copy_named_files(libs_dir, PCbuild_dir, ["python27"], ["lib"], True)
-parser = argparse.ArgumentParser(
- description='Install a custom Python distribution')
+parser = argparse.ArgumentParser(description="Install a custom Python distribution")
parser.add_argument(
- '--source',
- required=True,
- help='The root of the source tree where Python is built.')
+ "--source", required=True, help="The root of the source tree where Python is built."
+)
parser.add_argument(
- '--dest',
- required=True,
- help='The location to install the Python distributions.')
+ "--dest", required=True, help="The location to install the Python distributions."
+)
parser.add_argument(
- '--overwrite',
+ "--overwrite",
default=False,
- action='store_true',
- help='If the destination directory already exists, destroys its contents first.')
+ action="store_true",
+ help="If the destination directory already exists, destroys its contents first.",
+)
parser.add_argument(
- '--silent',
+ "--silent",
default=False,
- action='store_true',
- help='If --overwite was specified, suppress confirmation before deleting a directory tree.')
+ action="store_true",
+ help="If --overwite was specified, suppress confirmation before deleting a directory tree.",
+)
args = parser.parse_args()
@@ -153,23 +143,31 @@ args.source = os.path.normpath(args.source)
args.dest = os.path.normpath(args.dest)
if not os.path.exists(args.source):
- print('The source directory %s does not exist. Exiting...')
+ print("The source directory %s does not exist. Exiting...")
sys.exit(1)
if os.path.exists(args.dest):
if not args.overwrite:
- print('The destination directory \'%s\' already exists and --overwrite was not specified. Exiting...' % args.dest)
+ print(
+ "The destination directory '%s' already exists and --overwrite was not specified. Exiting..."
+ % args.dest
+ )
sys.exit(1)
while not args.silent:
- print('Ok to recursively delete \'%s\' and all contents (Y/N)? Choosing Y will permanently delete the contents.' % args.dest)
+ print(
+ "Ok to recursively delete '%s' and all contents (Y/N)? Choosing Y will permanently delete the contents."
+ % args.dest
+ )
result = str.upper(sys.stdin.read(1))
- if result == 'N':
- print('Unable to copy files to the destination. The destination already exists.')
+ if result == "N":
+ print(
+ "Unable to copy files to the destination. The destination already exists."
+ )
sys.exit(1)
- elif result == 'Y':
+ elif result == "Y":
break
shutil.rmtree(args.dest)
os.mkdir(args.dest)
-copy_distro(args.dest, 'x86', args.source, None)
-copy_distro(args.dest, 'x64', args.source, 'amd64')
+copy_distro(args.dest, "x86", args.source, None)
+copy_distro(args.dest, "x64", args.source, "amd64")
diff --git a/lldb/scripts/reproducer-replay.py b/lldb/scripts/reproducer-replay.py
index 40d7cebca05d..f44e3cf49353 100755
--- a/lldb/scripts/reproducer-replay.py
+++ b/lldb/scripts/reproducer-replay.py
@@ -10,39 +10,39 @@ import subprocess
def run_reproducer(path):
- proc = subprocess.Popen([LLDB, '--replay', path],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
+ proc = subprocess.Popen(
+ [LLDB, "--replay", path], stdout=subprocess.PIPE, stderr=subprocess.PIPE
+ )
reason = None
try:
outs, errs = proc.communicate(timeout=TIMEOUT)
success = proc.returncode == 0
- result = 'PASSED' if success else 'FAILED'
+ result = "PASSED" if success else "FAILED"
if not success:
outs = outs.decode()
errs = errs.decode()
# Do some pattern matching to find out the cause of the failure.
- if 'Encountered unexpected packet during replay' in errs:
- reason = 'Unexpected packet'
- elif 'Assertion failed' in errs:
- reason = 'Assertion failed'
- elif 'UNREACHABLE' in errs:
- reason = 'Unreachable executed'
- elif 'Segmentation fault' in errs:
- reason = 'Segmentation fault'
- elif 'Illegal instruction' in errs:
- reason = 'Illegal instruction'
+ if "Encountered unexpected packet during replay" in errs:
+ reason = "Unexpected packet"
+ elif "Assertion failed" in errs:
+ reason = "Assertion failed"
+ elif "UNREACHABLE" in errs:
+ reason = "Unreachable executed"
+ elif "Segmentation fault" in errs:
+ reason = "Segmentation fault"
+ elif "Illegal instruction" in errs:
+ reason = "Illegal instruction"
else:
- reason = f'Exit code {proc.returncode}'
+ reason = f"Exit code {proc.returncode}"
except subprocess.TimeoutExpired:
proc.kill()
success = False
outs, errs = proc.communicate()
- result = 'TIMEOUT'
+ result = "TIMEOUT"
if not FAILURE_ONLY or not success:
- reason_str = f' ({reason})' if reason else ''
- print(f'{result}: {path}{reason_str}')
+ reason_str = f" ({reason})" if reason else ""
+ print(f"{result}: {path}{reason_str}")
if VERBOSE:
if outs:
print(outs)
@@ -54,49 +54,51 @@ def find_reproducers(path):
for root, dirs, files in os.walk(path):
for dir in dirs:
_, extension = os.path.splitext(dir)
- if dir.startswith('Test') and extension == '.py':
+ if dir.startswith("Test") and extension == ".py":
yield os.path.join(root, dir)
-if __name__ == '__main__':
+if __name__ == "__main__":
parser = argparse.ArgumentParser(
- description='LLDB API Test Replay Driver. '
- 'Replay one or more reproducers in parallel using the specified LLDB driver. '
- 'The script will look for reproducers generated by the API lit test suite. '
- 'To generate the reproducers, pass --param \'lldb-run-with-repro=capture\' to lit.'
+ description="LLDB API Test Replay Driver. "
+ "Replay one or more reproducers in parallel using the specified LLDB driver. "
+ "The script will look for reproducers generated by the API lit test suite. "
+ "To generate the reproducers, pass --param 'lldb-run-with-repro=capture' to lit."
)
parser.add_argument(
- '-j',
- '--threads',
+ "-j",
+ "--threads",
type=int,
default=multiprocessing.cpu_count(),
- help='Number of threads. The number of CPU threads if not specified.')
+ help="Number of threads. The number of CPU threads if not specified.",
+ )
parser.add_argument(
- '-t',
- '--timeout',
+ "-t",
+ "--timeout",
type=int,
default=60,
- help='Replay timeout in seconds. 60 seconds if not specified.')
+ help="Replay timeout in seconds. 60 seconds if not specified.",
+ )
parser.add_argument(
- '-p',
- '--path',
+ "-p",
+ "--path",
type=str,
default=os.getcwd(),
- help=
- 'Path to the directory containing the reproducers. The current working directory if not specified.'
+ help="Path to the directory containing the reproducers. The current working directory if not specified.",
+ )
+ parser.add_argument(
+ "-l",
+ "--lldb",
+ type=str,
+ required=True,
+ help="Path to the LLDB command line driver",
+ )
+ parser.add_argument(
+ "-v", "--verbose", help="Print replay output.", action="store_true"
+ )
+ parser.add_argument(
+ "--failure-only", help="Only log failures.", action="store_true"
)
- parser.add_argument('-l',
- '--lldb',
- type=str,
- required=True,
- help='Path to the LLDB command line driver')
- parser.add_argument('-v',
- '--verbose',
- help='Print replay output.',
- action='store_true')
- parser.add_argument('--failure-only',
- help='Only log failures.',
- action='store_true')
args = parser.parse_args()
global LLDB
@@ -109,11 +111,11 @@ if __name__ == '__main__':
FAILURE_ONLY = args.failure_only
print(
- f'Replaying reproducers in {args.path} with {args.threads} threads and a {args.timeout} seconds timeout'
+ f"Replaying reproducers in {args.path} with {args.threads} threads and a {args.timeout} seconds timeout"
)
try:
pool = Pool(args.threads)
pool.map(run_reproducer, find_reproducers(args.path))
except KeyboardInterrupt:
- print('Interrupted')
+ print("Interrupted")
diff --git a/lldb/scripts/use_lldb_suite.py b/lldb/scripts/use_lldb_suite.py
index 84380f6a5592..6388d87b181c 100644
--- a/lldb/scripts/use_lldb_suite.py
+++ b/lldb/scripts/use_lldb_suite.py
@@ -7,7 +7,7 @@ def find_lldb_root():
lldb_root = os.path.dirname(inspect.getfile(inspect.currentframe()))
while True:
parent = os.path.dirname(lldb_root)
- if parent == lldb_root: # dirname('/') == '/'
+ if parent == lldb_root: # dirname('/') == '/'
raise Exception("use_lldb_suite_root.py not found")
lldb_root = parent
@@ -15,8 +15,10 @@ def find_lldb_root():
if os.path.isfile(test_path):
return lldb_root
+
lldb_root = find_lldb_root()
import imp
+
fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
try:
imp.load_module("use_lldb_suite_root", fp, pathname, desc)
diff --git a/lldb/scripts/verify_api.py b/lldb/scripts/verify_api.py
index f3f0748023bc..9d14a58121bf 100755
--- a/lldb/scripts/verify_api.py
+++ b/lldb/scripts/verify_api.py
@@ -10,58 +10,67 @@ import sys
def extract_exe_symbol_names(arch, exe_path, match_str):
command = 'dsymutil --arch %s -s "%s" | grep "%s" | colrm 1 69' % (
- arch, exe_path, match_str)
+ arch,
+ exe_path,
+ match_str,
+ )
(command_exit_status, command_output) = subprocess.getstatusoutput(command)
if command_exit_status == 0:
if command_output:
return command_output[0:-1].split("'\n")
else:
- print('error: command returned no output')
+ print("error: command returned no output")
else:
- print('error: command failed with exit status %i\n command: %s' % (command_exit_status, command))
+ print(
+ "error: command failed with exit status %i\n command: %s"
+ % (command_exit_status, command)
+ )
return list()
def verify_api(all_args):
- '''Verify the API in the specified library is valid given one or more binaries.'''
+ """Verify the API in the specified library is valid given one or more binaries."""
usage = "usage: verify_api --library <path> [ --library <path> ...] executable1 [executable2 ...]"
- description = '''Verify the API in the specified library is valid given one or more binaries.
+ description = """Verify the API in the specified library is valid given one or more binaries.
Example:
verify_api.py --library ~/Documents/src/lldb/build/Debug/LLDB.framework/LLDB --arch x86_64 /Applications/Xcode.app/Contents/PlugIns/DebuggerLLDB.ideplugin/Contents/MacOS/DebuggerLLDB --api-regex lldb
- '''
+ """
parser = optparse.OptionParser(
- description=description,
- prog='verify_api',
- usage=usage)
+ description=description, prog="verify_api", usage=usage
+ )
parser.add_option(
- '-v',
- '--verbose',
- action='store_true',
- dest='verbose',
- help='display verbose debug info',
- default=False)
+ "-v",
+ "--verbose",
+ action="store_true",
+ dest="verbose",
+ help="display verbose debug info",
+ default=False,
+ )
parser.add_option(
- '-a',
- '--arch',
- type='string',
- action='append',
- dest='archs',
- help='architecture to use when checking the api')
+ "-a",
+ "--arch",
+ type="string",
+ action="append",
+ dest="archs",
+ help="architecture to use when checking the api",
+ )
parser.add_option(
- '-r',
- '--api-regex',
- type='string',
- dest='api_regex_str',
- help='Exclude any undefined symbols that do not match this regular expression when searching for missing APIs.')
+ "-r",
+ "--api-regex",
+ type="string",
+ dest="api_regex_str",
+ help="Exclude any undefined symbols that do not match this regular expression when searching for missing APIs.",
+ )
parser.add_option(
- '-l',
- '--library',
- type='string',
- action='append',
- dest='libraries',
- help='Specify one or more libraries that will contain all needed APIs for the executables.')
+ "-l",
+ "--library",
+ type="string",
+ action="append",
+ dest="libraries",
+ help="Specify one or more libraries that will contain all needed APIs for the executables.",
+ )
(options, args) = parser.parse_args(all_args)
api_external_symbols = list()
@@ -69,18 +78,19 @@ def verify_api(all_args):
for arch in options.archs:
for library in options.libraries:
external_symbols = extract_exe_symbol_names(
- arch, library, "( SECT EXT)")
+ arch, library, "( SECT EXT)"
+ )
if external_symbols:
for external_symbol in external_symbols:
api_external_symbols.append(external_symbol)
else:
sys.exit(1)
else:
- print('error: must specify one or more architectures with the --arch option')
+ print("error: must specify one or more architectures with the --arch option")
sys.exit(4)
if options.verbose:
print("API symbols:")
- for (i, external_symbol) in enumerate(api_external_symbols):
+ for i, external_symbol in enumerate(api_external_symbols):
print("[%u] %s" % (i, external_symbol))
api_regex = None
@@ -92,24 +102,29 @@ def verify_api(all_args):
print('Verifying (%s) "%s"...' % (arch, exe_path))
exe_errors = 0
undefined_symbols = extract_exe_symbol_names(
- arch, exe_path, "( UNDF EXT)")
+ arch, exe_path, "( UNDF EXT)"
+ )
for undefined_symbol in undefined_symbols:
if api_regex:
match = api_regex.search(undefined_symbol)
if not match:
if options.verbose:
- print('ignoring symbol: %s' % (undefined_symbol))
+ print("ignoring symbol: %s" % (undefined_symbol))
continue
if undefined_symbol in api_external_symbols:
if options.verbose:
- print('verified symbol: %s' % (undefined_symbol))
+ print("verified symbol: %s" % (undefined_symbol))
else:
- print('missing symbol: %s' % (undefined_symbol))
+ print("missing symbol: %s" % (undefined_symbol))
exe_errors += 1
if exe_errors:
- print('error: missing %u API symbols from %s' % (exe_errors, options.libraries))
+ print(
+ "error: missing %u API symbols from %s"
+ % (exe_errors, options.libraries)
+ )
else:
- print('success')
+ print("success")
-if __name__ == '__main__':
+
+if __name__ == "__main__":
verify_api(sys.argv[1:])