2023-12-31 01:00:00 +01:00
|
|
|
// Copyright (c) 2014-2023 The Dash Core developers
|
2019-02-21 19:37:16 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-12-21 22:24:39 +01:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
2022-08-02 18:34:58 +02:00
|
|
|
#include <config/bitcoin-config.h>
|
2020-12-21 22:24:39 +01:00
|
|
|
#endif // HAVE_CONFIG_H
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <stacktraces.h>
|
|
|
|
#include <fs.h>
|
2021-02-04 01:48:30 +01:00
|
|
|
#include <logging.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <streams.h>
|
2021-06-09 14:02:42 +02:00
|
|
|
#include <threadsafety.h>
|
2021-06-27 08:33:13 +02:00
|
|
|
#include <util/strencodings.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
|
2019-02-21 19:37:16 +01:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
#include <atomic>
|
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(WIN32)
|
2019-02-21 19:37:16 +01:00
|
|
|
#include <windows.h>
|
|
|
|
#include <dbghelp.h>
|
2021-04-15 19:58:04 +02:00
|
|
|
#include <thread>
|
2019-02-21 19:37:16 +01:00
|
|
|
#else
|
2020-12-01 05:18:46 +01:00
|
|
|
#ifdef ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
#include <execinfo.h>
|
2020-12-01 05:18:46 +01:00
|
|
|
#endif
|
2019-02-21 19:37:16 +01:00
|
|
|
#include <unistd.h>
|
2021-04-15 19:58:04 +02:00
|
|
|
#include <csignal>
|
2019-02-21 19:37:16 +01:00
|
|
|
#endif
|
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if !defined(WIN32)
|
2019-02-21 19:37:16 +01:00
|
|
|
#include <dlfcn.h>
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if !defined(__APPLE__)
|
2019-07-02 06:16:11 +02:00
|
|
|
#include <link.h>
|
|
|
|
#endif
|
2019-02-21 19:37:16 +01:00
|
|
|
#endif
|
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(__APPLE__)
|
2019-02-21 19:37:16 +01:00
|
|
|
#include <mach-o/dyld.h>
|
2019-07-02 06:16:11 +02:00
|
|
|
#include <mach/mach_init.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <mach/mach_vm.h>
|
2019-02-21 19:37:16 +01:00
|
|
|
#endif
|
|
|
|
|
2020-12-01 05:18:46 +01:00
|
|
|
#ifdef ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
#include <backtrace.h>
|
2020-12-01 05:18:46 +01:00
|
|
|
#endif
|
|
|
|
|
2021-04-15 19:58:04 +02:00
|
|
|
#include <cstring>
|
2019-02-21 19:37:16 +01:00
|
|
|
|
2019-02-26 07:01:56 +01:00
|
|
|
std::string DemangleSymbol(const std::string& name)
|
|
|
|
{
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
2019-02-26 07:01:56 +01:00
|
|
|
int status = -4; // some arbitrary value to eliminate the compiler warning
|
|
|
|
char* str = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status);
|
|
|
|
if (status != 0) {
|
|
|
|
free(str);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
std::string ret = str;
|
|
|
|
free(str);
|
|
|
|
return ret;
|
|
|
|
#else
|
|
|
|
// TODO other platforms/compilers
|
|
|
|
return name;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-02-21 19:37:16 +01:00
|
|
|
// set to true when the abort signal should not handled
|
|
|
|
// this is the case when the terminate handler or an assert already handled the exception
|
|
|
|
static std::atomic<bool> skipAbortSignal(false);
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
static ssize_t GetExeFileNameImpl(char* buf, size_t bufSize)
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(WIN32)
|
2019-02-21 19:37:16 +01:00
|
|
|
std::vector<TCHAR> tmp(bufSize);
|
2019-08-06 05:08:33 +02:00
|
|
|
DWORD len = GetModuleFileName(nullptr, tmp.data(), bufSize);
|
2019-02-21 19:37:16 +01:00
|
|
|
if (len >= bufSize) {
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
buf[i] = (char)tmp[i];
|
|
|
|
}
|
|
|
|
return len;
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#elif defined(__APPLE__)
|
2019-02-21 19:37:16 +01:00
|
|
|
uint32_t bufSize2 = (uint32_t)bufSize;
|
|
|
|
if (_NSGetExecutablePath(buf, &bufSize2) != 0) {
|
|
|
|
// it's not entirely clear if the value returned by _NSGetExecutablePath includes the null character
|
|
|
|
return bufSize2 + 1;
|
|
|
|
}
|
|
|
|
// TODO do we have to call realpath()? The path returned by _NSGetExecutablePath may include ., .. symbolic links
|
|
|
|
return strlen(buf);
|
|
|
|
#else
|
|
|
|
ssize_t len = readlink("/proc/self/exe", buf, bufSize - 1);
|
|
|
|
if (len == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
static std::string GetExeFileName()
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
|
|
|
std::vector<char> buf(1024);
|
|
|
|
while (true) {
|
|
|
|
ssize_t len = GetExeFileNameImpl(buf.data(), buf.size());
|
|
|
|
if (len < 0) {
|
|
|
|
return "";
|
|
|
|
}
|
2022-02-11 17:15:26 +01:00
|
|
|
if (len < int64_t(buf.size())) {
|
2019-02-21 19:37:16 +01:00
|
|
|
return std::string(buf.begin(), buf.begin() + len);
|
|
|
|
}
|
|
|
|
buf.resize(buf.size() * 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
static std::string g_exeFileName = GetExeFileName();
|
|
|
|
static std::string g_exeFileBaseName = fs::path(g_exeFileName).filename().string();
|
|
|
|
|
2020-12-01 05:18:46 +01:00
|
|
|
#ifdef ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
static void my_backtrace_error_callback (void *data, const char *msg,
|
|
|
|
int errnum)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static backtrace_state* GetLibBacktraceState()
|
|
|
|
{
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(WIN32)
|
2019-07-02 06:16:11 +02:00
|
|
|
// libbacktrace is not able to handle the DWARF debuglink in the .exe
|
|
|
|
// but luckily we can just specify the .dbg file here as it's a valid PE/XCOFF file
|
|
|
|
static std::string debugFileName = g_exeFileName + ".dbg";
|
|
|
|
static const char* exeFileNamePtr = fs::exists(debugFileName) ? debugFileName.c_str() : g_exeFileName.c_str();
|
|
|
|
#else
|
|
|
|
static const char* exeFileNamePtr = g_exeFileName.empty() ? nullptr : g_exeFileName.c_str();
|
|
|
|
#endif
|
2019-08-06 05:08:33 +02:00
|
|
|
static backtrace_state* st = backtrace_create_state(exeFileNamePtr, 1, my_backtrace_error_callback, nullptr);
|
2019-02-21 19:37:16 +01:00
|
|
|
return st;
|
|
|
|
}
|
2020-12-01 05:18:46 +01:00
|
|
|
#endif // ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(WIN32)
|
2019-07-02 06:16:11 +02:00
|
|
|
static uint64_t GetBaseAddress()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-21 19:37:16 +01:00
|
|
|
// PC addresses returned by StackWalk64 are in the real mapped space, while libbacktrace expects them to be in the
|
|
|
|
// default mapped space starting at 0x400000. This method converts the address.
|
|
|
|
// TODO this is probably the same reason libbacktrace is not able to gather the stacktrace on Windows (returns pointers like 0x1 or 0xfffffff)
|
|
|
|
// If they ever fix this problem, we might end up converting to invalid addresses here
|
2019-07-02 06:16:11 +02:00
|
|
|
static uint64_t ConvertAddress(uint64_t addr)
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
|
|
|
|
if (!VirtualQuery((PVOID)addr, &mbi, sizeof(mbi)))
|
|
|
|
return 0;
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
uint64_t hMod = (uint64_t)mbi.AllocationBase;
|
|
|
|
uint64_t offset = addr - hMod;
|
2019-02-21 19:37:16 +01:00
|
|
|
return 0x400000 + offset;
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
static __attribute__((noinline)) std::vector<uint64_t> GetStackFrames(size_t skip, size_t max_frames, const CONTEXT* pContext = nullptr)
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
2020-12-01 05:18:46 +01:00
|
|
|
#ifdef ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
// We can't use libbacktrace for stack unwinding on Windows as it returns invalid addresses (like 0x1 or 0xffffffff)
|
2019-08-06 05:08:33 +02:00
|
|
|
static BOOL symInitialized = SymInitialize(GetCurrentProcess(), nullptr, TRUE);
|
2019-02-21 19:37:16 +01:00
|
|
|
|
|
|
|
// dbghelp is not thread safe
|
2021-06-09 14:02:42 +02:00
|
|
|
static StdMutex m;
|
|
|
|
StdLockGuard l(m);
|
2019-02-21 19:37:16 +01:00
|
|
|
|
|
|
|
HANDLE process = GetCurrentProcess();
|
|
|
|
HANDLE thread = GetCurrentThread();
|
|
|
|
|
|
|
|
CONTEXT context;
|
|
|
|
if (!pContext) {
|
|
|
|
memset(&context, 0, sizeof(CONTEXT));
|
|
|
|
context.ContextFlags = CONTEXT_FULL;
|
|
|
|
RtlCaptureContext(&context);
|
|
|
|
} else {
|
|
|
|
memcpy(&context, pContext, sizeof(CONTEXT));
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD image;
|
|
|
|
STACKFRAME64 stackframe;
|
|
|
|
ZeroMemory(&stackframe, sizeof(STACKFRAME64));
|
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(__i386__)
|
2019-02-21 19:37:16 +01:00
|
|
|
image = IMAGE_FILE_MACHINE_I386;
|
|
|
|
stackframe.AddrPC.Offset = context.Eip;
|
|
|
|
stackframe.AddrPC.Mode = AddrModeFlat;
|
|
|
|
stackframe.AddrFrame.Offset = context.Ebp;
|
|
|
|
stackframe.AddrFrame.Mode = AddrModeFlat;
|
|
|
|
stackframe.AddrStack.Offset = context.Esp;
|
|
|
|
stackframe.AddrStack.Mode = AddrModeFlat;
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#elif defined(__x86_64__)
|
2019-02-21 19:37:16 +01:00
|
|
|
image = IMAGE_FILE_MACHINE_AMD64;
|
|
|
|
stackframe.AddrPC.Offset = context.Rip;
|
|
|
|
stackframe.AddrPC.Mode = AddrModeFlat;
|
|
|
|
stackframe.AddrFrame.Offset = context.Rbp;
|
|
|
|
stackframe.AddrFrame.Mode = AddrModeFlat;
|
|
|
|
stackframe.AddrStack.Offset = context.Rsp;
|
|
|
|
stackframe.AddrStack.Mode = AddrModeFlat;
|
|
|
|
if (!pContext) {
|
|
|
|
skip++; // skip this method
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#error unsupported architecture
|
|
|
|
#endif
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
std::vector<uint64_t> ret;
|
2019-02-21 19:37:16 +01:00
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
while (ret.size() < max_frames) {
|
|
|
|
BOOL result = StackWalk64(
|
|
|
|
image, process, thread,
|
2019-08-06 05:08:33 +02:00
|
|
|
&stackframe, &context, nullptr,
|
|
|
|
SymFunctionTableAccess64, SymGetModuleBase64, nullptr);
|
2019-02-21 19:37:16 +01:00
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= skip) {
|
2019-07-02 06:16:11 +02:00
|
|
|
uint64_t pc = ConvertAddress(stackframe.AddrPC.Offset);
|
2019-02-21 19:37:16 +01:00
|
|
|
if (pc == 0) {
|
|
|
|
pc = stackframe.AddrPC.Offset;
|
|
|
|
}
|
|
|
|
ret.emplace_back(pc);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2020-12-01 05:18:46 +01:00
|
|
|
#else
|
|
|
|
return {};
|
|
|
|
#endif // ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
#else
|
2019-07-02 06:16:11 +02:00
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(__APPLE__)
|
2019-07-02 06:16:11 +02:00
|
|
|
static uint64_t GetBaseAddress()
|
|
|
|
{
|
|
|
|
mach_port_name_t target_task;
|
|
|
|
vm_map_offset_t vmoffset;
|
|
|
|
vm_map_size_t vmsize;
|
|
|
|
uint32_t nesting_depth = 0;
|
|
|
|
struct vm_region_submap_info_64 vbr;
|
|
|
|
mach_msg_type_number_t vbrcount = 16;
|
|
|
|
kern_return_t kr;
|
|
|
|
|
|
|
|
kr = task_for_pid(mach_task_self(), getpid(), &target_task);
|
|
|
|
if (kr != KERN_SUCCESS) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
kr = mach_vm_region_recurse(target_task, &vmoffset, &vmsize, &nesting_depth, (vm_region_recurse_info_t)&vbr, &vbrcount);
|
|
|
|
if (kr != KERN_SUCCESS) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vmoffset;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int dl_iterate_callback(struct dl_phdr_info* info, size_t s, void* data)
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
2022-08-11 01:05:44 +02:00
|
|
|
uint64_t* p = reinterpret_cast<uint64_t*>(data);
|
2019-08-06 05:08:33 +02:00
|
|
|
if (info->dlpi_name == nullptr || info->dlpi_name[0] == '\0') {
|
2019-07-02 06:16:11 +02:00
|
|
|
*p = info->dlpi_addr;
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
2020-03-01 14:24:48 +01:00
|
|
|
return 0;
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
static uint64_t GetBaseAddress()
|
|
|
|
{
|
|
|
|
uint64_t basePtr = 0;
|
|
|
|
dl_iterate_phdr(dl_iterate_callback, &basePtr);
|
|
|
|
return basePtr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static __attribute__((noinline)) std::vector<uint64_t> GetStackFrames(size_t skip, size_t max_frames)
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
2020-12-01 05:18:46 +01:00
|
|
|
#ifdef ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
// FYI, this is not using libbacktrace, but "backtrace()" from <execinfo.h>
|
|
|
|
std::vector<void*> buf(max_frames);
|
|
|
|
int count = backtrace(buf.data(), (int)buf.size());
|
|
|
|
if (count == 0) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
buf.resize((size_t)count);
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
std::vector<uint64_t> ret;
|
2019-02-21 19:37:16 +01:00
|
|
|
ret.reserve(count);
|
|
|
|
for (size_t i = skip + 1; i < buf.size(); i++) {
|
2019-07-02 06:16:11 +02:00
|
|
|
ret.emplace_back((uint64_t) buf[i]);
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
return ret;
|
2020-12-01 05:18:46 +01:00
|
|
|
#else
|
|
|
|
return {};
|
|
|
|
#endif // ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct stackframe_info {
|
2019-07-02 06:16:11 +02:00
|
|
|
uint64_t pc{0};
|
2019-02-21 19:37:16 +01:00
|
|
|
std::string filename;
|
2019-07-02 06:16:11 +02:00
|
|
|
int lineno{-1};
|
2019-02-21 19:37:16 +01:00
|
|
|
std::string function;
|
2019-07-02 06:16:11 +02:00
|
|
|
|
2021-05-27 17:17:29 +02:00
|
|
|
SERIALIZE_METHODS(stackframe_info, obj)
|
2019-07-02 06:16:11 +02:00
|
|
|
{
|
2021-05-27 17:17:29 +02:00
|
|
|
READWRITE(obj.pc, obj.filename, obj.lineno, obj.function);
|
2019-07-02 06:16:11 +02:00
|
|
|
}
|
2019-02-21 19:37:16 +01:00
|
|
|
};
|
|
|
|
|
2020-12-01 05:18:46 +01:00
|
|
|
#ifdef ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
static int my_backtrace_full_callback (void *data, uintptr_t pc, const char *filename, int lineno, const char *function)
|
|
|
|
{
|
|
|
|
auto sis = (std::vector<stackframe_info>*)data;
|
|
|
|
stackframe_info si;
|
|
|
|
si.pc = pc;
|
|
|
|
si.lineno = lineno;
|
|
|
|
if (filename) {
|
|
|
|
si.filename = filename;
|
|
|
|
}
|
|
|
|
if (function) {
|
|
|
|
si.function = DemangleSymbol(function);
|
|
|
|
}
|
|
|
|
sis->emplace_back(si);
|
|
|
|
if (sis->size() >= 128) {
|
|
|
|
// abort
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (si.function == "mainCRTStartup" ||
|
|
|
|
si.function == "pthread_create_wrapper" ||
|
|
|
|
si.function == "__tmainCRTStartup") {
|
|
|
|
// on Windows, stack frames are unwinded into invalid PCs after entry points
|
|
|
|
// this doesn't catch all cases unfortunately
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
static std::vector<stackframe_info> GetStackFrameInfos(const std::vector<uint64_t>& stackframes)
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
|
|
|
std::vector<stackframe_info> infos;
|
|
|
|
infos.reserve(stackframes.size());
|
|
|
|
|
2021-04-15 19:58:04 +02:00
|
|
|
for (uint64_t stackframe : stackframes) {
|
|
|
|
if (backtrace_pcinfo(GetLibBacktraceState(), stackframe, my_backtrace_full_callback, my_backtrace_error_callback, &infos)) {
|
2019-02-21 19:37:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return infos;
|
|
|
|
}
|
2020-12-01 05:18:46 +01:00
|
|
|
#else
|
|
|
|
static std::vector<stackframe_info> GetStackFrameInfos(const std::vector<uint64_t>& stackframes)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
#endif // ENABLE_STACKTRACES
|
2019-02-21 19:37:16 +01:00
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
struct crash_info_header
|
|
|
|
{
|
|
|
|
std::string magic;
|
2022-08-11 01:05:44 +02:00
|
|
|
uint16_t version{0};
|
2019-07-02 06:16:11 +02:00
|
|
|
std::string exeFileName;
|
|
|
|
|
2021-05-27 17:17:29 +02:00
|
|
|
SERIALIZE_METHODS(crash_info_header, obj)
|
2019-07-02 06:16:11 +02:00
|
|
|
{
|
2021-05-27 17:17:29 +02:00
|
|
|
READWRITE(obj.magic, obj.version, obj.exeFileName);
|
2019-07-02 06:16:11 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct crash_info
|
|
|
|
{
|
|
|
|
std::string crashDescription;
|
|
|
|
std::vector<uint64_t> stackframes;
|
|
|
|
std::vector<stackframe_info> stackframeInfos;
|
|
|
|
|
2021-05-27 17:17:29 +02:00
|
|
|
SERIALIZE_METHODS(crash_info, obj)
|
2019-07-02 06:16:11 +02:00
|
|
|
{
|
2021-05-27 17:17:29 +02:00
|
|
|
READWRITE(obj.crashDescription, obj.stackframes, obj.stackframeInfos);
|
2019-07-02 06:16:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertAddresses(int64_t offset)
|
|
|
|
{
|
|
|
|
for (auto& sf : stackframes) {
|
|
|
|
sf += offset;
|
|
|
|
}
|
|
|
|
for (auto& sfi : stackframeInfos) {
|
|
|
|
sfi.pc += offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::string GetCrashInfoStrNoDebugInfo(crash_info ci)
|
|
|
|
{
|
|
|
|
static uint64_t basePtr = GetBaseAddress();
|
|
|
|
|
|
|
|
CDataStream ds(SER_DISK, 0);
|
|
|
|
|
|
|
|
crash_info_header hdr;
|
|
|
|
hdr.magic = "DashCrashInfo";
|
|
|
|
hdr.version = 1;
|
|
|
|
hdr.exeFileName = g_exeFileBaseName;
|
|
|
|
ds << hdr;
|
|
|
|
|
|
|
|
ci.ConvertAddresses(-(int64_t)basePtr);
|
|
|
|
ds << ci;
|
|
|
|
|
2020-08-07 19:55:51 +02:00
|
|
|
auto ciStr = EncodeBase32(ds.str());
|
2019-07-02 06:16:11 +02:00
|
|
|
std::string s = ci.crashDescription + "\n";
|
|
|
|
s += strprintf("No debug information available for stacktrace. You should add debug information and then run:\n"
|
|
|
|
"%s -printcrashinfo=%s\n", g_exeFileBaseName, ciStr);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string GetCrashInfoStr(const crash_info& ci, size_t spaces = 2);
|
|
|
|
|
|
|
|
std::string GetCrashInfoStrFromSerializedStr(const std::string& ciStr)
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
2019-07-02 06:16:11 +02:00
|
|
|
static uint64_t basePtr = GetBaseAddress();
|
|
|
|
|
|
|
|
bool dataInvalid = false;
|
|
|
|
auto buf = DecodeBase32(ciStr.c_str(), &dataInvalid);
|
|
|
|
if (buf.empty() || dataInvalid) {
|
|
|
|
return "Error while deserializing crash info";
|
|
|
|
}
|
|
|
|
|
|
|
|
CDataStream ds(buf, SER_DISK, 0);
|
|
|
|
|
|
|
|
crash_info_header hdr;
|
|
|
|
try {
|
|
|
|
ds >> hdr;
|
|
|
|
} catch (...) {
|
|
|
|
return "Error while deserializing crash info header";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hdr.magic != "DashCrashInfo") {
|
|
|
|
return "Invalid magic string";
|
|
|
|
}
|
|
|
|
if (hdr.version != 1) {
|
|
|
|
return "Unsupported version";
|
|
|
|
}
|
|
|
|
if (hdr.exeFileName != g_exeFileBaseName) {
|
|
|
|
return "Crash info is not for this executable";
|
|
|
|
}
|
|
|
|
|
|
|
|
crash_info ci;
|
|
|
|
try {
|
|
|
|
ds >> ci;
|
|
|
|
} catch (...) {
|
|
|
|
return "Error while deserializing crash info";
|
|
|
|
}
|
|
|
|
|
|
|
|
ci.ConvertAddresses(basePtr);
|
|
|
|
|
|
|
|
if (ci.stackframeInfos.empty()) {
|
|
|
|
std::vector<uint64_t> stackframes(ci.stackframes.begin(), ci.stackframes.end());
|
|
|
|
ci.stackframeInfos = GetStackFrameInfos(stackframes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetCrashInfoStr(ci);
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string GetCrashInfoStr(const crash_info& ci, size_t spaces)
|
|
|
|
{
|
|
|
|
if (ci.stackframeInfos.empty()) {
|
|
|
|
return GetCrashInfoStrNoDebugInfo(ci);
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string sp;
|
|
|
|
for (size_t i = 0; i < spaces; i++) {
|
|
|
|
sp += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> lstrs;
|
2019-07-02 06:16:11 +02:00
|
|
|
lstrs.reserve(ci.stackframeInfos.size());
|
2019-02-21 19:37:16 +01:00
|
|
|
|
2021-04-15 19:58:04 +02:00
|
|
|
for (const auto& si : ci.stackframeInfos) {
|
2019-02-21 19:37:16 +01:00
|
|
|
std::string lstr;
|
|
|
|
if (!si.filename.empty()) {
|
2019-07-02 06:16:11 +02:00
|
|
|
lstr += fs::path(si.filename).filename().string();
|
2019-02-21 19:37:16 +01:00
|
|
|
} else {
|
|
|
|
lstr += "<unknown-file>";
|
|
|
|
}
|
|
|
|
if (si.lineno != 0) {
|
|
|
|
lstr += strprintf(":%d", si.lineno);
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrs.emplace_back(lstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get max "filename:line" length so we can better format it
|
|
|
|
size_t lstrlen = std::max_element(lstrs.begin(), lstrs.end(), [](const std::string& a, const std::string& b) { return a.size() < b.size(); })->size();
|
|
|
|
|
|
|
|
std::string fmtStr = strprintf("%%2d#: (0x%%08X) %%-%ds - %%s\n", lstrlen);
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
std::string s = ci.crashDescription + "\n";
|
|
|
|
for (size_t i = 0; i < ci.stackframeInfos.size(); i++) {
|
|
|
|
auto& si = ci.stackframeInfos[i];
|
2019-02-21 19:37:16 +01:00
|
|
|
|
|
|
|
auto& lstr = lstrs[i];
|
|
|
|
|
|
|
|
std::string fstr;
|
|
|
|
if (!si.function.empty()) {
|
|
|
|
fstr = si.function;
|
|
|
|
} else {
|
|
|
|
fstr = "???";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string s2 = strprintf(fmtStr, i, si.pc, lstr, fstr);
|
|
|
|
|
|
|
|
s += sp;
|
|
|
|
s += s2;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
static void PrintCrashInfo(const crash_info& ci)
|
|
|
|
{
|
|
|
|
auto str = GetCrashInfoStr(ci);
|
2020-06-12 07:01:11 +02:00
|
|
|
LogPrintf("%s", str); /* Continued */
|
2022-03-21 18:28:10 +01:00
|
|
|
tfm::format(std::cerr, "%s", str);
|
2019-07-02 06:16:11 +02:00
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_CRASH_HOOKS
|
2021-06-09 14:02:42 +02:00
|
|
|
static StdMutex g_stacktraces_mutex;
|
2019-07-02 06:16:11 +02:00
|
|
|
static std::map<void*, std::shared_ptr<std::vector<uint64_t>>> g_stacktraces;
|
2019-02-21 19:37:16 +01:00
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#ifdef CRASH_HOOKS_WRAPPED_CXX_ABI
|
2019-02-21 19:37:16 +01:00
|
|
|
// These come in through -Wl,-wrap
|
|
|
|
extern "C" void* __real___cxa_allocate_exception(size_t thrown_size);
|
|
|
|
extern "C" void __real___cxa_free_exception(void * thrown_exception);
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(WIN32)
|
2019-02-21 19:37:16 +01:00
|
|
|
extern "C" void __real__assert(const char *assertion, const char *file, unsigned int line);
|
|
|
|
extern "C" void __real__wassert(const wchar_t *assertion, const wchar_t *file, unsigned int line);
|
|
|
|
#else
|
|
|
|
extern "C" void __real___assert_fail(const char *assertion, const char *file, unsigned int line, const char *function);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
// Clang does not support -Wl,-wrap, so we must use dlsym
|
|
|
|
// This is ok because at the same time Clang only supports dynamic linking to libc/libc++
|
|
|
|
extern "C" void* __real___cxa_allocate_exception(size_t thrown_size)
|
|
|
|
{
|
|
|
|
static auto f = (void*(*)(size_t))dlsym(RTLD_NEXT, "__cxa_allocate_exception");
|
|
|
|
return f(thrown_size);
|
|
|
|
}
|
|
|
|
extern "C" void __real___cxa_free_exception(void * thrown_exception)
|
|
|
|
{
|
|
|
|
static auto f = (void(*)(void*))dlsym(RTLD_NEXT, "__cxa_free_exception");
|
|
|
|
return f(thrown_exception);
|
|
|
|
}
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(__clang__) && defined(__APPLE__)
|
2019-02-21 19:37:16 +01:00
|
|
|
extern "C" void __attribute__((noreturn)) __real___assert_rtn(const char *function, const char *file, int line, const char *assertion)
|
|
|
|
{
|
|
|
|
static auto f = (void(__attribute__((noreturn)) *) (const char*, const char*, int, const char*))dlsym(RTLD_NEXT, "__assert_rtn");
|
|
|
|
f(function, file, line, assertion);
|
|
|
|
}
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#elif defined(WIN32)
|
2019-02-21 19:37:16 +01:00
|
|
|
#error not supported on WIN32 (no dlsym support)
|
|
|
|
#else
|
|
|
|
extern "C" void __real___assert_fail(const char *assertion, const char *file, unsigned int line, const char *function)
|
|
|
|
{
|
|
|
|
static auto f = (void(*)(const char*, const char*, unsigned int, const char*))dlsym(RTLD_NEXT, "__assert_fail");
|
|
|
|
f(assertion, file, line, function);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#ifdef CRASH_HOOKS_WRAPPED_CXX_ABI
|
2019-02-21 19:37:16 +01:00
|
|
|
#define WRAPPED_NAME(x) __wrap_##x
|
|
|
|
#else
|
|
|
|
#define WRAPPED_NAME(x) x
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern "C" void* __attribute__((noinline)) WRAPPED_NAME(__cxa_allocate_exception)(size_t thrown_size)
|
|
|
|
{
|
|
|
|
// grab the current stack trace and store it in the global exception->stacktrace map
|
|
|
|
auto localSt = GetStackFrames(1, 16);
|
|
|
|
|
|
|
|
// WARNING keep this as it is and don't try to optimize it (no std::move, no std::make_shared, ...)
|
|
|
|
// trying to optimize this will cause the optimizer to move the GetStackFrames() call deep into the stl libs
|
2019-07-02 06:16:11 +02:00
|
|
|
std::shared_ptr<std::vector<uint64_t>> st(new std::vector<uint64_t>(localSt));
|
2019-02-21 19:37:16 +01:00
|
|
|
|
|
|
|
void* p = __real___cxa_allocate_exception(thrown_size);
|
|
|
|
|
2021-06-09 14:02:42 +02:00
|
|
|
StdLockGuard l(g_stacktraces_mutex);
|
2019-02-21 19:37:16 +01:00
|
|
|
g_stacktraces.emplace(p, st);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void __attribute__((noinline)) WRAPPED_NAME(__cxa_free_exception)(void * thrown_exception)
|
|
|
|
{
|
|
|
|
__real___cxa_free_exception(thrown_exception);
|
|
|
|
|
2021-06-09 14:02:42 +02:00
|
|
|
StdLockGuard l(g_stacktraces_mutex);
|
2019-02-21 19:37:16 +01:00
|
|
|
g_stacktraces.erase(thrown_exception);
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
static __attribute__((noinline)) crash_info GetCrashInfoFromAssertion(const char* assertion, const char* file, int line, const char* function)
|
|
|
|
{
|
|
|
|
crash_info ci;
|
|
|
|
ci.stackframes = GetStackFrames(1, 16);
|
|
|
|
ci.crashDescription = "Assertion failure:";
|
|
|
|
if (assertion) {
|
|
|
|
ci.crashDescription += strprintf("\n assertion: %s", assertion);
|
|
|
|
}
|
|
|
|
if (file) {
|
|
|
|
ci.crashDescription += strprintf("\n file: %s, line: %d", file, line);
|
|
|
|
}
|
|
|
|
if (function) {
|
|
|
|
ci.crashDescription += strprintf("\n function: %s", function);
|
|
|
|
}
|
|
|
|
ci.stackframeInfos = GetStackFrameInfos(ci.stackframes);
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(__clang__) && defined(__APPLE__)
|
2019-02-21 19:37:16 +01:00
|
|
|
extern "C" void __attribute__((noinline)) WRAPPED_NAME(__assert_rtn)(const char *function, const char *file, int line, const char *assertion)
|
|
|
|
{
|
2019-07-02 06:16:11 +02:00
|
|
|
auto ci = GetCrashInfoFromAssertion(assertion, file, line, function);
|
|
|
|
PrintCrashInfo(ci);
|
2019-02-21 19:37:16 +01:00
|
|
|
skipAbortSignal = true;
|
|
|
|
__real___assert_rtn(function, file, line, assertion);
|
|
|
|
}
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#elif defined(WIN32)
|
2019-02-21 19:37:16 +01:00
|
|
|
extern "C" void __attribute__((noinline)) WRAPPED_NAME(_assert)(const char *assertion, const char *file, unsigned int line)
|
|
|
|
{
|
2019-07-02 06:16:11 +02:00
|
|
|
auto ci = GetCrashInfoFromAssertion(assertion, file, line, nullptr);
|
|
|
|
PrintCrashInfo(ci);
|
2019-02-21 19:37:16 +01:00
|
|
|
skipAbortSignal = true;
|
|
|
|
__real__assert(assertion, file, line);
|
|
|
|
}
|
|
|
|
extern "C" void __attribute__((noinline)) WRAPPED_NAME(_wassert)(const wchar_t *assertion, const wchar_t *file, unsigned int line)
|
|
|
|
{
|
2019-07-02 06:16:11 +02:00
|
|
|
auto ci = GetCrashInfoFromAssertion(
|
|
|
|
assertion ? std::string(assertion, assertion + wcslen(assertion)).c_str() : nullptr,
|
|
|
|
file ? std::string(file, file + wcslen(file)).c_str() : nullptr,
|
|
|
|
line, nullptr);
|
|
|
|
PrintCrashInfo(ci);
|
2019-02-21 19:37:16 +01:00
|
|
|
skipAbortSignal = true;
|
|
|
|
__real__wassert(assertion, file, line);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
extern "C" void __attribute__((noinline)) WRAPPED_NAME(__assert_fail)(const char *assertion, const char *file, unsigned int line, const char *function)
|
|
|
|
{
|
2019-07-02 06:16:11 +02:00
|
|
|
auto ci = GetCrashInfoFromAssertion(assertion, file, line, function);
|
|
|
|
PrintCrashInfo(ci);
|
2019-02-21 19:37:16 +01:00
|
|
|
skipAbortSignal = true;
|
|
|
|
__real___assert_fail(assertion, file, line, function);
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-02 06:16:11 +02:00
|
|
|
#endif //ENABLE_CRASH_HOOKS
|
2019-02-21 19:37:16 +01:00
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
static std::shared_ptr<std::vector<uint64_t>> GetExceptionStacktrace(const std::exception_ptr& e)
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
2019-07-02 06:16:11 +02:00
|
|
|
#ifdef ENABLE_CRASH_HOOKS
|
2019-02-21 19:37:16 +01:00
|
|
|
void* p = *(void**)&e;
|
|
|
|
|
2021-06-09 14:02:42 +02:00
|
|
|
StdLockGuard l(g_stacktraces_mutex);
|
2019-02-21 19:37:16 +01:00
|
|
|
auto it = g_stacktraces.find(p);
|
|
|
|
if (it == g_stacktraces.end()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return it->second;
|
|
|
|
#else
|
2019-07-02 06:16:11 +02:00
|
|
|
return {};
|
2019-02-21 19:37:16 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
crash_info GetCrashInfoFromException(const std::exception_ptr& e)
|
2019-02-21 19:37:16 +01:00
|
|
|
{
|
2019-07-02 06:16:11 +02:00
|
|
|
crash_info ci;
|
|
|
|
ci.crashDescription = "Exception: ";
|
|
|
|
|
2019-02-21 19:37:16 +01:00
|
|
|
if (!e) {
|
2019-07-02 06:16:11 +02:00
|
|
|
ci.crashDescription += "<null>";
|
|
|
|
return ci;
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string type;
|
|
|
|
std::string what;
|
|
|
|
|
2020-08-09 18:28:34 +02:00
|
|
|
auto getExceptionType = [&]() -> std::string {
|
2020-08-02 18:32:18 +02:00
|
|
|
auto type = abi::__cxa_current_exception_type();
|
|
|
|
if (type && (strlen(type->name()) > 0)) {
|
|
|
|
return DemangleSymbol(type->name());
|
|
|
|
}
|
2020-08-11 11:07:56 +02:00
|
|
|
return "<unknown>";
|
2020-08-02 18:32:18 +02:00
|
|
|
};
|
|
|
|
|
2019-02-21 19:37:16 +01:00
|
|
|
try {
|
|
|
|
// rethrow and catch the exception as there is no other way to reliably cast to the real type (not possible with RTTI)
|
|
|
|
std::rethrow_exception(e);
|
2021-12-28 22:54:50 +01:00
|
|
|
} catch (const std::exception& e2) {
|
2020-08-02 18:32:18 +02:00
|
|
|
type = getExceptionType();
|
2021-12-28 22:54:50 +01:00
|
|
|
what = GetExceptionWhat(e2);
|
|
|
|
} catch (const std::string& e2) {
|
2020-08-02 18:32:18 +02:00
|
|
|
type = getExceptionType();
|
2021-12-28 22:54:50 +01:00
|
|
|
what = GetExceptionWhat(e2);
|
|
|
|
} catch (const char* e2) {
|
2020-08-02 18:32:18 +02:00
|
|
|
type = getExceptionType();
|
2021-12-28 22:54:50 +01:00
|
|
|
what = GetExceptionWhat(e2);
|
|
|
|
} catch (int e2) {
|
2020-08-02 18:32:18 +02:00
|
|
|
type = getExceptionType();
|
2021-12-28 22:54:50 +01:00
|
|
|
what = GetExceptionWhat(e2);
|
2019-02-21 19:37:16 +01:00
|
|
|
} catch (...) {
|
2020-08-02 18:32:18 +02:00
|
|
|
type = getExceptionType();
|
2019-02-21 19:37:16 +01:00
|
|
|
what = "<unknown>";
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
ci.crashDescription += strprintf("type=%s, what=\"%s\"", type, what);
|
2019-02-21 19:37:16 +01:00
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
auto stackframes = GetExceptionStacktrace(e);
|
|
|
|
if (stackframes) {
|
|
|
|
ci.stackframes = *stackframes;
|
|
|
|
ci.stackframeInfos = GetStackFrameInfos(ci.stackframes);
|
|
|
|
}
|
2019-02-21 19:37:16 +01:00
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetPrettyExceptionStr(const std::exception_ptr& e)
|
|
|
|
{
|
|
|
|
return GetCrashInfoStr(GetCrashInfoFromException(e));
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void terminate_handler()
|
|
|
|
{
|
|
|
|
auto exc = std::current_exception();
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
crash_info ci;
|
2019-02-21 19:37:16 +01:00
|
|
|
|
|
|
|
if (exc) {
|
2019-07-02 06:16:11 +02:00
|
|
|
auto ci2 = GetCrashInfoFromException(exc);
|
|
|
|
ci.crashDescription = strprintf("std::terminate() called due to unhandled exception\n%s", ci2.crashDescription);
|
|
|
|
ci.stackframes = std::move(ci2.stackframes);
|
|
|
|
ci.stackframeInfos = std::move(ci2.stackframeInfos);
|
2019-02-21 19:37:16 +01:00
|
|
|
} else {
|
2019-07-02 06:16:11 +02:00
|
|
|
ci.crashDescription = "std::terminate() called due unknown reason";
|
|
|
|
ci.stackframes = GetStackFrames(0, 16);
|
2021-12-28 22:54:50 +01:00
|
|
|
ci.stackframeInfos = GetStackFrameInfos(ci.stackframes);
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
PrintCrashInfo(ci);
|
2019-02-21 19:37:16 +01:00
|
|
|
|
|
|
|
skipAbortSignal = true;
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterPrettyTerminateHander()
|
|
|
|
{
|
|
|
|
std::set_terminate(terminate_handler);
|
|
|
|
}
|
|
|
|
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if !defined(WIN32)
|
2019-02-21 19:37:16 +01:00
|
|
|
static void HandlePosixSignal(int s)
|
|
|
|
{
|
|
|
|
if (s == SIGABRT && skipAbortSignal) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-02 06:16:11 +02:00
|
|
|
|
2019-02-21 19:37:16 +01:00
|
|
|
const char* name = strsignal(s);
|
|
|
|
if (!name) {
|
|
|
|
name = "UNKNOWN";
|
|
|
|
}
|
2019-07-02 06:16:11 +02:00
|
|
|
|
|
|
|
crash_info ci;
|
|
|
|
ci.crashDescription = strprintf("Posix Signal: %s", name);
|
|
|
|
ci.stackframes = GetStackFrames(0, 16);
|
|
|
|
ci.stackframeInfos = GetStackFrameInfos(ci.stackframes);
|
|
|
|
PrintCrashInfo(ci);
|
2019-02-21 19:37:16 +01:00
|
|
|
|
|
|
|
// avoid a signal loop
|
|
|
|
skipAbortSignal = true;
|
|
|
|
std::abort();
|
|
|
|
}
|
2019-02-26 07:01:56 +01:00
|
|
|
#else
|
2019-02-21 19:37:16 +01:00
|
|
|
static void DoHandleWindowsException(EXCEPTION_POINTERS * ExceptionInfo)
|
|
|
|
{
|
|
|
|
std::string excType;
|
|
|
|
switch(ExceptionInfo->ExceptionRecord->ExceptionCode)
|
|
|
|
{
|
|
|
|
case EXCEPTION_ACCESS_VIOLATION: excType = "EXCEPTION_ACCESS_VIOLATION"; break;
|
|
|
|
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: excType = "EXCEPTION_ARRAY_BOUNDS_EXCEEDED"; break;
|
|
|
|
case EXCEPTION_BREAKPOINT: excType = "EXCEPTION_BREAKPOINT"; break;
|
|
|
|
case EXCEPTION_DATATYPE_MISALIGNMENT: excType = "EXCEPTION_DATATYPE_MISALIGNMENT"; break;
|
|
|
|
case EXCEPTION_FLT_DENORMAL_OPERAND: excType = "EXCEPTION_FLT_DENORMAL_OPERAND"; break;
|
|
|
|
case EXCEPTION_FLT_DIVIDE_BY_ZERO: excType = "EXCEPTION_FLT_DIVIDE_BY_ZERO"; break;
|
|
|
|
case EXCEPTION_FLT_INEXACT_RESULT: excType = "EXCEPTION_FLT_INEXACT_RESULT"; break;
|
|
|
|
case EXCEPTION_FLT_INVALID_OPERATION: excType = "EXCEPTION_FLT_INVALID_OPERATION"; break;
|
|
|
|
case EXCEPTION_FLT_OVERFLOW: excType = "EXCEPTION_FLT_OVERFLOW"; break;
|
|
|
|
case EXCEPTION_FLT_STACK_CHECK: excType = "EXCEPTION_FLT_STACK_CHECK"; break;
|
|
|
|
case EXCEPTION_FLT_UNDERFLOW: excType = "EXCEPTION_FLT_UNDERFLOW"; break;
|
|
|
|
case EXCEPTION_ILLEGAL_INSTRUCTION: excType = "EXCEPTION_ILLEGAL_INSTRUCTION"; break;
|
|
|
|
case EXCEPTION_IN_PAGE_ERROR: excType = "EXCEPTION_IN_PAGE_ERROR"; break;
|
|
|
|
case EXCEPTION_INT_DIVIDE_BY_ZERO: excType = "EXCEPTION_INT_DIVIDE_BY_ZERO"; break;
|
|
|
|
case EXCEPTION_INT_OVERFLOW: excType = "EXCEPTION_INT_OVERFLOW"; break;
|
|
|
|
case EXCEPTION_INVALID_DISPOSITION: excType = "EXCEPTION_INVALID_DISPOSITION"; break;
|
|
|
|
case EXCEPTION_NONCONTINUABLE_EXCEPTION: excType = "EXCEPTION_NONCONTINUABLE_EXCEPTION"; break;
|
|
|
|
case EXCEPTION_PRIV_INSTRUCTION: excType = "EXCEPTION_PRIV_INSTRUCTION"; break;
|
|
|
|
case EXCEPTION_SINGLE_STEP: excType = "EXCEPTION_SINGLE_STEP"; break;
|
|
|
|
case EXCEPTION_STACK_OVERFLOW: excType = "EXCEPTION_STACK_OVERFLOW"; break;
|
|
|
|
default: excType = "UNKNOWN"; break;
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
crash_info ci;
|
|
|
|
ci.crashDescription = strprintf("Windows Exception: %s", excType);
|
|
|
|
ci.stackframes = GetStackFrames(0, 16, ExceptionInfo->ContextRecord);
|
|
|
|
ci.stackframeInfos = GetStackFrameInfos(ci.stackframes);
|
2019-02-21 19:37:16 +01:00
|
|
|
|
2019-07-02 06:16:11 +02:00
|
|
|
PrintCrashInfo(ci);
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LONG WINAPI HandleWindowsException(EXCEPTION_POINTERS * ExceptionInfo)
|
|
|
|
{
|
|
|
|
if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) {
|
|
|
|
// We can't directly do the exception handling in this thread anymore as we need stack space for this
|
|
|
|
// So let's do the handling in another thread
|
|
|
|
// On Wine, the exception handler is not called at all
|
|
|
|
std::thread([&]() {
|
|
|
|
DoHandleWindowsException(ExceptionInfo);
|
|
|
|
}).join();
|
|
|
|
} else {
|
|
|
|
DoHandleWindowsException(ExceptionInfo);
|
|
|
|
}
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void RegisterPrettySignalHandlers()
|
|
|
|
{
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(WIN32)
|
2019-02-21 19:37:16 +01:00
|
|
|
SetUnhandledExceptionFilter(HandleWindowsException);
|
|
|
|
#else
|
|
|
|
const std::vector<int> posix_signals = {
|
|
|
|
// Signals for which the default action is "Core".
|
|
|
|
SIGABRT, // Abort signal from abort(3)
|
|
|
|
SIGBUS, // Bus error (bad memory access)
|
|
|
|
SIGFPE, // Floating point exception
|
|
|
|
SIGILL, // Illegal Instruction
|
|
|
|
SIGIOT, // IOT trap. A synonym for SIGABRT
|
|
|
|
SIGQUIT, // Quit from keyboard
|
|
|
|
SIGSEGV, // Invalid memory reference
|
|
|
|
SIGSYS, // Bad argument to routine (SVr4)
|
|
|
|
SIGTRAP, // Trace/breakpoint trap
|
|
|
|
SIGXCPU, // CPU time limit exceeded (4.2BSD)
|
|
|
|
SIGXFSZ, // File size limit exceeded (4.2BSD)
|
ci: build TSan with clang 15 and add -Werror=thread-safety, fix-up stacktraces (#5375)
## Description
Pull request was inspired by the need to debug lock problems when
working on https://github.com/dashpay/dash/pull/5352.
As far as I'm aware, only macOS has `-Werror=thread-safety` as part of
its default `CXXFLAGS` despite the capability being present on Linux as
well. This PR introduces thread safety checks for that into our thread
sanitizer build.
Additionally, since we're using Clang, something that on first glimpse,
appears to be something that `stacktraces.cpp` isn't happy with, due to
`-Wl,-wrap` being available only on GCC, that no longer seems to be the
case, since the version of Clang with comes with `focal`, its `lld`
_does_ have support for `-wrap` (see [man page for `lld` on
`focal`](https://manpages.ubuntu.com/manpages/focal/en/man1/lld.1.html)).
The current `stable` version of Clang/LLVM is 15, at the time of this
pull request (see https://apt.llvm.org/) but `focal` ships with an older
version, requiring us to use the official LLVM APT repository. I feel we
should be testing with recent compilers alongside the ones shipped by
LTS distributions.
Certain bugs are only made apparent when testing on rolling release
distros or distros that have faster update cycles, like Fedora (see
https://github.com/dashpay/dash/pull/5295 for an illustration of that),
which ship with more recent compilers. Until we overhaul our CI systems
to test using those distros directly (our current infrastructure is
centered around using a "development image" with an LTS distro as the
base), this is the best we can do.
A similar pull request testing against the latest GCC stable will be
welcome as that is currently outside the scope of this PR as the changes
made were to make sure that builds were operating as expected on
Clang/LLVM 15.
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-05-26 20:49:29 +02:00
|
|
|
#if defined(__APPLE__)
|
2019-02-21 19:37:16 +01:00
|
|
|
SIGEMT, // emulation instruction executed
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto s : posix_signals) {
|
|
|
|
struct sigaction sa_segv;
|
|
|
|
sa_segv.sa_handler = HandlePosixSignal;
|
|
|
|
sigemptyset(&sa_segv.sa_mask);
|
|
|
|
sa_segv.sa_flags = 0;
|
2019-08-06 05:08:33 +02:00
|
|
|
sigaction(s, &sa_segv, nullptr);
|
2019-02-21 19:37:16 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|