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

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


The following commit(s) were added to refs/heads/master by this push:
     new 62aeaae8596 sched/assert: use LOG_EMERG to bypass setlogmask filter
62aeaae8596 is described below

commit 62aeaae85961779bd83b169ba982a380a8781159
Author: Bowen Wang <[email protected]>
AuthorDate: Mon May 18 21:09:49 2026 +0800

    sched/assert: use LOG_EMERG to bypass setlogmask filter
    
    The crash dump in sched/misc/assert.c is printed with _alert(), i.e. at
    LOG_ALERT. Once an application lowers the log mask with setlogmask(),
    for example to LOG_UPTO(LOG_EMERG) to silence the console, the whole
    assertion output disappears and the crash cannot be debugged.
    
    Add _emerg(), an unconditional LOG_EMERG counterpart of _alert(), and
    print the crash dump with it. LOG_EMERG is always let through by the
    log mask.
    
    The out-of-line _alert() used when the compiler has no variadic macros
    logged at LOG_EMERG instead of LOG_ALERT; log it at LOG_ALERT like the
    macro version, now that _emerg() covers LOG_EMERG.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 include/nuttx/debug.h      |  7 +++++++
 libs/libc/misc/lib_debug.c | 13 +++++++++++--
 sched/misc/assert.c        | 26 +++++++++++++-------------
 3 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/include/nuttx/debug.h b/include/nuttx/debug.h
index 3cb236db3f9..130a2857dba 100644
--- a/include/nuttx/debug.h
+++ b/include/nuttx/debug.h
@@ -119,6 +119,11 @@
 #  define __arch_syslog syslog
 #endif
 
+#ifdef CONFIG_CPP_HAVE_VARARGS
+#  define _emerg(format, ...) \
+   __arch_syslog(LOG_EMERG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__)
+#endif
+
 #if !defined(CONFIG_DEBUG_ALERT)
 #  define _alert      _none
 #elif defined(CONFIG_CPP_HAVE_VARARGS)
