void erts_check_memory(Process *p, Eterm *start, Eterm *end) { Eterm *pos = start; while (pos < end) { Eterm hval = *pos++; #ifdef DEBUG if (hval == DEBUG_BAD_WORD) { print_untagged_memory(start, end); erts_exit(ERTS_ERROR_EXIT, "Uninitialized HAlloc'ed memory found @ 0x%0*lx!\n", PTR_SIZE,(unsigned long)(pos - 1)); } #endif if (is_thing(hval)) { pos += thing_arityval(hval); continue; } if (verify_eterm(p,hval)) continue; erts_exit(ERTS_ERROR_EXIT, "Wild pointer found @ 0x%0*lx!\n", PTR_SIZE,(unsigned long)(pos - 1)); } }
static void print_heap(Eterm *pos, Eterm *end) { printf("From: 0x%0*lx to 0x%0*lx\n\r", 2*(int)sizeof(long), (unsigned long)pos, 2*(int)sizeof(long), (unsigned long)end); printf(" | H E A P |\r\n"); printf(" | %*s | %*s |\r\n", 2+2*(int)sizeof(long), "Address", 2+2*(int)sizeof(long), "Contents"); printf(" |%s|%s|\r\n", dashes, dashes); while (pos < end) { Eterm val = pos[0]; printf(" | 0x%0*lx | 0x%0*lx | ", 2*(int)sizeof(long), (unsigned long)pos, 2*(int)sizeof(long), (unsigned long)val); ++pos; if (is_arity_value(val)) printf("Arity(%lu)", arityval(val)); else if (is_thing(val)) { unsigned int ari = thing_arityval(val); printf("Thing Arity(%u) Tag(%lu)", ari, thing_subtag(val)); while (ari) { printf("\r\n | 0x%0*lx | 0x%0*lx | THING", 2*(int)sizeof(long), (unsigned long)pos, 2*(int)sizeof(long), (unsigned long)*pos); ++pos; --ari; } } else erts_printf("%.30T", val); printf("\r\n"); } printf(" |%s|%s|\r\n", dashes, dashes); }
/* * print_tagged_memory will print contents of given memory area and * display it as if it was tagged Erlang terms (which it hopefully * is). This function knows about forwarding pointers to be able to * print a heap during garbage collection. erts_printf("%T",val) * do not know about forwarding pointers though, so it will still * crash if they are encoutered... */ void print_tagged_memory(Eterm *pos, Eterm *end) { erts_printf("+-%s-+-%s-+\n",dashes,dashes); erts_printf("| 0x%0*lx - 0x%0*lx |\n", PTR_SIZE,(unsigned long)pos, PTR_SIZE,(unsigned long)(end - 1)); erts_printf("| %-*s | %-*s |\n",PTR_SIZE,"Address",PTR_SIZE,"Contents"); erts_printf("|-%s-|-%s-|\n",dashes,dashes); while( pos < end ) { Eterm val = pos[0]; erts_printf("| 0x%0*lx | 0x%0*lx | ", PTR_SIZE,(unsigned long)pos, PTR_SIZE,(unsigned long)val); ++pos; if( is_arity_value(val) ) { erts_printf("Arity(%lu)", arityval(val)); } else if( is_thing(val) ) { unsigned int ari = thing_arityval(val); erts_printf("Thing Arity(%u) Tag(%lu)", ari, thing_subtag(val)); while( ari ) { erts_printf("\n| 0x%0*lx | 0x%0*lx | THING", PTR_SIZE, (unsigned long)pos, PTR_SIZE, (unsigned long)*pos); ++pos; --ari; } } else { switch (primary_tag(val)) { case TAG_PRIMARY_BOXED: if (!is_header(*boxed_val(val))) { erts_printf("Moved -> 0x%0*lx\n",PTR_SIZE, (unsigned long)*boxed_val(val)); continue; } break; case TAG_PRIMARY_LIST: if (is_non_value(*list_val(val))) { erts_printf("Moved -> 0x%0*lx\n",PTR_SIZE, (unsigned long)*(list_val(val) + 1)); continue; } break; } erts_printf("%.30T", val); } erts_printf("\n"); } erts_printf("+-%s-+-%s-+\n",dashes,dashes); }
static void check_memory(Eterm *start, Eterm *end) { Eterm *pos = start; while (pos < end) { Eterm hval = *pos++; if (hval == ERTS_HOLE_MARKER) { erts_fprintf(stderr,"%s, line %d: ERTS_HOLE_MARKER found at 0x%0*lx\n", __FILE__, __LINE__,PTR_SIZE,(unsigned long)(pos-1)); print_untagged_memory(start,end); /* DEBUGSTUFF */ abort(); } else if (is_thing(hval)) { pos += (thing_arityval(hval)); } } }
BIF_RETTYPE hipe_bifs_show_term_1(BIF_ALIST_1) { Eterm obj = BIF_ARG_1; printf("0x%0*lx\r\n", 2*(int)sizeof(long), obj); do { Eterm *objp; int i, ary; if (is_list(obj)) { objp = list_val(obj); ary = 2; } else if (is_boxed(obj)) { Eterm header; objp = boxed_val(obj); header = objp[0]; if (is_thing(header)) ary = thing_arityval(header); else if (is_arity_value(header)) ary = arityval(header); else { printf("bad header %#lx\r\n", header); break; } ary += 1; } else break; for (i = 0; i < ary; ++i) printf("0x%0*lx: 0x%0*lx\r\n", 2*(int)sizeof(long), (unsigned long)&objp[i], 2*(int)sizeof(long), objp[i]); } while (0); erts_printf("%T", obj); printf("\r\n"); BIF_RET(am_true); }