]>
Commit | Line | Data |
---|---|---|
b27be85f AC |
1 | /* This file is part of the program GDB. |
2 | ||
3 | Copyright (C) 1997, Free Software Foundation, Inc. | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | ||
19 | */ | |
20 | ||
21 | ||
22 | #ifndef _SIM_ASSERT_H_ | |
23 | #define _SIM_ASSERT_H_ | |
24 | ||
fa21d299 AC |
25 | #define SIM_FILTER_PATH(FILE, PATH) \ |
26 | do \ | |
27 | { \ | |
28 | /* strip leading path */ \ | |
29 | const char *p = (PATH); \ | |
30 | (FILE) = p; \ | |
31 | while (*p != '\0' && *p != ':') \ | |
32 | { \ | |
33 | if (*p == '/') \ | |
34 | (FILE) = p; \ | |
35 | p++; \ | |
36 | } \ | |
37 | } \ | |
38 | while (0) | |
39 | ||
40 | /* The subtle difference between SIM_ASSERT and ASSERT is that | |
41 | SIM_ASSERT passes `sd' to sim_io_error for the SIM_DESC, | |
42 | ASSERT passes NULL. */ | |
43 | ||
44 | #if defined (WITH_ASSERT) | |
b27be85f | 45 | #define SIM_ASSERT(EXPRESSION) \ |
fa21d299 AC |
46 | do \ |
47 | { \ | |
48 | if (WITH_ASSERT) \ | |
49 | { \ | |
50 | if (!(EXPRESSION)) \ | |
51 | { \ | |
52 | /* report the failure */ \ | |
53 | const char *file; \ | |
54 | SIM_FILTER_PATH(file, __FILE__); \ | |
55 | sim_io_error (sd, "%s:%d: assertion failed - %s", \ | |
56 | file, __LINE__, #EXPRESSION); \ | |
57 | } \ | |
b27be85f | 58 | } \ |
b27be85f | 59 | } \ |
fa21d299 | 60 | while (0) |
b27be85f AC |
61 | #else |
62 | #define SIM_ASSERT(EXPRESSION) do { /*nothing*/; } while (0) | |
63 | #endif | |
64 | ||
65 | #if defined (WITH_ASSERT) | |
66 | #define ASSERT(EXPRESSION) \ | |
fa21d299 AC |
67 | do \ |
68 | { \ | |
69 | if (WITH_ASSERT) \ | |
70 | { \ | |
71 | if (!(EXPRESSION)) \ | |
72 | { \ | |
73 | /* report the failure */ \ | |
74 | const char *file; \ | |
75 | SIM_FILTER_PATH(file, __FILE__); \ | |
76 | sim_io_error (NULL, "%s:%d: assertion failed - %s", \ | |
77 | file, __LINE__, #EXPRESSION); \ | |
78 | } \ | |
b27be85f | 79 | } \ |
b27be85f | 80 | } \ |
fa21d299 | 81 | while (0) |
b27be85f AC |
82 | #else |
83 | #define ASSERT(EXPRESSION) do { /*nothing*/; } while (0) | |
84 | #endif | |
85 | ||
86 | #endif |