2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Desc: Runtime debugging support
10 * You can #define this in order to omit the whole code. Perhaps ROM-based systems
11 * will want to do this.
12 * However it's not advised to do so because this is a great aid in debugging
15 #ifndef NO_RUNTIME_DEBUG
17 #include <exec/execbase.h>
18 #include <exec/rawfmt.h>
19 #include <proto/exec.h>
24 #include "exec_debug.h"
26 #if defined(__AROSEXEC_SMP__)
27 #include <aros/atomic.h>
29 extern volatile ULONG safedebug
;
32 const char * const ExecFlagNames
[] =
37 (char *)-1, /* Reserved bit */
50 (char *)-1, /* NoLogServer */
51 (char *)-1, /* NoLogWindow */
52 (char *)-1, /* LogFile */
53 (char *)-1, /* LogKPrintF */
54 (char *)-1, /* PermMemTrack */
56 (char *)-1, /* CyberGuardDelay */
60 (char *)-1, /* PPCStart */
63 (char *)-1, /* Reserved bit */
68 void ExecLog(struct ExecBase
*SysBase
, ULONG flags
, const char *format
, ...)
72 flags
&= SysBase
->ex_DebugFlags
;
77 VLog(SysBase
, flags
, ExecFlagNames
, format
, ap
);
82 * The following stuff is a candidate to become a public API.
83 * Currently i have no idea into what component to put it, so for now
84 * it's exec.library's private property.
85 * The main problem is that we need it very early, before debug.library
86 * and whatever else wakes up.
90 * Return a set of flags specified on the command line.
91 * Option format: <flag1>,<flags>,...,<flagN>
92 * Or: "<flag1> <flag2> ... <flagN>"
94 ULONG
ParseFlags(char *opts
, const char * const *FlagNames
)
105 while (isalpha(*opts
))
110 /* Find the end of the word */
114 /* "ALL" means all flags */
115 if (!strnicmp(opts
, "all", 3))
118 /* Decode flag name */
119 for (i
= 0; FlagNames
[i
]; i
++)
121 const char *flagName
= FlagNames
[i
];
123 if (flagName
== (char *)-1)
126 if (!strnicmp(opts
, flagName
, strlen(flagName
)))
135 /* Skip separator characters */
138 /* If we hit closing quotes or end of line, this is the end */
146 /* Next word is found */
151 /* If the string is not quoted, only single comma is allowed as a separator */
162 void VLog(struct ExecBase
*SysBase
, ULONG flags
, const char * const *FlagNames
, const char *format
, va_list args
)
166 #if defined(__AROSEXEC_SMP__)
169 while (bit_test_and_set_long((ULONG
*)&safedebug
, 1)) { };
173 /* Prepend tag (if known) */
174 for (i
= 0; FlagNames
[i
]; i
++)
176 if (FlagNames
[i
] == (char *)-1)
179 if (flags
& (1UL << i
))
181 RawDoFmt("[EXEC] %s: ", (APTR
)&FlagNames
[i
], (VOID_FUNC
)RAWFMTFUNC_SERIAL
, NULL
);
186 /* Output the message and append a newline (in order not to bother about it every time) */
187 VNewRawDoFmt(format
, (VOID_FUNC
)RAWFMTFUNC_SERIAL
, NULL
, args
);
189 #if defined(__AROSEXEC_SMP__)
192 __AROS_ATOMIC_AND_L(safedebug
, ~(1 << 1));