Merge branch 'feature/silent_assertions' into 'master'
Add "silent" assertion option See merge request !984
This commit is contained in:
commit
399ec29a68
37
Kconfig
37
Kconfig
|
@ -47,14 +47,39 @@ config OPTIMIZATION_LEVEL_RELEASE
|
||||||
bool "Release (-Os)"
|
bool "Release (-Os)"
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config OPTIMIZATION_ASSERTIONS
|
choice OPTIMIZATION_ASSERTION_LEVEL
|
||||||
prompt "Enable assertions"
|
prompt "Assertion level"
|
||||||
bool
|
default OPTIMIZATION_ASSERTIONS_ENABLED
|
||||||
default y
|
|
||||||
help
|
help
|
||||||
Enable assertions.
|
Assertions can be:
|
||||||
|
- Enabled. Failure will print verbose assertion details. This is the default.
|
||||||
|
|
||||||
If disabled, -DNDEBUG is added to CFLAGS.
|
- Set to "silent" to save code size (failed assertions will abort() but user
|
||||||
|
needs to use the aborting address to find the line number with the failed assertion.)
|
||||||
|
|
||||||
|
- Disabled entirely (not recommended for most configurations.) -DNDEBUG is added
|
||||||
|
to CPPFLAGS in this case.
|
||||||
|
|
||||||
|
config OPTIMIZATION_ASSERTIONS_ENABLED
|
||||||
|
prompt "Enabled"
|
||||||
|
bool
|
||||||
|
help
|
||||||
|
Enable assertions. Assertion content and line number will be printed on failure.
|
||||||
|
|
||||||
|
config OPTIMIZATION_ASSERTIONS_SILENT
|
||||||
|
prompt "Silent (saves code size)"
|
||||||
|
bool
|
||||||
|
help
|
||||||
|
Enable silent assertions. Failed assertions will abort(), user needs to
|
||||||
|
use the aborting address to find the line number with the failed assertion.
|
||||||
|
|
||||||
|
config OPTIMIZATION_ASSERTIONS_DISABLED
|
||||||
|
prompt "Disabled (sets -DNDEBUG)"
|
||||||
|
bool
|
||||||
|
help
|
||||||
|
If assertions are disabled, -DNDEBUG is added to CPPFLAGS.
|
||||||
|
|
||||||
|
endchoice # assertions
|
||||||
|
|
||||||
endmenu # Optimization level
|
endmenu # Optimization level
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,4 @@ COMPONENT_ADD_LDFLAGS := $(LIBC_PATH) $(LIBM_PATH) -lnewlib
|
||||||
|
|
||||||
COMPONENT_ADD_LINKER_DEPS := $(LIBC_PATH) $(LIBM_PATH)
|
COMPONENT_ADD_LINKER_DEPS := $(LIBC_PATH) $(LIBM_PATH)
|
||||||
|
|
||||||
COMPONENT_ADD_INCLUDEDIRS := include platform_include
|
COMPONENT_ADD_INCLUDEDIRS := platform_include include
|
||||||
|
|
28
components/newlib/platform_include/assert.h
Normal file
28
components/newlib/platform_include/assert.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed 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.
|
||||||
|
|
||||||
|
|
||||||
|
/* This header file wraps newlib's own unmodified assert.h and adds
|
||||||
|
support for silent assertion failure.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <sdkconfig.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include_next <assert.h>
|
||||||
|
|
||||||
|
#if defined(CONFIG_OPTIMIZATION_ASSERTIONS_SILENT) && !defined(NDEBUG)
|
||||||
|
#undef assert
|
||||||
|
#define assert(__e) ((__e) ? (void)0 : abort())
|
||||||
|
#endif
|
|
@ -239,7 +239,7 @@ else
|
||||||
OPTIMIZATION_FLAGS = -Og
|
OPTIMIZATION_FLAGS = -Og
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ("$(CONFIG_OPTIMIZATION_ASSERTIONS)", "")
|
ifeq ("$(CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED)", "y")
|
||||||
CPPFLAGS += -DNDEBUG
|
CPPFLAGS += -DNDEBUG
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue