retdec
Namespaces | Functions
debug.h File Reference

Debugging support. More...

#include <cstdlib>
#include <llvm/Support/raw_ostream.h>

Go to the source code of this file.

Namespaces

 retdec
 
 retdec::llvmir2hll
 

Macros

Assertions and Preconditions
#define DEATH_TESTS_ENABLED   1
 
#define ABORT_IMPL(MSG)
 Implementation of aborting the program with an error message MSG. For internal use only. More...
 
#define ASSERT_MSG_IMPL(TEST, MSG)    ((TEST) ? static_cast<void>(0) : ABORT_IMPL(MSG))
 Implementation of assertion macros in the module. For internal use only. More...
 
#define ASSERT(TEST)    ASSERT_MSG_IMPL(TEST, "Assertion failed: `" << #TEST << "`")
 Aborts the program if the assertion TEST is false, and prints a text version of TEST. More...
 
#define ASSERT_MSG(TEST, MSG)
 Aborts the program if the assertion TEST is false, and prints a text version of TEST and a custom error message MSG. More...
 
#define PRECONDITION(TEST, MSG)
 Aborts the program if the precondition TEST is false, and prints a text version of TEST and a custom error message MSG. More...
 
#define PRECONDITION_NON_NULL(TEST)    PRECONDITION(TEST, "expected a non-null pointer")
 Aborts the program if the precondition TEST evaluates to a null pointer, and prints a text version of TEST and an error message. More...
 
#define PRECONDITION_FAILED(MSG)    ABORT_IMPL("Precondition failed: " << MSG)
 Aborts the program with a failed precondition and prints a custom error message MSG. More...
 
#define POSTCONDITION(TEST, MSG)
 Aborts the program if the postcondition TEST is false, and prints a text version of TEST and a custom error message MSG. More...
 
#define POSTCONDITION_NON_NULL(TEST)    POSTCONDITION(TEST, "expected a non-null pointer")
 Aborts the program if the POSTCONDITION TEST evaluates to a null pointer, and prints a text version of TEST and an error message. More...
 
#define POSTCONDITION_FAILED(MSG)    ABORT_IMPL("Postcondition failed: " << MSG)
 Aborts the program with a failed postcondition and prints a custom error message MSG. More...
 
#define INVARIANT(TEST, MSG)
 Aborts the program if the invariant TEST is false, and prints a text version of TEST and a custom error message MSG. More...
 
#define INVARIANT_NON_NULL(TEST)    INVARIANT(TEST, "expected a non-null pointer")
 Aborts the program if the INVARIANT TEST evaluates to a null pointer, and prints a text version of TEST and an error message. More...
 
#define INVARIANT_FAILED(MSG)    ABORT_IMPL("Invariant failed: " << MSG)
 Aborts the program with a failed invariant and prints a custom error message MSG. More...
 
#define FAIL(MSG)    ABORT_IMPL("Fail (" << MSG << ")")
 Aborts the program with the given message MSG. More...
 

Functions

template<typename T >
T & retdec::llvmir2hll::id (T &object)
 Returns object. More...
 
Dumps
template<class Container , class DumpFunc >
void retdec::llvmir2hll::dump (const Container &container, DumpFunc dumpFunc, const std::string &delim=", ", const std::string &end="\n")
 Dumps the contents of the given container to standard error using the given dumping function. More...
 
template<class Container >
void retdec::llvmir2hll::dump (const Container &container, const std::string &delim=", ", const std::string &end="\n")
 Dumps the contents of the given container to standard error. More...
 
template<class T >
std::string retdec::llvmir2hll::dumpFuncGetName (T object)
 A dumping function which, given an object pointer, calls getName() on it via ->. More...
 
template<class T >
std::string retdec::llvmir2hll::dumpFuncGetTextRepr (T object)
 A dumping function which, given an object pointer, calls getTextRepr() on it via ->. More...
 

Detailed Description

Debugging support.

Macro Definition Documentation

◆ ABORT_IMPL

#define ABORT_IMPL (   MSG)
Value:
(llvm::errs() << __FILE__ ":" << __LINE__ << ": " << __func__ << \
": " << MSG << ".\n", std::abort())

Implementation of aborting the program with an error message MSG. For internal use only.

◆ ASSERT

#define ASSERT (   TEST)     ASSERT_MSG_IMPL(TEST, "Assertion failed: `" << #TEST << "`")

Aborts the program if the assertion TEST is false, and prints a text version of TEST.

Equivalent of assert() from the C standard library.

◆ ASSERT_MSG

#define ASSERT_MSG (   TEST,
  MSG 
)
Value:
ASSERT_MSG_IMPL(TEST, "Assertion failed: `" << #TEST \
<< "` (" << MSG << ")")
#define ASSERT_MSG_IMPL(TEST, MSG)
Implementation of assertion macros in the module. For internal use only.
Definition: debug.h:34

