Added missing properties.
[AROS.git] / rom / exec / exec_debug.c
blob44642b31abf4d5a81abd018f3a993f5b663feb76
1 /*
2 Copyright © 1995-2011, 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 adviced to to so because this is a great aid in debugging on user's side.
14 #ifndef NO_RUNTIME_DEBUG
16 #include <exec/execbase.h>
17 #include <exec/rawfmt.h>
18 #include <proto/exec.h>
20 #include <ctype.h>
21 #include <string.h>
23 #include "exec_debug.h"
25 const char * const ExecFlagNames[] =
27 "InitResident",
28 "InitCode",
29 "FindResident",
30 (char *)-1, /* Reserved bit */
31 "CreateLibrary",
32 "SetFunction",
33 "NewSetFunction",
34 "ChipRam",
35 "AddTask",
36 "RemTask",
37 "GetTaskAttr",
38 "SetTaskAttr",
39 "ExceptHandler",
40 "AddDosNode",
41 "PCI",
42 "RamLib",
43 (char *)-1, /* NoLogServer */
44 (char *)-1, /* NoLogWindow */
45 (char *)-1, /* LogFile */
46 (char *)-1, /* LogKPrintF */
47 (char *)-1, /* PermMemTrack */
48 "MemTrack",
49 (char *)-1, /* CyberGuardDelay */
50 "LogExtended",
51 "LoadSeg",
52 "UnloadSeg",
53 (char *)-1, /* PPCStart */
54 "CGXDebug",
55 "InvZeroPage",
56 (char *)-1, /* Reserved bit */
57 "Init",
58 NULL
61 void ExecLog(struct ExecBase *SysBase, ULONG flags, const char *format, ...)
63 va_list ap;
65 flags &= SysBase->ex_DebugFlags;
66 if (!flags)
67 return;
69 va_start(ap, format);
70 VLog(SysBase, flags, ExecFlagNames, format, ap);
71 va_end(ap);
75 * The following stuff is a candidate to become a public API.
76 * Currently i have no idea into what component to put it, so for now
77 * it's exec.library's private property.
78 * The main problem is that we need it very early, before debug.library
79 * and whatever else wakes up.
83 * Return a set of flags specified on the command line.
84 * Option format: <flag1>,<flags>,...,<flagN>
85 * Or: "<flag1> <flag2> ... <flagN>"
87 ULONG ParseFlags(char *opts, const char * const *FlagNames)
89 ULONG ret = 0;
90 char quoted = 0;
92 if (*opts == '"')
94 quoted = 1;
95 opts++;
98 while (isalpha(*opts))
100 char *p = opts + 1;
101 unsigned int i;
103 /* Find the end of the word */
104 while (isalpha(*p))
105 p++;
107 /* "ALL" means all flags */
108 if (!strnicmp(opts, "all", 3))
109 return -1;
111 /* Decode flag name */
112 for (i = 0; FlagNames[i]; i++)
114 const char *flagName = FlagNames[i];
116 if (flagName == (char *)-1)
117 continue;
119 if (!strnicmp(opts, flagName, strlen(flagName)))
121 ret |= (1UL << i);
122 break;
126 if (quoted)
128 /* Skip separator characters */
129 while (!isalpha(*p))
131 /* If we hit closing quotes or end of line, this is the end */
132 if (*p == '"')
133 return ret;
135 if (*p == 0)
136 return ret;
139 /* Next word is found */
140 opts = p;
142 else
144 /* If the string is not quoted, only single comma is allowed as a separator */
145 if (*p != ',')
146 break;
148 opts = p + 1;
152 return ret;
155 void VLog(struct ExecBase *SysBase, ULONG flags, const char * const *FlagNames, const char *format, va_list args)
157 unsigned int i;
159 /* Prepend tag (if known) */
160 for (i = 0; FlagNames[i]; i++)
162 if (FlagNames[i] == (char *)-1)
163 continue;
165 if (flags & (1UL << i))
167 RawDoFmt("[%s] ", (APTR)&FlagNames[i], (VOID_FUNC)RAWFMTFUNC_SERIAL, NULL);
168 break;
172 /* Output the message and append a newline (in order not to bother about it every time) */
173 VNewRawDoFmt(format, (VOID_FUNC)RAWFMTFUNC_SERIAL, NULL, args);
174 RawPutChar('\n');
177 #endif