📄 break.c
字号:
}voidloaded(int to, void *to_arg){ int i; int old = 0; int cur = 0; Eterm* code; /* * Calculate and print totals. */ for (i = 0; i < module_code_size(); i++) { if (module_code(i) != NULL && ((module_code(i)->code_length != 0) || (module_code(i)->old_code_length != 0))) { cur += module_code(i)->code_length; if (module_code(i)->old_code_length != 0) { old += module_code(i)->old_code_length; } } } erts_print(to, to_arg, "Current code: %d\n", cur); erts_print(to, to_arg, "Old code: %d\n", old); /* * Print one line per module. */ for (i = 0; i < module_code_size(); i++) { if (!ERTS_IS_CRASH_DUMPING) { /* * Interactive dump; keep it brief. */ if (module_code(i) != NULL && ((module_code(i)->code_length != 0) || (module_code(i)->old_code_length != 0))) { erts_print(to, to_arg, "%T", make_atom(module_code(i)->module)); cur += module_code(i)->code_length; erts_print(to, to_arg, " %d", module_code(i)->code_length ); if (module_code(i)->old_code_length != 0) { erts_print(to, to_arg, " (%d old)", module_code(i)->old_code_length ); old += module_code(i)->old_code_length; } erts_print(to, to_arg, "\n"); } } else { /* * To crash dump; make it parseable. */ if (module_code(i) != NULL && ((module_code(i)->code_length != 0) || (module_code(i)->old_code_length != 0))) { erts_print(to, to_arg, "=mod:"); erts_print(to, to_arg, "%T", make_atom(module_code(i)->module)); erts_print(to, to_arg, "\n"); erts_print(to, to_arg, "Current size: %d\n", module_code(i)->code_length); code = module_code(i)->code; if (code != NULL && code[MI_ATTR_PTR]) { erts_print(to, to_arg, "Current attributes: "); dump_attributes(to, to_arg, (byte *) code[MI_ATTR_PTR], code[MI_ATTR_SIZE]); } if (code != NULL && code[MI_COMPILE_PTR]) { erts_print(to, to_arg, "Current compilation info: "); dump_attributes(to, to_arg, (byte *) code[MI_COMPILE_PTR], code[MI_COMPILE_SIZE]); } if (module_code(i)->old_code_length != 0) { erts_print(to, to_arg, "Old size: %d\n", module_code(i)->old_code_length); code = module_code(i)->old_code; if (code[MI_ATTR_PTR]) { erts_print(to, to_arg, "Old attributes: "); dump_attributes(to, to_arg, (byte *) code[MI_ATTR_PTR], code[MI_ATTR_SIZE]); } if (code[MI_COMPILE_PTR]) { erts_print(to, to_arg, "Old compilation info: "); dump_attributes(to, to_arg, (byte *) code[MI_COMPILE_PTR], code[MI_COMPILE_SIZE]); } } } } }}static voiddump_attributes(int to, void *to_arg, byte* ptr, int size){ while (size-- > 0) { erts_print(to, to_arg, "%02X", *ptr++); } erts_print(to, to_arg, "\n");}voiddo_break(void){#ifdef __WIN32__ int i; char* mode = getenv("ERL_CONSOLE_MODE"); /* check if we're in console mode and, if so, halt immediately if break is called */ if (mode != NULL) if (strcmp(mode, "window") != 0) halt_0(0);#else int i;#endif /* __WIN32__ */ erts_printf("\n" "BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded\n" " (v)ersion (k)ill (D)b-tables (d)istribution\n"); while (1) { if ((i = sys_get_key(0)) <= 0) erl_exit(0, ""); switch (i) { case 'q': case 'a': case '*': /* * The asterisk is an read error on windows, * where sys_get_key isn't that great in console mode. * The usual reason for a read error is Ctrl-C. Treat this as * 'a' to avoid infinite loop. */ erl_exit(0, ""); case 'A': /* Halt generating crash dump */ erl_exit(1, "Crash dump requested by user"); case 'c': return; case 'p': process_info(ERTS_PRINT_STDOUT, NULL); return; case 'm': return; case 'o': port_info(ERTS_PRINT_STDOUT, NULL); return; case 'i': info(ERTS_PRINT_STDOUT, NULL); return; case 'l': loaded(ERTS_PRINT_STDOUT, NULL); return; case 'v': erts_printf("Erlang (%s) emulator version " ERLANG_VERSION "\n", EMULATOR); erts_printf("Compiled on " ERLANG_COMPILE_DATE "\n"); return; case 'd': distribution_info(ERTS_PRINT_STDOUT, NULL); return; case 'D': db_info(ERTS_PRINT_STDOUT, NULL, 1); return; case 'k': process_killer(); return;#ifdef OPPROF case 'X': dump_frequencies(); return; case 'x': { int i; for (i = 0; i <= HIGHEST_OP; i++) { if (opc[i].name != NULL) { erts_printf("%-16s %8d\n", opc[i].name, opc[i].count); } } } return; case 'z': { int i; for (i = 0; i <= HIGHEST_OP; i++) opc[i].count = 0; } return;#endif#ifdef DEBUG case 't': p_slpq(); return; case 'b': bin_check(); return; case 'C': abort();#endif case '\n': continue; default: erts_printf("Eh?\n\n"); } }}#ifdef OPPROFstatic voiddump_frequencies(void){ int i; FILE* fp; time_t now; static char name[] = "op_freq.dump"; fp = fopen(name, "w"); if (fp == NULL) { fprintf(stderr, "Failed to open %s for writing\n", name); return; } time(&now); fprintf(fp, "# Generated %s\n", ctime(&now)); for (i = 0; i <= HIGHEST_OP; i++) { if (opc[i].name != NULL) { fprintf(fp, "%s %d\n", opc[i].name, opc[i].count); } } fclose(fp); erts_printf("Frequencies dumped to %s\n", name);}#endif#ifdef DEBUGstatic void bin_check(void){ Process *rp; ProcBin *bp; int i, printed; for (i=0; i < erts_max_processes; i++) { if ((rp = process_tab[i]) == NULL) continue; if (!(bp = rp->off_heap.mso)) continue; printed = 0; while (bp) { if (printed == 0) { erts_printf("Process %T holding binary data \n", rp->id); printed = 1; } erts_printf("0x%08lx orig_size: %ld, norefs = %ld\n", (unsigned long)bp->val, (long)bp->val->orig_size, erts_smp_atomic_read(&bp->val->refc)); bp = bp->next; } if (printed == 1) erts_printf("--------------------------------------\n"); } /* db_bin_check() has to be rewritten for the AVL trees... */ /*db_bin_check();*/ }#endif/* XXX THIS SHOULD BE IN SYSTEM !!!! */voiderl_crash_dump_v(char *file, int line, char* fmt, va_list args){ int fd; time_t now; char* dumpname; if (ERTS_IS_CRASH_DUMPING) return; /* Wait for all threads to block. If all threads haven't blocked * after a minute, we go anyway and hope for the best... * * We do not release system again. We expect an exit() or abort() after * dump has been written. * * NOTE: We allow gc therefore it is important not to lock *any* * process locks. */ switch (erts_smp_emergency_block_system(60000, ERTS_BS_FLG_ALLOW_GC)) { case 0: /* Ok, now we are alone... */ break; case ETIMEDOUT: /* Hmm, hope for the best... */ break; default: /* Should not happen; give up... */ abort(); } /* Allow us to pass certain places without locking... */#ifdef ERTS_SMP erts_smp_atomic_inc(&erts_writing_erl_crash_dump);#else erts_writing_erl_crash_dump = 1;#endif erts_sys_prepare_crash_dump(); dumpname = getenv("ERL_CRASH_DUMP"); if (!dumpname) { dumpname = "erl_crash.dump"; } fd = open(dumpname,O_WRONLY | O_CREAT | O_TRUNC,0640); if (fd < 0) return; /* Can't create the crash dump, skip it */ time(&now); erts_fdprintf(fd, "=erl_crash_dump:0.1\n%s", ctime(&now)); if (file != NULL) erts_fdprintf(fd, "The error occurred in file %s, line %d\n", file, line); if (fmt != NULL && *fmt != '\0') { erts_fdprintf(fd, "Slogan: "); erts_vfdprintf(fd, fmt, args); } erts_fdprintf(fd, "System version: "); erts_print_system_version(fd, NULL, NULL); erts_fdprintf(fd, "%s\n", "Compiled: " ERLANG_COMPILE_DATE); erts_fdprintf(fd, "Atoms: %d\n", atom_table_size()); info(fd, NULL); /* General system info */ if (process_tab != NULL) /* XXX true at init */ process_info(fd, NULL); /* Info about each process and port */ db_info(fd, NULL, 0); erts_print_bif_timer_info(fd, NULL); distribution_info(fd, NULL); erts_fdprintf(fd, "=loaded_modules\n"); loaded(fd, NULL); erts_dump_fun_entries(fd, NULL); erts_deep_process_dump(fd, NULL); erts_fdprintf(fd, "=atoms\n"); dump_atoms(fd, NULL); /* Keep the instrumentation data at the end of the dump */ if (erts_instr_memory_map || erts_instr_stat) { erts_fdprintf(fd, "=instr_data\n"); if (erts_instr_stat) { erts_fdprintf(fd, "=memory_status\n"); erts_instr_dump_stat_to_fd(fd, 0); } if (erts_instr_memory_map) { erts_fdprintf(fd, "=memory_map\n"); erts_instr_dump_memory_map_to_fd(fd); } } erts_fdprintf(fd, "=end\n"); close(fd); erts_fprintf(stderr,"\nCrash dump was written to: %s\n", dumpname);}voiderl_crash_dump(char* file, int line, char* fmt, ...){ va_list args; va_start(args, fmt); erl_crash_dump_v(file, line, fmt, args); va_end(args);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -