1
// Copyright (C) 2000 - 2002 Hewlett-Packard Company
3
// This program is free software; you can redistribute it and/or modify it
4
// under the term of the GNU Lesser General Public License as published by the
5
// Free Software Foundation; either version 2 of the License, or (at your
6
// option) any later version.
8
// This program is distributed in the hope that it will be useful, but WITHOUT
9
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13
// You should have received a copy of the GNU Lesser General Public License
14
// along with this program; if not, write to the Free Software Foundation,
15
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// @(#) $Revision: 4.13 $ $Source: /judy/src/JudyCommon/JudyPrintJP.c $
20
// JudyPrintJP() debugging/tracing function for Judy1 or JudyL code.
21
// The caller should #include this file, with its static function (replicated
22
// in each compilation unit), in another *.c file, and compile with one of
23
// -DJUDY1 or -DJUDYL.
25
// The caller can set __JudyIndex and/or __JudyPopulation non-zero to have
26
// those values reported, and also to control trace-enabling (see below).
28
// Tracing is disabled by default unless one or both of two env parameters is
29
// set (regardless of value). If either value is set but null or evaluates to
30
// zero, tracing is immediately enabled. To disable tracing until a particular
31
// __Judy*Index value is seen, set STARTINDEX=<hex-index> in the env. To
32
// disable it until a particular __Judy*Population value is seen, set
33
// STARTPOP=<decimal-population> in the env. Once either condition is met,
34
// tracing "latches on".
38
// STARTPOP=0 // immediate tracing.
39
// STARTINDEX=f35430a8 // not until one of these is met.
42
// Note: Trace-enabling does nothing unless the caller sets the appropriate
43
// global variable non-zero.
45
#if (! (JUDY1 || JUDYL))
46
Error: One of -DJUDY1 or -DJUDYL must be specified.
49
#include <stdlib.h> // for getenv() and strtoul().
52
// GLOBALS FROM CALLER:
54
// Note: This storage is declared once in each compilation unit that includes
55
// this file, but the linker should merge all cases into single locations, but
56
// ONLY if these are uninitialized, so ASSUME they are 0 to start.
58
Word_t __JudyIndex; // current Index itself, optional from caller.
59
Word_t __JudyPopulation; // Indexes in array, optional from caller.
63
static Word_t startindex = 0; // see usage below.
64
static Word_t startpop = 0;
65
static bool_t enabled = FALSE; // by default, unless env params set.
67
// Shorthand for announcing JP addresses, Desc (in context), and JP types:
69
// Note: Width is at least one blank wider than any JP type name, and the line
70
// is left unfinished.
72
// Note: Use a format for address printing compatible with other tracing
73
// facilities; in particular, %x not %lx, to truncate the "noisy" high part on
76
#define JPTYPE(Type) printf("0x%lx %s %-17s", (Word_t) Pjp, Desc, Type)
78
// Shorthands for announcing expanse populations from DcdPop0 fields:
80
#define POP0 printf("Pop1 = 0 ")
81
#define POP1 printf("Pop1 = %ld ", (Word_t) ((Pjp->jp_DcdPop0 & 0xff) + 1))
82
#define POP2 printf("Pop1 = %ld ", (Word_t) ((Pjp->jp_DcdPop0 & 0xffff) + 1))
83
#define POP3 printf("Pop1 = %ld ", (Word_t) ((Pjp->jp_DcdPop0 & 0xffffff) + 1))
85
#define POP4 printf("Pop1 = %ld ", (Word_t) ((Pjp->jp_DcdPop0 & 0xffffffff) + 1))
86
#define POP5 printf("Pop1 = %ld ", (Word_t) ((Pjp->jp_DcdPop0 & 0xffffffffff) + 1))
87
#define POP6 printf("Pop1 = %ld ", (Word_t) ((Pjp->jp_DcdPop0 & 0xffffffffffff) + 1))
88
#define POP7 printf("Pop1 = %ld ", (Word_t) ((Pjp->jp_DcdPop0 & 0xffffffffffffff) + 1))
91
// Shorthands for announcing populations of Immeds:
93
// Note: Line up the small populations that often occur together, but beyond
94
// that, don't worry about it because populations can get arbitrarily large.
96
#define POP_1 printf("Pop1 = 1 ")
97
#define POP_2 printf("Pop1 = 2 ")
98
#define POP_3 printf("Pop1 = 3 ")
99
#define POP_4 printf("Pop1 = 4 ")
100
#define POP_5 printf("Pop1 = 5 ")
101
#define POP_6 printf("Pop1 = 6 ")
102
#define POP_7 printf("Pop1 = 7 ")
103
#define POP_8 printf("Pop1 = 8 ")
104
#define POP_9 printf("Pop1 = 8 ")
105
#define POP_10 printf("Pop1 = 10 ")
106
#define POP_11 printf("Pop1 = 11 ")
107
#define POP_12 printf("Pop1 = 12 ")
108
#define POP_13 printf("Pop1 = 13 ")
109
#define POP_14 printf("Pop1 = 14 ")
110
#define POP_15 printf("Pop1 = 15 ")
112
// Shorthands for other announcements:
114
#define NUMJPSL printf("NumJPs = %d ", P_JBL(Pjp->jp_Addr)->jbl_NumJPs)
115
#define OOPS printf("-- OOPS, invalid Type\n"); exit(1)
117
// This is harder to compute:
121
Pjbb_t Pjbb = P_JBB(Pjp->jp_Addr); \
125
for (subexp = 0; subexp < cJU_NUMSUBEXPB; ++subexp) \
126
numJPs += __JudyCountBitsB(JU_JBB_BITMAP(Pjbb, subexp));\
128
printf("NumJPs = %d ", numJPs); \
132
// ****************************************************************************
133
// J U D Y P R I N T J P
135
// Dump information about a JP, at least its address, type, population, and
136
// number of JPs, as appropriate. Error out upon any unexpected JP type.
138
// TBD: Dump more detailed information about the JP?
140
FUNCTION static void JudyPrintJP(
141
Pjp_t Pjp, // JP to describe.
142
char * Desc, // brief description of caller, such as "i".
143
int Line) // caller's source line number.
145
static bool_t checked = FALSE; // set upon first entry and check for params.
146
char * value; // for getenv().
149
// CHECK FOR EXTERNAL ENABLING:
151
// If a parameter is set, report the value, even if it is null or otherwise
152
// evaluates to zero, in which case enable tracing immediately; otherwise wait
153
// for the value to be hit.
155
#define GETENV(Name,Value,Base) \
156
if ((value = getenv (Name)) != (char *) NULL) \
158
(Value) = strtoul (value, (char **) NULL, Base); \
159
enabled |= ((Value) == 0); /* see above */ \
161
(void) printf ("JudyPrintJP(\"%s\"): $%s = %lu\n", \
162
Desc, Name, Value); \
165
if (! checked) // only check once.
169
GETENV ("STARTINDEX", startindex, 16);
170
GETENV ("STARTPOP", startpop, 10);
172
(void) printf ("JudyPrintJP(\"%s\"): Tracing present %s\n", Desc,
173
enabled ? "and immediately enabled" :
174
(startindex || startpop) ?
175
"but disabled until start condition met" :
176
"but not enabled by env parameter");
179
if (! enabled) // check repeatedly until latched enabled:
181
if (startindex && (startindex == __JudyIndex))
183
(void) printf ("=== TRACING ENABLED (\"%s\"), "
184
"startindex = 0x%lx\n", Desc, startindex);
187
else if (startpop && (startpop == __JudyPopulation))
189
(void) printf ("=== TRACING ENABLED (\"%s\"), "
190
"startpop = %lu\n", Desc, startpop);
195
return; // print nothing this time.
200
// SWITCH ON JP TYPE:
202
switch (Pjp->jp_Type)
205
// Note: The following COULD be merged more tightly between Judy1 and JudyL,
206
// but we decided that the output should say cJ1*/cJL*, not cJU*, to be more
210
case cJ1_JPNULL1: JPTYPE("cJ1_JPNULL1"); POP0; break;
211
case cJ1_JPNULL2: JPTYPE("cJ1_JPNULL2"); POP0; break;
212
case cJ1_JPNULL3: JPTYPE("cJ1_JPNULL3"); POP0; break;
214
case cJ1_JPNULL4: JPTYPE("cJ1_JPNULL4"); POP0; break;
215
case cJ1_JPNULL5: JPTYPE("cJ1_JPNULL5"); POP0; break;
216
case cJ1_JPNULL6: JPTYPE("cJ1_JPNULL6"); POP0; break;
217
case cJ1_JPNULL7: JPTYPE("cJ1_JPNULL7"); POP0; break;
220
case cJ1_JPBRANCH_L2: JPTYPE("cJ1_JPBRANCH_L2"); POP2;NUMJPSL;break;
221
case cJ1_JPBRANCH_L3: JPTYPE("cJ1_JPBRANCH_L3"); POP3;NUMJPSL;break;
223
case cJ1_JPBRANCH_L4: JPTYPE("cJ1_JPBRANCH_L4"); POP4;NUMJPSL;break;
224
case cJ1_JPBRANCH_L5: JPTYPE("cJ1_JPBRANCH_L5"); POP5;NUMJPSL;break;
225
case cJ1_JPBRANCH_L6: JPTYPE("cJ1_JPBRANCH_L6"); POP6;NUMJPSL;break;
226
case cJ1_JPBRANCH_L7: JPTYPE("cJ1_JPBRANCH_L7"); POP7;NUMJPSL;break;
228
case cJ1_JPBRANCH_L: JPTYPE("cJ1_JPBRANCH_L"); NUMJPSL;break;
230
case cJ1_JPBRANCH_B2: JPTYPE("cJ1_JPBRANCH_B2"); POP2;NUMJPSB;break;
231
case cJ1_JPBRANCH_B3: JPTYPE("cJ1_JPBRANCH_B3"); POP3;NUMJPSB;break;
233
case cJ1_JPBRANCH_B4: JPTYPE("cJ1_JPBRANCH_B4"); POP4;NUMJPSB;break;
234
case cJ1_JPBRANCH_B5: JPTYPE("cJ1_JPBRANCH_B5"); POP5;NUMJPSB;break;
235
case cJ1_JPBRANCH_B6: JPTYPE("cJ1_JPBRANCH_B6"); POP6;NUMJPSB;break;
236
case cJ1_JPBRANCH_B7: JPTYPE("cJ1_JPBRANCH_B7"); POP7;NUMJPSB;break;
238
case cJ1_JPBRANCH_B: JPTYPE("cJ1_JPBRANCH_B"); NUMJPSB;break;
240
case cJ1_JPBRANCH_U2: JPTYPE("cJ1_JPBRANCH_U2"); POP2; break;
241
case cJ1_JPBRANCH_U3: JPTYPE("cJ1_JPBRANCH_U3"); POP3; break;
243
case cJ1_JPBRANCH_U4: JPTYPE("cJ1_JPBRANCH_U4"); POP4; break;
244
case cJ1_JPBRANCH_U5: JPTYPE("cJ1_JPBRANCH_U5"); POP5; break;
245
case cJ1_JPBRANCH_U6: JPTYPE("cJ1_JPBRANCH_U6"); POP6; break;
246
case cJ1_JPBRANCH_U7: JPTYPE("cJ1_JPBRANCH_U7"); POP7; break;
248
case cJ1_JPBRANCH_U: JPTYPE("cJ1_JPBRANCH_U"); break;
251
case cJ1_JPLEAF1: JPTYPE("cJ1_JPLEAF1"); POP1; break;
253
case cJ1_JPLEAF2: JPTYPE("cJ1_JPLEAF2"); POP2; break;
254
case cJ1_JPLEAF3: JPTYPE("cJ1_JPLEAF3"); POP3; break;
256
case cJ1_JPLEAF4: JPTYPE("cJ1_JPLEAF4"); POP4; break;
257
case cJ1_JPLEAF5: JPTYPE("cJ1_JPLEAF5"); POP5; break;
258
case cJ1_JPLEAF6: JPTYPE("cJ1_JPLEAF6"); POP6; break;
259
case cJ1_JPLEAF7: JPTYPE("cJ1_JPLEAF7"); POP7; break;
262
case cJ1_JPLEAF_B1: JPTYPE("cJ1_JPLEAF_B1"); POP1; break;
263
case cJ1_JPFULLPOPU1: JPTYPE("cJ1_JPFULLPOPU1"); POP1; break;
265
case cJ1_JPIMMED_1_01: JPTYPE("cJ1_JPIMMED_1_01"); POP_1; break;
266
case cJ1_JPIMMED_2_01: JPTYPE("cJ1_JPIMMED_2_01"); POP_1; break;
267
case cJ1_JPIMMED_3_01: JPTYPE("cJ1_JPIMMED_3_01"); POP_1; break;
269
case cJ1_JPIMMED_4_01: JPTYPE("cJ1_JPIMMED_4_01"); POP_1; break;
270
case cJ1_JPIMMED_5_01: JPTYPE("cJ1_JPIMMED_5_01"); POP_1; break;
271
case cJ1_JPIMMED_6_01: JPTYPE("cJ1_JPIMMED_6_01"); POP_1; break;
272
case cJ1_JPIMMED_7_01: JPTYPE("cJ1_JPIMMED_7_01"); POP_1; break;
275
case cJ1_JPIMMED_1_02: JPTYPE("cJ1_JPIMMED_1_02"); POP_2; break;
276
case cJ1_JPIMMED_1_03: JPTYPE("cJ1_JPIMMED_1_03"); POP_3; break;
277
case cJ1_JPIMMED_1_04: JPTYPE("cJ1_JPIMMED_1_04"); POP_4; break;
278
case cJ1_JPIMMED_1_05: JPTYPE("cJ1_JPIMMED_1_05"); POP_5; break;
279
case cJ1_JPIMMED_1_06: JPTYPE("cJ1_JPIMMED_1_06"); POP_6; break;
280
case cJ1_JPIMMED_1_07: JPTYPE("cJ1_JPIMMED_1_07"); POP_7; break;
282
case cJ1_JPIMMED_1_08: JPTYPE("cJ1_JPIMMED_1_08"); POP_8; break;
283
case cJ1_JPIMMED_1_09: JPTYPE("cJ1_JPIMMED_1_09"); POP_9; break;
284
case cJ1_JPIMMED_1_10: JPTYPE("cJ1_JPIMMED_1_10"); POP_10; break;
285
case cJ1_JPIMMED_1_11: JPTYPE("cJ1_JPIMMED_1_11"); POP_11; break;
286
case cJ1_JPIMMED_1_12: JPTYPE("cJ1_JPIMMED_1_12"); POP_12; break;
287
case cJ1_JPIMMED_1_13: JPTYPE("cJ1_JPIMMED_1_13"); POP_13; break;
288
case cJ1_JPIMMED_1_14: JPTYPE("cJ1_JPIMMED_1_14"); POP_14; break;
289
case cJ1_JPIMMED_1_15: JPTYPE("cJ1_JPIMMED_1_15"); POP_15; break;
291
case cJ1_JPIMMED_2_02: JPTYPE("cJ1_JPIMMED_2_02"); POP_2; break;
292
case cJ1_JPIMMED_2_03: JPTYPE("cJ1_JPIMMED_2_03"); POP_3; break;
294
case cJ1_JPIMMED_2_04: JPTYPE("cJ1_JPIMMED_2_04"); POP_4; break;
295
case cJ1_JPIMMED_2_05: JPTYPE("cJ1_JPIMMED_2_05"); POP_5; break;
296
case cJ1_JPIMMED_2_06: JPTYPE("cJ1_JPIMMED_2_06"); POP_6; break;
297
case cJ1_JPIMMED_2_07: JPTYPE("cJ1_JPIMMED_2_07"); POP_7; break;
300
case cJ1_JPIMMED_3_02: JPTYPE("cJ1_JPIMMED_3_02"); POP_2; break;
302
case cJ1_JPIMMED_3_03: JPTYPE("cJ1_JPIMMED_3_03"); POP_3; break;
303
case cJ1_JPIMMED_3_04: JPTYPE("cJ1_JPIMMED_3_04"); POP_4; break;
304
case cJ1_JPIMMED_3_05: JPTYPE("cJ1_JPIMMED_3_05"); POP_5; break;
305
case cJ1_JPIMMED_4_02: JPTYPE("cJ1_JPIMMED_4_02"); POP_2; break;
306
case cJ1_JPIMMED_4_03: JPTYPE("cJ1_JPIMMED_4_03"); POP_3; break;
307
case cJ1_JPIMMED_5_02: JPTYPE("cJ1_JPIMMED_5_02"); POP_2; break;
308
case cJ1_JPIMMED_5_03: JPTYPE("cJ1_JPIMMED_5_03"); POP_3; break;
309
case cJ1_JPIMMED_6_02: JPTYPE("cJ1_JPIMMED_6_02"); POP_2; break;
310
case cJ1_JPIMMED_7_02: JPTYPE("cJ1_JPIMMED_7_02"); POP_2; break;
312
case cJ1_JPIMMED_CAP: JPTYPE("cJ1_JPIMMED_CAP"); OOPS;
314
#else // JUDYL ===============================================================
316
case cJL_JPNULL1: JPTYPE("cJL_JPNULL1"); POP0; break;
317
case cJL_JPNULL2: JPTYPE("cJL_JPNULL2"); POP0; break;
318
case cJL_JPNULL3: JPTYPE("cJL_JPNULL3"); POP0; break;
320
case cJL_JPNULL4: JPTYPE("cJL_JPNULL4"); POP0; break;
321
case cJL_JPNULL5: JPTYPE("cJL_JPNULL5"); POP0; break;
322
case cJL_JPNULL6: JPTYPE("cJL_JPNULL6"); POP0; break;
323
case cJL_JPNULL7: JPTYPE("cJL_JPNULL7"); POP0; break;
326
case cJL_JPBRANCH_L2: JPTYPE("cJL_JPBRANCH_L2"); POP2;NUMJPSL;break;
327
case cJL_JPBRANCH_L3: JPTYPE("cJL_JPBRANCH_L3"); POP3;NUMJPSL;break;
329
case cJL_JPBRANCH_L4: JPTYPE("cJL_JPBRANCH_L4"); POP4;NUMJPSL;break;
330
case cJL_JPBRANCH_L5: JPTYPE("cJL_JPBRANCH_L5"); POP5;NUMJPSL;break;
331
case cJL_JPBRANCH_L6: JPTYPE("cJL_JPBRANCH_L6"); POP6;NUMJPSL;break;
332
case cJL_JPBRANCH_L7: JPTYPE("cJL_JPBRANCH_L7"); POP7;NUMJPSL;break;
334
case cJL_JPBRANCH_L: JPTYPE("cJL_JPBRANCH_L"); NUMJPSL;break;
336
case cJL_JPBRANCH_B2: JPTYPE("cJL_JPBRANCH_B2"); POP2;NUMJPSB;break;
337
case cJL_JPBRANCH_B3: JPTYPE("cJL_JPBRANCH_B3"); POP3;NUMJPSB;break;
339
case cJL_JPBRANCH_B4: JPTYPE("cJL_JPBRANCH_B4"); POP4;NUMJPSB;break;
340
case cJL_JPBRANCH_B5: JPTYPE("cJL_JPBRANCH_B5"); POP5;NUMJPSB;break;
341
case cJL_JPBRANCH_B6: JPTYPE("cJL_JPBRANCH_B6"); POP6;NUMJPSB;break;
342
case cJL_JPBRANCH_B7: JPTYPE("cJL_JPBRANCH_B7"); POP7;NUMJPSB;break;
344
case cJL_JPBRANCH_B: JPTYPE("cJL_JPBRANCH_B"); NUMJPSB;break;
346
case cJL_JPBRANCH_U2: JPTYPE("cJL_JPBRANCH_U2"); POP2; break;
347
case cJL_JPBRANCH_U3: JPTYPE("cJL_JPBRANCH_U3"); POP3; break;
349
case cJL_JPBRANCH_U4: JPTYPE("cJL_JPBRANCH_U4"); POP4; break;
350
case cJL_JPBRANCH_U5: JPTYPE("cJL_JPBRANCH_U5"); POP5; break;
351
case cJL_JPBRANCH_U6: JPTYPE("cJL_JPBRANCH_U6"); POP6; break;
352
case cJL_JPBRANCH_U7: JPTYPE("cJL_JPBRANCH_U7"); POP7; break;
354
case cJL_JPBRANCH_U: JPTYPE("cJL_JPBRANCH_U"); break;
356
case cJL_JPLEAF1: JPTYPE("cJL_JPLEAF1"); POP1; break;
357
case cJL_JPLEAF2: JPTYPE("cJL_JPLEAF2"); POP2; break;
358
case cJL_JPLEAF3: JPTYPE("cJL_JPLEAF3"); POP3; break;
360
case cJL_JPLEAF4: JPTYPE("cJL_JPLEAF4"); POP4; break;
361
case cJL_JPLEAF5: JPTYPE("cJL_JPLEAF5"); POP5; break;
362
case cJL_JPLEAF6: JPTYPE("cJL_JPLEAF6"); POP6; break;
363
case cJL_JPLEAF7: JPTYPE("cJL_JPLEAF7"); POP7; break;
366
case cJL_JPLEAF_B1: JPTYPE("cJL_JPLEAF_B1"); POP1; break;
368
case cJL_JPIMMED_1_01: JPTYPE("cJL_JPIMMED_1_01"); POP_1; break;
369
case cJL_JPIMMED_2_01: JPTYPE("cJL_JPIMMED_2_01"); POP_1; break;
370
case cJL_JPIMMED_3_01: JPTYPE("cJL_JPIMMED_3_01"); POP_1; break;
372
case cJL_JPIMMED_4_01: JPTYPE("cJL_JPIMMED_4_01"); POP_1; break;
373
case cJL_JPIMMED_5_01: JPTYPE("cJL_JPIMMED_5_01"); POP_1; break;
374
case cJL_JPIMMED_6_01: JPTYPE("cJL_JPIMMED_6_01"); POP_1; break;
375
case cJL_JPIMMED_7_01: JPTYPE("cJL_JPIMMED_7_01"); POP_1; break;
378
case cJL_JPIMMED_1_02: JPTYPE("cJL_JPIMMED_1_02"); POP_2; break;
379
case cJL_JPIMMED_1_03: JPTYPE("cJL_JPIMMED_1_03"); POP_3; break;
381
case cJL_JPIMMED_1_04: JPTYPE("cJL_JPIMMED_1_04"); POP_4; break;
382
case cJL_JPIMMED_1_05: JPTYPE("cJL_JPIMMED_1_05"); POP_5; break;
383
case cJL_JPIMMED_1_06: JPTYPE("cJL_JPIMMED_1_06"); POP_6; break;
384
case cJL_JPIMMED_1_07: JPTYPE("cJL_JPIMMED_1_07"); POP_7; break;
385
case cJL_JPIMMED_2_02: JPTYPE("cJL_JPIMMED_2_02"); POP_2; break;
386
case cJL_JPIMMED_2_03: JPTYPE("cJL_JPIMMED_2_03"); POP_3; break;
387
case cJL_JPIMMED_3_02: JPTYPE("cJL_JPIMMED_3_02"); POP_2; break;
389
case cJL_JPIMMED_CAP: JPTYPE("cJL_JPIMMED_CAP"); OOPS;
393
default: printf("Unknown Type = %d", Pjp->jp_Type); OOPS;
396
if (__JudyIndex) printf("Index = 0x%lx", __JudyIndex);
397
if (__JudyPopulation) printf("Pop = %lu", __JudyPopulation);
399
printf("line = %d\n", Line);