1# DExTer : Debugging Experience Tester
2# ~~~~~~   ~         ~~         ~   ~~
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7"""List debuggers tool."""
8
9from dex.debugger.Debuggers import add_debugger_tool_base_arguments
10from dex.debugger.Debuggers import handle_debugger_tool_base_options
11from dex.debugger.Debuggers import Debuggers
12from dex.tools import ToolBase
13from dex.utils import Timer
14from dex.utils.Exceptions import DebuggerException, Error
15from dex.utils.ReturnCode import ReturnCode
16
17
18class Tool(ToolBase):
19    """List all of the potential debuggers that DExTer knows about and whether
20    there is currently a valid interface available for them.
21    """
22
23    @property
24    def name(self):
25        return 'DExTer list debuggers'
26
27    def add_tool_arguments(self, parser, defaults):
28        parser.description = Tool.__doc__
29        add_debugger_tool_base_arguments(parser, defaults)
30
31    def handle_options(self, defaults):
32        handle_debugger_tool_base_options(self.context, defaults)
33
34    def go(self) -> ReturnCode:
35        with Timer('list debuggers'):
36            try:
37                Debuggers(self.context).list()
38            except DebuggerException as e:
39                raise Error(e)
40        return ReturnCode.OK
41