Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib api: Add debug output support

Adding support for warning/info/debug output within libapi code. Adding
following macros:

pr_warning(fmt, ...)
pr_info(fmt, ...)
pr_debug(fmt, ...)

Also adding libapi_set_print function to set above functions. This will
be used in perf to set standard debug handlers for libapi.

Adding 2 header files:
debug.h
- to be used outside libapi, contains
libapi_set_print interface

debug-internal.h
- to be used within libapi, contains
pr_warning/pr_info/pr_debug definitions

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1455465826-8426-2-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
975f14fa d646ae0a

+60
+1
tools/lib/api/Build
··· 1 1 libapi-y += fd/ 2 2 libapi-y += fs/ 3 3 libapi-y += cpu.o 4 + libapi-y += debug.o
+1
tools/lib/api/Makefile
··· 18 18 CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) 19 19 CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC 20 20 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 21 + CFLAGS += -I$(srctree)/tools/lib/api 21 22 22 23 RM = rm -f 23 24
+20
tools/lib/api/debug-internal.h
··· 1 + #ifndef __API_DEBUG_INTERNAL_H__ 2 + #define __API_DEBUG_INTERNAL_H__ 3 + 4 + #include "debug.h" 5 + 6 + #define __pr(func, fmt, ...) \ 7 + do { \ 8 + if ((func)) \ 9 + (func)("libapi: " fmt, ##__VA_ARGS__); \ 10 + } while (0) 11 + 12 + extern libapi_print_fn_t __pr_warning; 13 + extern libapi_print_fn_t __pr_info; 14 + extern libapi_print_fn_t __pr_debug; 15 + 16 + #define pr_warning(fmt, ...) __pr(__pr_warning, fmt, ##__VA_ARGS__) 17 + #define pr_info(fmt, ...) __pr(__pr_info, fmt, ##__VA_ARGS__) 18 + #define pr_debug(fmt, ...) __pr(__pr_debug, fmt, ##__VA_ARGS__) 19 + 20 + #endif /* __API_DEBUG_INTERNAL_H__ */
+28
tools/lib/api/debug.c
··· 1 + #include <stdio.h> 2 + #include <stdarg.h> 3 + #include "debug.h" 4 + #include "debug-internal.h" 5 + 6 + static int __base_pr(const char *format, ...) 7 + { 8 + va_list args; 9 + int err; 10 + 11 + va_start(args, format); 12 + err = vfprintf(stderr, format, args); 13 + va_end(args); 14 + return err; 15 + } 16 + 17 + libapi_print_fn_t __pr_warning = __base_pr; 18 + libapi_print_fn_t __pr_info = __base_pr; 19 + libapi_print_fn_t __pr_debug; 20 + 21 + void libapi_set_print(libapi_print_fn_t warn, 22 + libapi_print_fn_t info, 23 + libapi_print_fn_t debug) 24 + { 25 + __pr_warning = warn; 26 + __pr_info = info; 27 + __pr_debug = debug; 28 + }
+10
tools/lib/api/debug.h
··· 1 + #ifndef __API_DEBUG_H__ 2 + #define __API_DEBUG_H__ 3 + 4 + typedef int (*libapi_print_fn_t)(const char *, ...); 5 + 6 + void libapi_set_print(libapi_print_fn_t warn, 7 + libapi_print_fn_t info, 8 + libapi_print_fn_t debug); 9 + 10 + #endif /* __API_DEBUG_H__ */