gdb_assert.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* GDB-friendly replacement for <assert.h>.
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef COMMON_GDB_ASSERT_H
  15. #define COMMON_GDB_ASSERT_H
  16. #include "errors.h"
  17. /* A static assertion. This will cause a compile-time error if EXPR,
  18. which must be a compile-time constant, is false. */
  19. #define gdb_static_assert(expr) static_assert (expr, "")
  20. /* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather
  21. than upper case) macro since that provides the closest fit to the
  22. existing lower case macro <assert.h>:assert() that it is
  23. replacing. */
  24. #define gdb_assert(expr) \
  25. ((void) ((expr) ? 0 : \
  26. (gdb_assert_fail (#expr, __FILE__, __LINE__, __func__), 0)))
  27. /* This prints an "Assertion failed" message, asking the user if they
  28. want to continue, dump core, or just exit. */
  29. #define gdb_assert_fail(assertion, file, line, function) \
  30. internal_error (file, line, _("%s: Assertion `%s' failed."), \
  31. function, assertion)
  32. /* The canonical form of gdb_assert (0).
  33. MESSAGE is a string to include in the error message. */
  34. #define gdb_assert_not_reached(message, ...) \
  35. internal_error (__FILE__, __LINE__, _("%s: " message), __func__, \
  36. ##__VA_ARGS__)
  37. #endif /* COMMON_GDB_ASSERT_H */