/* * Kernel Debugger Architecture Independent Console I/O handler * * 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-2006 Silicon Graphics, Inc. All Rights Reserved. * Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved. */ #include <linux/types.h> #include <linux/ctype.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/kdev_t.h> #include <linux/console.h> #include <linux/string.h> #include <linux/sched.h> #include <linux/smp.h> #include <linux/nmi.h> #include <linux/delay.h> #include <linux/kgdb.h> #include <linux/kdb.h> #include <linux/kallsyms.h> #include "kdb_private.h" #define CMD_BUFLEN … char kdb_prompt_str[CMD_BUFLEN]; int kdb_trap_printk; int kdb_printf_cpu = …; static int kgdb_transition_check(char *buffer) { … } /** * kdb_handle_escape() - validity check on an accumulated escape sequence. * @buf: Accumulated escape characters to be examined. Note that buf * is not a string, it is an array of characters and need not be * nil terminated. * @sz: Number of accumulated escape characters. * * Return: -1 if the escape sequence is unwanted, 0 if it is incomplete, * otherwise it returns a mapped key value to pass to the upper layers. */ static int kdb_handle_escape(char *buf, size_t sz) { … } /** * kdb_getchar() - Read a single character from a kdb console (or consoles). * * Other than polling the various consoles that are currently enabled, * most of the work done in this function is dealing with escape sequences. * * An escape key could be the start of a vt100 control sequence such as \e[D * (left arrow) or it could be a character in its own right. The standard * method for detecting the difference is to wait for 2 seconds to see if there * are any other characters. kdb is complicated by the lack of a timer service * (interrupts are off), by multiple input sources. Escape sequence processing * has to be done as states in the polling loop. * * Return: The key pressed or a control code derived from an escape sequence. */ char kdb_getchar(void) { … } /** * kdb_position_cursor() - Place cursor in the correct horizontal position * @prompt: Nil-terminated string containing the prompt string * @buffer: Nil-terminated string containing the entire command line * @cp: Cursor position, pointer the character in buffer where the cursor * should be positioned. * * The cursor is positioned by sending a carriage-return and then printing * the content of the line until we reach the correct cursor position. * * There is some additional fine detail here. * * Firstly, even though kdb_printf() will correctly format zero-width fields * we want the second call to kdb_printf() to be conditional. That keeps things * a little cleaner when LOGGING=1. * * Secondly, we can't combine everything into one call to kdb_printf() since * that renders into a fixed length buffer and the combined print could result * in unwanted truncation. */ static void kdb_position_cursor(char *prompt, char *buffer, char *cp) { … } /* * kdb_read * * This function reads a string of characters, terminated by * a newline, or by reaching the end of the supplied buffer, * from the current kernel debugger console device. * Parameters: * buffer - Address of character buffer to receive input characters. * bufsize - size, in bytes, of the character buffer * Returns: * Returns a pointer to the buffer containing the received * character string. This string will be terminated by a * newline character. * Locking: * No locks are required to be held upon entry to this * function. It is not reentrant - it relies on the fact * that while kdb is running on only one "master debug" cpu. * Remarks: * The buffer size must be >= 2. */ static char *kdb_read(char *buffer, size_t bufsize) { … } /* * kdb_getstr * * Print the prompt string and read a command from the * input device. * * Parameters: * buffer Address of buffer to receive command * bufsize Size of buffer in bytes * prompt Pointer to string to use as prompt string * Returns: * Pointer to command buffer. * Locking: * None. * Remarks: * For SMP kernels, the processor number will be * substituted for %d, %x or %o in the prompt. */ char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt) { … } /* * kdb_input_flush * * Get rid of any buffered console input. * * Parameters: * none * Returns: * nothing * Locking: * none * Remarks: * Call this function whenever you want to flush input. If there is any * outstanding input, it ignores all characters until there has been no * data for approximately 1ms. */ static void kdb_input_flush(void) { … } /* * kdb_printf * * Print a string to the output device(s). * * Parameters: * printf-like format and optional args. * Returns: * 0 * Locking: * None. * Remarks: * use 'kdbcons->write()' to avoid polluting 'log_buf' with * kdb output. * * If the user is doing a cmd args | grep srch * then kdb_grepping_flag is set. * In that case we need to accumulate full lines (ending in \n) before * searching for the pattern. */ static char kdb_buffer[256]; /* A bit too big to go on stack */ static char *next_avail = …; static int size_avail; static int suspend_grep; /* * search arg1 to see if it contains arg2 * (kdmain.c provides flags for ^pat and pat$) * * return 1 for found, 0 for not found */ static int kdb_search_string(char *searched, char *searchfor) { … } static void kdb_msg_write(const char *msg, int msg_len) { … } int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) { … } int kdb_printf(const char *fmt, ...) { … } EXPORT_SYMBOL_GPL(…);