2007-08-20 06:58:56 +02:00
|
|
|
/*
|
|
|
|
|
2018-04-09 09:04:33 +02:00
|
|
|
Copyright (c) 2007-2018, Arvid Norberg
|
2007-08-20 06:58:56 +02:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-08-15 01:55:41 +02:00
|
|
|
#include "libtorrent/config.hpp"
|
2015-04-18 04:33:39 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2011-08-15 01:55:41 +02:00
|
|
|
|
2015-08-21 22:56:57 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
|
|
|
|
2015-04-18 04:33:39 +02:00
|
|
|
#ifdef TORRENT_PRODUCTION_ASSERTS
|
2016-05-01 09:38:35 +02:00
|
|
|
#include <atomic>
|
2013-03-28 00:41:04 +01:00
|
|
|
#endif
|
|
|
|
|
2016-06-18 14:31:07 +02:00
|
|
|
#if TORRENT_USE_ASSERTS \
|
2014-11-30 11:07:19 +01:00
|
|
|
|| defined TORRENT_ASIO_DEBUGGING \
|
|
|
|
|| defined TORRENT_PROFILE_CALLS \
|
|
|
|
|| defined TORRENT_DEBUG_BUFFERS
|
2012-02-16 19:24:53 +01:00
|
|
|
|
2008-12-19 10:17:55 +01:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <AvailabilityMacros.h>
|
|
|
|
#endif
|
|
|
|
|
2007-12-27 07:15:52 +01:00
|
|
|
#include <string>
|
2008-04-29 23:46:32 +02:00
|
|
|
#include <cstring>
|
2016-07-10 05:17:55 +02:00
|
|
|
#include <cstdlib>
|
2016-05-17 15:24:06 +02:00
|
|
|
#include <cstdarg>
|
|
|
|
#include <cstdio> // for snprintf
|
|
|
|
#include <cinttypes> // for PRId64 et.al.
|
2016-05-15 19:28:22 +02:00
|
|
|
#include <array>
|
2007-12-27 07:15:52 +01:00
|
|
|
|
2015-08-21 22:56:57 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
|
|
|
|
2009-10-20 18:44:11 +02:00
|
|
|
// uClibc++ doesn't have cxxabi.h
|
2009-11-28 23:41:21 +01:00
|
|
|
#if defined __GNUC__ && __GNUC__ >= 3 \
|
|
|
|
&& !defined __UCLIBCXX_MAJOR__
|
2009-10-20 18:44:11 +02:00
|
|
|
|
|
|
|
#include <cxxabi.h>
|
|
|
|
|
2018-05-13 21:59:50 +02:00
|
|
|
namespace libtorrent {
|
2007-12-27 07:15:52 +01:00
|
|
|
std::string demangle(char const* name)
|
|
|
|
{
|
|
|
|
// in case this string comes
|
2008-12-19 07:12:55 +01:00
|
|
|
// this is needed on linux
|
2017-09-12 23:10:11 +02:00
|
|
|
char const* start = std::strchr(name, '(');
|
2016-07-09 22:26:26 +02:00
|
|
|
if (start != nullptr)
|
2008-12-19 07:12:55 +01:00
|
|
|
{
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// this is needed on macos x
|
|
|
|
start = strstr(name, "0x");
|
2016-07-09 22:26:26 +02:00
|
|
|
if (start != nullptr)
|
2008-12-19 07:12:55 +01:00
|
|
|
{
|
2017-09-12 23:10:11 +02:00
|
|
|
start = std::strchr(start, ' ');
|
2016-07-09 22:26:26 +02:00
|
|
|
if (start != nullptr) ++start;
|
2008-12-19 07:12:55 +01:00
|
|
|
else start = name;
|
|
|
|
}
|
|
|
|
else start = name;
|
|
|
|
}
|
|
|
|
|
2017-09-12 23:10:11 +02:00
|
|
|
char const* end = std::strchr(start, '+');
|
2008-12-19 07:12:55 +01:00
|
|
|
if (end) while (*(end-1) == ' ') --end;
|
2007-12-27 07:15:52 +01:00
|
|
|
|
|
|
|
std::string in;
|
2016-07-09 22:26:26 +02:00
|
|
|
if (end == nullptr) in.assign(start);
|
2007-12-27 07:15:52 +01:00
|
|
|
else in.assign(start, end);
|
|
|
|
|
|
|
|
size_t len;
|
|
|
|
int status;
|
2016-07-09 22:26:26 +02:00
|
|
|
char* unmangled = ::abi::__cxa_demangle(in.c_str(), nullptr, &len, &status);
|
|
|
|
if (unmangled == nullptr) return in;
|
2007-12-27 07:15:52 +01:00
|
|
|
std::string ret(unmangled);
|
2017-09-12 23:10:11 +02:00
|
|
|
::free(unmangled);
|
2007-12-27 07:15:52 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2018-05-13 21:59:50 +02:00
|
|
|
}
|
2016-05-24 05:02:52 +02:00
|
|
|
#elif defined _WIN32
|
2012-01-26 11:33:39 +01:00
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "dbghelp.h"
|
|
|
|
|
2018-05-13 21:59:50 +02:00
|
|
|
namespace libtorrent {
|
2015-06-20 22:42:18 +02:00
|
|
|
std::string demangle(char const* name)
|
2015-06-20 06:13:38 +02:00
|
|
|
{
|
2012-01-26 11:33:39 +01:00
|
|
|
char demangled_name[256];
|
|
|
|
if (UnDecorateSymbolName(name, demangled_name, sizeof(demangled_name), UNDNAME_NO_THROW_SIGNATURES) == 0)
|
|
|
|
demangled_name[0] = 0;
|
|
|
|
return demangled_name;
|
|
|
|
}
|
2018-05-13 21:59:50 +02:00
|
|
|
}
|
2007-12-27 07:15:52 +01:00
|
|
|
|
2009-10-20 18:44:11 +02:00
|
|
|
#else
|
2018-05-13 21:59:50 +02:00
|
|
|
namespace libtorrent {
|
2009-10-20 18:44:11 +02:00
|
|
|
std::string demangle(char const* name) { return name; }
|
2018-05-13 21:59:50 +02:00
|
|
|
}
|
2007-12-27 07:15:52 +01:00
|
|
|
#endif
|
|
|
|
|
2016-07-10 05:17:55 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <csignal>
|
2009-01-14 09:41:14 +01:00
|
|
|
#include "libtorrent/version.hpp"
|
2008-12-19 07:12:55 +01:00
|
|
|
|
2013-05-26 23:36:20 +02:00
|
|
|
#if TORRENT_USE_EXECINFO
|
2007-08-20 06:58:56 +02:00
|
|
|
#include <execinfo.h>
|
2008-12-19 07:12:55 +01:00
|
|
|
|
2018-05-13 21:59:50 +02:00
|
|
|
namespace libtorrent {
|
|
|
|
|
2016-05-15 19:28:22 +02:00
|
|
|
TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*)
|
2008-12-19 07:12:55 +01:00
|
|
|
{
|
|
|
|
void* stack[50];
|
2017-09-12 23:10:11 +02:00
|
|
|
int size = ::backtrace(stack, 50);
|
|
|
|
char** symbols = ::backtrace_symbols(stack, size);
|
2008-12-19 07:12:55 +01:00
|
|
|
|
2011-04-15 10:37:27 +02:00
|
|
|
for (int i = 1; i < size && len > 0; ++i)
|
2008-12-19 07:12:55 +01:00
|
|
|
{
|
2017-01-09 07:43:57 +01:00
|
|
|
int ret = std::snprintf(out, std::size_t(len), "%d: %s\n", i, demangle(symbols[i]).c_str());
|
2011-04-15 10:37:27 +02:00
|
|
|
out += ret;
|
|
|
|
len -= ret;
|
2012-04-01 02:42:31 +02:00
|
|
|
if (i - 1 == max_depth && max_depth > 0) break;
|
2008-12-19 07:12:55 +01:00
|
|
|
}
|
|
|
|
|
2017-09-12 23:10:11 +02:00
|
|
|
::free(symbols);
|
2008-12-19 07:12:55 +01:00
|
|
|
}
|
2018-05-13 21:59:50 +02:00
|
|
|
}
|
2012-01-26 11:33:39 +01:00
|
|
|
|
2016-05-27 21:35:53 +02:00
|
|
|
#elif defined _WIN32
|
2012-01-26 11:33:39 +01:00
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "libtorrent/utf8.hpp"
|
2016-07-25 14:05:26 +02:00
|
|
|
#include <mutex>
|
2012-01-26 11:33:39 +01:00
|
|
|
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "dbghelp.h"
|
|
|
|
|
2018-05-13 21:59:50 +02:00
|
|
|
namespace libtorrent {
|
|
|
|
|
2016-05-15 19:28:22 +02:00
|
|
|
TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth
|
|
|
|
, void* ctx)
|
2012-01-26 11:33:39 +01:00
|
|
|
{
|
2016-07-25 14:05:26 +02:00
|
|
|
// all calls to DbgHlp.dll are thread-unsafe. i.e. they all need to be
|
|
|
|
// synchronized and not called concurrently. This mutex serializes access
|
|
|
|
static std::mutex dbghlp_mutex;
|
|
|
|
std::lock_guard<std::mutex> l(dbghlp_mutex);
|
|
|
|
|
2016-05-15 19:28:22 +02:00
|
|
|
CONTEXT context_record;
|
|
|
|
if (ctx)
|
|
|
|
{
|
|
|
|
context_record = *static_cast<CONTEXT*>(ctx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// use the current thread's context
|
|
|
|
RtlCaptureContext(&context_record);
|
|
|
|
}
|
2012-01-26 11:33:39 +01:00
|
|
|
|
2016-05-15 19:28:22 +02:00
|
|
|
int size = 0;
|
|
|
|
std::array<void*, 50> stack;
|
2012-01-26 11:33:39 +01:00
|
|
|
|
2016-12-12 02:24:26 +01:00
|
|
|
STACKFRAME64 stack_frame = {};
|
2016-05-15 19:28:22 +02:00
|
|
|
#if defined(_WIN64)
|
|
|
|
int const machine_type = IMAGE_FILE_MACHINE_AMD64;
|
|
|
|
stack_frame.AddrPC.Offset = context_record.Rip;
|
|
|
|
stack_frame.AddrFrame.Offset = context_record.Rbp;
|
|
|
|
stack_frame.AddrStack.Offset = context_record.Rsp;
|
|
|
|
#else
|
|
|
|
int const machine_type = IMAGE_FILE_MACHINE_I386;
|
|
|
|
stack_frame.AddrPC.Offset = context_record.Eip;
|
|
|
|
stack_frame.AddrFrame.Offset = context_record.Ebp;
|
|
|
|
stack_frame.AddrStack.Offset = context_record.Esp;
|
|
|
|
#endif
|
|
|
|
stack_frame.AddrPC.Mode = AddrModeFlat;
|
|
|
|
stack_frame.AddrFrame.Mode = AddrModeFlat;
|
|
|
|
stack_frame.AddrStack.Mode = AddrModeFlat;
|
|
|
|
while (StackWalk64(machine_type,
|
|
|
|
GetCurrentProcess(),
|
|
|
|
GetCurrentThread(),
|
|
|
|
&stack_frame,
|
|
|
|
&context_record,
|
|
|
|
nullptr,
|
|
|
|
&SymFunctionTableAccess64,
|
|
|
|
&SymGetModuleBase64,
|
2016-12-05 02:15:49 +01:00
|
|
|
nullptr) && size < int(stack.size()))
|
2012-01-26 11:33:39 +01:00
|
|
|
{
|
2016-05-15 19:28:22 +02:00
|
|
|
stack[size++] = reinterpret_cast<void*>(stack_frame.AddrPC.Offset);
|
2012-01-26 11:33:39 +01:00
|
|
|
}
|
|
|
|
|
2016-05-15 19:28:22 +02:00
|
|
|
struct symbol_bundle : SYMBOL_INFO
|
|
|
|
{
|
|
|
|
wchar_t name[MAX_SYM_NAME];
|
|
|
|
};
|
2012-01-26 11:33:39 +01:00
|
|
|
|
|
|
|
HANDLE p = GetCurrentProcess();
|
|
|
|
static bool sym_initialized = false;
|
|
|
|
if (!sym_initialized)
|
|
|
|
{
|
|
|
|
sym_initialized = true;
|
2016-06-20 17:32:06 +02:00
|
|
|
SymInitialize(p, nullptr, true);
|
2012-01-26 11:33:39 +01:00
|
|
|
}
|
2016-05-15 19:28:22 +02:00
|
|
|
SymRefreshModuleList(p);
|
|
|
|
for (int i = 0; i < size && len > 0; ++i)
|
2012-01-26 11:33:39 +01:00
|
|
|
{
|
2016-05-15 19:28:22 +02:00
|
|
|
DWORD_PTR frame_ptr = reinterpret_cast<DWORD_PTR>(stack[i]);
|
|
|
|
|
|
|
|
DWORD64 displacement = 0;
|
|
|
|
symbol_bundle symbol;
|
|
|
|
symbol.MaxNameLen = MAX_SYM_NAME;
|
|
|
|
symbol.SizeOfStruct = sizeof(SYMBOL_INFO);
|
|
|
|
BOOL const has_symbol = SymFromAddr(p, frame_ptr, &displacement, &symbol);
|
|
|
|
|
|
|
|
DWORD line_displacement = 0;
|
|
|
|
IMAGEHLP_LINE64 line = {};
|
|
|
|
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
|
|
|
|
BOOL const has_line = SymGetLineFromAddr64(GetCurrentProcess(), frame_ptr,
|
|
|
|
&line_displacement, &line);
|
|
|
|
|
2016-05-17 15:24:06 +02:00
|
|
|
int ret = std::snprintf(out, len, "%2d: %p", i, stack[i]);
|
2016-05-15 19:28:22 +02:00
|
|
|
out += ret; len -= ret; if (len <= 0) break;
|
|
|
|
|
|
|
|
if (has_symbol)
|
|
|
|
{
|
2016-05-17 15:24:06 +02:00
|
|
|
ret = std::snprintf(out, len, " %s +%-4" PRId64
|
2016-05-15 21:40:53 +02:00
|
|
|
, demangle(symbol.Name).c_str(), displacement);
|
2016-05-15 19:28:22 +02:00
|
|
|
out += ret; len -= ret; if (len <= 0) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_line)
|
|
|
|
{
|
2016-05-17 15:24:06 +02:00
|
|
|
ret = std::snprintf(out, len, " %s:%d"
|
2016-12-13 16:30:36 +01:00
|
|
|
, line.FileName, int(line.LineNumber));
|
2016-05-15 19:28:22 +02:00
|
|
|
out += ret; len -= ret; if (len <= 0) break;
|
|
|
|
}
|
|
|
|
|
2012-01-26 11:33:39 +01:00
|
|
|
|
2016-05-17 15:24:06 +02:00
|
|
|
ret = std::snprintf(out, len, "\n");
|
2012-01-26 11:33:39 +01:00
|
|
|
out += ret;
|
|
|
|
len -= ret;
|
2016-05-15 19:28:22 +02:00
|
|
|
|
2012-04-01 02:42:31 +02:00
|
|
|
if (i == max_depth && max_depth > 0) break;
|
2012-01-26 11:33:39 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-13 21:59:50 +02:00
|
|
|
}
|
2012-01-26 11:33:39 +01:00
|
|
|
|
2008-12-19 07:12:55 +01:00
|
|
|
#else
|
|
|
|
|
2018-05-13 21:59:50 +02:00
|
|
|
namespace libtorrent {
|
|
|
|
|
2016-05-15 19:28:22 +02:00
|
|
|
TORRENT_EXPORT void print_backtrace(char* out, int len, int /*max_depth*/, void* /* ctx */)
|
2015-06-20 22:36:23 +02:00
|
|
|
{
|
|
|
|
out[0] = 0;
|
2017-04-12 05:53:13 +02:00
|
|
|
std::strncat(out, "<not supported>", std::size_t(len));
|
2015-06-20 22:36:23 +02:00
|
|
|
}
|
2008-12-19 07:12:55 +01:00
|
|
|
|
2018-05-13 21:59:50 +02:00
|
|
|
}
|
|
|
|
|
2007-09-17 04:32:51 +02:00
|
|
|
#endif
|
2007-08-20 06:58:56 +02:00
|
|
|
|
2014-01-08 06:45:13 +01:00
|
|
|
#endif
|
|
|
|
|
2018-05-22 10:01:45 +02:00
|
|
|
#if (TORRENT_USE_ASSERTS || defined TORRENT_ASIO_DEBUGGING) && \
|
|
|
|
defined TORRENT_PRODUCTION_ASSERTS
|
2010-05-16 07:26:43 +02:00
|
|
|
char const* libtorrent_assert_log = "asserts.log";
|
2015-08-21 22:56:57 +02:00
|
|
|
namespace {
|
2013-03-28 00:41:04 +01:00
|
|
|
// the number of asserts we've printed to the log
|
2016-05-01 09:38:35 +02:00
|
|
|
std::atomic<int> assert_counter(0);
|
2015-08-21 22:56:57 +02:00
|
|
|
}
|
2010-05-16 07:26:43 +02:00
|
|
|
#endif
|
|
|
|
|
2018-05-22 10:01:45 +02:00
|
|
|
namespace libtorrent {
|
|
|
|
|
|
|
|
#if TORRENT_USE_ASSERTS || defined TORRENT_ASIO_DEBUGGING
|
|
|
|
|
2015-05-10 07:11:51 +02:00
|
|
|
TORRENT_FORMAT(1,2)
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_EXPORT void assert_print(char const* fmt, ...)
|
2007-08-20 06:58:56 +02:00
|
|
|
{
|
2015-04-18 04:33:39 +02:00
|
|
|
#ifdef TORRENT_PRODUCTION_ASSERTS
|
2014-07-06 21:18:00 +02:00
|
|
|
if (assert_counter > 500) return;
|
2013-03-28 00:41:04 +01:00
|
|
|
|
2010-05-16 07:26:43 +02:00
|
|
|
FILE* out = fopen(libtorrent_assert_log, "a+");
|
2018-04-02 00:03:43 +02:00
|
|
|
if (out == nullptr) out = stderr;
|
2010-05-06 04:18:08 +02:00
|
|
|
#else
|
|
|
|
FILE* out = stderr;
|
|
|
|
#endif
|
2014-07-06 21:18:00 +02:00
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2017-09-12 23:10:11 +02:00
|
|
|
std::vfprintf(out, fmt, va);
|
2014-07-06 21:18:00 +02:00
|
|
|
va_end(va);
|
|
|
|
|
2015-04-18 04:33:39 +02:00
|
|
|
#ifdef TORRENT_PRODUCTION_ASSERTS
|
2014-07-06 21:18:00 +02:00
|
|
|
if (out != stderr) fclose(out);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-11 06:48:13 +02:00
|
|
|
// we deliberately don't want asserts to be marked as no-return, since that
|
|
|
|
// would trigger warnings in debug builds of any code coming after the assert
|
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
2015-08-21 22:56:57 +02:00
|
|
|
#endif
|
2016-06-11 06:48:13 +02:00
|
|
|
|
2015-08-21 22:56:57 +02:00
|
|
|
TORRENT_EXPORT void assert_fail(char const* expr, int line
|
2015-04-18 04:33:39 +02:00
|
|
|
, char const* file, char const* function, char const* value, int kind)
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
2015-04-18 04:33:39 +02:00
|
|
|
#ifdef TORRENT_PRODUCTION_ASSERTS
|
2014-07-06 21:18:00 +02:00
|
|
|
// no need to flood the assert log with infinite number of asserts
|
2014-08-01 09:32:54 +02:00
|
|
|
if (assert_counter.fetch_add(1) + 1 > 500) return;
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif
|
2010-05-06 04:18:08 +02:00
|
|
|
|
2011-04-15 10:37:27 +02:00
|
|
|
char stack[8192];
|
2013-09-04 07:50:40 +02:00
|
|
|
stack[0] = '\0';
|
2012-04-01 02:42:31 +02:00
|
|
|
print_backtrace(stack, sizeof(stack), 0);
|
2011-04-15 10:37:27 +02:00
|
|
|
|
2014-03-23 08:40:43 +01:00
|
|
|
char const* message = "assertion failed. Please file a bugreport at "
|
2015-06-20 06:13:38 +02:00
|
|
|
"https://github.com/arvidn/libtorrent/issues\n"
|
2007-08-20 06:58:56 +02:00
|
|
|
"Please include the following information:\n\n"
|
2015-11-16 04:36:55 +01:00
|
|
|
"version: " LIBTORRENT_VERSION "-" LIBTORRENT_REVISION "\n";
|
2014-03-23 08:40:43 +01:00
|
|
|
|
|
|
|
switch (kind)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
message = "A precondition of a libtorrent function has been violated.\n"
|
|
|
|
"This indicates a bug in the client application using libtorrent\n";
|
|
|
|
}
|
2015-05-31 18:14:46 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
assert_print("%s\n"
|
2015-04-18 04:33:39 +02:00
|
|
|
#ifdef TORRENT_PRODUCTION_ASSERTS
|
2014-07-06 21:18:00 +02:00
|
|
|
"#: %d\n"
|
|
|
|
#endif
|
2007-08-20 06:58:56 +02:00
|
|
|
"file: '%s'\n"
|
|
|
|
"line: %d\n"
|
2007-09-01 06:08:39 +02:00
|
|
|
"function: %s\n"
|
2010-09-25 19:46:13 +02:00
|
|
|
"expression: %s\n"
|
2011-04-15 10:37:27 +02:00
|
|
|
"%s%s\n"
|
|
|
|
"stack:\n"
|
|
|
|
"%s\n"
|
2014-07-06 21:18:00 +02:00
|
|
|
, message
|
2015-04-18 04:33:39 +02:00
|
|
|
#ifdef TORRENT_PRODUCTION_ASSERTS
|
2014-08-01 09:32:54 +02:00
|
|
|
, assert_counter.load()
|
2014-07-06 21:18:00 +02:00
|
|
|
#endif
|
|
|
|
, file, line, function, expr
|
2011-04-15 10:37:27 +02:00
|
|
|
, value ? value : "", value ? "\n" : ""
|
|
|
|
, stack);
|
2007-08-20 06:58:56 +02:00
|
|
|
|
2010-05-06 04:18:08 +02:00
|
|
|
// if production asserts are defined, don't abort, just print the error
|
2014-07-06 21:18:00 +02:00
|
|
|
#ifndef TORRENT_PRODUCTION_ASSERTS
|
2017-08-05 01:30:22 +02:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
// SIGINT doesn't trigger a break with msvc
|
|
|
|
DebugBreak();
|
|
|
|
#else
|
2015-05-31 18:14:46 +02:00
|
|
|
// send SIGINT to the current process
|
|
|
|
// to break into the debugger
|
2017-09-29 17:30:52 +02:00
|
|
|
::raise(SIGABRT);
|
2017-08-05 01:30:22 +02:00
|
|
|
#endif
|
2017-09-12 23:10:11 +02:00
|
|
|
::abort();
|
2010-05-06 04:18:08 +02:00
|
|
|
#endif
|
2007-08-20 06:58:56 +02:00
|
|
|
}
|
|
|
|
|
2016-06-11 06:48:13 +02:00
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2015-09-02 07:30:40 +02:00
|
|
|
#elif !TORRENT_USE_ASSERTS
|
2007-10-05 02:30:00 +02:00
|
|
|
|
2015-09-02 07:30:40 +02:00
|
|
|
// these are just here to make it possible for a client that built with debug
|
|
|
|
// enable to be able to link against a release build (just possible, not
|
|
|
|
// necessarily supported)
|
2015-05-10 07:11:51 +02:00
|
|
|
TORRENT_FORMAT(1,2)
|
2015-04-19 15:18:54 +02:00
|
|
|
TORRENT_EXPORT void assert_print(char const*, ...) {}
|
2015-04-22 02:59:35 +02:00
|
|
|
TORRENT_EXPORT void assert_fail(char const*, int, char const*
|
2015-04-19 15:18:54 +02:00
|
|
|
, char const*, char const*, int) {}
|
2007-10-05 02:30:00 +02:00
|
|
|
|
2007-08-20 06:58:56 +02:00
|
|
|
#endif
|
2018-05-13 21:59:50 +02:00
|
|
|
|
|
|
|
} // libtorrent namespace
|
|
|
|
|