Skip to content

Commit

Permalink
kdb: core for kgdb back end (1 of 2)
Browse files Browse the repository at this point in the history
This patch contains only the kdb core.  Because the change set was
large, it was split.  The next patch in the series includes the
instrumentation into the core kernel which are mainly helper functions
for kdb.

This work is directly derived from kdb v4.4 found at:

ftp://oss.sgi.com/projects/kdb/download/v4.4/

The kdb internals have been re-organized to make them mostly platform
independent and to connect everything to the debug core which is used by
gdbstub (which has long been known as kgdb).

The original version of kdb was 58,000 lines worth of changes to
support x86.  From that implementation only the kdb shell, and basic
commands for memory access, runcontrol, lsmod, and dmesg where carried
forward.

This is a generic implementation which aims to cover all the current
architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and
blackfin.  More archictectures can be added by implementing the
architecture specific kgdb functions.

[[email protected]: Compile fix with hugepages enabled]
[[email protected]: Clean breakpoint code renaming kdba_ -> kdb_]
[[email protected]: fix new line after printing registers]
[[email protected]: Remove the concept of global vs. local breakpoints]
[[email protected]: Rework kdb_si_swapinfo to use more generic name]
[[email protected]: fix the information dump macros, remove 'arch' from the names]
[[email protected]: include fixup to include linux/slab.h]

CC: [email protected]
Signed-off-by: Jason Wessel <[email protected]>
Signed-off-by: Martin Hicks <[email protected]>
  • Loading branch information
jwessel committed May 21, 2010
1 parent e886112 commit 5d5314d
Show file tree
Hide file tree
Showing 12 changed files with 5,967 additions and 0 deletions.
113 changes: 113 additions & 0 deletions include/linux/kdb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#ifndef _KDB_H
#define _KDB_H

/*
* Kernel Debugger Architecture Independent Global Headers
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
* Copyright (c) 2000-2007 Silicon Graphics, Inc. All Rights Reserved.
* Copyright (C) 2000 Stephane Eranian <[email protected]>
* Copyright (C) 2009 Jason Wessel <[email protected]>
*/

#ifdef CONFIG_KGDB_KDB
#include <linux/init.h>
#include <linux/sched.h>
#include <asm/atomic.h>

#define KDB_POLL_FUNC_MAX 5

/*
* kdb_initial_cpu is initialized to -1, and is set to the cpu
* number whenever the kernel debugger is entered.
*/
extern int kdb_initial_cpu;
extern atomic_t kdb_event;

/*
* kdb_diemsg
*
* Contains a pointer to the last string supplied to the
* kernel 'die' panic function.
*/
extern const char *kdb_diemsg;

#define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */
#define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */
#define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */
#define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */
#define KDB_FLAG_ONLY_DO_DUMP (1 << 4) /* Only do a dump, used when
* kdb is off */
#define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
* kdb is disabled */
#define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do
* not use keyboard */
#define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
* not use keyboard */

extern int kdb_flags; /* Global flags, see kdb_state for per cpu state */

extern void kdb_save_flags(void);
extern void kdb_restore_flags(void);

#define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag)
#define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag))
#define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag))

/*
* External entry point for the kernel debugger. The pt_regs
* at the time of entry are supplied along with the reason for
* entry to the kernel debugger.
*/

typedef enum {
KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */
KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */
KDB_REASON_DEBUG, /* Debug Fault - regs valid */
KDB_REASON_OOPS, /* Kernel Oops - regs valid */
KDB_REASON_SWITCH, /* CPU switch - regs valid*/
KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */
KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */
KDB_REASON_RECURSE, /* Recursive entry to kdb;
* regs probably valid */
KDB_REASON_SSTEP, /* Single Step trap. - regs valid */
} kdb_reason_t;

extern int kdb_printf(const char *, ...)
__attribute__ ((format (printf, 1, 2)));
typedef int (*kdb_printf_t)(const char *, ...)
__attribute__ ((format (printf, 1, 2)));

extern void kdb_init(int level);

/* Access to kdb specific polling devices */
typedef int (*get_char_func)(void);
extern get_char_func kdb_poll_funcs[];
extern int kdb_get_kbd_char(void);

static inline
int kdb_process_cpu(const struct task_struct *p)
{
unsigned int cpu = task_thread_info(p)->cpu;
if (cpu > num_possible_cpus())
cpu = 0;
return cpu;
}

/* kdb access to register set for stack dumping */
extern struct pt_regs *kdb_current_regs;

#else /* ! CONFIG_KGDB_KDB */
#define kdb_printf(...)
#define kdb_init(x)
#endif /* CONFIG_KGDB_KDB */
enum {
KDB_NOT_INITIALIZED,
KDB_INIT_EARLY,
KDB_INIT_FULL,
};
#endif /* !_KDB_H */
1 change: 1 addition & 0 deletions kernel/debug/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#

obj-$(CONFIG_KGDB) += debug_core.o gdbstub.o
obj-$(CONFIG_KGDB_KDB) += kdb/
1 change: 1 addition & 0 deletions kernel/debug/kdb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gen-kdb_cmds.c
24 changes: 24 additions & 0 deletions kernel/debug/kdb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
# for more details.
#
# Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved.
# Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved.
#

CCVERSION := $(shell $(CC) -v 2>&1 | sed -ne '$$p')
obj-y := kdb_io.o kdb_main.o kdb_support.o kdb_bt.o gen-kdb_cmds.o kdb_bp.o kdb_debugger.o

clean-files := gen-kdb_cmds.c

quiet_cmd_gen-kdb = GENKDB $@
cmd_gen-kdb = $(AWK) 'BEGIN {print "\#include <linux/stddef.h>"; print "\#include <linux/init.h>"} \
/^\#/{next} \
/^[ \t]*$$/{next} \
{gsub(/"/, "\\\"", $$0); \
print "static __initdata char kdb_cmd" cmds++ "[] = \"" $$0 "\\n\";"} \
END {print "extern char *kdb_cmds[]; char __initdata *kdb_cmds[] = {"; for (i = 0; i < cmds; ++i) {print " kdb_cmd" i ","}; print(" NULL\n};");}' \
$(filter-out %/Makefile,$^) > $@#

$(obj)/gen-kdb_cmds.c: $(src)/kdb_cmds $(src)/Makefile
$(call cmd,gen-kdb)
Loading

0 comments on commit 5d5314d

Please sign in to comment.