#!/usr/bin/env python3 # # Copyright (c) 2020 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 import binascii import logging import struct from gdbstubs.gdbstub import GdbStub logger = logging.getLogger("gdbstub") class RegNum(): # Matches the enum i386_regnum in GDB EAX = 0 ECX = 1 EDX = 2 EBX = 3 ESP = 4 EBP = 5 ESI = 6 EDI = 7 EIP = 8 EFLAGS = 9 CS = 10 SS = 11 DS = 12 ES = 13 FS = 14 GS = 15 class ExceptionVectors(): # Matches arch/x86/include/kernel_arch_data.h IV_DIVIDE_ERROR = 0 IV_DEBUG = 1 IV_NON_MASKABLE_INTERRUPT = 2 IV_BREAKPOINT = 3 IV_OVERFLOW = 4 IV_BOUND_RANGE = 5 IV_INVALID_OPCODE = 6 IV_DEVICE_NOT_AVAILABLE = 7 IV_DOUBLE_FAULT = 8 IV_COPROC_SEGMENT_OVERRUN = 9 IV_INVALID_TSS = 10 IV_SEGMENT_NOT_PRESENT = 11 IV_STACK_FAULT = 12 IV_GENERAL_PROTECTION = 13 IV_PAGE_FAULT = 14 IV_RESERVED = 15 IV_X87_FPU_FP_ERROR = 16 IV_ALIGNMENT_CHECK = 17 IV_MACHINE_CHECK = 18 IV_SIMD_FP = 19 IV_VIRT_EXCEPTION = 20 IV_SECURITY_EXCEPTION = 30 class GdbStub_x86(GdbStub): ARCH_DATA_BLK_STRUCT = " unknown value # Send in "xxxxxxxx" pkt += b'x' * 8 idx += 1 self.put_gdb_packet(pkt) def handle_register_single_read_packet(self, pkt): # Mark registers as "". # 'p' packets are usually used for registers # other than the general ones (e.g. eax, ebx) # so we can safely reply "xxxxxxxx" here. self.put_gdb_packet(b'x' * 8)