You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/10/23 17:48:26 UTC

[GitHub] ccollins476ad closed pull request #1471: sys/sys: Add `DEBUG_PANIC()` macro

ccollins476ad closed pull request #1471: sys/sys: Add `DEBUG_PANIC()` macro
URL: https://github.com/apache/mynewt-core/pull/1471
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/kernel/os/include/os/mynewt.h b/kernel/os/include/os/mynewt.h
index 3f6943e176..ca544eebd4 100644
--- a/kernel/os/include/os/mynewt.h
+++ b/kernel/os/include/os/mynewt.h
@@ -25,5 +25,6 @@
 #include "sysflash/sysflash.h"
 #include "os/os.h"
 #include "defs/error.h"
+#include "sys/debug_panic.h"
 
 #endif
diff --git a/kernel/os/include/os/os_fault.h b/kernel/os/include/os/os_fault.h
index 60f5faa7f5..63b13097d9 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 45c466407c..108dfec665 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 8a131b5b86..147f452503 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 09124902c8..7f6dc3cbbf 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
diff --git a/sys/sys/include/sys/debug_panic.h b/sys/sys/include/sys/debug_panic.h
new file mode 100644
index 0000000000..1c3ef70ab7
--- /dev/null
+++ b/sys/sys/include/sys/debug_panic.h
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_DEBUG_PANIC_
+#define H_DEBUG_PANIC_
+
+#include "os/mynewt.h"
+
+#if MYNEWT_VAL(DEBUG_PANIC_ENABLED)
+#define DEBUG_PANIC() OS_CRASH()
+#else
+#define DEBUG_PANIC()
+#endif
+
+#endif
diff --git a/sys/sys/syscfg.yml b/sys/sys/syscfg.yml
new file mode 100644
index 0000000000..f910e31e11
--- /dev/null
+++ b/sys/sys/syscfg.yml
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+syscfg.defs:
+    DEBUG_PANIC_ENABLED:
+        description: >
+            If enabled, the `DEBUG_PANIC()` macro to trigger a crash.  When
+            disabled, `DEBUG_PANIC()` has no effect.
+        value: 1


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services