Skip to content

Commit

Permalink
Add custom assertion mechanism with backtrace printing
Browse files Browse the repository at this point in the history
This change will allow getting more complete reports from assertion
failures. This will smooth the the bug report process, as users won't
have to get a backtrace from a debugger. As part of this change,
assertions are now enabled in release builds of the compiler, as
discussed in #1553. They still are disabled in release builds of the
runtime.

In the future, this system could be extended with even more precise
information like line numbers. Parsing the debug information of the
executables and libraries will be required for this.

Closes #1553.
  • Loading branch information
Benoit Vey committed Feb 24, 2017
1 parent c714443 commit 510a2df
Show file tree
Hide file tree
Showing 104 changed files with 1,398 additions and 1,214 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ ifneq (,$(filter $(OSTYPE), osx freebsd))
endif

# target specific build options
libponyrt.buildoptions = -DPONY_NO_ASSERT

libponyc.buildoptions = -D__STDC_CONSTANT_MACROS
libponyc.buildoptions += -D__STDC_FORMAT_MACROS
libponyc.buildoptions += -D__STDC_LIMIT_MACROS
Expand All @@ -398,6 +400,8 @@ libgbenchmark.buildoptions := -DHAVE_POSIX_REGEX

ponyc.buildoptions = $(libponyc.buildoptions)

ponyc.linkoptions += -rdynamic

ifeq ($(OSTYPE), linux)
libponyrt-pic.buildoptions += -fpic
endif
Expand Down
10 changes: 10 additions & 0 deletions src/common/pony/detail/atomics.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ using std::atomic_compare_exchange_strong_explicit;
using std::atomic_fetch_add_explicit;
using std::atomic_fetch_sub_explicit;
using std::atomic_thread_fence;
using std::atomic_flag_test_and_set_explicit;

using std::atomic_flag;
# endif
#elif defined(__GNUC__) && !defined(__clang__)
# include <features.h>
Expand All @@ -46,6 +49,8 @@ using std::atomic_thread_fence;
# elif __GNUC_PREREQ(4, 7)
// Valid on x86 and ARM given our uses of atomics.
# define PONY_ATOMIC(T) T
# define atomic_flag bool
# define ATOMIC_FLAG_INIT false
# define PONY_ATOMIC_BUILTINS
# else
# error "Please use GCC >= 4.7"
Expand All @@ -59,6 +64,8 @@ using std::atomic_thread_fence;
# elif __clang_major__ >= 3 && __clang_minor__ >= 3
// Valid on x86 and ARM given our uses of atomics.
# define PONY_ATOMIC(T) T
# define atomic_flag bool
# define ATOMIC_FLAG_INIT false
# define PONY_ATOMIC_BUILTINS
# else
# error "Please use Clang >= 3.3"
Expand Down Expand Up @@ -205,6 +212,9 @@ namespace ponyint_atomics
# define atomic_thread_fence(MO) \
__atomic_thread_fence(MO)

# define atomic_flag_test_and_set_explicit(PTR, MO) \
__atomic_test_and_set(PTR, MO)

# undef PONY_ATOMIC_BUILTINS
# endif
#endif
Expand Down
21 changes: 21 additions & 0 deletions src/common/ponyassert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef PLATFORM_PONYASSERT_H
#define PLATFORM_PONYASSERT_H

#include "platform.h"

PONY_EXTERN_C_BEGIN

#if defined(NDEBUG) && defined(PONY_NO_ASSERT)
# define pony_assert(expr) ((void)0)
#else
# define pony_assert(expr) \
((expr) ? (void)0 : \
ponyint_assert_fail(#expr, __FILE__, __LINE__, __func__))
#endif

void ponyint_assert_fail(const char* expr, const char* file, size_t line,
const char* func);

PONY_EXTERN_C_END

#endif
Loading

0 comments on commit 510a2df

Please sign in to comment.