1#!/usr/bin/env python3
2#
3# Copyright (c) 2020 Intel Corporation
4#
5# SPDX-License-Identifier: Apache-2.0
6
7from gdbstubs.arch.x86 import GdbStub_x86
8from gdbstubs.arch.x86_64 import GdbStub_x86_64
9from gdbstubs.arch.arm_cortex_m import GdbStub_ARM_CortexM
10from gdbstubs.arch.risc_v import GdbStub_RISC_V
11from gdbstubs.arch.xtensa import GdbStub_Xtensa
12from gdbstubs.arch.arm64 import GdbStub_ARM64
13
14class TgtCode:
15    UNKNOWN = 0
16    X86 = 1
17    X86_64 = 2
18    ARM_CORTEX_M = 3
19    RISC_V = 4
20    XTENSA = 5
21    ARM64 = 6
22
23def get_gdbstub(logfile, elffile):
24    stub = None
25
26    tgt_code = logfile.log_hdr['tgt_code']
27
28    if tgt_code == TgtCode.X86:
29        stub = GdbStub_x86(logfile=logfile, elffile=elffile)
30    elif tgt_code == TgtCode.X86_64:
31        stub = GdbStub_x86_64(logfile=logfile, elffile=elffile)
32    elif tgt_code == TgtCode.ARM_CORTEX_M:
33        stub = GdbStub_ARM_CortexM(logfile=logfile, elffile=elffile)
34    elif tgt_code == TgtCode.RISC_V:
35        stub = GdbStub_RISC_V(logfile=logfile, elffile=elffile)
36    elif tgt_code == TgtCode.XTENSA:
37        stub = GdbStub_Xtensa(logfile=logfile, elffile=elffile)
38    elif tgt_code == TgtCode.ARM64:
39        stub = GdbStub_ARM64(logfile=logfile, elffile=elffile)
40
41    return stub
42