You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2018/10/23 17:48:31 UTC
[mynewt-core] 01/02: kernel/os: Create `OS_CRASH()` macro
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 07843426952df45530c5dd95b47454b5707b2d86
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Oct 19 10:32:39 2018 -0700
kernel/os: Create `OS_CRASH()` macro
This macro just expands to a call to `__assert_func()`. Unlike the
`assert()` macro, defining `NDEBUG` does not disable this macro.
This macro can be used to trigger an unconditional crash.
---
kernel/os/include/os/os_fault.h | 8 +++++++-
kernel/os/syscfg.yml | 5 +++++
libc/baselibc/include/assert.h | 15 ++-------------
libc/baselibc/syscfg.yml | 5 ++---
4 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/kernel/os/include/os/os_fault.h b/kernel/os/include/os/os_fault.h
index 60f5faa..63b1309 100644
--- a/kernel/os/include/os/os_fault.h
+++ b/kernel/os/include/os/os_fault.h
@@ -24,9 +24,15 @@
extern "C" {
#endif
-void __assert_func(const char *, int, const char *, const char *)
+void __assert_func(const char *file, int line, const char *func, const char *e)
__attribute((noreturn));
+#if MYNEWT_VAL(OS_CRASH_FILE_LINE)
+#define OS_CRASH() __assert_func(__FILE__, __LINE__, NULL, NULL)
+#else
+#define OS_CRASH() __assert_func(NULL, 0, NULL, NULL)
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/kernel/os/syscfg.yml b/kernel/os/syscfg.yml
index 45c4664..108dfec 100644
--- a/kernel/os/syscfg.yml
+++ b/kernel/os/syscfg.yml
@@ -135,6 +135,11 @@ syscfg.defs:
description: >
Enables debug runtime checks for time-related functionality.
value: 0
+ OS_CRASH_FILE_LINE:
+ description: >
+ Include filename and line number in crash messages. Aids in
+ debugging, but increases text size.
+ value: 0
syscfg.vals.OS_DEBUG_MODE:
OS_CRASH_STACKTRACE: 1
diff --git a/libc/baselibc/include/assert.h b/libc/baselibc/include/assert.h
index 8a131b5..147f452 100644
--- a/libc/baselibc/include/assert.h
+++ b/libc/baselibc/include/assert.h
@@ -5,8 +5,6 @@
#ifndef _ASSERT_H
#define _ASSERT_H
-#include "syscfg/syscfg.h"
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -23,18 +21,9 @@ extern "C" {
#else
#include <stddef.h>
+#include "os/mynewt.h"
-extern void __assert_func(const char *, int, const char *, const char *)
- __attribute((noreturn));
-
-#if MYNEWT_VAL(BASELIBC_ASSERT_FILE_LINE)
-#define assert(x) ((x) ? (void)0 : \
- __assert_func(__FILE__, __LINE__, NULL, NULL))
-#else
-#define assert(x) ((x) ? (void)0 : \
- __assert_func(NULL, 0, NULL, NULL))
-#endif
-
+#define assert(x) ((x) ? (void)0 : OS_CRASH())
#endif
diff --git a/libc/baselibc/syscfg.yml b/libc/baselibc/syscfg.yml
index 0912490..7f6dc3c 100644
--- a/libc/baselibc/syscfg.yml
+++ b/libc/baselibc/syscfg.yml
@@ -23,7 +23,6 @@ syscfg.defs:
value: 1
BASELIBC_ASSERT_FILE_LINE:
- description: >
- Include filename and line number in assert messages. Aids in
- debugging, but increases text size.
+ defunct: 1
+ description: 'Use OS_CRASH_FILE_LINE instead'
value: 0