1# Copyright (c) 2017 Linaro Limited.
2#
3# SPDX-License-Identifier: Apache-2.0
4
5'''Runner for debugging with xt-gdb.'''
6
7from os import path
8
9from runners.core import ZephyrBinaryRunner, RunnerCaps
10
11
12class XtensaBinaryRunner(ZephyrBinaryRunner):
13    '''Runner front-end for xt-gdb.'''
14
15    @classmethod
16    def name(cls):
17        return 'xtensa'
18
19    @classmethod
20    def capabilities(cls):
21        return RunnerCaps(commands={'debug'})
22
23    @classmethod
24    def do_add_parser(cls, parser):
25        parser.add_argument('--xcc-tools', required=True,
26                            help='path to XTensa tools')
27
28    @classmethod
29    def do_create(cls, cfg, args):
30        # Override any GDB with the one provided by the XTensa tools.
31        cfg.gdb = path.join(args.xcc_tools, 'bin', 'xt-gdb')
32        return XtensaBinaryRunner(cfg)
33
34    def do_run(self, command, **kwargs):
35        gdb_cmd = [self.cfg.gdb, self.cfg.elf_file]
36        self.require(gdb_cmd[0])
37        self.check_call(gdb_cmd)
38