Modules | Defines

Debugging
[Core]

Collaboration diagram for Debugging:

Modules

 Assert
 

assert functions and macros


 Fatal Error Handler
 

Functions to help clean up when fatal error is encountered.


 Logging
 

Logging functions and macros.


Defines

#define NS_ABORT_MSG(msg)
 Abnormal program termination.
#define NS_ABORT_IF(cond)
 Abnormal program termination if cond is true.
#define NS_ABORT_MSG_IF(cond, msg)
 Abnormal program termination if cond is true.
#define NS_ABORT_UNLESS(cond)   NS_ABORT_IF(!(cond))
 Abnormal program termination if cond is false.
#define NS_ABORT_MSG_UNLESS(cond, msg)   NS_ABORT_MSG_IF(!(cond),msg)
 Abnormal program termination if cond is false.
#define NS_BREAKPOINT()   ns3::BreakpointFallback ()
#define NS_FATAL_ERROR_NO_MSG()
 fatal error handling
#define NS_FATAL_ERROR(msg)
 fatal error handling

Define Documentation

#define NS_ABORT_IF (   cond  ) 
Value:
do {                                                                  \
    if (cond)                                                           \
      {                                                                 \
        std::cerr << "aborted. cond=\"" << #cond << ", ";               \
        NS_FATAL_ERROR_NO_MSG ();                                       \
      }                                                                 \
  } while (false)

Abnormal program termination if cond is true.

Parameters:
cond condition to be evaluated.

This is similar to NS_ASSERT(!(cond)), except this check is enabled in all builds. If cond is evaluated to true, the espression evaluating to true is printed to stderr, followed by a call to the NS_FATAL_ERROR_NO_MSG() macro which prints the details of filename and line number to stderr. The program will be halted by calling std::terminate(), triggering any clean up code registered by std::set_terminate (NS3 default is a stream-flushing code, but may be overridden).

This macro is enable unconditionally in all builds, including debug and optimized builds.

#define NS_ABORT_MSG (   msg  ) 
Value:
do {                                                          \
    std::cerr << "aborted. ";                                   \
    NS_FATAL_ERROR (msg);                                       \
  } while (false)

Abnormal program termination.

Parameters:
msg message to output when this macro is hit.

This macro is essentially equivalent to NS_FATAL_ERROR, excepts it prepends the error message with the string "aborted. ". When this macro is hit a runtime, the program will be halted using std::terminate, which triggers clean up code regestered by std::set_terminate.

This macro is enable unconditionally in all builds, including debug and optimized builds.

See also:
NS_FATAL_ERROR
#define NS_ABORT_MSG_IF (   cond,
  msg 
)
Value:
do {                                                                  \
    if (cond)                                                           \
      {                                                                 \
        std::cerr << "aborted. cond=\"" << #cond << "\", ";             \
        NS_FATAL_ERROR (msg);                                           \
      }                                                                 \
  } while (false)

Abnormal program termination if cond is true.

Parameters:
cond condition to be evaluated.
msg message to output when cond is true.

This is similar to NS_ASSERT_MSG(!(cond)), except this check is enabled in all builds. If cond is evaluated to true, the espression evaluating to true is printed to stderr, followed by a call to the NS_FATAL_ERROR() macro which prints the user-specified error message, and details of filename and line number to stderr. The program will be halted by calling std::terminate(), triggering any clean up code registered by std::set_terminate (NS3 default is a stream-flushing code, but may be overridden).

This macro is enable unconditionally in all builds, including debug and optimized builds.

#define NS_ABORT_MSG_UNLESS (   cond,
  msg 
)    NS_ABORT_MSG_IF(!(cond),msg)

Abnormal program termination if cond is false.

Parameters:
cond condition to be evaluated.
msg message to output if cond is false.

This is an alias for NS_ABORT_MSG_IF(!(cond))

See also:
NS_ABORT_MSG_IF
#define NS_ABORT_UNLESS (   cond  )     NS_ABORT_IF(!(cond))

Abnormal program termination if cond is false.

Parameters:
cond condition to be evaluated.

This is an alias for NS_ABORT_IF(!(cond))

See also:
NS_ABORT_IF
#define NS_BREAKPOINT (  )     ns3::BreakpointFallback ()

Inserts a breakpoint instruction (or equivalent system call) into the code for selected machines. When an NS_ASSERT cannot verify its condition, this macro is used. Falls back to calling AssertBreakpoint() for architectures where breakpoint assembly instructions are not supported.

#define NS_FATAL_ERROR (   msg  ) 
Value:
do                                                    \
    {                                                   \
      std::cerr << "msg=\"" << msg << "\", ";           \
      NS_FATAL_ERROR_NO_MSG();                          \
    }                                                   \
  while (false)

fatal error handling

Parameters:
msg message to output when this macro is hit.

When this macro is hit at runtime, the user-specified error message is printed to stderr, followed by a call to the NS_FATAL_ERROR_NO_MSG() macro which prints the details of filename and line number to stderr. The program will be halted by calling std::terminate(), triggering any clean up code registered by std::set_terminate (NS3 default is a stream-flushing code, but may be overridden).

This macro is enabled unconditionally in all builds, including debug and optimized builds.

#define NS_FATAL_ERROR_NO_MSG (  ) 
Value:
do                                                      \
    {                                                     \
      std::cerr << "file=" << __FILE__ << ", line=" <<    \
        __LINE__ << std::endl;                            \
      ::ns3::FatalImpl::FlushStreams ();                  \
      std::terminate ();                                  \
    }                                                     \
  while (false)

fatal error handling

When this macro is hit at runtime, details of filename and line number is printed to stderr, and the program is halted by calling std::terminate(). This will trigger any clean up code registered by std::set_terminate (NS3 default is a stream-flushing code), but may be overridden.

This macro is enabled unconditionally in all builds, including debug and optimized builds.