1# Copyright (c) 2018 Open Source Foundries Limited.
2# Copyright 2019 Foundries.io
3# Copyright (c) 2020 Nordic Semiconductor ASA
4#
5# SPDX-License-Identifier: Apache-2.0
6
7'''west "debug", "debugserver", and "attach" commands.'''
8
9from textwrap import dedent
10
11from west.commands import WestCommand
12
13from run_common import add_parser_common, do_run_common
14
15
16class Debug(WestCommand):
17
18    def __init__(self):
19        super(Debug, self).__init__(
20            'debug',
21            # Keep this in sync with the string in west-commands.yml.
22            'flash and interactively debug a Zephyr application',
23            dedent('''
24            Connect to the board, flash the program, and start a
25            debugging session. Use "west attach" instead to attach
26            a debugger without reflashing.'''),
27            accepts_unknown_args=True)
28        self.runner_key = 'debug-runner'  # in runners.yaml
29
30    def do_add_parser(self, parser_adder):
31        return add_parser_common(self, parser_adder)
32
33    def do_run(self, my_args, runner_args):
34        do_run_common(self, my_args, runner_args)
35
36
37class DebugServer(WestCommand):
38
39    def __init__(self):
40        super(DebugServer, self).__init__(
41            'debugserver',
42            # Keep this in sync with the string in west-commands.yml.
43            'connect to board and launch a debug server',
44            dedent('''
45            Connect to the board and launch a debug server which accepts
46            incoming connections for debugging the connected board.
47
48            The debug server binds to a known port, and allows client software
49            started elsewhere to connect to it and debug the running
50            Zephyr image.'''),
51            accepts_unknown_args=True)
52        self.runner_key = 'debug-runner'  # in runners.yaml
53
54    def do_add_parser(self, parser_adder):
55        return add_parser_common(self, parser_adder)
56
57    def do_run(self, my_args, runner_args):
58        do_run_common(self, my_args, runner_args)
59
60
61class Attach(WestCommand):
62
63    def __init__(self):
64        super(Attach, self).__init__(
65            'attach',
66            # Keep this in sync with the string in west-commands.yml.
67            'interactively debug a board',
68            "Like \"west debug\", but doesn't reflash the program.",
69            accepts_unknown_args=True)
70        self.runner_key = 'debug-runner'  # in runners.yaml
71
72    def do_add_parser(self, parser_adder):
73        return add_parser_common(self, parser_adder)
74
75    def do_run(self, my_args, runner_args):
76        do_run_common(self, my_args, runner_args)
77