forked from TelegramMessenger/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlldb_common.py
More file actions
46 lines (34 loc) · 1.3 KB
/
Copy pathlldb_common.py
File metadata and controls
46 lines (34 loc) · 1.3 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
"""Common utilities for LLDB scripts in the VSCode/Cursor debugging workflow."""
import json
import os
import pathlib
import sys
from typing import Any
import lldb
# These files are generated by the lldb_launch_and_debug.sh script.
LAUNCH_INFO_PATH = pathlib.Path(".bsp/skbsp_generated/lldb.json")
BAZEL_INFO_PATH = pathlib.Path(".bsp/skbsp_generated/bazel_info.json")
def _load_file(path: pathlib.Path) -> str:
if not path.exists():
print(f"File not found: {path}. Exiting.", file=sys.stderr, flush=True)
lldb.SBDebugger.Terminate()
os._exit(0)
return path.read_text()
def load_launch_info() -> dict[str, Any]:
return json.loads(_load_file(LAUNCH_INFO_PATH))
def load_bazel_info() -> dict[str, Any]:
return json.loads(_load_file(BAZEL_INFO_PATH))
def run_command(command: str) -> None:
print(f"(lldb) {command}", flush=True)
result = lldb.SBCommandReturnObject()
lldb.debugger.GetCommandInterpreter().HandleCommand(command, result)
if result.Succeeded():
output = result.GetOutput()
if output:
print(output, flush=True)
else:
output = result.GetError()
if output:
print(output, file=sys.stderr, flush=True)
msg = "Command failed. See above for any error messages."
raise RuntimeError(msg)