@@ -1470,6 +1475,8 @@ void lib_dumpvfile(int fd, FAR const char *msg, FAR const 
struct iovec *iov,
  */
 
 #ifndef CONFIG_CPP_HAVE_VARARGS
+void _emerg(FAR const char *format, ...) syslog_like(1, 2);
+
 #ifdef CONFIG_DEBUG_ALERT
 void _alert(FAR const char *format, ...) syslog_like(1, 2);
 #endif
diff --git a/libs/libc/misc/lib_debug.c b/libs/libc/misc/lib_debug.c
index 4fcbde4fd4e..27944612410 100644
--- a/libs/libc/misc/lib_debug.c
+++ b/libs/libc/misc/lib_debug.c
@@ -38,7 +38,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: _alert, _err, _warn, and _info
+ * Name: _emerg, _alert, _err, _warn, and _info
  *
  * Description:
  *  If the cross-compiler's pre-processor does not support variable
@@ -46,13 +46,22 @@
  *
  ****************************************************************************/
 
+void _emerg(FAR const char *format, ...)
+{
+  va_list ap;
+
+  va_start(ap, format);
+  vsyslog(LOG_EMERG, format, ap);
+  va_end(ap);
+}
+
 #ifdef CONFIG_DEBUG_ALERT
 void _alert(FAR const char *format, ...)
 {
   va_list ap;
 
   va_start(ap, format);
-  vsyslog(LOG_EMERG, format, ap);
+  vsyslog(LOG_ALERT, format, ap);
   va_end(ap);
 }
 #endif /* CONFIG_DEBUG_ALERT */
diff --git a/sched/misc/assert.c b/sched/misc/assert.c
index d6fc372d044..f81fa47f834 100644
--- a/sched/misc/assert.c
+++ b/sched/misc/assert.c
@@ -186,7 +186,7 @@ static int assert_tracecallback(FAR struct usbtrace_s 
*trace, FAR void *arg)
 
 static void sp_out_of_range(uintptr_t sp)
 {
-  _alert("ERROR: Stack pointer %" PRIxPTR " is not within the stack\n", sp);
+  _emerg("ERROR: Stack pointer %" PRIxPTR " is not within the stack\n", sp);
 }
 
 #ifdef CONFIG_SCHED_DUMP_STACK
@@ -202,7 +202,7 @@ static void stack_dump(uintptr_t sp, uintptr_t stack_top)
     {
       FAR uintptr_t *ptr = (FAR uintptr_t *)stack;
 
-      _alert("%p:"DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT
+      _emerg("%p:"DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT
              DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT DUMP_FORMAT "\n",
              (FAR void *)stack, DUMP_PTR(ptr, 0), DUMP_PTR(ptr , 1),
              DUMP_PTR(ptr, 2), DUMP_PTR(ptr, 3), DUMP_PTR(ptr, 4),
@@ -218,16 +218,16 @@ static void stack_dump(uintptr_t sp, uintptr_t stack_top)
 static void dump_stackinfo(FAR const char *tag, uintptr_t sp,
                            uintptr_t base, size_t size, size_t used)
 {
-  _alert("%s Stack:\n", tag);
-  _alert("  base: %p\n", (FAR void *)base);
-  _alert("  size: %08zu\n", size);
+  _emerg("%s Stack:\n", tag);
+  _emerg("  base: %p\n", (FAR void *)base);
+  _emerg("  size: %08zu\n", size);
 
 #ifdef CONFIG_SCHED_DUMP_STACK
   if (sp != 0)
     {
       uintptr_t top = base + size;
 
-      _alert("    sp: %p\n", (FAR void *)sp);
+      _emerg("    sp: %p\n", (FAR void *)sp);
 
       /* Get more information */
 
@@ -427,7 +427,7 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
 
   /* Dump interesting properties of this task */
 
-  _alert("   %4d %5d"
+  _emerg("   %4d %5d"
 #ifdef CONFIG_SMP
          "  %4d"
 #endif
@@ -513,7 +513,7 @@ static void dump_tasks(void)
 
   /* Dump interesting properties of each task in the crash environment */
 
-  _alert("   PID GROUP"
+  _emerg("   PID GROUP"
 #ifdef CONFIG_SMP
          "   CPU"
 #endif
@@ -546,7 +546,7 @@ static void dump_tasks(void)
         }
 #  endif
 
-      _alert("  ----   ---"
+      _emerg("  ----   ---"
 #  ifdef CONFIG_SMP
              "  %4d"
 #  endif
@@ -631,7 +631,7 @@ static void dump_lockholder(pid_t tid)
 
   backtrace_format(buf, sizeof(buf), stack, depth);
 
-  _alert("Deadlock(%d) holder(%d) backtrace: %s\n", tid, holder, buf);
+  _emerg("Deadlock(%d) holder(%d) backtrace: %s\n", tid, holder, buf);
 }
 
 /****************************************************************************
@@ -742,11 +742,11 @@ static void dump_assert_info(FAR struct tcb_s *rtcb,
     }
 
   uname(&name);
-  _alert("Current Version: %s %s %s %s %s\n",
+  _emerg("Current Version: %s %s %s %s %s\n",
          name.sysname, name.nodename,
          name.release, name.version, name.machine);
 
-  _alert("Assertion failed %s: at file: %s:%d task"
+  _emerg("Assertion failed %s: at file: %s:%d task"
 #ifdef CONFIG_SMP
          "(CPU%d)"
 #endif
@@ -793,7 +793,7 @@ static void dump_fatal_info(FAR struct tcb_s *rtcb,
           continue;
         }
 
-      _alert("Dump CPU%d: %s\n", cpu,
+      _emerg("Dump CPU%d: %s\n", cpu,
              g_cpu_paused[cpu] ? "PAUSED" : "RUNNING");
 
       if (g_cpu_paused[cpu])

Reply via email to