14e98e3e1Schristos /* This file is part of the program GDB. 24e98e3e1Schristos 3*88241920Schristos Copyright (C) 1997-2024 Free Software Foundation, Inc. 44e98e3e1Schristos 54e98e3e1Schristos This program is free software; you can redistribute it and/or modify 64e98e3e1Schristos it under the terms of the GNU General Public License as published by 74e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or 84e98e3e1Schristos (at your option) any later version. 94e98e3e1Schristos 104e98e3e1Schristos This program is distributed in the hope that it will be useful, 114e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 124e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 134e98e3e1Schristos GNU General Public License for more details. 144e98e3e1Schristos 154e98e3e1Schristos You should have received a copy of the GNU General Public License 164e98e3e1Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. 174e98e3e1Schristos 184e98e3e1Schristos */ 194e98e3e1Schristos 204e98e3e1Schristos 21212397c6Schristos #ifndef SIM_ASSERT_H 22212397c6Schristos #define SIM_ASSERT_H 234e98e3e1Schristos 244b169a6bSchristos #include "libiberty.h" 254b169a6bSchristos 264e98e3e1Schristos /* The subtle difference between SIM_ASSERT and ASSERT is that 274e98e3e1Schristos SIM_ASSERT passes `sd' to sim_io_error for the SIM_DESC, 284e98e3e1Schristos ASSERT passes NULL. */ 294e98e3e1Schristos 304e98e3e1Schristos #if !defined (SIM_ASSERT) 314e98e3e1Schristos #if defined (WITH_ASSERT) 32212397c6Schristos #include "sim-io.h" 334e98e3e1Schristos #define SIM_ASSERT(EXPRESSION) \ 344e98e3e1Schristos do \ 354e98e3e1Schristos { \ 364e98e3e1Schristos if (WITH_ASSERT) \ 374e98e3e1Schristos { \ 384e98e3e1Schristos if (!(EXPRESSION)) \ 394e98e3e1Schristos { \ 404e98e3e1Schristos /* report the failure */ \ 414e98e3e1Schristos sim_io_error (sd, "%s:%d: assertion failed - %s", \ 42212397c6Schristos lbasename (__FILE__), __LINE__, #EXPRESSION); \ 434e98e3e1Schristos } \ 444e98e3e1Schristos } \ 454e98e3e1Schristos } \ 464e98e3e1Schristos while (0) 474e98e3e1Schristos #else 484e98e3e1Schristos #define SIM_ASSERT(EXPRESSION) do { /*nothing*/; } while (0) 494e98e3e1Schristos #endif 504e98e3e1Schristos #endif 514e98e3e1Schristos 524e98e3e1Schristos #if !defined (ASSERT) 534e98e3e1Schristos #if defined (WITH_ASSERT) 54212397c6Schristos #include "sim-io.h" 554e98e3e1Schristos #define ASSERT(EXPRESSION) \ 564e98e3e1Schristos do \ 574e98e3e1Schristos { \ 584e98e3e1Schristos if (WITH_ASSERT) \ 594e98e3e1Schristos { \ 604e98e3e1Schristos if (!(EXPRESSION)) \ 614e98e3e1Schristos { \ 624e98e3e1Schristos /* report the failure */ \ 634e98e3e1Schristos sim_io_error (NULL, "%s:%d: assertion failed - %s", \ 64212397c6Schristos lbasename (__FILE__), __LINE__, #EXPRESSION); \ 654e98e3e1Schristos } \ 664e98e3e1Schristos } \ 674e98e3e1Schristos } \ 684e98e3e1Schristos while (0) 694e98e3e1Schristos #else 704e98e3e1Schristos #define ASSERT(EXPRESSION) do { /*nothing*/; } while (0) 714e98e3e1Schristos #endif 724e98e3e1Schristos #endif 734e98e3e1Schristos 744e98e3e1Schristos #endif 75