linux/arch/x86/kernel/kgdb.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 */

/*
 * Copyright (C) 2004 Amit S. Kale <[email protected]>
 * Copyright (C) 2000-2001 VERITAS Software Corporation.
 * Copyright (C) 2002 Andi Kleen, SuSE Labs
 * Copyright (C) 2004 LinSysSoft Technologies Pvt. Ltd.
 * Copyright (C) 2007 MontaVista Software, Inc.
 * Copyright (C) 2007-2008 Jason Wessel, Wind River Systems, Inc.
 */
/****************************************************************************
 *  Contributor:     Lake Stevens Instrument Division$
 *  Written by:      Glenn Engel $
 *  Updated by:	     Amit Kale<[email protected]>
 *  Updated by:	     Tom Rini <[email protected]>
 *  Updated by:	     Jason Wessel <[email protected]>
 *  Modified for 386 by Jim Kingdon, Cygnus Support.
 *  Original kgdb, compatibility with 2.1.xx kernel by
 *  David Grothe <[email protected]>
 *  Integrated into 2.2.5 kernel by Tigran Aivazian <[email protected]>
 *  X86_64 changes from Andi Kleen's patch merged by Jim Houston
 */
#include <linux/spinlock.h>
#include <linux/kdebug.h>
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/ptrace.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/kgdb.h>
#include <linux/smp.h>
#include <linux/nmi.h>
#include <linux/hw_breakpoint.h>
#include <linux/uaccess.h>
#include <linux/memory.h>

#include <asm/text-patching.h>
#include <asm/debugreg.h>
#include <asm/apicdef.h>
#include <asm/apic.h>
#include <asm/nmi.h>
#include <asm/switch_to.h>

struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] =;

int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
{}

char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
{}

/**
 *	sleeping_thread_to_gdb_regs - Convert ptrace regs to GDB regs
 *	@gdb_regs: A pointer to hold the registers in the order GDB wants.
 *	@p: The &struct task_struct of the desired process.
 *
 *	Convert the register values of the sleeping process in @p to
 *	the format that GDB expects.
 *	This function is called when kgdb does not have access to the
 *	&struct pt_regs and therefore it should fill the gdb registers
 *	@gdb_regs with what has	been saved in &struct thread_struct
 *	thread field during switch_to.
 */
void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
{}

static struct hw_breakpoint {} breakinfo[HBP_NUM];

static unsigned long early_dr7;

static void kgdb_correct_hw_break(void)
{}

static int hw_break_reserve_slot(int breakno)
{}

static int hw_break_release_slot(int breakno)
{}

static int
kgdb_remove_hw_break(unsigned long addr, int len, enum kgdb_bptype bptype)
{}

static void kgdb_remove_all_hw_break(void)
{}

static int
kgdb_set_hw_break(unsigned long addr, int len, enum kgdb_bptype bptype)
{}

/**
 *	kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
 *	@regs: Current &struct pt_regs.
 *
 *	This function will be called if the particular architecture must
 *	disable hardware debugging while it is processing gdb packets or
 *	handling exception.
 */
static void kgdb_disable_hw_debug(struct pt_regs *regs)
{}

#ifdef CONFIG_SMP
/**
 *	kgdb_roundup_cpus - Get other CPUs into a holding pattern
 *
 *	On SMP systems, we need to get the attention of the other CPUs
 *	and get them be in a known state.  This should do what is needed
 *	to get the other CPUs to call kgdb_wait(). Note that on some arches,
 *	the NMI approach is not used for rounding up all the CPUs. For example,
 *	in case of MIPS, smp_call_function() is used to roundup CPUs.
 *
 *	On non-SMP systems, this is not called.
 */
void kgdb_roundup_cpus(void)
{}
#endif

/**
 *	kgdb_arch_handle_exception - Handle architecture specific GDB packets.
 *	@e_vector: The error vector of the exception that happened.
 *	@signo: The signal number of the exception that happened.
 *	@err_code: The error code of the exception that happened.
 *	@remcomInBuffer: The buffer of the packet we have read.
 *	@remcomOutBuffer: The buffer of %BUFMAX bytes to write a packet into.
 *	@linux_regs: The &struct pt_regs of the current process.
 *
 *	This function MUST handle the 'c' and 's' command packets,
 *	as well packets to set / remove a hardware breakpoint, if used.
 *	If there are additional packets which the hardware needs to handle,
 *	they are handled here.  The code should return -1 if it wants to
 *	process more packets, and a %0 or %1 if it wants to exit from the
 *	kgdb callback.
 */
int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
			       char *remcomInBuffer, char *remcomOutBuffer,
			       struct pt_regs *linux_regs)
{}

static inline int
single_step_cont(struct pt_regs *regs, struct die_args *args)
{}

static DECLARE_BITMAP(was_in_debug_nmi, NR_CPUS);

static int kgdb_nmi_handler(unsigned int cmd, struct pt_regs *regs)
{}

static int __kgdb_notify(struct die_args *args, unsigned long cmd)
{}

int kgdb_ll_trap(int cmd, const char *str,
		 struct pt_regs *regs, long err, int trap, int sig)
{}

static int
kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
{}

static struct notifier_block kgdb_notifier =;

/**
 *	kgdb_arch_init - Perform any architecture specific initialization.
 *
 *	This function will handle the initialization of any architecture
 *	specific callbacks.
 */
int kgdb_arch_init(void)
{}

static void kgdb_hw_overflow_handler(struct perf_event *event,
		struct perf_sample_data *data, struct pt_regs *regs)
{}

void kgdb_arch_late(void)
{}

/**
 *	kgdb_arch_exit - Perform any architecture specific uninitalization.
 *
 *	This function will handle the uninitalization of any architecture
 *	specific callbacks, for dynamic registration and unregistration.
 */
void kgdb_arch_exit(void)
{}

/**
 *	kgdb_skipexception - Bail out of KGDB when we've been triggered.
 *	@exception: Exception vector number
 *	@regs: Current &struct pt_regs.
 *
 *	On some architectures we need to skip a breakpoint exception when
 *	it occurs after a breakpoint has been removed.
 *
 * Skip an int3 exception when it occurs after a breakpoint has been
 * removed. Backtrack eip by 1 since the int3 would have caused it to
 * increment by 1.
 */
int kgdb_skipexception(int exception, struct pt_regs *regs)
{}

unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
{}

void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
{}

int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
{}

int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
{}

const struct kgdb_arch arch_kgdb_ops =;