Typos in comments [ci skip]
[ghc.git] / rts / Printer.c
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1994-2000.
4 *
5 * Heap printer
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #include "PosixSource.h"
10 #include "ghcconfig.h"
11
12 #include "Rts.h"
13 #include "rts/Bytecodes.h" /* for InstrPtr */
14
15 #include "sm/Storage.h"
16 #include "Hash.h"
17 #include "Printer.h"
18 #include "RtsUtils.h"
19
20 #ifdef PROFILING
21 #include "Profiling.h"
22 #endif
23
24 #include <string.h>
25
26 #ifdef DEBUG
27
28 #include "Disassembler.h"
29 #include "Apply.h"
30
31 /* --------------------------------------------------------------------------
32 * local function decls
33 * ------------------------------------------------------------------------*/
34
35 static void printStdObjPayload( const StgClosure *obj );
36
37 /* --------------------------------------------------------------------------
38 * Printer
39 * ------------------------------------------------------------------------*/
40
41 void printPtr( StgPtr p )
42 {
43 const char *raw;
44 raw = lookupGHCName(p);
45 if (raw != NULL) {
46 debugBelch("<%s>", raw);
47 debugBelch("[%p]", p);
48 } else {
49 debugBelch("%p", p);
50 }
51 }
52
53 void printObj( StgClosure *obj )
54 {
55 debugBelch("Object "); printPtr((StgPtr)obj); debugBelch(" = ");
56 printClosure(obj);
57 }
58
59 STATIC_INLINE void
60 printStdObjHdr( const StgClosure *obj, char* tag )
61 {
62 debugBelch("%s(",tag);
63 printPtr((StgPtr)obj->header.info);
64 #ifdef PROFILING
65 debugBelch(", %s", obj->header.prof.ccs->cc->label);
66 #endif
67 }
68
69 static void
70 printStdObjPayload( const StgClosure *obj )
71 {
72 StgWord i, j;
73 const StgInfoTable* info;
74
75 info = get_itbl(obj);
76 for (i = 0; i < info->layout.payload.ptrs; ++i) {
77 debugBelch(", ");
78 printPtr((StgPtr)obj->payload[i]);
79 }
80 for (j = 0; j < info->layout.payload.nptrs; ++j) {
81 debugBelch(", %pd#",obj->payload[i+j]);
82 }
83 debugBelch(")\n");
84 }
85
86 static void
87 printThunkPayload( StgThunk *obj )
88 {
89 StgWord i, j;
90 const StgInfoTable* info;
91
92 info = get_itbl((StgClosure *)obj);
93 for (i = 0; i < info->layout.payload.ptrs; ++i) {
94 debugBelch(", ");
95 printPtr((StgPtr)obj->payload[i]);
96 }
97 for (j = 0; j < info->layout.payload.nptrs; ++j) {
98 debugBelch(", %pd#",obj->payload[i+j]);
99 }
100 debugBelch(")\n");
101 }
102
103 static void
104 printThunkObject( StgThunk *obj, char* tag )
105 {
106 printStdObjHdr( (StgClosure *)obj, tag );
107 printThunkPayload( obj );
108 }
109
110 void
111 printClosure( const StgClosure *obj )
112 {
113 const StgInfoTable *info;
114
115 obj = UNTAG_CONST_CLOSURE(obj);
116 info = get_itbl(obj);
117
118 switch ( info->type ) {
119 case INVALID_OBJECT:
120 barf("Invalid object");
121
122 case CONSTR:
123 case CONSTR_1_0: case CONSTR_0_1:
124 case CONSTR_1_1: case CONSTR_0_2: case CONSTR_2_0:
125 case CONSTR_NOCAF:
126 {
127 StgWord i, j;
128 const StgConInfoTable *con_info = get_con_itbl (obj);
129
130 debugBelch("%s(", GET_CON_DESC(con_info));
131 for (i = 0; i < info->layout.payload.ptrs; ++i) {
132 if (i != 0) debugBelch(", ");
133 printPtr((StgPtr)obj->payload[i]);
134 }
135 for (j = 0; j < info->layout.payload.nptrs; ++j) {
136 if (i != 0 || j != 0) debugBelch(", ");
137 debugBelch("%p#", obj->payload[i+j]);
138 }
139 debugBelch(")\n");
140 break;
141 }
142
143 case FUN:
144 case FUN_1_0: case FUN_0_1:
145 case FUN_1_1: case FUN_0_2: case FUN_2_0:
146 case FUN_STATIC:
147 debugBelch("FUN/%d(",(int)itbl_to_fun_itbl(info)->f.arity);
148 printPtr((StgPtr)obj->header.info);
149 #ifdef PROFILING
150 debugBelch(", %s", obj->header.prof.ccs->cc->label);
151 #endif
152 printStdObjPayload(obj);
153 break;
154
155 case PRIM:
156 debugBelch("PRIM(");
157 printPtr((StgPtr)obj->header.info);
158 printStdObjPayload(obj);
159 break;
160
161 case MUT_PRIM:
162 debugBelch("MUT_PRIM(");
163 printPtr((StgPtr)obj->header.info);
164 printStdObjPayload(obj);
165 break;
166
167 case THUNK:
168 case THUNK_1_0: case THUNK_0_1:
169 case THUNK_1_1: case THUNK_0_2: case THUNK_2_0:
170 case THUNK_STATIC:
171 /* ToDo: will this work for THUNK_STATIC too? */
172 #ifdef PROFILING
173 printThunkObject((StgThunk *)obj,GET_PROF_DESC(info));
174 #else
175 printThunkObject((StgThunk *)obj,"THUNK");
176 #endif
177 break;
178
179 case THUNK_SELECTOR:
180 printStdObjHdr(obj, "THUNK_SELECTOR");
181 debugBelch(", %p)\n", ((StgSelector *)obj)->selectee);
182 break;
183
184 case BCO:
185 disassemble( (StgBCO*)obj );
186 break;
187
188 case AP:
189 {
190 StgAP* ap = (StgAP*)obj;
191 StgWord i;
192 debugBelch("AP("); printPtr((StgPtr)ap->fun);
193 for (i = 0; i < ap->n_args; ++i) {
194 debugBelch(", ");
195 printPtr((P_)ap->payload[i]);
196 }
197 debugBelch(")\n");
198 break;
199 }
200
201 case PAP:
202 {
203 StgPAP* pap = (StgPAP*)obj;
204 StgWord i;
205 debugBelch("PAP/%d(",(int)pap->arity);
206 printPtr((StgPtr)pap->fun);
207 for (i = 0; i < pap->n_args; ++i) {
208 debugBelch(", ");
209 printPtr((StgPtr)pap->payload[i]);
210 }
211 debugBelch(")\n");
212 break;
213 }
214
215 case AP_STACK:
216 {
217 StgAP_STACK* ap = (StgAP_STACK*)obj;
218 StgWord i;
219 debugBelch("AP_STACK("); printPtr((StgPtr)ap->fun);
220 for (i = 0; i < ap->size; ++i) {
221 debugBelch(", ");
222 printPtr((P_)ap->payload[i]);
223 }
224 debugBelch(")\n");
225 break;
226 }
227
228 case IND:
229 debugBelch("IND(");
230 printPtr((StgPtr)((StgInd*)obj)->indirectee);
231 debugBelch(")\n");
232 break;
233
234 case IND_STATIC:
235 debugBelch("IND_STATIC(");
236 printPtr((StgPtr)((StgInd*)obj)->indirectee);
237 debugBelch(")\n");
238 break;
239
240 case BLACKHOLE:
241 debugBelch("BLACKHOLE(");
242 printPtr((StgPtr)((StgInd*)obj)->indirectee);
243 debugBelch(")\n");
244 break;
245
246 /* Cannot happen -- use default case.
247 case RET_BCO:
248 case RET_SMALL:
249 case RET_BIG:
250 case RET_FUN:
251 */
252
253 case UPDATE_FRAME:
254 {
255 StgUpdateFrame* u = (StgUpdateFrame*)obj;
256 debugBelch("%s(", info_update_frame(obj));
257 printPtr((StgPtr)GET_INFO((StgClosure *)u));
258 debugBelch(",");
259 printPtr((StgPtr)u->updatee);
260 debugBelch(")\n");
261 break;
262 }
263
264 case CATCH_FRAME:
265 {
266 StgCatchFrame* u = (StgCatchFrame*)obj;
267 debugBelch("CATCH_FRAME(");
268 printPtr((StgPtr)GET_INFO((StgClosure *)u));
269 debugBelch(",");
270 printPtr((StgPtr)u->handler);
271 debugBelch(")\n");
272 break;
273 }
274
275 case UNDERFLOW_FRAME:
276 {
277 StgUnderflowFrame* u = (StgUnderflowFrame*)obj;
278 debugBelch("UNDERFLOW_FRAME(");
279 printPtr((StgPtr)u->next_chunk);
280 debugBelch(")\n");
281 break;
282 }
283
284 case STOP_FRAME:
285 {
286 StgStopFrame* u = (StgStopFrame*)obj;
287 debugBelch("STOP_FRAME(");
288 printPtr((StgPtr)GET_INFO((StgClosure *)u));
289 debugBelch(")\n");
290 break;
291 }
292
293 case ARR_WORDS:
294 {
295 StgWord i;
296 debugBelch("ARR_WORDS(\"");
297 for (i=0; i<arr_words_words((StgArrBytes *)obj); i++)
298 debugBelch("%" FMT_Word, (W_)((StgArrBytes *)obj)->payload[i]);
299 debugBelch("\")\n");
300 break;
301 }
302
303 case MUT_ARR_PTRS_CLEAN:
304 debugBelch("MUT_ARR_PTRS_CLEAN(size=%" FMT_Word ")\n", (W_)((StgMutArrPtrs *)obj)->ptrs);
305 break;
306
307 case MUT_ARR_PTRS_DIRTY:
308 debugBelch("MUT_ARR_PTRS_DIRTY(size=%" FMT_Word ")\n", (W_)((StgMutArrPtrs *)obj)->ptrs);
309 break;
310
311 case MUT_ARR_PTRS_FROZEN:
312 debugBelch("MUT_ARR_PTRS_FROZEN(size=%" FMT_Word ")\n", (W_)((StgMutArrPtrs *)obj)->ptrs);
313 break;
314
315 case SMALL_MUT_ARR_PTRS_CLEAN:
316 debugBelch("SMALL_MUT_ARR_PTRS_CLEAN(size=%" FMT_Word ")\n",
317 (W_)((StgSmallMutArrPtrs *)obj)->ptrs);
318 break;
319
320 case SMALL_MUT_ARR_PTRS_DIRTY:
321 debugBelch("SMALL_MUT_ARR_PTRS_DIRTY(size=%" FMT_Word ")\n",
322 (W_)((StgSmallMutArrPtrs *)obj)->ptrs);
323 break;
324
325 case SMALL_MUT_ARR_PTRS_FROZEN:
326 debugBelch("SMALL_MUT_ARR_PTRS_FROZEN(size=%" FMT_Word ")\n",
327 (W_)((StgSmallMutArrPtrs *)obj)->ptrs);
328 break;
329
330 case MVAR_CLEAN:
331 case MVAR_DIRTY:
332 {
333 StgMVar* mv = (StgMVar*)obj;
334 debugBelch("MVAR(head=%p, tail=%p, value=%p)\n", mv->head, mv->tail, mv->value);
335 break;
336 }
337
338 case TVAR:
339 {
340 StgTVar* tv = (StgTVar*)obj;
341 debugBelch("TVAR(value=%p, wq=%p, num_updates=%" FMT_Word ")\n", tv->current_value, tv->first_watch_queue_entry, tv->num_updates);
342 break;
343 }
344
345 case MUT_VAR_CLEAN:
346 {
347 StgMutVar* mv = (StgMutVar*)obj;
348 debugBelch("MUT_VAR_CLEAN(var=%p)\n", mv->var);
349 break;
350 }
351
352 case MUT_VAR_DIRTY:
353 {
354 StgMutVar* mv = (StgMutVar*)obj;
355 debugBelch("MUT_VAR_DIRTY(var=%p)\n", mv->var);
356 break;
357 }
358
359 case WEAK:
360 debugBelch("WEAK(");
361 debugBelch(" key=%p value=%p finalizer=%p",
362 (StgPtr)(((StgWeak*)obj)->key),
363 (StgPtr)(((StgWeak*)obj)->value),
364 (StgPtr)(((StgWeak*)obj)->finalizer));
365 debugBelch(")\n");
366 /* ToDo: chase 'link' ? */
367 break;
368
369 case TSO:
370 debugBelch("TSO(");
371 debugBelch("%lu (%p)",(unsigned long)(((StgTSO*)obj)->id), (StgTSO*)obj);
372 debugBelch(")\n");
373 break;
374
375 case STACK:
376 debugBelch("STACK");
377 break;
378
379 #if 0
380 /* Symptomatic of a problem elsewhere, have it fall-through & fail */
381 case EVACUATED:
382 debugBelch("EVACUATED(");
383 printClosure((StgEvacuated*)obj->evacuee);
384 debugBelch(")\n");
385 break;
386 #endif
387
388 case COMPACT_NFDATA:
389 debugBelch("COMPACT_NFDATA(size=%" FMT_Word ")\n",
390 (W_)((StgCompactNFData *)obj)->totalW * sizeof(W_));
391 break;
392
393
394 default:
395 //barf("printClosure %d",get_itbl(obj)->type);
396 debugBelch("*** printClosure: unknown type %d ****\n",
397 (int)get_itbl(obj)->type );
398 barf("printClosure %d",get_itbl(obj)->type);
399 return;
400 }
401 }
402
403 // If you know you have an UPDATE_FRAME, but want to know exactly which.
404 const char *info_update_frame(const StgClosure *closure)
405 {
406 // Note: We intentionally don't take the info table pointer as
407 // an argument. As it will be confusing whether one should pass
408 // it pointing to the code or struct members when compiling with
409 // TABLES_NEXT_TO_CODE.
410 const StgInfoTable *info = closure->header.info;
411 if (info == &stg_upd_frame_info) {
412 return "NORMAL_UPDATE_FRAME";
413 } else if (info == &stg_bh_upd_frame_info) {
414 return "BH_UPDATE_FRAME";
415 } else if (info == &stg_marked_upd_frame_info) {
416 return "MARKED_UPDATE_FRAME";
417 } else {
418 return "ERROR: Not an update frame!!!";
419 }
420 }
421
422 /*
423 void printGraph( StgClosure *obj )
424 {
425 printClosure(obj);
426 }
427 */
428
429 static void
430 printSmallBitmap( StgPtr spBottom, StgPtr payload, StgWord bitmap,
431 uint32_t size )
432 {
433 uint32_t i;
434
435 for(i = 0; i < size; i++, bitmap >>= 1 ) {
436 debugBelch(" stk[%ld] (%p) = ", (long)(spBottom-(payload+i)), payload+i);
437 if ((bitmap & 1) == 0) {
438 printPtr((P_)payload[i]);
439 debugBelch("\n");
440 } else {
441 debugBelch("Word# %" FMT_Word "\n", (W_)payload[i]);
442 }
443 }
444 }
445
446 static void
447 printLargeBitmap( StgPtr spBottom, StgPtr payload, StgLargeBitmap* large_bitmap,
448 uint32_t size )
449 {
450 StgWord bmp;
451 uint32_t i, j;
452
453 i = 0;
454 for (bmp=0; i < size; bmp++) {
455 StgWord bitmap = large_bitmap->bitmap[bmp];
456 j = 0;
457 for(; i < size && j < BITS_IN(W_); j++, i++, bitmap >>= 1 ) {
458 debugBelch(" stk[%" FMT_Word "] (%p) = ", (W_)(spBottom-(payload+i)), payload+i);
459 if ((bitmap & 1) == 0) {
460 printPtr((P_)payload[i]);
461 debugBelch("\n");
462 } else {
463 debugBelch("Word# %" FMT_Word "\n", (W_)payload[i]);
464 }
465 }
466 }
467 }
468
469 void
470 printStackChunk( StgPtr sp, StgPtr spBottom )
471 {
472 StgWord bitmap;
473 const StgInfoTable *info;
474
475 ASSERT(sp <= spBottom);
476 for (; sp < spBottom; sp += stack_frame_sizeW((StgClosure *)sp)) {
477
478 info = get_itbl((StgClosure *)sp);
479
480 switch (info->type) {
481
482 case UPDATE_FRAME:
483 case CATCH_FRAME:
484 case UNDERFLOW_FRAME:
485 case STOP_FRAME:
486 printClosure((StgClosure*)sp);
487 continue;
488
489 case RET_SMALL: {
490 StgWord c = *sp;
491 if (c == (StgWord)&stg_ctoi_R1p_info) {
492 debugBelch("tstg_ctoi_ret_R1p_info\n" );
493 } else if (c == (StgWord)&stg_ctoi_R1n_info) {
494 debugBelch("stg_ctoi_ret_R1n_info\n" );
495 } else if (c == (StgWord)&stg_ctoi_F1_info) {
496 debugBelch("stg_ctoi_ret_F1_info\n" );
497 } else if (c == (StgWord)&stg_ctoi_D1_info) {
498 debugBelch("stg_ctoi_ret_D1_info\n" );
499 } else if (c == (StgWord)&stg_ctoi_V_info) {
500 debugBelch("stg_ctoi_ret_V_info\n" );
501 } else if (c == (StgWord)&stg_ap_v_info) {
502 debugBelch("stg_ap_v_info\n" );
503 } else if (c == (StgWord)&stg_ap_f_info) {
504 debugBelch("stg_ap_f_info\n" );
505 } else if (c == (StgWord)&stg_ap_d_info) {
506 debugBelch("stg_ap_d_info\n" );
507 } else if (c == (StgWord)&stg_ap_l_info) {
508 debugBelch("stg_ap_l_info\n" );
509 } else if (c == (StgWord)&stg_ap_n_info) {
510 debugBelch("stg_ap_n_info\n" );
511 } else if (c == (StgWord)&stg_ap_p_info) {
512 debugBelch("stg_ap_p_info\n" );
513 } else if (c == (StgWord)&stg_ap_pp_info) {
514 debugBelch("stg_ap_pp_info\n" );
515 } else if (c == (StgWord)&stg_ap_ppp_info) {
516 debugBelch("stg_ap_ppp_info\n" );
517 } else if (c == (StgWord)&stg_ap_pppp_info) {
518 debugBelch("stg_ap_pppp_info\n" );
519 } else if (c == (StgWord)&stg_ap_ppppp_info) {
520 debugBelch("stg_ap_ppppp_info\n" );
521 } else if (c == (StgWord)&stg_ap_pppppp_info) {
522 debugBelch("stg_ap_pppppp_info\n" );
523 #ifdef PROFILING
524 } else if (c == (StgWord)&stg_restore_cccs_info) {
525 debugBelch("stg_restore_cccs_info\n" );
526 fprintCCS(stderr, (CostCentreStack*)sp[1]);
527 debugBelch("\n" );
528 continue;
529 } else if (c == (StgWord)&stg_restore_cccs_eval_info) {
530 debugBelch("stg_restore_cccs_eval_info\n" );
531 fprintCCS(stderr, (CostCentreStack*)sp[1]);
532 debugBelch("\n" );
533 continue;
534 #endif
535 } else {
536 debugBelch("RET_SMALL (%p)\n", info);
537 }
538 bitmap = info->layout.bitmap;
539 printSmallBitmap(spBottom, sp+1,
540 BITMAP_BITS(bitmap), BITMAP_SIZE(bitmap));
541 continue;
542 }
543
544 case RET_BCO: {
545 StgBCO *bco;
546
547 bco = ((StgBCO *)sp[1]);
548
549 debugBelch("RET_BCO (%p)\n", sp);
550 printLargeBitmap(spBottom, sp+2,
551 BCO_BITMAP(bco), BCO_BITMAP_SIZE(bco));
552 continue;
553 }
554
555 case RET_BIG:
556 barf("todo");
557
558 case RET_FUN:
559 {
560 const StgFunInfoTable *fun_info;
561 StgRetFun *ret_fun;
562
563 ret_fun = (StgRetFun *)sp;
564 fun_info = get_fun_itbl(ret_fun->fun);
565 debugBelch("RET_FUN (%p) (type=%d)\n", ret_fun->fun, (int)fun_info->f.fun_type);
566 switch (fun_info->f.fun_type) {
567 case ARG_GEN:
568 printSmallBitmap(spBottom, sp+2,
569 BITMAP_BITS(fun_info->f.b.bitmap),
570 BITMAP_SIZE(fun_info->f.b.bitmap));
571 break;
572 case ARG_GEN_BIG:
573 printLargeBitmap(spBottom, sp+2,
574 GET_FUN_LARGE_BITMAP(fun_info),
575 GET_FUN_LARGE_BITMAP(fun_info)->size);
576 break;
577 default:
578 printSmallBitmap(spBottom, sp+2,
579 BITMAP_BITS(stg_arg_bitmaps[fun_info->f.fun_type]),
580 BITMAP_SIZE(stg_arg_bitmaps[fun_info->f.fun_type]));
581 break;
582 }
583 continue;
584 }
585
586 default:
587 debugBelch("unknown object %d\n", (int)info->type);
588 barf("printStackChunk");
589 }
590 }
591 }
592
593 void printTSO( StgTSO *tso )
594 {
595 printStackChunk( tso->stackobj->sp,
596 tso->stackobj->stack+tso->stackobj->stack_size);
597 }
598
599 /* --------------------------------------------------------------------------
600 * Address printing code
601 *
602 * Uses symbol table in (unstripped executable)
603 * ------------------------------------------------------------------------*/
604
605 /* --------------------------------------------------------------------------
606 * Simple lookup table
607 * address -> function name
608 * ------------------------------------------------------------------------*/
609
610 static HashTable * add_to_fname_table = NULL;
611
612 const char *lookupGHCName( void *addr )
613 {
614 if (add_to_fname_table == NULL)
615 return NULL;
616
617 return lookupHashTable(add_to_fname_table, (StgWord)addr);
618 }
619
620 /* --------------------------------------------------------------------------
621 * Symbol table loading
622 * ------------------------------------------------------------------------*/
623
624 /* Causing linking trouble on Win32 plats, so I'm
625 disabling this for now.
626 */
627 #ifdef USING_LIBBFD
628 # define PACKAGE 1
629 # define PACKAGE_VERSION 1
630 /* Those PACKAGE_* defines are workarounds for bfd:
631 * https://sourceware.org/bugzilla/show_bug.cgi?id=14243
632 * ghc's build system filter PACKAGE_* values out specifically to avoid clashes
633 * with user's autoconf-based Cabal packages.
634 * It's a shame <bfd.h> checks for unrelated fields instead of actually used
635 * macros.
636 */
637 # include <bfd.h>
638
639 /* Fairly ad-hoc piece of code that seems to filter out a lot of
640 * rubbish like the obj-splitting symbols
641 */
642
643 static bool isReal( flagword flags STG_UNUSED, const char *name )
644 {
645 #if 0
646 /* ToDo: make this work on BFD */
647 int tp = type & N_TYPE;
648 if (tp == N_TEXT || tp == N_DATA) {
649 return (name[0] == '_' && name[1] != '_');
650 } else {
651 return false;
652 }
653 #else
654 if (*name == '\0' ||
655 (name[0] == 'g' && name[1] == 'c' && name[2] == 'c') ||
656 (name[0] == 'c' && name[1] == 'c' && name[2] == '.')) {
657 return false;
658 }
659 return true;
660 #endif
661 }
662
663 extern void DEBUG_LoadSymbols( const char *name )
664 {
665 bfd* abfd;
666 char **matching;
667
668 bfd_init();
669 abfd = bfd_openr(name, "default");
670 if (abfd == NULL) {
671 barf("can't open executable %s to get symbol table", name);
672 }
673 if (!bfd_check_format_matches (abfd, bfd_object, &matching)) {
674 barf("mismatch");
675 }
676
677 {
678 long storage_needed;
679 asymbol **symbol_table;
680 long number_of_symbols;
681 long num_real_syms = 0;
682 long i;
683
684 storage_needed = bfd_get_symtab_upper_bound (abfd);
685
686 if (storage_needed < 0) {
687 barf("can't read symbol table");
688 }
689 symbol_table = (asymbol **) stgMallocBytes(storage_needed,"DEBUG_LoadSymbols");
690
691 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
692
693 if (number_of_symbols < 0) {
694 barf("can't canonicalise symbol table");
695 }
696
697 if (add_to_fname_table == NULL)
698 add_to_fname_table = allocHashTable();
699
700 for( i = 0; i != number_of_symbols; ++i ) {
701 symbol_info info;
702 bfd_get_symbol_info(abfd,symbol_table[i],&info);
703 if (isReal(info.type, info.name)) {
704 insertHashTable(add_to_fname_table,
705 info.value, (void*)info.name);
706 num_real_syms += 1;
707 }
708 }
709
710 IF_DEBUG(interpreter,
711 debugBelch("Loaded %ld symbols. Of which %ld are real symbols\n",
712 number_of_symbols, num_real_syms)
713 );
714
715 stgFree(symbol_table);
716 }
717 }
718
719 #else /* USING_LIBBFD */
720
721 extern void DEBUG_LoadSymbols( const char *name STG_UNUSED )
722 {
723 /* nothing, yet */
724 }
725
726 #endif /* USING_LIBBFD */
727
728 void findPtr(P_ p, int); /* keep gcc -Wall happy */
729
730 int searched = 0;
731
732 static int
733 findPtrBlocks (StgPtr p, bdescr *bd, StgPtr arr[], int arr_size, int i)
734 {
735 StgPtr q, r, end;
736 for (; bd; bd = bd->link) {
737 searched++;
738 for (q = bd->start; q < bd->free; q++) {
739 if (UNTAG_CONST_CLOSURE((StgClosure*)*q) == (const StgClosure *)p) {
740 if (i < arr_size) {
741 for (r = bd->start; r < bd->free; r = end) {
742 // skip over zeroed-out slop
743 while (*r == 0) r++;
744 if (!LOOKS_LIKE_CLOSURE_PTR(r)) {
745 debugBelch("%p found at %p, no closure at %p\n",
746 p, q, r);
747 break;
748 }
749 end = r + closure_sizeW((StgClosure*)r);
750 if (q < end) {
751 debugBelch("%p = ", r);
752 printClosure((StgClosure *)r);
753 arr[i++] = r;
754 break;
755 }
756 }
757 if (r >= bd->free) {
758 debugBelch("%p found at %p, closure?", p, q);
759 }
760 } else {
761 return i;
762 }
763 }
764 }
765 }
766 return i;
767 }
768
769 void
770 findPtr(P_ p, int follow)
771 {
772 uint32_t g, n;
773 bdescr *bd;
774 const int arr_size = 1024;
775 StgPtr arr[arr_size];
776 int i = 0;
777 searched = 0;
778
779 for (n = 0; n < n_capabilities; n++) {
780 bd = nurseries[i].blocks;
781 i = findPtrBlocks(p,bd,arr,arr_size,i);
782 if (i >= arr_size) return;
783 }
784
785 for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
786 bd = generations[g].blocks;
787 i = findPtrBlocks(p,bd,arr,arr_size,i);
788 bd = generations[g].large_objects;
789 i = findPtrBlocks(p,bd,arr,arr_size,i);
790 if (i >= arr_size) return;
791 }
792 if (follow && i == 1) {
793 debugBelch("-->\n");
794 findPtr(arr[0], 1);
795 }
796 }
797
798 const char *what_next_strs[] = {
799 [0] = "(unknown)",
800 [ThreadRunGHC] = "ThreadRunGHC",
801 [ThreadInterpret] = "ThreadInterpret",
802 [ThreadKilled] = "ThreadKilled",
803 [ThreadComplete] = "ThreadComplete"
804 };
805
806 #else /* DEBUG */
807 void printPtr( StgPtr p )
808 {
809 debugBelch("ptr 0x%p (enable -DDEBUG for more info) " , p );
810 }
811
812 void printObj( StgClosure *obj )
813 {
814 debugBelch("obj 0x%p (enable -DDEBUG for more info) " , obj );
815 }
816
817
818 #endif /* DEBUG */
819
820 /* -----------------------------------------------------------------------------
821 Closure types
822
823 NOTE: must be kept in sync with the closure types in includes/ClosureTypes.h
824 -------------------------------------------------------------------------- */
825
826 const char *closure_type_names[] = {
827 [INVALID_OBJECT] = "INVALID_OBJECT",
828 [CONSTR] = "CONSTR",
829 [CONSTR_1_0] = "CONSTR_1_0",
830 [CONSTR_0_1] = "CONSTR_0_1",
831 [CONSTR_2_0] = "CONSTR_2_0",
832 [CONSTR_1_1] = "CONSTR_1_1",
833 [CONSTR_0_2] = "CONSTR_0_2",
834 [CONSTR_NOCAF] = "CONSTR_NOCAF",
835 [FUN] = "FUN",
836 [FUN_1_0] = "FUN_1_0",
837 [FUN_0_1] = "FUN_0_1",
838 [FUN_2_0] = "FUN_2_0",
839 [FUN_1_1] = "FUN_1_1",
840 [FUN_0_2] = "FUN_0_2",
841 [FUN_STATIC] = "FUN_STATIC",
842 [THUNK] = "THUNK",
843 [THUNK_1_0] = "THUNK_1_0",
844 [THUNK_0_1] = "THUNK_0_1",
845 [THUNK_2_0] = "THUNK_2_0",
846 [THUNK_1_1] = "THUNK_1_1",
847 [THUNK_0_2] = "THUNK_0_2",
848 [THUNK_STATIC] = "THUNK_STATIC",
849 [THUNK_SELECTOR] = "THUNK_SELECTOR",
850 [BCO] = "BCO",
851 [AP] = "AP",
852 [PAP] = "PAP",
853 [AP_STACK] = "AP_STACK",
854 [IND] = "IND",
855 [IND_STATIC] = "IND_STATIC",
856 [RET_BCO] = "RET_BCO",
857 [RET_SMALL] = "RET_SMALL",
858 [RET_BIG] = "RET_BIG",
859 [RET_FUN] = "RET_FUN",
860 [UPDATE_FRAME] = "UPDATE_FRAME",
861 [CATCH_FRAME] = "CATCH_FRAME",
862 [UNDERFLOW_FRAME] = "UNDERFLOW_FRAME",
863 [STOP_FRAME] = "STOP_FRAME",
864 [BLOCKING_QUEUE] = "BLOCKING_QUEUE",
865 [BLACKHOLE] = "BLACKHOLE",
866 [MVAR_CLEAN] = "MVAR_CLEAN",
867 [MVAR_DIRTY] = "MVAR_DIRTY",
868 [TVAR] = "TVAR",
869 [ARR_WORDS] = "ARR_WORDS",
870 [MUT_ARR_PTRS_CLEAN] = "MUT_ARR_PTRS_CLEAN",
871 [MUT_ARR_PTRS_DIRTY] = "MUT_ARR_PTRS_DIRTY",
872 [MUT_ARR_PTRS_FROZEN0] = "MUT_ARR_PTRS_FROZEN0",
873 [MUT_ARR_PTRS_FROZEN] = "MUT_ARR_PTRS_FROZEN",
874 [MUT_VAR_CLEAN] = "MUT_VAR_CLEAN",
875 [MUT_VAR_DIRTY] = "MUT_VAR_DIRTY",
876 [WEAK] = "WEAK",
877 [PRIM] = "PRIM",
878 [MUT_PRIM] = "MUT_PRIM",
879 [TSO] = "TSO",
880 [STACK] = "STACK",
881 [TREC_CHUNK] = "TREC_CHUNK",
882 [ATOMICALLY_FRAME] = "ATOMICALLY_FRAME",
883 [CATCH_RETRY_FRAME] = "CATCH_RETRY_FRAME",
884 [CATCH_STM_FRAME] = "CATCH_STM_FRAME",
885 [WHITEHOLE] = "WHITEHOLE",
886 [COMPACT_NFDATA] = "COMPACT_NFDATA"
887 };
888
889 const char *
890 info_type(const StgClosure *closure){
891 return closure_type_names[get_itbl(closure)->type];
892 }
893
894 const char *
895 info_type_by_ip(const StgInfoTable *ip){
896 return closure_type_names[ip->type];
897 }
898
899 void
900 info_hdr_type(const StgClosure *closure, char *res){
901 strcpy(res,closure_type_names[get_itbl(closure)->type]);
902 }