Aborts the program if the assertion TEST is false, and prints a text version of TEST and a custom error message MSG.

After the text version of TEST, it prints the custom message MSG, which can be anything that can be emitted. You can even sequence several objects into the message using the << operator. For example,

ASSERT_MSG(i > 10, "i = " << i);
#define ASSERT_MSG(TEST, MSG)
Aborts the program if the assertion TEST is false, and prints a text version of TEST and a custom err...
Definition: debug.h:57

◆ ASSERT_MSG_IMPL

#define ASSERT_MSG_IMPL (   TEST,
  MSG 
)     ((TEST) ? static_cast<void>(0) : ABORT_IMPL(MSG))

Implementation of assertion macros in the module. For internal use only.

◆ DEATH_TESTS_ENABLED

#define DEATH_TESTS_ENABLED   1

◆ FAIL

#define FAIL (   MSG)     ABORT_IMPL("Fail (" << MSG << ")")

Aborts the program with the given message MSG.

See ASSERT_MSG for more information on the parameter MSG.

◆ INVARIANT

#define INVARIANT (   TEST,
  MSG 
)
Value:
ASSERT_MSG_IMPL(TEST, "Invariant failed: `" << #TEST \
<< "` (" << MSG << ")")

Aborts the program if the invariant TEST is false, and prints a text version of TEST and a custom error message MSG.

See ASSERT_MSG for more information on the parameter MSG.

◆ INVARIANT_FAILED

#define INVARIANT_FAILED (   MSG)     ABORT_IMPL("Invariant failed: " << MSG)

Aborts the program with a failed invariant and prints a custom error message MSG.

Example:

INVARIANT_FAILED("statement " << stmt << doesn't exist");
#define INVARIANT_FAILED(MSG)
Aborts the program with a failed invariant and prints a custom error message MSG.
Definition: debug.h:156

◆ INVARIANT_NON_NULL

#define INVARIANT_NON_NULL (   TEST)     INVARIANT(TEST, "expected a non-null pointer")

Aborts the program if the INVARIANT TEST evaluates to a null pointer, and prints a text version of TEST and an error message.

◆ POSTCONDITION

#define POSTCONDITION (   TEST,
  MSG 
)
Value:
ASSERT_MSG_IMPL(TEST, "Postcondition failed: `" << #TEST \
<< "` (" << MSG << ")")

Aborts the program if the postcondition TEST is false, and prints a text version of TEST and a custom error message MSG.

See ASSERT_MSG for more information on the parameter MSG.

◆ POSTCONDITION_FAILED

#define POSTCONDITION_FAILED (   MSG)     ABORT_IMPL("Postcondition failed: " << MSG)

Aborts the program with a failed postcondition and prints a custom error message MSG.

Example:

POSTCONDITION_FAILED("statement " << stmt << doesn't exist");
#define POSTCONDITION_FAILED(MSG)
Aborts the program with a failed postcondition and prints a custom error message MSG.
Definition: debug.h:127

◆ POSTCONDITION_NON_NULL

#define POSTCONDITION_NON_NULL (   TEST)     POSTCONDITION(TEST, "expected a non-null pointer")

Aborts the program if the POSTCONDITION TEST evaluates to a null pointer, and prints a text version of TEST and an error message.

◆ PRECONDITION

#define PRECONDITION (   TEST,
  MSG 
)
Value:
ASSERT_MSG_IMPL(TEST, "Precondition failed: `" << #TEST \
<< "` (" << MSG << ")")

Aborts the program if the precondition TEST is false, and prints a text version of TEST and a custom error message MSG.

See ASSERT_MSG for more information on the parameter MSG.

Example:

PRECONDITION(!module || enableCaching,
"when module is non-null, caching has to be enabled");
ShPtr< Module > module
The current module.
Definition: hll_writer.cpp:100
#define PRECONDITION(TEST, MSG)
Aborts the program if the precondition TEST is false, and prints a text version of TEST and a custom ...
Definition: debug.h:73

◆ PRECONDITION_FAILED

#define PRECONDITION_FAILED (   MSG)     ABORT_IMPL("Precondition failed: " << MSG)

Aborts the program with a failed precondition and prints a custom error message MSG.

Example:

PRECONDITION_FAILED("statement " << stmt << doesn't exist");
#define PRECONDITION_FAILED(MSG)
Aborts the program with a failed precondition and prints a custom error message MSG.
Definition: debug.h:98

◆ PRECONDITION_NON_NULL

#define PRECONDITION_NON_NULL (   TEST)     PRECONDITION(TEST, "expected a non-null pointer")

Aborts the program if the precondition TEST evaluates to a null pointer, and prints a text version of TEST and an error message.

Example:

PRECONDITION_NON_NULL(aliasAnalysis);
#define PRECONDITION_NON_NULL(TEST)
Aborts the program if the precondition TEST evaluates to a null pointer, and prints a text version of...
Definition: debug.h:86