NCBI C++ ToolKit
ncbidbg_p.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef NCBIDBG_P__HPP
2 #define NCBIDBG_P__HPP
3 
4 /* $Id: ncbidbg_p.hpp 82263 2018-05-16 11:33:29Z ivanov $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Andrei Gourianov, gouriano@ncbi.nlm.nih.gov
30  *
31  * File Description:
32  * declaration of debugging function(s)
33  *
34  */
35 
37 #include <corelib/ncbithr.hpp>
38 #include <corelib/ncbiexpt.hpp>
39 #include <corelib/ncbistr.hpp>
40 
41 #include <assert.h>
42 
44 
45 
46 // If "expression" evaluates to FALSE then the behavior depends on whether
47 // _DEBUG is defined (implemented in the DiagValidate(...)):
48 // - _DEBUG is defined:
49 // Abort execution (by default), or throw exception (if explicitly specified
50 // by calling xncbi_SetValidateAction(eValidate_Throw))
51 // - _DEBUG is not defined:
52 // throw an exception
53 # define xncbi_Validate(expression, message) \
54  do { \
55  if ( !(expression) ) \
56  NCBI_NS_NCBI::CNcbiDiag::DiagValidate(DIAG_COMPILE_INFO, #expression, message); \
57  } while ( 0 )
58 
59 
60 # define xncbi_ValidateAndErrnoReport(expression, message) \
61  do { \
62  if ( !(expression) ) { \
63  string ext_message(message); \
64  ext_message += " (errno=" + NStr::NumericToString(NCBI_ERRNO_CODE_WRAPPER()) + \
65  ": " + \
66  string(NCBI_ERRNO_STR_WRAPPER(NCBI_ERRNO_CODE_WRAPPER())) + ")"; \
67  NCBI_NS_NCBI::CNcbiDiag::DiagValidate(DIAG_COMPILE_INFO, #expression, ext_message.c_str()); \
68  } \
69  } while ( 0 )
70 
71 
72 // The pthread functions (at least on most platforms) do not set the errno
73 // variable. They return an errno value instead.
74 // In some cases (IBM ?) the errno is set and the return value is -1 in case of
75 // errors.
76 #if defined(NCBI_POSIX_THREADS)
77  # define xncbi_ValidatePthread(expression, expected_value, message) \
78  do { \
79  auto xvp_retval = expression; \
80  if (xvp_retval != expected_value) { \
81  string msg(message); \
82  msg += "(pthread error=" + NStr::NumericToString(xvp_retval) + \
83  ": " + \
84  string(NCBI_ERRNO_STR_WRAPPER(xvp_retval)); \
85  if ( xvp_retval == -1 ) { \
86  msg += " errno=" + NStr::NumericToString(errno); \
87  } \
88  msg += ")"; \
89  NCBI_NS_NCBI::CNcbiDiag::DiagValidate(DIAG_COMPILE_INFO, #expression, msg.c_str()); \
90  } \
91  } while ( 0 )
92 #endif
93 
94 
95 bool xncbi_VerifyReport(const char * expr);
96 
97 #if defined(_DEBUG)
98 
99 // 'simple' verify
100 # define xncbi_Verify(expression) assert(expression)
101 # define xncbi_VerifyAndErrorReport(expression) \
102  do { \
103  if ( !(expression) ) \
104  assert(xncbi_VerifyReport(#expression)); \
105  } while ( 0 )
106 
107 #else // _DEBUG
108 
109 // 'simple' verify - just evaluate the expression
110 # define xncbi_Verify(expression) while ( expression ) break
111 
112 # define xncbi_VerifyAndErrorReport(expression) \
113  do { \
114  if ( !(expression) ) \
115  xncbi_VerifyReport(#expression); \
116  } while ( 0 )
117 
118 #endif // _DEBUG
119 
120 
122 
123 #endif // NCBIDBG_P__HPP
The NCBI C++ standard methods for dealing with std::string.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
Static variables safety - create on demand, destroy on application termination.
bool xncbi_VerifyReport(const char *expr)
Definition: ncbidbg.cpp:99
Defines NCBI C++ exception handling.
Multi-threading – classes, functions, and features.
Modified on Wed Apr 24 14:15:22 2024 by modify_doxy.py rev. 669887