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 22, 2017
1 parent 75e1fa7 commit 5fa5af2
Show file tree
Hide file tree
Showing 103 changed files with 1,366 additions and 1,212 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
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 5fa5af2

Please sign in to comment.