Fix backtraces in asserts
This commit is contained in:
parent
3fed6f13cb
commit
0bb278bcdd
@ -17,9 +17,10 @@ namespace cpputils {
|
|||||||
namespace _assert {
|
namespace _assert {
|
||||||
inline std::string format(const char *expr, const char *message, const char *file, int line) {
|
inline std::string format(const char *expr, const char *message, const char *file, int line) {
|
||||||
// get void*'s for all entries on the stack
|
// get void*'s for all entries on the stack
|
||||||
void *array[10];
|
constexpr unsigned int MAX_SIZE = 100;
|
||||||
size_t size = backtrace(array, sizeof(array));
|
void *array[MAX_SIZE];
|
||||||
char **backtrace_str = backtrace_symbols(array, sizeof(backtrace_str));
|
size_t size = backtrace(array, MAX_SIZE);
|
||||||
|
char **backtrace_str = backtrace_symbols(array, size);
|
||||||
std::string result = std::string()+"Assertion ["+expr+"] failed in "+file+":"+std::to_string(line)+": "+message+"\n\n";
|
std::string result = std::string()+"Assertion ["+expr+"] failed in "+file+":"+std::to_string(line)+": "+message+"\n\n";
|
||||||
for (unsigned int i = 0; i < size; ++i) {
|
for (unsigned int i = 0; i < size; ++i) {
|
||||||
result += std::string(backtrace_str[i]) + "\n";
|
result += std::string(backtrace_str[i]) + "\n";
|
||||||
|
@ -9,8 +9,9 @@
|
|||||||
namespace cpputils {
|
namespace cpputils {
|
||||||
|
|
||||||
void sigsegv_handler(int) {
|
void sigsegv_handler(int) {
|
||||||
void *array[100];
|
constexpr unsigned int MAX_SIZE = 100;
|
||||||
size_t size = backtrace(array, sizeof(array));
|
void *array[MAX_SIZE];
|
||||||
|
size_t size = backtrace(array, MAX_SIZE);
|
||||||
|
|
||||||
std::cerr << "Error: SIGSEGV" << std::endl;
|
std::cerr << "Error: SIGSEGV" << std::endl;
|
||||||
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user