JubeatPlus 3.9.11
Loading...
Searching...
No Matches
neDebugLog.h
Go to the documentation of this file.
1
7
8// This code is NOT part of the original binary. It is compiled in only when the build defines
9// JBDBG (see the JBDBG CMake option, which is enable-able in any build configuration and is
10// turned on in CI). With JBDBG off the helpers below collapse to no-ops, so every translation
11// unit that only logs matches the reconstructed original exactly -- WITHOUT any `#if JBDBG` at
12// the call site:
13//
14// * neDebugLog(...) becomes an empty inline, so a bare log call vanishes.
15// * NE_DBG_FIRST(n) becomes `(false)`, so an `if (NE_DBG_FIRST(n)) { ... }` block turns into
16// `if (false) { ... }` and is dead-code-eliminated; debug-only locals declared inside the
17// block stay "used" within it, so -Werror stays quiet. Put all diagnostic work inside that
18// block.
19// * NE_DBG_EVERY is the uncapped form of the same guard, for a site that fires rarely enough
20// that a call cap would hide the very repetition being investigated (a screen transition, a
21// button press). Never use it on a per-frame path.
22// * NE_DBG(...) wraps debug statements that have real side effects we must NOT run in the
23// faithful build (for example glGetError(), which clears GL error state). It expands to the
24// statements when JBDBG is on and to nothing otherwise.
25//
26
27#pragma once
28
29#ifndef JBDBG
31#define JBDBG 0
32#endif
33
34#if JBDBG
35
36// The C spellings, not <cstdarg>/<cstdio>: this header is included from pure Objective-C (.m)
37// translation units, where the C++ headers do not exist.
38#include <os/log.h>
39#include <stdarg.h>
40#include <stdio.h>
41
42// printf-style wrapper over os_log (works in .c, .m, .cpp, and .mm translation units alike; os_log
43// lines are what idevicesyslog captures).
44static inline void neDebugLog(const char *fmt, ...) {
45 char buf[512];
46 va_list ap;
47 va_start(ap, fmt);
48 vsnprintf(buf, sizeof(buf), fmt, ap);
49 va_end(ap);
50 os_log(OS_LOG_DEFAULT, "JBPDBG %{public}s", buf);
51}
52
62#define NE_DBG_FIRST(limit) \
63 __extension__({ \
64 static int _c = 0; \
65 _c < (limit) ? (++_c, 1) : 0; \
66 })
67
75#define NE_DBG_EVERY (1)
76
84#define NE_DBG(...) \
85 do { \
86 __VA_ARGS__; \
87 } while (0)
88
89#else
90
91// No-op fallbacks: a bare, unguarded log call still compiles away to nothing, and
92// NE_DBG_FIRST(n) collapses an `if (...) { ... }` diagnostic block to dead code that the optimiser
93// drops.
94static inline void neDebugLog(const char *fmt, ...) {
95 (void)fmt;
96}
97
98// A plain 0 rather than `false`, which is a keyword only in C++ and would need <stdbool.h> in the
99// pure Objective-C translation units.
100#define NE_DBG_FIRST(limit) (0)
101#define NE_DBG_EVERY (0)
102#define NE_DBG(...) ((void)0)
103
104#endif
105
106#ifndef JBDBG_BUILD_SHA
113#define JBDBG_BUILD_SHA "unknown"
114#endif