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