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. extern void abort(void);
  29. void bh_assert_internal(int v, const char *file_name, int line_number,
  30. const char *expr_string)
  31. {
  32. if (v)
  33. return;
  34. if (!file_name)
  35. file_name = "NULL FILENAME";
  36. if (!expr_string)
  37. expr_string = "NULL EXPR_STRING";
  38. printk("\nASSERTION FAILED: %s, at FILE=%s, LINE=%d\n", expr_string,
  39. file_name, line_number);
  40. #ifdef BH_TEST
  41. longjmp(bh_test_jb, 1);
  42. #endif
  43. abort();
  44. }
  45. void bh_debug_internal(const char *file_name, int line_number, const char *fmt,
  46. ...)
  47. {
  48. #ifndef JEFF_TEST_VERIFIER
  49. va_list args;
  50. va_start(args, fmt);
  51. bh_assert(file_name);
  52. printf("\nDebug info FILE=%s, LINE=%d: ", file_name, line_number);
  53. vprintf(fmt, args);
  54. va_end(args);
  55. printf("\n");
  56. #endif
  57. }