* 'common_debug' of https://github.com/ooprala/util-linux:
  clean up redundant macros and defines
  libfdisk: use include/debug.h
  libblkid: use include/debug.h
  libmount: further debug.h integration
  libcommon: don't mention lib versions in debug macros
  libcommon: define more debugging macros
  libmount: use macros from include/debug.h
  libcommon: add common debugging routines
This commit is contained in:
Karel Zak 2014-03-21 10:59:58 +01:00
commit 9a7769141a
8 changed files with 93 additions and 91 deletions

View File

@ -12,6 +12,7 @@ dist_noinst_HEADERS += \
include/cpuset.h \
include/crc32.h \
include/crc64.h \
include/debug.h \
include/env.h \
include/exec_shell.h \
include/exitcodes.h \

66
include/debug.h Normal file
View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2014 Ondrej Oprala <ooprala@redhat.com>
*
* This file may be distributed under the terms of the
* GNU Lesser General Public License.
*/
#ifndef UTIL_LINUX_DEBUG_H
#define UTIL_LINUX_DEBUG_H
#include <stdarg.h>
#define UL_DEBUG_DEFINE_MASK(m) int m ## _debug_mask
#define UL_DEBUG_DECLARE_MASK(m) extern UL_DEBUG_DEFINE_MASK(m)
/* p - flag prefix, m - flag postfix */
#define UL_DEBUG_DEFINE_FLAG(p, m) p ## m
/* l - library name, p - flag prefix, m - flag postfix, x - function */
# define __UL_DBG(l, p, m, x) \
do { \
if ((p ## m) & l ## _debug_mask) { \
fprintf(stderr, "%d: %s: %8s: ", getpid(), # l, # m); \
x; \
} \
} while (0)
#define __UL_INIT_DEBUG(lib, pref, mask, env) do { \
if (lib ## _debug_mask & pref ## INIT) \
; \
else if (!mask) { \
char *str = getenv(# env); \
if (str) \
lib ## _debug_mask = strtoul(str, 0, 0); \
} else \
lib ## _debug_mask = mask; \
lib ## _debug_mask |= pref ## INIT; \
if (lib ## _debug_mask != pref ## INIT) { \
__UL_DBG(lib, pref, INIT, ul_debug("library debug mask: 0x%04x", \
lib ## _debug_mask)); \
} \
} while (0)
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
ul_debug(const char *mesg, ...)
{
va_list ap;
va_start(ap, mesg);
vfprintf(stderr, mesg, ap);
va_end(ap);
fputc('\n', stderr);
}
static inline void __attribute__ ((__format__ (__printf__, 2, 3)))
ul_debugobj(void *handler, const char *mesg, ...)
{
va_list ap;
if (handler)
fprintf(stderr, "[%p]: ", handler);
va_start(ap, mesg);
vfprintf(stderr, mesg, ap);
va_end(ap);
fputc('\n', stderr);
}
#endif /* UTIL_LINUX_DEBUG_H */

View File

@ -30,6 +30,7 @@
#include "bitops.h" /* $(top_srcdir)/include/ */
#include "blkdev.h"
#include "debug.h"
#include "blkid.h"
#include "list.h"
@ -337,17 +338,13 @@ struct blkid_struct_cache
#define BLKID_DEBUG_INIT 0x8000
#define BLKID_DEBUG_ALL 0xFFFF
#ifdef CONFIG_BLKID_DEBUG
extern int libblkid_debug_mask;
#define BLKID_DEF_FLAG(m) UL_DEFINE_FLAG(BLKID_DEBUG_, m)
UL_DEBUG_DECLARE_MASK(libblkid);
extern void blkid_debug_dump_dev(blkid_dev dev);
extern void blkid_debug_dump_tag(blkid_tag tag);
# define DBG(m,x) do { \
if ((BLKID_DEBUG_ ## m) & libblkid_debug_mask) { \
fprintf(stderr, "%d: libblkid: %8s: ", getpid(), # m); \
x; \
} \
} while (0)
#define DBG(m, x) do { __UL_DBG(libblkid, BLKID_DEBUG_, m, x); } while (0)
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
blkid_debug(const char *mesg, ...)
@ -359,10 +356,6 @@ blkid_debug(const char *mesg, ...)
fputc('\n', stderr);
}
#else /* !CONFIG_BLKID_DEBUG */
# define DBG(m,x) do { ; } while (0)
#endif /* CONFIG_BLKID_DEBUG */
/* devno.c */
struct dir_list {
char *name;

View File

@ -15,7 +15,7 @@
#include "blkidP.h"
int libblkid_debug_mask;
UL_DEBUG_DEFINE_MASK(libblkid);
/**
* blkid_init_debug:
@ -29,24 +29,12 @@ int libblkid_debug_mask;
*/
void blkid_init_debug(int mask)
{
if (libblkid_debug_mask & BLKID_DEBUG_INIT)
return;
if (!mask) {
char *str = getenv("LIBBLKID_DEBUG");
if (str)
libblkid_debug_mask = strtoul(str, 0, 0);
} else
libblkid_debug_mask = mask;
libblkid_debug_mask |= BLKID_DEBUG_INIT;
__UL_INIT_DEBUG(libblkid, BLKID_DEBUG_, mask, LIBBLKID_DEBUG);
if (libblkid_debug_mask != BLKID_DEBUG_INIT) {
const char *ver = NULL;
const char *date = NULL;
DBG(INIT, blkid_debug("library debug mask: 0x%04x",
libblkid_debug_mask));
blkid_get_library_version(&ver, &date);
DBG(INIT, blkid_debug("library version: %s [%s]", ver, date));
}

View File

@ -23,6 +23,7 @@
#include "nls.h" /* temporary before dialog API will be implamented */
#include "list.h"
#include "tt.h"
#include "debug.h"
/* features */
#define CONFIG_LIBFDISK_ASSERT
@ -39,7 +40,6 @@
#define CONFIG_LIBFDISK_DEBUG
#endif
#ifdef CONFIG_LIBFDISK_DEBUG
# include <stdio.h>
# include <stdarg.h>
@ -55,22 +55,19 @@
#define FDISK_DEBUG_TAB (1 << 9)
#define FDISK_DEBUG_ALL 0xFFFF
#define FDISK_DEF_FLAG(m) UL_DEFINE_FLAG(FDISK_DEBUG_, m)
#define DBG(m, x) do { __UL_DBG(libfdisk, FDISK_DEBUG_, m, x); } while (0)
# define ON_DBG(m, x) do { \
if ((FDISK_DEBUG_ ## m) & fdisk_debug_mask) { \
if ((FDISK_DEBUG_ ## m) & libfdisk_debug_mask) { \
x; \
} \
} while (0)
# define DBG(m, x) do { \
if ((FDISK_DEBUG_ ## m) & fdisk_debug_mask) { \
fprintf(stderr, "%d: fdisk: %8s: ", getpid(), # m); \
x; \
} \
} while (0)
# define DBG_FLUSH do { \
if (fdisk_debug_mask && \
fdisk_debug_mask != FDISK_DEBUG_INIT) \
if (libfdisk_debug_mask && \
libfdisk_debug_mask != FDISK_DEBUG_INIT) \
fflush(stderr); \
} while(0)
@ -84,14 +81,7 @@ dbgprint(const char *mesg, ...)
fputc('\n', stderr);
}
extern int fdisk_debug_mask;
#else /* !CONFIG_LIBFDISK_DEBUG */
# define ON_DBG(m,x) do { ; } while (0)
# define DBG(m,x) do { ; } while (0)
# define DBG_FLUSH do { ; } while(0)
#endif
UL_DEBUG_DECLARE_MASK(libfdisk);
#ifdef TEST_PROGRAM
struct fdisk_test {

View File

@ -1,8 +1,7 @@
#include "fdiskP.h"
int fdisk_debug_mask;
UL_DEBUG_DEFINE_MASK(libfdisk);
/**
* fdisk_init_debug:
@ -16,18 +15,5 @@ int fdisk_debug_mask;
*/
void fdisk_init_debug(int mask)
{
if (fdisk_debug_mask & FDISK_DEBUG_INIT)
return;
if (!mask) {
char *str = getenv("LIBFDISK_DEBUG");
if (str)
fdisk_debug_mask = strtoul(str, 0, 0);
} else
fdisk_debug_mask = mask;
if (fdisk_debug_mask)
fprintf(stderr, "libfdisk: debug mask set to 0x%04x.\n",
fdisk_debug_mask);
fdisk_debug_mask |= FDISK_DEBUG_INIT;
__UL_INIT_DEBUG(libfdisk, FDISK_DEBUG_, mask, LIBFDISK_DEBUG);
}

View File

@ -15,7 +15,7 @@
#include "mountP.h"
int libmount_debug_mask;
UL_DEBUG_DEFINE_MASK(libmount);
/**
* mnt_init_debug:
@ -29,24 +29,12 @@ int libmount_debug_mask;
*/
void mnt_init_debug(int mask)
{
if (libmount_debug_mask & MNT_DEBUG_INIT)
return;
if (!mask) {
char *str = getenv("LIBMOUNT_DEBUG");
if (str)
libmount_debug_mask = strtoul(str, 0, 0);
} else
libmount_debug_mask = mask;
libmount_debug_mask |= MNT_DEBUG_INIT;
__UL_INIT_DEBUG(libmount, MNT_DEBUG_, mask, LIBMOUNT_DEBUG);
if (libmount_debug_mask != MNT_DEBUG_INIT) {
const char *ver = NULL;
const char **features = NULL, **p;
DBG(INIT, mnt_debug("library debug mask: 0x%04x",
libmount_debug_mask));
mnt_get_library_version(&ver);
mnt_get_library_features(&features);

View File

@ -20,6 +20,7 @@
#include "c.h"
#include "list.h"
#include "debug.h"
#include "libmount.h"
/* features */
@ -52,10 +53,13 @@
#define MNT_DEBUG_DIFF (1 << 11)
#define MNT_DEBUG_ALL 0xFFFF
#ifdef CONFIG_LIBMOUNT_DEBUG
#define MNT_DEF_FLAG(m) UL_DEFINE_FLAG(MNT_DEBUG_, m)
# include <stdio.h>
# include <stdarg.h>
#define DBG(m, x) do { __UL_DBG(libmount, MNT_DEBUG_, m, x); } while (0)
# define WARN_REFCOUNT(m, o, r) \
do { \
if ((MNT_DEBUG_ ## m) & libmount_debug_mask && r != 0) \
@ -69,20 +73,13 @@
} \
} while (0)
# define DBG(m, x) do { \
if ((MNT_DEBUG_ ## m) & libmount_debug_mask) { \
fprintf(stderr, "%d: libmount: %8s: ", getpid(), # m); \
x; \
} \
} while (0)
# define DBG_FLUSH do { \
if (libmount_debug_mask && \
libmount_debug_mask != MNT_DEBUG_INIT) \
fflush(stderr); \
} while(0)
extern int libmount_debug_mask;
UL_DEBUG_DECLARE_MASK(libmount);
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
mnt_debug(const char *mesg, ...)
@ -107,13 +104,6 @@ mnt_debug_h(void *handler, const char *mesg, ...)
fputc('\n', stderr);
}
#else /* !CONFIG_LIBMOUNT_DEBUG */
# define WARN_REFCOUNT(m,o,r) do { ; } while (0)
# define ON_DBG(m,x) do { ; } while (0)
# define DBG(m,x) do { ; } while (0)
# define DBG_FLUSH do { ; } while(0)
#endif
/* extension for files in the directory */
#define MNT_MNTTABDIR_EXT ".fstab"