Cancel redefinition of DOSBase for the 'cdrom' test utility. Now the
[AROS.git] / rom / exec / exec_debug.c
blobb77d70f5f92560760dd548c46ea85c5ca26bb17b
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Runtime debugging support
6 Lang: english
7 */
9 /*
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
13 * on user's side.
15 #ifndef NO_RUNTIME_DEBUG
17 #include <exec/execbase.h>
18 #include <exec/rawfmt.h>
19 #include <proto/exec.h>
21 #include <ctype.h>
22 #include <string.h>
24 #include "exec_debug.h"
26 const char * const ExecFlagNames[] =
28 "InitResident",
29 "InitCode",
30 "FindResident",
31 (char *)-1, /* Reserved bit */
32 "CreateLibrary",
33 "SetFunction",
34 "NewSetFunction",
35 "ChipRam",
36 "AddTask",
37 "RemTask",
38 "GetTaskAttr",
39 "SetTaskAttr",
40 "ExceptHandler",
41 "AddDosNode",
42 "PCI",
43 "RamLib",
44 (char *)-1, /* NoLogServer */
45 (char *)-1, /* NoLogWindow */
46 (char *)-1, /* LogFile */
47 (char *)-1, /* LogKPrintF */
48 (char *)-1, /* PermMemTrack */
49 "MemTrack",
50 (char *)-1, /* CyberGuardDelay */
51 "LogExtended",
52 "LoadSeg",
53 "UnloadSeg",
54 (char *)-1, /* PPCStart */
55 "CGXDebug",
56 "InvZeroPage",
57 (char *)-1, /* Reserved bit */
58 "Init",
59 NULL
62 void ExecLog(struct ExecBase *SysBase, ULONG flags, const char *format, ...)
64 va_list ap;
66 flags &= SysBase->ex_DebugFlags;
67 if (!flags)
68 return;
70 va_start(ap, format);
71 VLog(SysBase, flags, ExecFlagNames, format, ap);
72 va_end(ap);
76 * The following stuff is a candidate to become a public API.
77 * Currently i have no idea into what component to put it, so for now
78 * it's exec.library's private property.
79 * The main problem is that we need it very early, before debug.library
80 * and whatever else wakes up.
84 * Return a set of flags specified on the command line.
85 * Option format: <flag1>,<flags>,...,<flagN>
86 * Or: "<flag1> <flag2> ... <flagN>"
88 ULONG ParseFlags(char *opts, const char * const *FlagNames)
90 ULONG ret = 0;
91 char quoted = 0;
93 if (*opts == '"')
95 quoted = 1;
96 opts++;
99 while (isalpha(*opts))
101 char *p = opts + 1;
102 unsigned int i;
104 /* Find the end of the word */
105 while (isalpha(*p))
106 p++;
108 /* "ALL" means all flags */
109 if (!strnicmp(opts, "all", 3))
110 return -1;
112 /* Decode flag name */
113 for (i = 0; FlagNames[i]; i++)
115 const char *flagName = FlagNames[i];
117 if (flagName == (char *)-1)
118 continue;
120 if (!strnicmp(opts, flagName, strlen(flagName)))
122 ret |= (1UL << i);
123 break;
127 if (quoted)
129 /* Skip separator characters */
130 while (!isalpha(*p))
132 /* If we hit closing quotes or end of line, this is the end */
133 if (*p == '"')
134 return ret;
136 if (*p == 0)
137 return ret;
140 /* Next word is found */
141 opts = p;
143 else
145 /* If the string is not quoted, only single comma is allowed as a separator */
146 if (*p != ',')
147 break;
149 opts = p + 1;
153 return ret;
156 void VLog(struct ExecBase *SysBase, ULONG flags, const char * const *FlagNames, const char *format, va_list args)
158 unsigned int i;
160 /* Prepend tag (if known) */
161 for (i = 0; FlagNames[i]; i++)
163 if (FlagNames[i] == (char *)-1)
164 continue;
166 if (flags & (1UL << i))
168 RawDoFmt("[%s] ", (APTR)&FlagNames[i], (VOID_FUNC)RAWFMTFUNC_SERIAL, NULL);
169 break;
173 /* Output the message and append a newline (in order not to bother about it every time) */
174 VNewRawDoFmt(format, (VOID_FUNC)RAWFMTFUNC_SERIAL, NULL, args);
175 RawPutChar('\n');
178 #endif