add errorexit function to print error message, backtrace and exit application

test16bit
Steffen Pohle 3 years ago
parent b77a3d7509
commit aeb43f5a46

@ -8,6 +8,7 @@
#include <string> #include <string>
#include <list> #include <list>
#include "simpleskycam.h"
#include "videodev.h" #include "videodev.h"
#include "json.h" #include "json.h"

@ -5,7 +5,9 @@
*****************************************************************************************/ *****************************************************************************************/
#include <sys/time.h> #include <sys/time.h>
#include <execinfo.h>
#include "simpleskycam.h"
#include "config.h" #include "config.h"
#include "configuration.h" #include "configuration.h"
#include "gui.h" #include "gui.h"
@ -88,3 +90,39 @@ float get_cycletime(struct timeval *t) {
return f; return f;
} }
/*
* print error message and the backtrace
*/
#define SIZE 100
void errorexit (char *fmt,...) {
//
// error message
va_list args;
char text[4096];
va_start (args, fmt);
vsnprintf (text, 4096, fmt, args);
va_end (args);
printf ("***************************\n");
printf (" ERROR\n");
printf ("***************************\n");
printf ("%s", text);
//
// backtrace
int j, nptrs;
void *buffer[SIZE];
char **s;
nptrs = backtrace(buffer, SIZE);
if ((s = (char**) backtrace_symbols(buffer, nptrs)) == NULL) {
for (j = 0; j < nptrs; j++) printf ("%-5d %p\n", j, buffer[j]);
}
else {
for (j = 0; j < nptrs; j++) printf ("%-5d %s\n", j, s[j]);
}
exit (-1);
}

Loading…
Cancel
Save