From 5aee73e34d8cee474b719b4e0b9c5535ee84768c Mon Sep 17 00:00:00 2001 From: tracer-ysyx Date: Wed, 20 Mar 2024 17:38:26 +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=2017:38:26=20=20up=20=20=204?= =?UTF-8?q?:44,=20=202=20users,=20=20load=20average:=200.67,=200.30,=200.2?= =?UTF-8?q?5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nemu/src/utils/ftrace.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/nemu/src/utils/ftrace.c b/nemu/src/utils/ftrace.c index 5d1c780..55d4801 100644 --- a/nemu/src/utils/ftrace.c +++ b/nemu/src/utils/ftrace.c @@ -28,13 +28,12 @@ const char *get_func_name(vaddr_t addr) { } void init_elf(const char *path) { - bool success = false; FILE *elf_file = fopen(path, "rb"); Elf32_Ehdr header; Elf32_Shdr section_header[200], *psh; func_table = (func_t *)calloc(func_table_size, sizeof(func_t)); - FAILED_GOTO(failed_nosym, func_table == NULL); + 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); @@ -56,7 +55,7 @@ void init_elf(const char *path) { int sym_length = symtab->sh_size / sizeof(Elf32_Sym); Elf32_Sym *sym = calloc(sym_length, sizeof(Elf32_Sym)); - FAILED_GOTO(failed_nosym, sym == NULL); + 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); @@ -79,17 +78,23 @@ void init_elf(const char *path) { } } qsort(func_table, func_table_len, sizeof(func_t), cmp_func_t); - success = true; + goto success; + +success: + free(sym); + free(shstrtab); + return; + failed: -// for(int i = 0; i < func_table_len; i++) { -// func_t *f = &func_table[i]; -// if(f->name) { free(f->name); } -// } -// free(func_table); -// free(sym); + free(sym); failed_shstrtab: -// free(shstrtab); + free(shstrtab); failed_nosym: - if(success) return; - else Error("Failed reading elf file"); + for(int i = 0; i < func_table_len; i++) { + func_t *f = &func_table[i]; + if(f->name) { free(f->name); } + } + free(func_table); + Error("Failed reading elf file"); + return; }