serial: add ctrl+@ to force crash system for debugging

Change-Id: Iee65ac6c94ff298cfadf4429936b3744c16b8698
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2021-04-29 17:02:34 +08:00 committed by Alan Carvalho de Assis
parent c1250dcbd1
commit 136662f5f9
3 changed files with 50 additions and 10 deletions

View File

@ -173,6 +173,21 @@ config SERIAL_TERMIOS
If this is not defined, then the terminal settings (baud, parity, etc).
are not configurable at runtime; serial streams cannot be flushed, etc..
config TTY_FORCE_PANIC
bool "Enable TTY force crash"
default n
depends on DEBUG_FEATURES
---help---
This is for debugging system busyloop or deadlock, when the shell can't run,
then use this force crash the system to see the dumplog.
config TTY_FORCE_PANIC_CHAR
hex "TTY force crash characters"
default 0x0
depends on TTY_FORCE_PANIC
---help---
Use Ctrl-@ NULL(0x0) inputs to determine whether panic system
config TTY_SIGINT
bool "Support SIGINT"
default n

View File

@ -24,6 +24,7 @@
#include <nuttx/config.h>
#include <assert.h>
#include <sys/types.h>
#include <stdint.h>
#include <debug.h>
@ -55,22 +56,31 @@
*
****************************************************************************/
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
static int uart_check_signo(const char *buf, size_t size)
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC)
static int uart_check_signo(int pid, const char *buf, size_t size)
{
size_t i;
for (i = 0; i < size; i++)
{
#ifdef CONFIG_TTY_FORCE_PANIC
if (buf[i] == CONFIG_TTY_FORCE_PANIC_CHAR)
{
PANIC();
return 0;
}
#endif
#ifdef CONFIG_TTY_SIGINT
if (buf[i] == CONFIG_TTY_SIGINT_CHAR)
if (pid > 0 && buf[i] == CONFIG_TTY_SIGINT_CHAR)
{
return SIGINT;
}
#endif
#ifdef CONFIG_TTY_SIGTSTP
if (buf[i] == CONFIG_TTY_SIGTSTP_CHAR)
if (pid > 0 && buf[i] == CONFIG_TTY_SIGTSTP_CHAR)
{
return SIGTSTP;
}
@ -94,7 +104,8 @@ static int uart_check_signo(const char *buf, size_t size)
****************************************************************************/
#if defined(CONFIG_SERIAL_RXDMA) && \
(defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP))
(defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC))
static int uart_recvchars_signo(FAR uart_dev_t *dev)
{
FAR struct uart_dmaxfer_s *xfer = &dev->dmarx;
@ -104,19 +115,20 @@ static int uart_recvchars_signo(FAR uart_dev_t *dev)
if (xfer->nbytes <= xfer->length)
{
return uart_check_signo(xfer->buffer, xfer->nbytes);
return uart_check_signo(dev->pid, xfer->buffer, xfer->nbytes);
}
else
{
/* REVISIT: Additional signals could be in the second region. */
signo = uart_check_signo(xfer->buffer, xfer->length);
signo = uart_check_signo(dev->pid, xfer->buffer, xfer->length);
if (signo != 0)
{
return signo;
}
return uart_check_signo(xfer->nbuffer, xfer->nbytes - xfer->length);
return uart_check_signo(dev->pid, xfer->nbuffer,
xfer->nbytes - xfer->length);
}
}
#endif
@ -356,14 +368,15 @@ void uart_recvchars_done(FAR uart_dev_t *dev)
FAR struct uart_dmaxfer_s *xfer = &dev->dmarx;
FAR struct uart_buffer_s *rxbuf = &dev->recv;
size_t nbytes = xfer->nbytes;
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP) || \
defined(CONFIG_TTY_FORCE_PANIC)
int signo = 0;
/* Check if the SIGINT character is anywhere in the newly received DMA
* buffer.
*/
if (dev->pid >= 0 && (dev->tc_lflag & ISIG))
if ((dev->tc_lflag & ISIG))
{
signo = uart_recvchars_signo(dev);
}

View File

@ -28,6 +28,7 @@
# include <nuttx/irq.h>
#endif
#include <assert.h>
#include <sys/types.h>
#include <stdint.h>
#include <debug.h>
@ -240,6 +241,17 @@ void uart_recvchars(FAR uart_dev_t *dev)
}
else
#endif
#ifdef CONFIG_TTY_FORCE_PANIC
/* Is this the special character that will generate the SIGTSTP
* signal?
*/
if ((dev->tc_lflag & ISIG) && ch == CONFIG_TTY_FORCE_PANIC_CHAR)
{
PANIC();
}
else
#endif
/* If the RX buffer becomes full, then the serial data is discarded.
* This is necessary because on most serial hardware, you must read