Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/sys: Add DEBUG_PANIC() macro #1471

Merged
merged 2 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions kernel/os/include/os/mynewt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
#include "sysflash/sysflash.h"
#include "os/os.h"
#include "defs/error.h"
#include "sys/debug_panic.h"

#endif
8 changes: 7 additions & 1 deletion kernel/os/include/os/os_fault.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions kernel/os/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions libc/baselibc/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#ifndef _ASSERT_H
#define _ASSERT_H

#include "syscfg/syscfg.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -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

Expand Down
5 changes: 2 additions & 3 deletions libc/baselibc/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions sys/sys/include/sys/debug_panic.h
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions sys/sys/syscfg.yml
Original file line number Diff line number Diff line change
@@ -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