From 2028e7fd97170e430b55b8c0e1a6ca1edca7680c Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Tue, 8 Sep 2009 13:55:42 -0400 Subject: [PATCH] update error system --- libust/Makefile.am | 1 + {libust => share}/localerr.h | 0 share/usterr.h | 21 ++++++++++++++++----- ust/Makefile.am | 6 ++---- ust/localerr.h | 11 ----------- ust/ust.c | 1 + ustd/localerr.h | 12 ------------ 7 files changed, 20 insertions(+), 32 deletions(-) rename {libust => share}/localerr.h (100%) delete mode 100644 ust/localerr.h delete mode 100644 ustd/localerr.h diff --git a/libust/Makefile.am b/libust/Makefile.am index e3d45419..1f18f8b9 100644 --- a/libust/Makefile.am +++ b/libust/Makefile.am @@ -5,3 +5,4 @@ lib_LTLIBRARIES = libust.la libust_la_SOURCES = marker.c marker.h tracepoint.c tracepoint.h immediate.h channels.c channels.h marker-control.c marker-control.h relay.c relay.h tracer.c tracer.h tracercore.c tracercore.h serialize.c tracectl.c $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/share/usterr.h localerr.h libust_la_LDFLAGS = -no-undefined -version-info 0:0:0 libust_la_LIBADD = $(URCU_LIBS) -lpthread +libust_la_CFLAGS = -DUST_COMPONENT="libust" diff --git a/libust/localerr.h b/share/localerr.h similarity index 100% rename from libust/localerr.h rename to share/localerr.h diff --git a/share/usterr.h b/share/usterr.h index 9c4be7ee..a96a36f2 100644 --- a/share/usterr.h +++ b/share/usterr.h @@ -1,15 +1,26 @@ #ifndef USTERR_H #define USTERR_H -//#define DEBUG +#ifndef UST_COMPONENT +//#error UST_COMPONENT is undefined +#define UST_COMPONENT libust +#endif + +/* To stringify the expansion of a define */ +#define XSTR(d) STR(d) +#define STR(s) #s + +#define UST_STR_COMPONENT XSTR(UST_COMPONENT) + +#define DEBUG #ifdef DEBUG -# define DBG(fmt, args...) do { fprintf(stderr, fmt "\n", ## args); fflush(stderr); } while(0) +# define DBG(fmt, args...) do { fprintf(stderr, UST_STR_COMPONENT ": " fmt "(" __FILE__ ":" XSTR(__LINE__) ")\n", ## args); fflush(stderr); } while(0) #else # define DBG(fmt, args...) do {} while(0) #endif -#define WARN(fmt, args...) fprintf(stderr, "libust: WARNING: " fmt "\n", ## args); fflush(stderr) -#define ERR(fmt, args...) fprintf(stderr, "libust: ERROR: " fmt "\n", ## args); fflush(stderr) -#define BUG(fmt, args...) fprintf(stderr, "libust: BUG: " fmt "\n", ## args); fflush(stderr) +#define WARN(fmt, args...) fprintf(stderr, UST_STR_COMPONENT ": Warning: " fmt "\n", ## args); fflush(stderr) +#define ERR(fmt, args...) fprintf(stderr, UST_STR_COMPONENT ": Error: " fmt "\n", ## args); fflush(stderr) +#define BUG(fmt, args...) fprintf(stderr, UST_STR_COMPONENT ": BUG: " fmt "\n", ## args); fflush(stderr) #define PERROR(call) perror("ust: ERROR: " call) #define BUG_ON(condition) do { if (unlikely(condition)) ERR("condition not respected (BUG)"); } while(0) diff --git a/ust/Makefile.am b/ust/Makefile.am index e353751e..f6a6e9c4 100644 --- a/ust/Makefile.am +++ b/ust/Makefile.am @@ -1,10 +1,8 @@ bin_PROGRAMS = ust ust_SOURCES = ust.c $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/libustcomm/ustcomm.h $(top_builddir)/libustcmd/ustcmd.c $(top_builddir)/libustcmd/ustcmd.h localerr.h +ust_CFLAGS = -DUST_COMPONENT=ust -#INCLUDES = -I$(top_builddir)/share -#INCLUDES += -I@URCU_PATH@ INCLUDES = $(KCOMPAT_CFLAGS) -#INCLUDES += -I$(top_builddir)/libust INCLUDES += -I$(top_builddir)/libustcomm INCLUDES += -I$(top_builddir)/libustcmd - +INCLUDES += -I$(top_builddir)/share diff --git a/ust/localerr.h b/ust/localerr.h deleted file mode 100644 index bfb9527b..00000000 --- a/ust/localerr.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef LOCALERR_H -#define LOCALERR_H - -#include - -#define DBG(fmt, args...) fprintf(stderr, "ust: " fmt "\n", ## args); fflush(stderr) -#define WARN(fmt, args...) fprintf(stderr, "ust: WARNING: " fmt "\n", ## args); fflush(stderr) -#define ERR(fmt, args...) fprintf(stderr, "ust: ERROR: " fmt "\n", ## args); fflush(stderr) -#define PERROR(a) perror(a) - -#endif /* LOCALERR_H */ diff --git a/ust/ust.c b/ust/ust.c index d8916653..53ede09c 100644 --- a/ust/ust.c +++ b/ust/ust.c @@ -25,6 +25,7 @@ #include "ustcomm.h" #include "ustcmd.h" +#include "usterr.h" enum command { START_TRACE, diff --git a/ustd/localerr.h b/ustd/localerr.h deleted file mode 100644 index d4276eb5..00000000 --- a/ustd/localerr.h +++ /dev/null @@ -1,12 +0,0 @@ -#include - -//#define DEBUG -#ifdef DEBUG -# define DBG(fmt, args...) fprintf(stderr, "ustd: " fmt "\n", ## args); fflush(stderr) -#else -# define DBG(fmt, args...) do {} while(0) -#endif - -#define WARN(fmt, args...) fprintf(stderr, "ustd: WARNING: " fmt "\n", ## args); fflush(stderr) -#define ERR(fmt, args...) fprintf(stderr, "ustd: ERROR: " fmt "\n", ## args); fflush(stderr) -#define PERROR(a) perror(a) -- 2.34.1