1 // Copyright (c) 2011-2016 Ryan Prichard
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 #ifndef WINPTY_ASSERT_H
22 #define WINPTY_ASSERT_H
24 #ifdef WINPTY_AGENT_ASSERT
27 void agentAssertFail(const char *file, int line, const char *cond);
29 // Calling the standard assert() function does not work in the agent because
30 // the error message would be printed to the console, and the only way the
31 // user can see the console is via a working agent! Moreover, the console may
32 // be frozen, so attempting to write to it would block forever. This custom
33 // assert function instead sends the message to the DebugServer, then attempts
34 // to close the console, then quietly exits.
35 #define ASSERT(cond) \
38 agentAssertFail(__FILE__, __LINE__, #cond); \
44 void assertTrace(const char *file, int line, const char *cond);
46 // In the other targets, log the assert failure to the debugserver, then fail
47 // using the ordinary assert mechanism. In case assert is compiled out, fail
48 // using abort. The amount of code inlined is unfortunate, but asserts aren't
49 // used much outside the agent.
52 #define ASSERT_CONDITION(cond) (false && (cond))
53 #define ASSERT(cond) \
56 assertTrace(__FILE__, __LINE__, #cond); \
57 assert(ASSERT_CONDITION(#cond)); \
64 #endif // WINPTY_ASSERT_H