added production assert mode

This commit is contained in:
Arvid Norberg 2010-05-06 02:18:08 +00:00
parent 85824b1924
commit 08d145a6e9
4 changed files with 29 additions and 7 deletions

View File

@ -237,6 +237,10 @@ feature.compose <fiemap>on : <define>HAVE_LINUX_FIEMAP_H ;
feature full-stats : on off : composite propagated link-incompatible ;
feature.compose <full-stats>off : <define>TORRENT_DISABLE_FULL_STATS ;
feature asserts : on off production : composite propagated ;
feature.compose <asserts>production : <define>TORRENT_PRODUCTION_ASSERTS=1 ;
feature.compose <asserts>off : <define>TORRENT_NO_ASSERTS=1 ;
feature pool-allocators : on off : composite propagated link-incompatible ;
feature.compose <pool-allocators>off : <define>TORRENT_DISABLE_POOL_ALLOCATOR ;

View File

@ -266,6 +266,12 @@ Build features:
| | requires you to link against librt.a. This is |
| | typically the case on x86 64 bit systems. |
+--------------------------+----------------------------------------------------+
| ``asserts`` | * ``on`` - asserts are on if in debug mode |
| | * ``off`` - asserts are disabled |
| | * ``production`` - assertion failures are logged |
| | to ``asserts.log`` in the current working |
| | directory, but won't abort the process. |
+--------------------------+----------------------------------------------------+
| ``zlib`` | * ``system`` - links against the zlib supplied |
| | with your operating system. |
| | * ``shipped`` - links against the zlib bundled |

View File

@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#if !defined TORRENT_DEBUG
#if !defined TORRENT_DEBUG || TORRENT_NO_ASSERTS
#define TORRENT_ASSERT(a) do {} while(false)
#else

View File

@ -97,30 +97,37 @@ std::string demangle(char const* name) { return name; }
#if (defined __linux__ || (defined __APPLE__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050))
#include <execinfo.h>
void print_backtrace(char const* label)
void print_backtrace(FILE* out, char const* label)
{
void* stack[50];
int size = backtrace(stack, 50);
char** symbols = backtrace_symbols(stack, size);
fprintf(stderr, "%s\n", label);
fprintf(out, "%s\n", label);
for (int i = 1; i < size; ++i)
{
fprintf(stderr, "%d: %s\n", i, demangle(symbols[i]).c_str());
fprintf(out, "%d: %s\n", i, demangle(symbols[i]).c_str());
}
free(symbols);
}
#else
void print_backtrace(char const* label) {}
void print_backtrace(FILE* out, char const* label) {}
#endif
void assert_fail(char const* expr, int line, char const* file, char const* function)
{
fprintf(stderr, "assertion failed. Please file a bugreport at "
#if TORRENT_PRODUCTION_ASSERTS
FILE* out = fopen("asserts.log", "a+");
if (out == 0) out = stderr;
#else
FILE* out = stderr;
#endif
fprintf(out, "assertion failed. Please file a bugreport at "
"http://code.rasterbar.com/libtorrent/newticket\n"
"Please include the following information:\n\n"
"version: " LIBTORRENT_VERSION "\n"
@ -130,12 +137,17 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct
"function: %s\n"
"expression: %s\n", LIBTORRENT_REVISION, file, line, function, expr);
print_backtrace("stack:");
print_backtrace(out, "stack:");
// if production asserts are defined, don't abort, just print the error
#if TORRENT_PRODUCTION_ASSERTS
if (out != stderr) fclose(out);
#else
// send SIGINT to the current process
// to break into the debugger
raise(SIGINT);
abort();
#endif
}
#else