Add manual error tracing

Error messages and function names/line numbers are traced via
__func__ or __FUNCTION__, __LINE__, etc (or just "unknown" if
not available). A manual stack is kept onto which these values
are pushed which can then be dumped to stderr/stdout.

stderr is used to report this information since no other
facility appears to be provided.
This commit is contained in:
Charles Mita
2018-03-27 17:53:00 +01:00
parent af6c98765d
commit db16131db4
6 changed files with 308 additions and 126 deletions
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2018 Diamond Light Source Ltd.
* Author: Charles Mita
*/
#ifndef NXS_XDS_ERR_H
#define NXS_XDS_ERR_H
#define ERR_MAX_FILENAME_LENGTH 64
#define ERR_MAX_FUNCNAME_LENGTH 128
#define ERR_MAX_MESSAGE_LENGTH 1024
#define ERR_MAX_STACK_SIZE 128
/* obtain __func__ from GCC if no C99 */
#if __STDC_VERSION__ < 199901L
# if __GNUC__ >= 2
# define __func__ __FUNCTION__
# else
# define __func__ "<unknown>"
# endif
#endif
#if __GNUC__ >= 2
# define __line__ __LINE__
#else
# define __line__ 0
#endif
#if __GNUC__ >= 2
# define __file__ __FILE__
#else
# define __file__ "unknown"
#endif
#define ERROR_JUMP(err, target, message) \
{ \
push_error_stack(__file__, __func__, __line__, err, message); \
retval = err; \
goto target; \
}
void push_error_stack(const char *file, const char *func, int line, int err, const char *message);
void dump_error_stack(FILE *out);
void reset_error_stack();
#endif /* NXS_XDS_ERR_H */