bh_assert.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "bh_platform.h"
  17. #include "bh_assert.h"
  18. #include <stdarg.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #ifdef BH_TEST
  22. #include <setjmp.h>
  23. #endif
  24. #ifdef BH_TEST
  25. /* for exception throwing */
  26. jmp_buf bh_test_jb;
  27. #endif
  28. void bh_assert_internal(int v, const char *file_name, int line_number,
  29. const char *expr_string)
  30. {
  31. if (v)
  32. return;
  33. if (!file_name)
  34. file_name = "NULL FILENAME";
  35. if (!expr_string)
  36. expr_string = "NULL EXPR_STRING";
  37. printf("\nASSERTION FAILED: %s, at FILE=%s, LINE=%d\n", expr_string,
  38. file_name, line_number);
  39. #ifdef BH_TEST
  40. longjmp(bh_test_jb, 1);
  41. #endif
  42. abort();
  43. }
  44. void bh_debug_internal(const char *file_name, int line_number, const char *fmt,
  45. ...)
  46. {
  47. #ifndef JEFF_TEST_VERIFIER
  48. va_list args;
  49. va_start(args, fmt);
  50. bh_assert(file_name);
  51. printf("\nDebug info FILE=%s, LINE=%d: ", file_name, line_number);
  52. vprintf(fmt, args);
  53. va_end(args);
  54. printf("\n");
  55. #endif
  56. }