2008-04-17 22:05:37 +04:00
|
|
|
/*
|
|
|
|
* This provides the callbacks and functions that KGDB needs to share between
|
|
|
|
* the core, I/O and arch-specific portions.
|
|
|
|
*
|
|
|
|
* Author: Amit Kale <amitkale@linsyssoft.com> and
|
|
|
|
* Tom Rini <trini@kernel.crashing.org>
|
|
|
|
*
|
|
|
|
* 2001-2004 (c) Amit S. Kale and 2003-2005 (c) MontaVista Software, Inc.
|
|
|
|
* This file is licensed under the terms of the GNU General Public License
|
|
|
|
* version 2. This program is licensed "as is" without any warranty of any
|
|
|
|
* kind, whether express or implied.
|
|
|
|
*/
|
|
|
|
#ifndef _KGDB_H_
|
|
|
|
#define _KGDB_H_
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <linux/init.h>
|
2011-07-27 03:09:06 +04:00
|
|
|
#include <linux/atomic.h>
|
2020-09-28 00:15:29 +03:00
|
|
|
#include <linux/kprobes.h>
|
2010-05-21 06:04:21 +04:00
|
|
|
#ifdef CONFIG_HAVE_ARCH_KGDB
|
2008-04-17 22:05:37 +04:00
|
|
|
#include <asm/kgdb.h>
|
2010-05-21 06:04:21 +04:00
|
|
|
#endif
|
2008-04-17 22:05:37 +04:00
|
|
|
|
2010-05-21 06:04:21 +04:00
|
|
|
#ifdef CONFIG_KGDB
|
2008-04-17 22:05:37 +04:00
|
|
|
struct pt_regs;
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
|
|
|
* kgdb_skipexception - (optional) exit kgdb_handle_exception early
|
2008-04-17 22:05:37 +04:00
|
|
|
* @exception: Exception vector number
|
|
|
|
* @regs: Current &struct pt_regs.
|
|
|
|
*
|
2008-03-20 21:43:45 +03:00
|
|
|
* On some architectures it is required to skip a breakpoint
|
|
|
|
* exception when it occurs after a breakpoint has been removed.
|
2010-01-07 20:58:37 +03:00
|
|
|
* This can be implemented in the architecture specific portion of kgdb.
|
2008-04-17 22:05:37 +04:00
|
|
|
*/
|
|
|
|
extern int kgdb_skipexception(int exception, struct pt_regs *regs);
|
|
|
|
|
|
|
|
struct tasklet_struct;
|
|
|
|
struct task_struct;
|
|
|
|
struct uart_port;
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
|
|
|
* kgdb_breakpoint - compiled in breakpoint
|
|
|
|
*
|
2010-01-07 20:58:37 +03:00
|
|
|
* This will be implemented as a static inline per architecture. This
|
2008-03-20 21:43:45 +03:00
|
|
|
* function is called by the kgdb core to execute an architecture
|
|
|
|
* specific trap to cause kgdb to enter the exception processing.
|
|
|
|
*
|
|
|
|
*/
|
2008-04-17 22:05:37 +04:00
|
|
|
void kgdb_breakpoint(void);
|
|
|
|
|
|
|
|
extern int kgdb_connected;
|
2010-05-21 06:04:25 +04:00
|
|
|
extern int kgdb_io_module_registered;
|
2008-04-17 22:05:37 +04:00
|
|
|
|
|
|
|
extern atomic_t kgdb_setting_breakpoint;
|
|
|
|
extern atomic_t kgdb_cpu_doing_single_step;
|
|
|
|
|
|
|
|
extern struct task_struct *kgdb_usethread;
|
|
|
|
extern struct task_struct *kgdb_contthread;
|
|
|
|
|
|
|
|
enum kgdb_bptype {
|
|
|
|
BP_BREAKPOINT = 0,
|
|
|
|
BP_HARDWARE_BREAKPOINT,
|
|
|
|
BP_WRITE_WATCHPOINT,
|
|
|
|
BP_READ_WATCHPOINT,
|
2012-03-23 18:35:05 +04:00
|
|
|
BP_ACCESS_WATCHPOINT,
|
|
|
|
BP_POKE_BREAKPOINT,
|
2008-04-17 22:05:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum kgdb_bpstate {
|
|
|
|
BP_UNDEFINED = 0,
|
|
|
|
BP_REMOVED,
|
|
|
|
BP_SET,
|
|
|
|
BP_ACTIVE
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kgdb_bkpt {
|
|
|
|
unsigned long bpt_addr;
|
|
|
|
unsigned char saved_instr[BREAK_INSTR_SIZE];
|
|
|
|
enum kgdb_bptype type;
|
|
|
|
enum kgdb_bpstate state;
|
|
|
|
};
|
|
|
|
|
2010-08-05 18:22:20 +04:00
|
|
|
struct dbg_reg_def_t {
|
|
|
|
char *name;
|
|
|
|
int size;
|
|
|
|
int offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef DBG_MAX_REG_NUM
|
|
|
|
#define DBG_MAX_REG_NUM 0
|
|
|
|
#else
|
|
|
|
extern struct dbg_reg_def_t dbg_reg_def[];
|
|
|
|
extern char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs);
|
|
|
|
extern int dbg_set_reg(int regno, void *mem, struct pt_regs *regs);
|
|
|
|
#endif
|
2008-04-17 22:05:37 +04:00
|
|
|
#ifndef KGDB_MAX_BREAKPOINTS
|
|
|
|
# define KGDB_MAX_BREAKPOINTS 1000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define KGDB_HW_BREAKPOINT 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions each KGDB-supporting architecture must provide:
|
|
|
|
*/
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
2021-05-29 14:03:03 +03:00
|
|
|
* kgdb_arch_init - Perform any architecture specific initialization.
|
2008-04-17 22:05:37 +04:00
|
|
|
*
|
2021-05-29 14:03:03 +03:00
|
|
|
* This function will handle the initialization of any architecture
|
2008-04-17 22:05:37 +04:00
|
|
|
* specific callbacks.
|
|
|
|
*/
|
|
|
|
extern int kgdb_arch_init(void);
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
2008-04-17 22:05:37 +04:00
|
|
|
* kgdb_arch_exit - Perform any architecture specific uninitalization.
|
|
|
|
*
|
|
|
|
* This function will handle the uninitalization of any architecture
|
|
|
|
* specific callbacks, for dynamic registration and unregistration.
|
|
|
|
*/
|
|
|
|
extern void kgdb_arch_exit(void);
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
2008-04-17 22:05:37 +04:00
|
|
|
* pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs
|
|
|
|
* @gdb_regs: A pointer to hold the registers in the order GDB wants.
|
|
|
|
* @regs: The &struct pt_regs of the current process.
|
|
|
|
*
|
|
|
|
* Convert the pt_regs in @regs into the format for registers that
|
|
|
|
* GDB expects, stored in @gdb_regs.
|
|
|
|
*/
|
|
|
|
extern void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs);
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
2008-04-17 22:05:37 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
extern void
|
|
|
|
sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p);
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
2008-04-17 22:05:37 +04:00
|
|
|
* gdb_regs_to_pt_regs - Convert GDB regs to ptrace regs.
|
|
|
|
* @gdb_regs: A pointer to hold the registers we've received from GDB.
|
|
|
|
* @regs: A pointer to a &struct pt_regs to hold these values in.
|
|
|
|
*
|
|
|
|
* Convert the GDB regs in @gdb_regs into the pt_regs, and store them
|
|
|
|
* in @regs.
|
|
|
|
*/
|
|
|
|
extern void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs);
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
2008-04-17 22:05:37 +04:00
|
|
|
* kgdb_arch_handle_exception - Handle architecture specific GDB packets.
|
|
|
|
* @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.
|
|
|
|
* @remcom_in_buffer: The buffer of the packet we have read.
|
|
|
|
* @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
extern int
|
|
|
|
kgdb_arch_handle_exception(int vector, int signo, int err_code,
|
|
|
|
char *remcom_in_buffer,
|
|
|
|
char *remcom_out_buffer,
|
|
|
|
struct pt_regs *regs);
|
|
|
|
|
2020-06-23 08:36:42 +03:00
|
|
|
/**
|
|
|
|
* kgdb_arch_handle_qxfer_pkt - Handle architecture specific GDB XML
|
|
|
|
* packets.
|
|
|
|
* @remcom_in_buffer: The buffer of the packet we have read.
|
|
|
|
* @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern void
|
|
|
|
kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer,
|
|
|
|
char *remcom_out_buffer);
|
|
|
|
|
2018-12-05 06:38:26 +03:00
|
|
|
/**
|
|
|
|
* kgdb_call_nmi_hook - Call kgdb_nmicallback() on the current CPU
|
|
|
|
* @ignored: This parameter is only here to match the prototype.
|
|
|
|
*
|
|
|
|
* If you're using the default implementation of kgdb_roundup_cpus()
|
|
|
|
* this function will be called per CPU. If you don't implement
|
|
|
|
* kgdb_call_nmi_hook() a default will be used.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern void kgdb_call_nmi_hook(void *ignored);
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
2008-04-17 22:05:37 +04:00
|
|
|
* kgdb_roundup_cpus - Get other CPUs into a holding pattern
|
|
|
|
*
|
|
|
|
* On SMP systems, we need to get the attention of the other CPUs
|
2010-01-07 20:58:37 +03:00
|
|
|
* and get them into a known state. This should do what is needed
|
2008-04-17 22:05:37 +04:00
|
|
|
* to get the other CPUs to call kgdb_wait(). Note that on some arches,
|
2018-12-05 06:38:26 +03:00
|
|
|
* the NMI approach is not used for rounding up all the CPUs. Normally
|
|
|
|
* those architectures can just not implement this and get the default.
|
2008-04-17 22:05:37 +04:00
|
|
|
*
|
|
|
|
* On non-SMP systems, this is not called.
|
|
|
|
*/
|
2018-12-05 06:38:25 +03:00
|
|
|
extern void kgdb_roundup_cpus(void);
|
2008-04-17 22:05:37 +04:00
|
|
|
|
2010-05-21 06:04:24 +04:00
|
|
|
/**
|
|
|
|
* kgdb_arch_set_pc - Generic call back to the program counter
|
|
|
|
* @regs: Current &struct pt_regs.
|
|
|
|
* @pc: The new value for the program counter
|
|
|
|
*
|
|
|
|
* This function handles updating the program counter and requires an
|
|
|
|
* architecture specific implementation.
|
|
|
|
*/
|
|
|
|
extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc);
|
|
|
|
|
|
|
|
|
2008-04-17 22:05:37 +04:00
|
|
|
/* Optional functions. */
|
|
|
|
extern int kgdb_validate_break_address(unsigned long addr);
|
2012-03-21 19:17:03 +04:00
|
|
|
extern int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt);
|
|
|
|
extern int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt);
|
2008-04-17 22:05:37 +04:00
|
|
|
|
2010-05-21 06:04:29 +04:00
|
|
|
/**
|
2021-05-29 14:03:03 +03:00
|
|
|
* kgdb_arch_late - Perform any architecture specific initialization.
|
2010-05-21 06:04:29 +04:00
|
|
|
*
|
2021-05-29 14:03:03 +03:00
|
|
|
* This function will handle the late initialization of any
|
2010-05-21 06:04:29 +04:00
|
|
|
* architecture specific callbacks. This is an optional function for
|
|
|
|
* handling things like late initialization of hw breakpoints. The
|
|
|
|
* default implementation does nothing.
|
|
|
|
*/
|
|
|
|
extern void kgdb_arch_late(void);
|
|
|
|
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
2008-04-17 22:05:37 +04:00
|
|
|
* struct kgdb_arch - Describe architecture specific values.
|
|
|
|
* @gdb_bpt_instr: The instruction to trigger a breakpoint.
|
|
|
|
* @flags: Flags for the breakpoint, currently just %KGDB_HW_BREAKPOINT.
|
|
|
|
* @set_breakpoint: Allow an architecture to specify how to set a software
|
|
|
|
* breakpoint.
|
|
|
|
* @remove_breakpoint: Allow an architecture to specify how to remove a
|
|
|
|
* software breakpoint.
|
|
|
|
* @set_hw_breakpoint: Allow an architecture to specify how to set a hardware
|
|
|
|
* breakpoint.
|
|
|
|
* @remove_hw_breakpoint: Allow an architecture to specify how to remove a
|
|
|
|
* hardware breakpoint.
|
2010-08-18 15:02:00 +04:00
|
|
|
* @disable_hw_break: Allow an architecture to specify how to disable
|
|
|
|
* hardware breakpoints for a single cpu.
|
2008-04-17 22:05:37 +04:00
|
|
|
* @remove_all_hw_break: Allow an architecture to specify how to remove all
|
|
|
|
* hardware breakpoints.
|
|
|
|
* @correct_hw_break: Allow an architecture to specify how to correct the
|
|
|
|
* hardware debug registers.
|
2012-09-25 01:27:50 +04:00
|
|
|
* @enable_nmi: Manage NMI-triggered entry to KGDB
|
2008-04-17 22:05:37 +04:00
|
|
|
*/
|
|
|
|
struct kgdb_arch {
|
|
|
|
unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
int (*set_breakpoint)(unsigned long, char *);
|
|
|
|
int (*remove_breakpoint)(unsigned long, char *);
|
|
|
|
int (*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
|
|
|
|
int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
|
2010-08-18 15:02:00 +04:00
|
|
|
void (*disable_hw_break)(struct pt_regs *regs);
|
2008-04-17 22:05:37 +04:00
|
|
|
void (*remove_all_hw_break)(void);
|
|
|
|
void (*correct_hw_break)(void);
|
2012-09-25 01:27:50 +04:00
|
|
|
|
|
|
|
void (*enable_nmi)(bool on);
|
2008-04-17 22:05:37 +04:00
|
|
|
};
|
|
|
|
|
2008-03-20 21:43:45 +03:00
|
|
|
/**
|
2008-04-17 22:05:37 +04:00
|
|
|
* struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
|
|
|
|
* @name: Name of the I/O driver.
|
|
|
|
* @read_char: Pointer to a function that will return one char.
|
|
|
|
* @write_char: Pointer to a function that will write one char.
|
|
|
|
* @flush: Pointer to a function that will flush any pending writes.
|
|
|
|
* @init: Pointer to a function that will initialize the device.
|
kgdboc: Add kgdboc_earlycon to support early kgdb using boot consoles
We want to enable kgdb to debug the early parts of the kernel.
Unfortunately kgdb normally is a client of the tty API in the kernel
and serial drivers don't register to the tty layer until fairly late
in the boot process.
Serial drivers do, however, commonly register a boot console. Let's
enable the kgdboc driver to work with boot consoles to provide early
debugging.
This change co-opts the existing read() function pointer that's part
of "struct console". It's assumed that if a boot console (with the
flag CON_BOOT) has implemented read() that both the read() and write()
function are polling functions. That means they work without
interrupts and read() will return immediately (with 0 bytes read) if
there's nothing to read. This should be a safe assumption since it
appears that no current boot consoles implement read() right now and
there seems no reason to do so unless they wanted to support
"kgdboc_earlycon".
The normal/expected way to make all this work is to use
"kgdboc_earlycon" and "kgdboc" together. You should point them both
to the same physical serial connection. At boot time, as the system
transitions from the boot console to the normal console (and registers
a tty), kgdb will switch over.
One awkward part of all this, though, is that there can be a window
where the boot console goes away and we can't quite transtion over to
the main kgdboc that uses the tty layer. There are two main problems:
1. The act of registering the tty doesn't cause any call into kgdboc
so there is a window of time when the tty is there but kgdboc's
init code hasn't been called so we can't transition to it.
2. On some serial drivers the normal console inits (and replaces the
boot console) quite early in the system. Presumably these drivers
were coded up before earlycon worked as well as it does today and
probably they don't need to do this anymore, but it causes us
problems nontheless.
Problem #1 is not too big of a deal somewhat due to the luck of probe
ordering. kgdboc is last in the tty/serial/Makefile so its probe gets
right after all other tty devices. It's not fun to rely on this, but
it does work for the most part.
Problem #2 is a big deal, but only for some serial drivers. Other
serial drivers end up registering the console (which gets rid of the
boot console) and tty at nearly the same time.
The way we'll deal with the window when the system has stopped using
the boot console and the time when we're setup using the tty is to
keep using the boot console. This may sound surprising, but it has
been found to work well in practice. If it doesn't work, it shouldn't
be too hard for a given serial driver to make it keep working.
Specifically, it's expected that the read()/write() function provided
in the boot console should be the same (or nearly the same) as the
normal kgdb polling functions. That means continuing to use them
should work just fine. To make things even more likely to work work
we'll also trap the recently added exit() function in the boot console
we're using and delay any calls to it until we're all done with the
boot console.
NOTE: there could be ways to use all this in weird / unexpected ways.
If you do something like this, it's a bit of a buyer beware situation.
Specifically:
- If you specify only "kgdboc_earlycon" but not "kgdboc" then
(depending on your serial driver) things will probably work OK, but
you'll get a warning printed the first time you use kgdb after the
boot console is gone. You'd only be able to do this, of course, if
the serial driver you're running atop provided an early boot console.
- If your "kgdboc_earlycon" and "kgdboc" devices are not the same
device things should work OK, but it'll be your job to switch over
which device you're monitoring (including figuring out how to switch
over gdb in-flight if you're using it).
When trying to enable "kgdboc_earlycon" it should be noted that the
names that are registered through the boot console layer and the tty
layer are not the same for the same port. For example when debugging
on one board I'd need to pass "kgdboc_earlycon=qcom_geni
kgdboc=ttyMSM0" to enable things properly. Since digging up the boot
console name is a pain and there will rarely be more than one boot
console enabled, you can provide the "kgdboc_earlycon" parameter
without specifying the name of the boot console. In this case we'll
just pick the first boot that implements read() that we find.
This new "kgdboc_earlycon" parameter should be contrasted to the
existing "ekgdboc" parameter. While both provide a way to debug very
early, the usage and mechanisms are quite different. Specifically
"kgdboc_earlycon" is meant to be used in tandem with "kgdboc" and
there is a transition from one to the other. The "ekgdboc" parameter,
on the other hand, replaces the "kgdboc" parameter. It runs the same
logic as the "kgdboc" parameter but just relies on your TTY driver
being present super early. The only known usage of the old "ekgdboc"
parameter is documented as "ekgdboc=kbd earlyprintk=vga". It should
be noted that "kbd" has special treatment allowing it to init early as
a tty device.
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Sumit Garg <sumit.garg@linaro.org>
Link: https://lore.kernel.org/r/20200507130644.v4.8.I8fba5961bf452ab92350654aa61957f23ecf0100@changeid
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
2020-05-07 23:08:46 +03:00
|
|
|
* @deinit: Pointer to a function that will deinit the device. Implies that
|
|
|
|
* this I/O driver is temporary and expects to be replaced. Called when
|
|
|
|
* an I/O driver is replaced or explicitly unregistered.
|
2008-04-17 22:05:37 +04:00
|
|
|
* @pre_exception: Pointer to a function that will do any prep work for
|
|
|
|
* the I/O driver.
|
|
|
|
* @post_exception: Pointer to a function that will do any cleanup work
|
|
|
|
* for the I/O driver.
|
2020-06-04 13:01:19 +03:00
|
|
|
* @cons: valid if the I/O device is a console; else NULL.
|
2008-04-17 22:05:37 +04:00
|
|
|
*/
|
|
|
|
struct kgdb_io {
|
|
|
|
const char *name;
|
|
|
|
int (*read_char) (void);
|
|
|
|
void (*write_char) (u8);
|
|
|
|
void (*flush) (void);
|
|
|
|
int (*init) (void);
|
kgdboc: Add kgdboc_earlycon to support early kgdb using boot consoles
We want to enable kgdb to debug the early parts of the kernel.
Unfortunately kgdb normally is a client of the tty API in the kernel
and serial drivers don't register to the tty layer until fairly late
in the boot process.
Serial drivers do, however, commonly register a boot console. Let's
enable the kgdboc driver to work with boot consoles to provide early
debugging.
This change co-opts the existing read() function pointer that's part
of "struct console". It's assumed that if a boot console (with the
flag CON_BOOT) has implemented read() that both the read() and write()
function are polling functions. That means they work without
interrupts and read() will return immediately (with 0 bytes read) if
there's nothing to read. This should be a safe assumption since it
appears that no current boot consoles implement read() right now and
there seems no reason to do so unless they wanted to support
"kgdboc_earlycon".
The normal/expected way to make all this work is to use
"kgdboc_earlycon" and "kgdboc" together. You should point them both
to the same physical serial connection. At boot time, as the system
transitions from the boot console to the normal console (and registers
a tty), kgdb will switch over.
One awkward part of all this, though, is that there can be a window
where the boot console goes away and we can't quite transtion over to
the main kgdboc that uses the tty layer. There are two main problems:
1. The act of registering the tty doesn't cause any call into kgdboc
so there is a window of time when the tty is there but kgdboc's
init code hasn't been called so we can't transition to it.
2. On some serial drivers the normal console inits (and replaces the
boot console) quite early in the system. Presumably these drivers
were coded up before earlycon worked as well as it does today and
probably they don't need to do this anymore, but it causes us
problems nontheless.
Problem #1 is not too big of a deal somewhat due to the luck of probe
ordering. kgdboc is last in the tty/serial/Makefile so its probe gets
right after all other tty devices. It's not fun to rely on this, but
it does work for the most part.
Problem #2 is a big deal, but only for some serial drivers. Other
serial drivers end up registering the console (which gets rid of the
boot console) and tty at nearly the same time.
The way we'll deal with the window when the system has stopped using
the boot console and the time when we're setup using the tty is to
keep using the boot console. This may sound surprising, but it has
been found to work well in practice. If it doesn't work, it shouldn't
be too hard for a given serial driver to make it keep working.
Specifically, it's expected that the read()/write() function provided
in the boot console should be the same (or nearly the same) as the
normal kgdb polling functions. That means continuing to use them
should work just fine. To make things even more likely to work work
we'll also trap the recently added exit() function in the boot console
we're using and delay any calls to it until we're all done with the
boot console.
NOTE: there could be ways to use all this in weird / unexpected ways.
If you do something like this, it's a bit of a buyer beware situation.
Specifically:
- If you specify only "kgdboc_earlycon" but not "kgdboc" then
(depending on your serial driver) things will probably work OK, but
you'll get a warning printed the first time you use kgdb after the
boot console is gone. You'd only be able to do this, of course, if
the serial driver you're running atop provided an early boot console.
- If your "kgdboc_earlycon" and "kgdboc" devices are not the same
device things should work OK, but it'll be your job to switch over
which device you're monitoring (including figuring out how to switch
over gdb in-flight if you're using it).
When trying to enable "kgdboc_earlycon" it should be noted that the
names that are registered through the boot console layer and the tty
layer are not the same for the same port. For example when debugging
on one board I'd need to pass "kgdboc_earlycon=qcom_geni
kgdboc=ttyMSM0" to enable things properly. Since digging up the boot
console name is a pain and there will rarely be more than one boot
console enabled, you can provide the "kgdboc_earlycon" parameter
without specifying the name of the boot console. In this case we'll
just pick the first boot that implements read() that we find.
This new "kgdboc_earlycon" parameter should be contrasted to the
existing "ekgdboc" parameter. While both provide a way to debug very
early, the usage and mechanisms are quite different. Specifically
"kgdboc_earlycon" is meant to be used in tandem with "kgdboc" and
there is a transition from one to the other. The "ekgdboc" parameter,
on the other hand, replaces the "kgdboc" parameter. It runs the same
logic as the "kgdboc" parameter but just relies on your TTY driver
being present super early. The only known usage of the old "ekgdboc"
parameter is documented as "ekgdboc=kbd earlyprintk=vga". It should
be noted that "kbd" has special treatment allowing it to init early as
a tty device.
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Sumit Garg <sumit.garg@linaro.org>
Link: https://lore.kernel.org/r/20200507130644.v4.8.I8fba5961bf452ab92350654aa61957f23ecf0100@changeid
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
2020-05-07 23:08:46 +03:00
|
|
|
void (*deinit) (void);
|
2008-04-17 22:05:37 +04:00
|
|
|
void (*pre_exception) (void);
|
|
|
|
void (*post_exception) (void);
|
2020-06-04 13:01:19 +03:00
|
|
|
struct console *cons;
|
2008-04-17 22:05:37 +04:00
|
|
|
};
|
|
|
|
|
2018-12-06 23:07:40 +03:00
|
|
|
extern const struct kgdb_arch arch_kgdb_ops;
|
2008-04-17 22:05:37 +04:00
|
|
|
|
2014-10-14 05:00:25 +04:00
|
|
|
extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs);
|
2008-04-25 01:57:23 +04:00
|
|
|
|
tty/serial: Add kgdb_nmi driver
This special driver makes it possible to temporary use NMI debugger port
as a normal console by issuing 'nmi_console' command (assuming that the
port is attached to KGDB).
Unlike KDB's disable_nmi command, with this driver you are always able
to go back to the debugger using KGDB escape sequence ($3#33). This is
because this console driver processes the input in NMI context, and thus
is able to intercept the magic sequence.
Note that since the console interprets input and uses polling
communication methods, for things like PPP it is still better to fully
detach debugger port from the KGDB NMI (i.e. disable_nmi), and use raw
console.
Usually, to enter the debugger one have to type the magic sequence, so
initially the kernel will print the following prompt on the NMI debugger
console:
Type $3#33 to enter the debugger>
For convenience, there is a kgdb_fiq.knock kernel command line option,
when set to 0, this turns the special command to just a return key
press, so the kernel will be printing this:
Hit <return> to enter the debugger>
This is more convenient for long debugging sessions, although it makes
nmi_console feature somewhat useless.
And for the cases when NMI connected to a dedicated button, the knocking
can be disabled altogether by setting kgdb_fiq.knock to -1.
Suggested-by: Colin Cross <ccross@android.com>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Acked-by: Alan Cox <alan@linux.intel.com>
Acked-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-09-25 01:27:56 +04:00
|
|
|
#ifdef CONFIG_SERIAL_KGDB_NMI
|
|
|
|
extern int kgdb_register_nmi_console(void);
|
|
|
|
extern int kgdb_unregister_nmi_console(void);
|
|
|
|
extern bool kgdb_nmi_poll_knock(void);
|
|
|
|
#else
|
|
|
|
static inline int kgdb_register_nmi_console(void) { return 0; }
|
|
|
|
static inline int kgdb_unregister_nmi_console(void) { return 0; }
|
2020-05-07 14:06:49 +03:00
|
|
|
static inline bool kgdb_nmi_poll_knock(void) { return true; }
|
tty/serial: Add kgdb_nmi driver
This special driver makes it possible to temporary use NMI debugger port
as a normal console by issuing 'nmi_console' command (assuming that the
port is attached to KGDB).
Unlike KDB's disable_nmi command, with this driver you are always able
to go back to the debugger using KGDB escape sequence ($3#33). This is
because this console driver processes the input in NMI context, and thus
is able to intercept the magic sequence.
Note that since the console interprets input and uses polling
communication methods, for things like PPP it is still better to fully
detach debugger port from the KGDB NMI (i.e. disable_nmi), and use raw
console.
Usually, to enter the debugger one have to type the magic sequence, so
initially the kernel will print the following prompt on the NMI debugger
console:
Type $3#33 to enter the debugger>
For convenience, there is a kgdb_fiq.knock kernel command line option,
when set to 0, this turns the special command to just a return key
press, so the kernel will be printing this:
Hit <return> to enter the debugger>
This is more convenient for long debugging sessions, although it makes
nmi_console feature somewhat useless.
And for the cases when NMI connected to a dedicated button, the knocking
can be disabled altogether by setting kgdb_fiq.knock to -1.
Suggested-by: Colin Cross <ccross@android.com>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Acked-by: Alan Cox <alan@linux.intel.com>
Acked-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-09-25 01:27:56 +04:00
|
|
|
#endif
|
|
|
|
|
2008-04-17 22:05:37 +04:00
|
|
|
extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
|
|
|
|
extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
|
2010-04-02 20:48:03 +04:00
|
|
|
extern struct kgdb_io *dbg_io_ops;
|
2008-04-17 22:05:37 +04:00
|
|
|
|
2008-04-25 01:57:23 +04:00
|
|
|
extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
|
2010-08-05 18:22:21 +04:00
|
|
|
extern char *kgdb_mem2hex(char *mem, char *buf, int count);
|
2008-04-17 22:05:37 +04:00
|
|
|
extern int kgdb_hex2mem(char *buf, char *mem, int count);
|
|
|
|
|
|
|
|
extern int kgdb_isremovedbreak(unsigned long addr);
|
2020-06-23 08:37:25 +03:00
|
|
|
extern int kgdb_has_hit_break(unsigned long addr);
|
2008-04-17 22:05:37 +04:00
|
|
|
|
|
|
|
extern int
|
|
|
|
kgdb_handle_exception(int ex_vector, int signo, int err_code,
|
|
|
|
struct pt_regs *regs);
|
|
|
|
extern int kgdb_nmicallback(int cpu, void *regs);
|
2014-01-14 20:25:52 +04:00
|
|
|
extern int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code,
|
|
|
|
atomic_t *snd_rdy);
|
2011-03-18 19:54:31 +03:00
|
|
|
extern void gdbstub_exit(int status);
|
2008-04-17 22:05:37 +04:00
|
|
|
|
2020-09-28 00:15:29 +03:00
|
|
|
/*
|
|
|
|
* kgdb and kprobes both use the same (kprobe) blocklist (which makes sense
|
|
|
|
* given they are both typically hooked up to the same trap meaning on most
|
|
|
|
* architectures one cannot be used to debug the other)
|
|
|
|
*
|
|
|
|
* However on architectures where kprobes is not (yet) implemented we permit
|
|
|
|
* breakpoints everywhere rather than blocking everything by default.
|
|
|
|
*/
|
|
|
|
static inline bool kgdb_within_blocklist(unsigned long addr)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_KGDB_HONOUR_BLOCKLIST
|
|
|
|
return within_kprobe_blacklist(addr);
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-04-17 22:05:37 +04:00
|
|
|
extern int kgdb_single_step;
|
|
|
|
extern atomic_t kgdb_active;
|
2010-05-21 06:04:21 +04:00
|
|
|
#define in_dbg_master() \
|
2020-05-06 19:42:23 +03:00
|
|
|
(irqs_disabled() && (smp_processor_id() == atomic_read(&kgdb_active)))
|
2010-05-21 06:04:29 +04:00
|
|
|
extern bool dbg_is_early;
|
|
|
|
extern void __init dbg_late_init(void);
|
2019-09-26 02:47:45 +03:00
|
|
|
extern void kgdb_panic(const char *msg);
|
2021-02-26 04:22:38 +03:00
|
|
|
extern void kgdb_free_init_mem(void);
|
2010-05-21 06:04:21 +04:00
|
|
|
#else /* ! CONFIG_KGDB */
|
|
|
|
#define in_dbg_master() (0)
|
2010-05-21 06:04:29 +04:00
|
|
|
#define dbg_late_init()
|
2019-09-26 02:47:45 +03:00
|
|
|
static inline void kgdb_panic(const char *msg) {}
|
2021-02-26 04:22:38 +03:00
|
|
|
static inline void kgdb_free_init_mem(void) { }
|
2010-05-21 06:04:21 +04:00
|
|
|
#endif /* ! CONFIG_KGDB */
|
2008-04-17 22:05:37 +04:00
|
|
|
#endif /* _KGDB_H_ */
|