From 8e0d229f49a4c25ea4022f66a88515c920dcf45a Mon Sep 17 00:00:00 2001 From: tracer-ysyx Date: Wed, 20 Mar 2024 19:46:03 +0800 Subject: [PATCH] =?UTF-8?q?>=20compile=20NEMU=20ysyx=5F22040000=20?= =?UTF-8?q?=E6=9D=8E=E5=BF=83=E6=9D=A8=20Linux=20calcite=206.6.19=20#1-Nix?= =?UTF-8?q?OS=20SMP=20PREEMPT=5FDYNAMIC=20Fri=20Mar=20=201=2012:35:11=20UT?= =?UTF-8?q?C=202024=20x86=5F64=20GNU/Linux=20=2019:46:03=20=20up=20=20=206?= =?UTF-8?q?:51,=20=202=20users,=20=20load=20average:=200.76,=200.68,=200.6?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nemu/Kconfig | 9 ++++++--- nemu/src/utils/ftrace.c | 18 +++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/nemu/Kconfig b/nemu/Kconfig index cad0512..ae1921f 100644 --- a/nemu/Kconfig +++ b/nemu/Kconfig @@ -143,8 +143,11 @@ config TRACE_END config ITRACE depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER - bool "Enable instruction tracer" + bool "Enable instruction tracing" default y + help + Instraction tracing will log past instructions into a ring buffer + and print them when NEMU exit unexpectedly. config ITRACE_COND depends on ITRACE @@ -158,7 +161,7 @@ config ITRACE_BUFFER config MTRACE depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER - bool "Enable memory tracer" + bool "Enable memory tracing" default n config MTRACE_RANGE @@ -176,7 +179,7 @@ config MTRACE_RANGE_MAX config FTRACE depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER - bool "Enable function tracer" + bool "Enable function tracing" default y config FTRACE_STACK_SIZE diff --git a/nemu/src/utils/ftrace.c b/nemu/src/utils/ftrace.c index 3416f97..25f097a 100644 --- a/nemu/src/utils/ftrace.c +++ b/nemu/src/utils/ftrace.c @@ -35,9 +35,9 @@ void init_elf(const char *path) { func_table = (func_t *)calloc(func_table_size, sizeof(func_t)); assert(func_table); - FAILED_GOTO(failed_nosym, fread(&header, sizeof(Elf32_Ehdr), 1, elf_file) <= 0); - FAILED_GOTO(failed_nosym, fseek(elf_file, header.e_shoff, SEEK_SET) != 0); - FAILED_GOTO(failed_nosym, fread(section_header, header.e_shentsize, header.e_shnum, elf_file) <= 0); + FAILED_GOTO(failed_header, fread(&header, sizeof(Elf32_Ehdr), 1, elf_file) <= 0); + FAILED_GOTO(failed_header, fseek(elf_file, header.e_shoff, SEEK_SET) != 0); + FAILED_GOTO(failed_header, fread(section_header, header.e_shentsize, header.e_shnum, elf_file) <= 0); char *shstrtab = calloc(1, section_header[header.e_shstrndx].sh_size); FAILED_GOTO(failed_shstrtab, fseek(elf_file, section_header[header.e_shstrndx].sh_offset, SEEK_SET) != 0); @@ -56,16 +56,16 @@ void init_elf(const char *path) { int sym_length = symtab->sh_size / sizeof(Elf32_Sym); Elf32_Sym *sym = calloc(sym_length, sizeof(Elf32_Sym)); assert(sym); - FAILED_GOTO(failed, fseek(elf_file, symtab->sh_offset, SEEK_SET) != 0); - FAILED_GOTO(failed, fread(sym, sizeof(Elf32_Sym), sym_length, elf_file) <= 0); + FAILED_GOTO(failed_funcname, fseek(elf_file, symtab->sh_offset, SEEK_SET) != 0); + FAILED_GOTO(failed_funcname, fread(sym, sizeof(Elf32_Sym), sym_length, elf_file) <= 0); for(int j = 0; j < sym_length; j++) { if(ELF32_ST_TYPE(sym[j].st_info) != STT_FUNC) continue; // Only read function type symbol func_t *f = &func_table[func_table_len]; char *func = (char *)malloc(30); - FAILED_GOTO(failed, fseek(elf_file, strtab->sh_offset + sym[j].st_name, SEEK_SET) != 0); - FAILED_GOTO(failed, fgets(func, 30, elf_file) <= 0); + FAILED_GOTO(failed_funcname, fseek(elf_file, strtab->sh_offset + sym[j].st_name, SEEK_SET) != 0); + FAILED_GOTO(failed_funcname, fgets(func, 30, elf_file) <= 0); f->start = sym[j].st_value; f->len = sym[j].st_size; f->name = func; @@ -85,11 +85,11 @@ success: free(shstrtab); return; -failed: +failed_funcname: free(sym); failed_shstrtab: free(shstrtab); -failed_nosym: +failed_header: for(int i = 0; i < func_table_len; i++) { func_t *f = &func_table[i]; if(f->name) { free(f->name); }