You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/07/13 17:45:17 UTC

[incubator-nuttx] branch master updated: serial: add ctrl+@ to force crash system for debugging

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 136662f  serial: add ctrl+@ to force crash system for debugging
136662f is described below

commit 136662f5f9d94f277a2b4c1de606537804013297
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Apr 29 17:02:34 2021 +0800

    serial: add ctrl+@ to force crash system for debugging
    
    Change-Id: Iee65ac6c94ff298cfadf4429936b3744c16b8698
    Signed-off-by: ligd <li...@xiaomi.com>
---
 drivers/serial/Kconfig      | 15 +++++++++++++++
 drivers/serial/serial_dma.c | 33 +++++++++++++++++++++++----------
 drivers/serial/serial_io.c  | 12 ++++++++++++
 3 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 3611fa4..194ce76 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -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
diff --git a/drivers/serial/serial_dma.c b/drivers/serial/serial_dma.c
index ac4f460..b328c5d 100644
--- a/drivers/serial/serial_dma.c
+++ b/drivers/serial/serial_dma.c
@@ -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);
     }
diff --git a/drivers/serial/serial_io.c b/drivers/serial/serial_io.c
index 1781e2e..3add7e9 100644
--- a/drivers/serial/serial_io.c
+++ b/drivers/serial/serial_io.c
@@ -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