OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2006-2009 NVIDIA Corporation. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: |
| 7 * |
| 8 * Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. |
| 10 * |
| 11 * Redistributions in binary form must reproduce the above copyright notice, |
| 12 * this list of conditions and the following disclaimer in the documentation |
| 13 * and/or other materials provided with the distribution. |
| 14 * |
| 15 * Neither the name of the NVIDIA Corporation nor the names of its contributors |
| 16 * may be used to endorse or promote products derived from this software |
| 17 * without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 * POSSIBILITY OF SUCH DAMAGE. |
| 30 * |
| 31 */ |
| 32 |
| 33 |
| 34 #ifndef INCLUDED_NVASSERT_H |
| 35 #define INCLUDED_NVASSERT_H |
| 36 |
| 37 #include "nvcommon.h" |
| 38 |
| 39 #if defined(__cplusplus) |
| 40 extern "C" |
| 41 { |
| 42 #endif |
| 43 |
| 44 /** NvOsBreakPoint - break into debugger. |
| 45 * @param file is the file name (usually from the built-in __FILE__ macro) |
| 46 * in which the debug assertion message is to refer. If NULL, no debug assertion |
| 47 * message is printed. |
| 48 * @param line is the line number within 'file' at which the assertion occurred. |
| 49 * @param condition is the assertion condition that failed. If NULL, no conditio
n |
| 50 * string will be displayed. |
| 51 */ |
| 52 void |
| 53 NvOsBreakPoint(const char* file, NvU32 line, const char* condition); |
| 54 |
| 55 /** |
| 56 * Macro to break into debugger without printing an assertion message. |
| 57 */ |
| 58 #define NV_OS_BREAK_POINT() NvOsBreakPoint(NULL, 0, NULL) |
| 59 |
| 60 |
| 61 /** |
| 62 * Runtime condition check with break into debugger if the assert fails. |
| 63 * Compiles out in release builds. |
| 64 * |
| 65 * We provide two variants of assert: one that prints out the failing assert |
| 66 * condition (the "#x" string in the macro), and another that doesn't. By |
| 67 * default, we print the condition string in x86 builds only. The assumption |
| 68 * is that x86 systems have boatloads of memory and can afford to put all these |
| 69 * extra strings in the binary, whereas other systems are our target systems |
| 70 * and tend to have less memory available. Also, we want to be careful about |
| 71 * anything that might make it take too long to transfer system images over to |
| 72 * the target system. |
| 73 * |
| 74 * We also allow individual developers to override this default behavior, |
| 75 * either globally or on a per-source-file basis. To do this, set |
| 76 * NV_ASSERT_PROVIDE_CONDITION_STRING to either 0 or 1, either in your own |
| 77 * source code, in your own makefile, or by uncommenting the lines below. |
| 78 */ |
| 79 |
| 80 #if !defined(NV_ASSERT) |
| 81 #if NV_DEBUG |
| 82 |
| 83 // Uncomment me to override default assert behavior |
| 84 //#define NV_ASSERT_PROVIDE_CONDITION_STRING 0 |
| 85 //#define NV_ASSERT_PROVIDE_CONDITION_STRING 1 |
| 86 |
| 87 // Default behavior: provide condition string in x86 builds only |
| 88 #if !defined(NV_ASSERT_PROVIDE_CONDITION_STRING) |
| 89 #if NVCPU_IS_X86 |
| 90 #define NV_ASSERT_PROVIDE_CONDITION_STRING 1 |
| 91 #else |
| 92 #define NV_ASSERT_PROVIDE_CONDITION_STRING 0 |
| 93 #endif |
| 94 #endif |
| 95 |
| 96 #if NV_ASSERT_PROVIDE_CONDITION_STRING |
| 97 #define NV_ASSERT(x) \ |
| 98 do { \ |
| 99 if (!(x)) \ |
| 100 { \ |
| 101 /* print message and break into the debugger */ \ |
| 102 NvOsBreakPoint(__FILE__, __LINE__, #x); \ |
| 103 } \ |
| 104 } while( 0 ) |
| 105 #else // NV_ASSERT_PROVIDE_CONDITION_STRING |
| 106 #define NV_ASSERT(x) \ |
| 107 do { \ |
| 108 if (!(x)) \ |
| 109 { \ |
| 110 /* print message and break into the debugger */ \ |
| 111 NvOsBreakPoint(__FILE__, __LINE__, NULL); \ |
| 112 } \ |
| 113 } while( 0 ) |
| 114 #endif // NV_ASSERT_PROVIDE_CONDITION_STRING |
| 115 |
| 116 #else // NV_DEBUG |
| 117 #define NV_ASSERT(x) do {} while(0) |
| 118 #endif // NV_DEBUG |
| 119 #endif //!defined(NV_ASSERT) |
| 120 |
| 121 /** |
| 122 * NV_CT_ASSERT: compile-time assert for constant values. |
| 123 * |
| 124 * This works by declaring a function with an array parameter. If the |
| 125 * assert condition is true, then the array size will be 1, otherwise |
| 126 * the array size will be -1, which will generate a compilation error. |
| 127 * |
| 128 * No code should be generated by this macro. |
| 129 * |
| 130 * Three levels of macros are needed to properly expand the line number. |
| 131 * |
| 132 * This macro was taken in spirit from: |
| 133 * //sw/main/drivers/common/inc/nvctassert.h |
| 134 */ |
| 135 #define NV_CT_ASSERT( x ) NV_CT_ASSERT_I( x, __LINE__ ) |
| 136 #define NV_CT_ASSERT_I( x,line ) NV_CT_ASSERT_II( x, line ) |
| 137 #define NV_CT_ASSERT_II( x, line ) \ |
| 138 void compile_time_assertion_failed_in_line_##line( \ |
| 139 int _compile_time_assertion_failed_in_line_##line[(x) ? 1 : -1]) |
| 140 |
| 141 /** |
| 142 * A macro to assert (rather than check) that something succeeded. The use of |
| 143 * this macro is strongly discouraged in any production-worthy code. It is, |
| 144 * however, a step up from ignoring the NvError return code of a function, and |
| 145 * it is trivial to use and harmless to your release builds. If everyone uses |
| 146 * it, it also makes it easy to search the tree for missing error handling code. |
| 147 * |
| 148 * In this macro, we don't worry about the stack space wasted from multiple |
| 149 * NvError locals in a single function -- production-quality code shouldn't be |
| 150 * using this macro in the first place. |
| 151 */ |
| 152 #if NV_DEBUG |
| 153 #define NV_ASSERT_SUCCESS(expr) \ |
| 154 do \ |
| 155 { \ |
| 156 NvError AssertSuccessError = (expr); \ |
| 157 NV_ASSERT(AssertSuccessError == NvSuccess); \ |
| 158 } while (0) |
| 159 #else |
| 160 #define NV_ASSERT_SUCCESS(expr) \ |
| 161 do \ |
| 162 { \ |
| 163 (void)(expr); \ |
| 164 } while (0) |
| 165 #endif |
| 166 |
| 167 #if defined(__cplusplus) |
| 168 } |
| 169 #endif |
| 170 |
| 171 #endif // INCLUDED_NVASSERT_H |
OLD | NEW |