[860c7d]: src / runtime / print.c Maximize Restore History

Download this file

print.c    905 lines (788 with data), 26.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
/* code for low-level debugging/diagnostic output */
/*
* This software is part of the SBCL system. See the README file for
* more information.
*
* This software is derived from the CMU CL system, which was
* written at Carnegie Mellon University and released into the
* public domain. The software is in the public domain and is
* provided with absolutely no warranty. See the COPYING and CREDITS
* files for more information.
*/
/*
* FIXME:
* Some of the code in here (the various
* foo_slots[], at least) is deeply broken, depending on guessing
* already out-of-date values instead of getting them from sbcl.h.
*/
#include <stdio.h>
#include <string.h>
#include "sbcl.h"
#include "print.h"
#include "runtime.h"
#include <stdarg.h>
#include "thread.h" /* genesis/primitive-objects.h needs this */
#include <errno.h>
#include <stdlib.h>
/* FSHOW and odxprint provide debugging output for low-level information
* (signal handling, exceptions, safepoints) which is hard to debug by
* other means.
*
* If enabled at all, environment variables control whether calls of the
* form odxprint(name, ...) are enabled at run-time, e.g. using
* SBCL_DYNDEBUG="fshow fshow_signal safepoints".
*
* In the case of FSHOW and FSHOW_SIGNAL, old-style code from runtime.h
* can also be used to enable or disable these more aggressively.
*/
struct dyndebug_config dyndebug_config = {
QSHOW == 2, QSHOW_SIGNALS == 2
};
void
dyndebug_init()
{
#define DYNDEBUG_NFLAGS (sizeof(struct dyndebug_config) / sizeof(int))
#define dyndebug_init1(lowercase, uppercase) \
do { \
int *ptr = &dyndebug_config.dyndebug_##lowercase; \
ptrs[n] = ptr; \
names[n] = #lowercase; \
char *val = getenv("SBCL_DYNDEBUG__" uppercase); \
*ptr = val && strlen(val); \
n++; \
} while (0)
int n = 0;
char *names[DYNDEBUG_NFLAGS];
int *ptrs[DYNDEBUG_NFLAGS];
dyndebug_init1(fshow, "FSHOW");
dyndebug_init1(fshow_signal, "FSHOW_SIGNAL");
dyndebug_init1(gencgc_verbose, "GENCGC_VERBOSE");
dyndebug_init1(safepoints, "SAFEPOINTS");
dyndebug_init1(seh, "SEH");
dyndebug_init1(misc, "MISC");
dyndebug_init1(pagefaults, "PAGEFAULTS");
dyndebug_init1(io, "IO");
dyndebug_init1(runtime_link, "RUNTIME_LINK");
int n_output_flags = n;
dyndebug_init1(backtrace_when_lost, "BACKTRACE_WHEN_LOST");
dyndebug_init1(sleep_when_lost, "SLEEP_WHEN_LOST");
if (n != DYNDEBUG_NFLAGS)
fprintf(stderr, "Bug in dyndebug_init\n");
#if defined(LISP_FEATURE_GENCGC)
gencgc_verbose = dyndebug_config.dyndebug_gencgc_verbose;
#endif
char *featurelist = getenv("SBCL_DYNDEBUG");
if (featurelist) {
int err = 0;
featurelist = strdup(featurelist);
char *ptr = featurelist;
for (;;) {
char *token = strtok(ptr, " ");
if (!token) break;
unsigned i;
if (!strcmp(token, "all"))
for (i = 0; i < n_output_flags; i++)
*ptrs[i] = 1;
else {
for (i = 0; i < DYNDEBUG_NFLAGS; i++)
if (!strcmp(token, names[i])) {
*ptrs[i] = 1;
break;
}
if (i == DYNDEBUG_NFLAGS) {
fprintf(stderr, "No such dyndebug flag: `%s'\n", token);
err = 1;
}
}
ptr = 0;
}
free(featurelist);
if (err) {
fprintf(stderr, "Valid flags are:\n");
fprintf(stderr, " all ;enables all of the following:\n");
unsigned i;
for (i = 0; i < DYNDEBUG_NFLAGS; i++) {
if (i == n_output_flags)
fprintf(stderr, "Additional options:\n");
fprintf(stderr, " %s\n", names[i]);
}
}
}
#undef dyndebug_init1
#undef DYNDEBUG_NFLAGS
}
/* Temporarily, odxprint merely performs the equivalent of a traditional
* FSHOW call, i.e. it merely formats to stderr. Ultimately, it should
* be restored to its full win32 branch functionality, where output to a
* file or to the debugger can be selected at runtime. */
void vodxprint_fun(const char *, va_list);
void
odxprint_fun(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vodxprint_fun(fmt, args);
va_end(args);
}
void
vodxprint_fun(const char *fmt, va_list args)
{
#ifdef LISP_FEATURE_WIN32
DWORD lastError = GetLastError();
#endif
int original_errno = errno;
QSHOW_BLOCK;
char buf[1024];
#ifdef LISP_FEATURE_SB_THREAD
struct thread *arch_os_get_current_thread(void);
struct thread *self = arch_os_get_current_thread();
void *pth = self ? (void *) self->os_thread : 0;
snprintf(buf, sizeof(buf), "[%p/%p] ", self, pth);
#endif
int n = strlen(buf);
vsnprintf(buf + n, sizeof(buf) - n - 1, fmt, args);
/* buf is now zero-terminated (even in case of overflow).
* Our caller took care of the newline (if any) through `fmt'. */
/* A sufficiently POSIXy implementation of stdio will provide
* per-FILE locking, as defined in the spec for flockfile. At least
* glibc complies with this. Hence we do not need to perform
* locking ourselves here. (Should it turn out, of course, that
* other libraries opt for speed rather than safety, we need to
* revisit this decision.) */
fputs(buf, stderr);
#ifdef LISP_FEATURE_WIN32
/* stdio's stderr is line-bufferred, i.e. \n ought to flush it.
* Unfortunately, MinGW does not behave the way I would expect it
* to. Let's be safe: */
fflush(stderr);
#endif
QSHOW_UNBLOCK;
#ifdef LISP_FEATURE_WIN32
SetLastError(lastError);
#endif
errno = original_errno;
}
/* Translate the rather awkward syntax
* FSHOW((stderr, "xyz"))
* into the new and cleaner
* odxprint("xyz").
* If we were willing to clean up all existing call sites, we could remove
* this wrapper function. (This is a function, because I don't know how to
* strip the extra parens in a macro.) */
void
fshow_fun(void __attribute__((__unused__)) *ignored,
const char *fmt,
...)
{
va_list args;
va_start(args, fmt);
vodxprint_fun(fmt, args);
va_end(args);
}
/* This file can be skipped if we're not supporting LDB. */
#if defined(LISP_FEATURE_SB_LDB)
#include "monitor.h"
#include "vars.h"
#include "os.h"
#ifdef LISP_FEATURE_GENCGC
#include "gencgc-alloc-region.h" /* genesis/thread.h needs this */
#endif
#if defined(LISP_FEATURE_WIN32)
# include "win32-thread-private-events.h" /* genesis/thread.h needs this */
#endif
#include "genesis/static-symbols.h"
#include "genesis/primitive-objects.h"
#include "genesis/static-symbols.h"
#include "genesis/tagnames.h"
static int max_lines = 20, cur_lines = 0;
static int max_depth = 5, brief_depth = 2, cur_depth = 0;
static int max_length = 5;
static boolean dont_descend = 0, skip_newline = 0;
static int cur_clock = 0;
static void print_obj(char *prefix, lispobj obj);
#define NEWLINE_OR_RETURN if (continue_p(1)) newline(NULL); else return;
static void indent(int in)
{
static char *spaces = " ";
while (in > 64) {
fputs(spaces, stdout);
in -= 64;
}
if (in != 0)
fputs(spaces + 64 - in, stdout);
}
static boolean continue_p(boolean newline)
{
char buffer[256];
if (cur_depth >= max_depth || dont_descend)
return 0;
if (newline) {
if (skip_newline)
skip_newline = 0;
else
putchar('\n');
if (cur_lines >= max_lines) {
printf("More? [y] ");
fflush(stdout);
if (fgets(buffer, sizeof(buffer), stdin)) {
if (buffer[0] == 'n' || buffer[0] == 'N')
throw_to_monitor();
else
cur_lines = 0;
} else {
printf("\nUnable to read response, assuming y.\n");
cur_lines = 0;
}
}
}
return 1;
}
static void newline(char *label)
{
cur_lines++;
if (label != NULL)
fputs(label, stdout);
putchar('\t');
indent(cur_depth * 2);
}
static void print_unknown(lispobj obj)
{
printf("unknown object: %p", (void *)obj);
}
static void brief_fixnum(lispobj obj)
{
/* KLUDGE: Rather than update the tables in print_obj(), we
declare all fixnum-or-unknown tags to be fixnums and sort it
out here with a guard clause. */
if (!fixnump(obj)) return print_unknown(obj);
#ifndef LISP_FEATURE_ALPHA
printf("%ld", ((long)obj)>>N_FIXNUM_TAG_BITS);
#else
printf("%d", ((s32)obj)>>N_FIXNUM_TAG_BITS);
#endif
}
static void print_fixnum(lispobj obj)
{
/* KLUDGE: Rather than update the tables in print_obj(), we
declare all fixnum-or-unknown tags to be fixnums and sort it
out here with a guard clause. */
if (!fixnump(obj)) return print_unknown(obj);
#ifndef LISP_FEATURE_ALPHA
printf(": %ld", ((long)obj)>>N_FIXNUM_TAG_BITS);
#else
printf(": %d", ((s32)obj)>>N_FIXNUM_TAG_BITS);
#endif
}
static void brief_otherimm(lispobj obj)
{
int type, c;
char buffer[10];
type = widetag_of(obj);
switch (type) {
case CHARACTER_WIDETAG:
c = (obj>>8)&0xff;
switch (c) {
case '\0':
printf("#\\Null");
break;
case '\n':
printf("#\\Newline");
break;
case '\b':
printf("#\\Backspace");
break;
case '\177':
printf("#\\Delete");
break;
default:
strcpy(buffer, "#\\");
if (c >= 128) {
strcat(buffer, "m-");
c -= 128;
}
if (c < 32) {
strcat(buffer, "c-");
c += '@';
}
printf("%s%c", buffer, c);
break;
}
break;
case UNBOUND_MARKER_WIDETAG:
printf("<unbound marker>");
break;
default:
printf("%s", widetag_names[type >> 2]);
break;
}
}
static void print_otherimm(lispobj obj)
{
printf(", %s", widetag_names[widetag_of(obj) >> 2]);
switch (widetag_of(obj)) {
case CHARACTER_WIDETAG:
printf(": ");
brief_otherimm(obj);
break;
case SAP_WIDETAG:
case UNBOUND_MARKER_WIDETAG:
break;
default:
printf(": data=%ld", (long) (obj>>8)&0xffffff);
break;
}
}
static void brief_list(lispobj obj)
{
int space = 0;
int length = 0;
if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj)))
printf("(invalid Lisp-level address)");
else if (obj == NIL)
printf("NIL");
else {
putchar('(');
while (lowtag_of(obj) == LIST_POINTER_LOWTAG) {
struct cons *cons = (struct cons *)native_pointer(obj);
if (space)
putchar(' ');
if (++length >= max_length) {
printf("...");
obj = NIL;
break;
}
print_obj("", cons->car);
obj = cons->cdr;
space = 1;
if (obj == NIL)
break;
}
if (obj != NIL) {
printf(" . ");
print_obj("", obj);
}
putchar(')');
}
}
static void print_list(lispobj obj)
{
if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj))) {
printf("(invalid address)");
} else if (obj == NIL) {
printf(" (NIL)");
} else {
struct cons *cons = (struct cons *)native_pointer(obj);
print_obj("car: ", cons->car);
print_obj("cdr: ", cons->cdr);
}
}
static void brief_struct(lispobj obj)
{
struct instance *instance = (struct instance *)native_pointer(obj);
if (!is_valid_lisp_addr((os_vm_address_t)instance)) {
printf("(invalid address)");
} else {
printf("#<ptr to 0x%08lx instance>",
(unsigned long) instance->slots[0]);
}
}
static void print_struct(lispobj obj)
{
struct instance *instance = (struct instance *)native_pointer(obj);
unsigned int i;
char buffer[16];
if (!is_valid_lisp_addr((os_vm_address_t)instance)) {
printf("(invalid address)");
} else {
print_obj("type: ", ((struct instance *)native_pointer(obj))->slots[0]);
for (i = 1; i < HeaderValue(instance->header); i++) {
sprintf(buffer, "slot %d: ", i);
print_obj(buffer, instance->slots[i]);
}
}
}
static void brief_otherptr(lispobj obj)
{
lispobj *ptr, header;
int type;
struct symbol *symbol;
struct vector *vector;
char *charptr;
ptr = (lispobj *) native_pointer(obj);
if (!is_valid_lisp_addr((os_vm_address_t)obj)) {
printf("(invalid address)");
return;
}
header = *ptr;
type = widetag_of(header);
switch (type) {
case SYMBOL_HEADER_WIDETAG:
symbol = (struct symbol *)ptr;
vector = (struct vector *)native_pointer(symbol->name);
for (charptr = (char *)vector->data; *charptr != '\0'; charptr++) {
if (*charptr == '"')
putchar('\\');
putchar(*charptr);
}
break;
case SIMPLE_BASE_STRING_WIDETAG:
vector = (struct vector *)ptr;
putchar('"');
for (charptr = (char *)vector->data; *charptr != '\0'; charptr++) {
if (*charptr == '"')
putchar('\\');
putchar(*charptr);
}
putchar('"');
break;
default:
printf("#<ptr to ");
brief_otherimm(header);
putchar('>');
}
}
static void print_slots(char **slots, int count, lispobj *ptr)
{
while (count-- > 0) {
if (*slots) {
print_obj(*slots++, *ptr++);
} else {
print_obj("???: ", *ptr++);
}
}
}
/* FIXME: Yikes! This needs to depend on the values in sbcl.h (or
* perhaps be generated automatically by GENESIS as part of
* sbcl.h). */
static char *symbol_slots[] = {"value: ", "hash: ",
"info: ", "name: ", "package: ",
#ifdef LISP_FEATURE_SB_THREAD
"tls-index: " ,
#endif
NULL};
static char *ratio_slots[] = {"numer: ", "denom: ", NULL};
static char *complex_slots[] = {"real: ", "imag: ", NULL};
static char *code_slots[] = {"words: ", "entry: ", "debug: ", NULL};
static char *fn_slots[] = {
"self: ", "next: ", "name: ", "arglist: ", "type: ", NULL};
static char *closure_slots[] = {"fn: ", NULL};
static char *funcallable_instance_slots[] = {"fn: ", "lexenv: ", "layout: ", NULL};
static char *weak_pointer_slots[] = {"value: ", NULL};
static char *fdefn_slots[] = {"name: ", "function: ", "raw_addr: ", NULL};
static char *value_cell_slots[] = {"value: ", NULL};
static void print_otherptr(lispobj obj)
{
if (!is_valid_lisp_addr((os_vm_address_t)obj)) {
printf("(invalid address)");
} else {
#ifndef LISP_FEATURE_ALPHA
lispobj *ptr;
unsigned long header;
unsigned long length;
#else
u32 *ptr;
u32 header;
u32 length;
#endif
int count, type, index;
char *cptr, buffer[16];
ptr = (lispobj*) native_pointer(obj);
if (ptr == NULL) {
printf(" (NULL Pointer)");
return;
}
header = *ptr++;
length = fixnum_value(*ptr);
count = HeaderValue(header);
type = widetag_of(header);
print_obj("header: ", header);
if (!other_immediate_lowtag_p(header)) {
NEWLINE_OR_RETURN;
printf("(invalid header object)");
return;
}
switch (type) {
case BIGNUM_WIDETAG:
ptr += count;
NEWLINE_OR_RETURN;
printf("0x");
while (count-- > 0)
printf("%08lx", (unsigned long) *--ptr);
break;
case RATIO_WIDETAG:
print_slots(ratio_slots, count, ptr);
break;
case COMPLEX_WIDETAG:
print_slots(complex_slots, count, ptr);
break;
case SYMBOL_HEADER_WIDETAG:
print_slots(symbol_slots, count, ptr);
break;
#if N_WORD_BITS == 32
case SINGLE_FLOAT_WIDETAG:
NEWLINE_OR_RETURN;
printf("%g", ((struct single_float *)native_pointer(obj))->value);
break;
#endif
case DOUBLE_FLOAT_WIDETAG:
NEWLINE_OR_RETURN;
printf("%g", ((struct double_float *)native_pointer(obj))->value);
break;
#ifdef LONG_FLOAT_WIDETAG
case LONG_FLOAT_WIDETAG:
NEWLINE_OR_RETURN;
printf("%Lg", ((struct long_float *)native_pointer(obj))->value);
break;
#endif
#ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
case COMPLEX_SINGLE_FLOAT_WIDETAG:
NEWLINE_OR_RETURN;
#ifdef LISP_FEATURE_X86_64
printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[0]);
#else
printf("%g", ((struct complex_single_float *)native_pointer(obj))->real);
#endif
NEWLINE_OR_RETURN;
#ifdef LISP_FEATURE_X86_64
printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[1]);
#else
printf("%g", ((struct complex_single_float *)native_pointer(obj))->imag);
#endif
break;
#endif
#ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
case COMPLEX_DOUBLE_FLOAT_WIDETAG:
NEWLINE_OR_RETURN;
printf("%g", ((struct complex_double_float *)native_pointer(obj))->real);
NEWLINE_OR_RETURN;
printf("%g", ((struct complex_double_float *)native_pointer(obj))->imag);
break;
#endif
#ifdef COMPLEX_LONG_FLOAT_WIDETAG
case COMPLEX_LONG_FLOAT_WIDETAG:
NEWLINE_OR_RETURN;
printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->real);
NEWLINE_OR_RETURN;
printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->imag);
break;
#endif
case SIMPLE_BASE_STRING_WIDETAG:
#ifdef SIMPLE_CHARACTER_STRING_WIDETAG
case SIMPLE_CHARACTER_STRING_WIDETAG: /* FIXME */
#endif
NEWLINE_OR_RETURN;
cptr = (char *)(ptr+1);
putchar('"');
while (length-- > 0)
putchar(*cptr++);
putchar('"');
break;
case SIMPLE_VECTOR_WIDETAG:
NEWLINE_OR_RETURN;
printf("length = %ld", length);
ptr++;
index = 0;
while (length-- > 0) {
sprintf(buffer, "%d: ", index++);
print_obj(buffer, *ptr++);
}
break;
case INSTANCE_HEADER_WIDETAG:
NEWLINE_OR_RETURN;
printf("length = %ld", (long) count);
index = 0;
while (count-- > 0) {
sprintf(buffer, "%d: ", index++);
print_obj(buffer, *ptr++);
}
break;
case SIMPLE_ARRAY_WIDETAG:
case SIMPLE_BIT_VECTOR_WIDETAG:
case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
case SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG:
case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
#endif
#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
#endif
#ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
#endif
#ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
#endif
case SIMPLE_ARRAY_FIXNUM_WIDETAG:
#ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
#endif
#ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
#endif
case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
#ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
#endif
#ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
#endif
#ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
#endif
#ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
#endif
case COMPLEX_BASE_STRING_WIDETAG:
#ifdef COMPLEX_CHARACTER_STRING_WIDETAG
case COMPLEX_CHARACTER_STRING_WIDETAG:
#endif
case COMPLEX_VECTOR_NIL_WIDETAG:
case COMPLEX_BIT_VECTOR_WIDETAG:
case COMPLEX_VECTOR_WIDETAG:
case COMPLEX_ARRAY_WIDETAG:
break;
case CODE_HEADER_WIDETAG:
print_slots(code_slots, count-1, ptr);
break;
case SIMPLE_FUN_HEADER_WIDETAG:
print_slots(fn_slots, 5, ptr);
break;
case RETURN_PC_HEADER_WIDETAG:
print_obj("code: ", obj - (count * 4));
break;
case CLOSURE_HEADER_WIDETAG:
print_slots(closure_slots, count, ptr);
break;
case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
print_slots(funcallable_instance_slots, count, ptr);
break;
case VALUE_CELL_HEADER_WIDETAG:
print_slots(value_cell_slots, 1, ptr);
break;
case SAP_WIDETAG:
NEWLINE_OR_RETURN;
#ifndef LISP_FEATURE_ALPHA
printf("0x%08lx", (unsigned long) *ptr);
#else
printf("0x%016lx", *(lispobj*)(ptr+1));
#endif
break;
case WEAK_POINTER_WIDETAG:
print_slots(weak_pointer_slots, 1, ptr);
break;
case CHARACTER_WIDETAG:
case UNBOUND_MARKER_WIDETAG:
NEWLINE_OR_RETURN;
printf("pointer to an immediate?");
break;
case FDEFN_WIDETAG:
print_slots(fdefn_slots, count, ptr);
break;
default:
NEWLINE_OR_RETURN;
printf("Unknown header object?");
break;
}
}
}
static void print_obj(char *prefix, lispobj obj)
{
#ifdef LISP_FEATURE_X86_64
static void (*verbose_fns[])(lispobj obj)
= {print_fixnum, print_otherimm, print_fixnum, print_struct,
print_fixnum, print_otherimm, print_fixnum, print_list,
print_fixnum, print_otherimm, print_fixnum, print_otherptr,
print_fixnum, print_otherimm, print_fixnum, print_otherptr};
static void (*brief_fns[])(lispobj obj)
= {brief_fixnum, brief_otherimm, brief_fixnum, brief_struct,
brief_fixnum, brief_otherimm, brief_fixnum, brief_list,
brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr,
brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr};
#else
static void (*verbose_fns[])(lispobj obj)
= {print_fixnum, print_struct, print_otherimm, print_list,
print_fixnum, print_otherptr, print_otherimm, print_otherptr};
static void (*brief_fns[])(lispobj obj)
= {brief_fixnum, brief_struct, brief_otherimm, brief_list,
brief_fixnum, brief_otherptr, brief_otherimm, brief_otherptr};
#endif
int type = lowtag_of(obj);
struct var *var = lookup_by_obj(obj);
char buffer[256];
boolean verbose = cur_depth < brief_depth;
if (!continue_p(verbose))
return;
if (var != NULL && var_clock(var) == cur_clock)
dont_descend = 1;
if (var == NULL && is_lisp_pointer(obj))
var = define_var(NULL, obj, 0);
if (var != NULL)
var_setclock(var, cur_clock);
cur_depth++;
if (verbose) {
if (var != NULL) {
sprintf(buffer, "$%s=", var_name(var));
newline(buffer);
}
else
newline(NULL);
printf("%s0x%08lx: ", prefix, (unsigned long) obj);
if (cur_depth < brief_depth) {
fputs(lowtag_names[type], stdout);
(*verbose_fns[type])(obj);
}
else
(*brief_fns[type])(obj);
}
else {
if (dont_descend)
printf("$%s", var_name(var));
else {
if (var != NULL)
printf("$%s=", var_name(var));
(*brief_fns[type])(obj);
}
}
cur_depth--;
dont_descend = 0;
}
void reset_printer()
{
cur_clock++;
cur_lines = 0;
dont_descend = 0;
}
void print(lispobj obj)
{
skip_newline = 1;
cur_depth = 0;
max_depth = 5;
max_lines = 20;
print_obj("", obj);
putchar('\n');
}
void brief_print(lispobj obj)
{
skip_newline = 1;
cur_depth = 0;
max_depth = 1;
max_lines = 5000;
cur_lines = 0;
print_obj("", obj);
putchar('\n');
}
#else
void
brief_print(lispobj obj)
{
printf("lispobj 0x%lx\n", (unsigned long)obj);
}
#endif /* defined(LISP_FEATURE_SB_LDB) */