aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/Shell/ScriptInterpreter/Python
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2023-05-25 08:48:57 -0700
committerJonas Devlieghere <jonas@devlieghere.com>2023-05-25 12:54:09 -0700
commit2238dcc39358353cac21df75c3c3286ab20b8f53 (patch)
tree1bb7ec8d7405ccd7fdb5a8a78d0cf5ef40bcc963 /lldb/test/Shell/ScriptInterpreter/Python
parentdaeee56798c51e8f007e8e8e6e677a420b14c9ef (diff)
downloadllvm-2238dcc39358353cac21df75c3c3286ab20b8f53.zip
llvm-2238dcc39358353cac21df75c3c3286ab20b8f53.tar.gz
llvm-2238dcc39358353cac21df75c3c3286ab20b8f53.tar.bz2
[NFC][Py Reformat] Reformat python files in lldb
This is an ongoing series of commits that are reformatting our Python code. Reformatting is done with `black` (23.1.0). If you end up having problems merging this commit because you have made changes to a python file, the best way to handle that is to run `git checkout --ours <yourfile>` and then reformat it with black. RFC: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style Differential revision: https://reviews.llvm.org/D151460
Diffstat (limited to 'lldb/test/Shell/ScriptInterpreter/Python')
-rw-r--r--lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py37
-rw-r--r--lldb/test/Shell/ScriptInterpreter/Python/Inputs/sbaddress.py4
2 files changed, 22 insertions, 19 deletions
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py
index 56558bc..f417a09 100644
--- a/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py
+++ b/lldb/test/Shell/ScriptInterpreter/Python/Crashlog/patch-crashlog.py
@@ -9,9 +9,8 @@ import argparse
class CrashLogPatcher:
-
- SYMBOL_REGEX = re.compile(r'^([0-9a-fA-F]+) T _(.*)$')
- UUID_REGEX = re.compile(r'UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*')
+ SYMBOL_REGEX = re.compile(r"^([0-9a-fA-F]+) T _(.*)$")
+ UUID_REGEX = re.compile(r"UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
def __init__(self, data, binary, offsets, json):
self.data = data
@@ -24,7 +23,9 @@ class CrashLogPatcher:
self.data = self.data.replace("@NAME@", os.path.basename(self.binary))
def patch_uuid(self):
- output = subprocess.check_output(['dwarfdump', '--uuid', self.binary]).decode("utf-8")
+ output = subprocess.check_output(["dwarfdump", "--uuid", self.binary]).decode(
+ "utf-8"
+ )
m = self.UUID_REGEX.match(output)
if m:
self.data = self.data.replace("@UUID@", m.group(1))
@@ -32,39 +33,39 @@ class CrashLogPatcher:
def patch_addresses(self):
if not self.offsets:
return
- output = subprocess.check_output(['nm', self.binary]).decode("utf-8")
+ output = subprocess.check_output(["nm", self.binary]).decode("utf-8")
for line in output.splitlines():
m = self.SYMBOL_REGEX.match(line)
if m:
address = m.group(1)
symbol = m.group(2)
if symbol in self.offsets:
- patch_addr = int(m.group(1), 16) + int(
- self.offsets[symbol])
+ patch_addr = int(m.group(1), 16) + int(self.offsets[symbol])
if self.json:
patch_addr = patch_addr - 0x100000000
representation = int
else:
representation = hex
self.data = self.data.replace(
- "@{}@".format(symbol), str(representation(patch_addr)))
+ "@{}@".format(symbol), str(representation(patch_addr))
+ )
def remove_metadata(self):
- self.data= self.data[self.data.index('\n') + 1:]
+ self.data = self.data[self.data.index("\n") + 1 :]
-if __name__ == '__main__':
- parser = argparse.ArgumentParser(description='Crashlog Patcher')
- parser.add_argument('--binary', required=True)
- parser.add_argument('--crashlog', required=True)
- parser.add_argument('--offsets', required=True)
- parser.add_argument('--json', default=False, action='store_true')
- parser.add_argument('--no-metadata', default=False, action='store_true')
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description="Crashlog Patcher")
+ parser.add_argument("--binary", required=True)
+ parser.add_argument("--crashlog", required=True)
+ parser.add_argument("--offsets", required=True)
+ parser.add_argument("--json", default=False, action="store_true")
+ parser.add_argument("--no-metadata", default=False, action="store_true")
args = parser.parse_args()
offsets = json.loads(args.offsets)
- with open(args.crashlog, 'r') as file:
+ with open(args.crashlog, "r") as file:
data = file.read()
p = CrashLogPatcher(data, args.binary, offsets, args.json)
@@ -75,5 +76,5 @@ if __name__ == '__main__':
if args.no_metadata:
p.remove_metadata()
- with open(args.crashlog, 'w') as file:
+ with open(args.crashlog, "w") as file:
file.write(p.data)
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/Inputs/sbaddress.py b/lldb/test/Shell/ScriptInterpreter/Python/Inputs/sbaddress.py
index 132d284..415900c 100644
--- a/lldb/test/Shell/ScriptInterpreter/Python/Inputs/sbaddress.py
+++ b/lldb/test/Shell/ScriptInterpreter/Python/Inputs/sbaddress.py
@@ -1,7 +1,9 @@
import lldb
+
def test(debugger, command, result, internal_dict):
return int(lldb.SBAddress())
+
def __lldb_init_module(debugger, internal_dict):
- debugger.HandleCommand('command script add -f sbaddress.test test')
+ debugger.HandleCommand("command script add -f sbaddress.test test")