Debian Codegraph @

include/private/debug.h

raw
1 /*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright © 2009 CNRS
4 * Copyright © 2009-2020 Inria. All rights reserved.
5 * Copyright © 2009, 2011 Université Bordeaux
6 * Copyright © 2011 Cisco Systems, Inc. All rights reserved.
7 * See COPYING in top-level directory.
8 */
9
10 /* The configuration file */
11
12 #ifndef HWLOC_DEBUG_H
13 #define HWLOC_DEBUG_H
14
15 #include "private/autogen/config.h"
16 #include "private/misc.h"
17
18 #ifdef HWLOC_DEBUG
19 #include <stdarg.h>
20 #include <stdio.h>
21 #endif
22
23 #ifdef ANDROID
24 extern void JNIDebug(char *text);
25 #endif
26
27 /* Compile-time assertion */
28 #define HWLOC_BUILD_ASSERT(condition) ((void)sizeof(char[1 - 2*!(condition)]))
29
30 #ifdef HWLOC_DEBUG
31 static __hwloc_inline int hwloc_debug_enabled(void)
32 {
33 static int checked = 0;
34 static int enabled = 1;
35 if (!checked) {
36 const char *env = getenv("HWLOC_DEBUG_VERBOSE");
37 if (env)
38 enabled = atoi(env);
39 if (enabled)
40 fprintf(stderr, "hwloc verbose debug enabled, may be disabled with HWLOC_DEBUG_VERBOSE=0 in the environment.\n");
41 checked = 1;
42 }
43 return enabled;
44 }
45 #endif
46
47 static __hwloc_inline void hwloc_debug(const char *s __hwloc_attribute_unused, ...) __hwloc_attribute_format(printf, 1, 2);
48 static __hwloc_inline void hwloc_debug(const char *s __hwloc_attribute_unused, ...)
49 {
50 #ifdef HWLOC_DEBUG
51 if (hwloc_debug_enabled()) {
52 #ifdef ANDROID
53 char buffer[256];
54 #endif
55 va_list ap;
56 va_start(ap, s);
57 #ifdef ANDROID
58 vsprintf(buffer, s, ap);
59 JNIDebug(buffer);
60 #else
61 vfprintf(stderr, s, ap);
62 #endif
63 va_end(ap);
64 }
65 #endif
66 }
67
68 #ifdef HWLOC_DEBUG
69 #define hwloc_debug_bitmap(fmt, bitmap) do { \
70 if (hwloc_debug_enabled()) { \
71 char *s; \
72 hwloc_bitmap_asprintf(&s, bitmap); \
73 hwloc_debug(fmt, s); \
74 free(s); \
75 } } while (0)
76 #define hwloc_debug_1arg_bitmap(fmt, arg1, bitmap) do { \
77 if (hwloc_debug_enabled()) { \
78 char *s; \
79 hwloc_bitmap_asprintf(&s, bitmap); \
80 hwloc_debug(fmt, arg1, s); \
81 free(s); \
82 } } while (0)
83 #define hwloc_debug_2args_bitmap(fmt, arg1, arg2, bitmap) do { \
84 if (hwloc_debug_enabled()) { \
85 char *s; \
86 hwloc_bitmap_asprintf(&s, bitmap); \
87 hwloc_debug(fmt, arg1, arg2, s); \
88 free(s); \
89 } } while (0)
90 #else
91 #define hwloc_debug_bitmap(s, bitmap) do { } while(0)
92 #define hwloc_debug_1arg_bitmap(s, arg1, bitmap) do { } while(0)
93 #define hwloc_debug_2args_bitmap(s, arg1, arg2, bitmap) do { } while(0)
94 #endif
95
96 #endif /* HWLOC_DEBUG_H */