Skip to content

Commit 975f14f

Browse files
olsajiriacmel
authored andcommitted
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>
1 parent d646ae0 commit 975f14f

5 files changed

Lines changed: 60 additions & 0 deletions

File tree

tools/lib/api/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
libapi-y += fd/
22
libapi-y += fs/
33
libapi-y += cpu.o
4+
libapi-y += debug.o

tools/lib/api/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ LIBFILE = $(OUTPUT)libapi.a
1818
CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
1919
CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC
2020
CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
21+
CFLAGS += -I$(srctree)/tools/lib/api
2122

2223
RM = rm -f
2324

tools/lib/api/debug-internal.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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__ */

tools/lib/api/debug.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

tools/lib/api/debug.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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__ */

0 commit comments

Comments
 (0)