The UDS Collection

Configuring UDS


back to main page

To use some of the features UDS provides, you have to configure the library in your program. This has to be done at compile time. You do this by defining the variable uds::flags.
That might look like the following:

#include <uds/uds.hh>

// configure UDS
const uds::uds_flags_t uds::flags = uds::leak_check | uds::summon_zombies;
The available flags are:
force_core_dumps
force core dumps when an UDS exception is thrown
leak_check
check for memory leaks
summon_zombies
create zombie objects
log_allocs
log all memory [de]allocations to stderr
rename_cores
rename cores that are dumped by UDS exceptions
In the UDS library uds::flags is defined as weak symbol. If you don't want to set any flags, you don't have to provide uds::flags. However, UDS defines global new and delete operators (also as weak symbols). If you don't set any flags, there is still a small performance overhead. Fortunately, there is a workaround.
The UDS Collection comes with a source file ([prefix]/share/uds/udsdeff.cc) that, when added to your program, will #include config.h if present and sets the uds flags according to [non]defined macros. Additionally, when it is not necessary to use UDS new / delete operators, the original new and delete operators are restored.
If you want to use the debugging facilities during development, and run your releases at full speed, add udsdeff.cc to your project and add the following lines to your configure.in (taken from Frost).
enableval=$debug
AC_MSG_CHECKING(whether to force core dumps on fatal errors)
AC_ARG_ENABLE(core-dumps,[  --enable-core-dumps		dump the core on fatal errors])
if test "$enableval" != "no"; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(FORCE_CORE_DUMPS,,[force core dumps on fatal errors])
else
	AC_MSG_RESULT(no)
fi

enableval=$debug
AC_MSG_CHECKING(whether to check for memory leaks)
AC_ARG_ENABLE(leak-check,[  --enable-leak-check		check for memory leaks])
if test "$enableval" != "no"; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(LEAK_CHECK,,[check for memory leaks])
else
	AC_MSG_RESULT(no)
fi

enableval=$debug
AC_MSG_CHECKING(whether to create zombie objects)
AC_ARG_ENABLE(zombies,[  --enable-zombies		create zombie objects])
if test "$enableval" != "no"; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(SUMMON_ZOMBIES,,[create zombie objects])
else
	AC_MSG_RESULT(no)
fi

enableval=no
AC_MSG_CHECKING(whether to log memory allocations)
AC_ARG_ENABLE(log-allocs,[  --enable-log-allocs		log memory allocations])
if test "$enableval" != "no"; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(LOG_ALLOCS,,[log memory allocations])
else
	AC_MSG_RESULT(no)
fi

enableval=$debug
AC_MSG_CHECKING(whether to rename uds coredumps)
AC_ARG_ENABLE(rename-cores,[  --enable-rename-cores		rename uds coredumps])
if test "$enableval" != "no"; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(RENAME_UDS_CORES,,[rename uds coredumps])
else
	AC_MSG_RESULT(no)
fi
In this code, it is assumed that the variable 'debug' is 'yes' when debugging is enabled, and 'no' when it is disabled. It depends on the value of 'debug' whether some features are enabled by default.
If you have to enable eg memory logging during a development session, you don't have to reconfigure and rebuild your whole program. Simply comment the #ifdef LOG_ALLOCS line in udsdeff.cc out. This way you have to rebuild only one object file.