From d9e0f2936ddf97e545913101331f3bf1b83317e3 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Thu, 18 Sep 2014 17:08:32 +0400 Subject: [PATCH] Adding jerry_unreachable and jerry_unimplemented routines that print file name and line for corresponding unreachable, unimplemented marks. --- src/globals.h | 10 ++--- src/libruntime/target/linux/jerry-assert.c | 39 +++++++++++++++++++- src/libruntime/target/linux/jerry-libc.c | 11 +++++- src/libruntime/target/stm32f4/jerry-assert.c | 28 +++++++++++++- 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/src/globals.h b/src/globals.h index 11d009730..1bdea3a40 100644 --- a/src/globals.h +++ b/src/globals.h @@ -98,6 +98,8 @@ typedef enum extern uint32_t jerry_unreferenced_expression; extern void __noreturn jerry_assert_fail (const char *assertion, const char *file, const uint32_t line); +extern void __noreturn jerry_unreachable (const char *comment, const char *file, const uint32_t line); +extern void __noreturn jerry_unimplemented (const char *comment, const char *file, const uint32_t line); #ifndef JERRY_NDEBUG #define JERRY_ASSERT(x) do { if (__builtin_expect (!(x), 0)) { jerry_assert_fail (#x, __FILE__, __LINE__); } } while (0) @@ -112,21 +114,19 @@ extern void jerry_ref_unused_variables (int unused_variables_follow, ...); #define JERRY_UNREACHABLE() \ do \ { \ - JERRY_ASSERT (false); \ - jerry_exit (ERR_FAILED_INTERNAL_ASSERTION); \ + jerry_unreachable (NULL, __FILE__, __LINE__); \ } while (0) #define JERRY_UNIMPLEMENTED() \ do \ { \ - JERRY_ASSERT (false); \ - jerry_exit (ERR_UNIMPLEMENTED_CASE); \ + jerry_unimplemented (NULL, __FILE__, __LINE__); \ } while (0) #define JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(...) \ do \ { \ - JERRY_UNIMPLEMENTED (); \ + jerry_unimplemented (NULL, __FILE__, __LINE__); \ if (false) \ { \ jerry_ref_unused_variables (0, __VA_ARGS__); \ diff --git a/src/libruntime/target/linux/jerry-assert.c b/src/libruntime/target/linux/jerry-assert.c index d2d82055e..a0822394d 100644 --- a/src/libruntime/target/linux/jerry-assert.c +++ b/src/libruntime/target/linux/jerry-assert.c @@ -24,9 +24,46 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */ const char *file, /**< file name */ const uint32_t line) /** line */ { - __printf ("Assertion '%s' failed at %s:%u\n", + __printf ("Assertion '%s' failed at %s:%u.\n", assertion, file, line); __exit (-ERR_FAILED_INTERNAL_ASSERTION); } /* jerry_assert_fail */ +/** + * Handle execution of control path that should be unreachable + */ +void __noreturn +jerry_unreachable (const char *comment, /**< comment to unreachable mark if exists, + NULL - otherwise */ + const char *file, /**< file name */ + const uint32_t line) /**< line */ +{ + __printf ("Unreachable control path at %s:%u was executed", file, line); + if (comment != NULL) + { + __printf ("(%s)", comment); + } + __printf (".\n"); + + __exit (-ERR_FAILED_INTERNAL_ASSERTION); +} /* jerry_unreachable */ + +/** + * Handle unimplemented case execution + */ +void __noreturn +jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if exists, + NULL - otherwise */ + const char *file, /**< file name */ + const uint32_t line) /**< line */ +{ + __printf ("Unimplemented case at %s:%u was executed", file, line); + if (comment != NULL) + { + __printf ("(%s)", comment); + } + __printf (".\n"); + + __exit (-ERR_UNIMPLEMENTED_CASE); +} /* jerry_unimplemented */ diff --git a/src/libruntime/target/linux/jerry-libc.c b/src/libruntime/target/linux/jerry-libc.c index a4c6a832a..743023e0f 100644 --- a/src/libruntime/target/linux/jerry-libc.c +++ b/src/libruntime/target/linux/jerry-libc.c @@ -385,11 +385,18 @@ __putchar (int c) return putchar (c); } /* __putchar */ -/** exit - cause normal process termination */ +/** + * Exit - cause normal process termination with specified status code + */ void __noreturn -__exit (int status) +__exit (int status) /**< status code */ { exit (status); + + while (true) + { + /* unreachable */ + } } /* __exit */ /** diff --git a/src/libruntime/target/stm32f4/jerry-assert.c b/src/libruntime/target/stm32f4/jerry-assert.c index 53ae8925c..3f260de93 100644 --- a/src/libruntime/target/stm32f4/jerry-assert.c +++ b/src/libruntime/target/stm32f4/jerry-assert.c @@ -21,8 +21,32 @@ */ void __noreturn jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */ - const char *file __unused, /**< file name */ - const uint32_t line __unused) /** line */ + const char *file __unused, /**< file name */ + const uint32_t line __unused) /** line */ { __exit (-ERR_FAILED_INTERNAL_ASSERTION); } /* jerry_assert_fail */ + +/** + * Handle execution of control path that should be unreachable + */ +void __noreturn +jerry_unreachable (const char *comment __unused, /**< comment to unreachable mark if exists, + NULL - otherwise */ + const char *file __unused, /**< file name */ + const uint32_t line __unused) /**< line */ +{ + __exit (-ERR_FAILED_INTERNAL_ASSERTION); +} /* jerry_unreachable */ + +/** + * Handle unimplemented case execution + */ +void __noreturn +jerry_unimplemented (const char *comment __unused, /**< comment to unimplemented mark if exists, + NULL - otherwise */ + const char *file __unused, /**< file name */ + const uint32_t line __unused) /**< line */ +{ + __exit (-ERR_UNIMPLEMENTED_CASE); +} /* jerry_unimplemented */