-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbase_command.py
More file actions
64 lines (48 loc) · 1.71 KB
/
base_command.py
File metadata and controls
64 lines (48 loc) · 1.71 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
"""Base command definition."""
from abc import ABC, abstractmethod
from typing import Any, Union
from lldb import SBCommandReturnObject, SBDebugger, SBExecutionContext
from commands.base_container import BaseContainer
class BaseCommand(ABC):
"""An abstract base class for all commands."""
alias_set: dict[Any, Any] = {}
@abstractmethod
def __init__(self) -> None:
pass
@property
@abstractmethod
def container(self) -> Union[type[BaseContainer], None]:
"""Container property."""
@property
@abstractmethod
def program(self) -> str:
"""Program property."""
@abstractmethod
def __call__(
self,
debugger: SBDebugger,
command: str,
exe_ctx: SBExecutionContext,
result: SBCommandReturnObject,
) -> None:
pass
@staticmethod
@abstractmethod
def get_short_help() -> str:
"""Get short help string."""
@staticmethod
@abstractmethod
def get_long_help() -> str:
"""Get long help string."""
@classmethod
def lldb_self_register(cls, debugger: SBDebugger, module_name: str) -> None:
"""Automatically register a subcommand."""
if cls.container is not None:
command = f"command script add -c {module_name}.{cls.__name__} {cls.container.container_verb} {cls.program}"
else:
command = f"command script add -c {module_name}.{cls.__name__} {cls.program}"
debugger.HandleCommand(command)
# If alias_set exists, then load it into LLDB.
for alias, arguments in cls.alias_set.items():
alias_command = f"command alias {alias} {cls.program} {arguments}"
debugger.HandleCommand(alias_command)