> compile NEMU
ysyx_22040000 李心杨 Linux calcite 6.6.19 #1-NixOS SMP PREEMPT_DYNAMIC Fri Mar 1 12:35:11 UTC 2024 x86_64 GNU/Linux 19:46:03 up 6:51, 2 users, load average: 0.76, 0.68, 0.61
This commit is contained in:
parent
3358125504
commit
8e0d229f49
2 changed files with 15 additions and 12 deletions
|
@ -143,8 +143,11 @@ config TRACE_END
|
||||||
|
|
||||||
config ITRACE
|
config ITRACE
|
||||||
depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
|
depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
|
||||||
bool "Enable instruction tracer"
|
bool "Enable instruction tracing"
|
||||||
default y
|
default y
|
||||||
|
help
|
||||||
|
Instraction tracing will log past instructions into a ring buffer
|
||||||
|
and print them when NEMU exit unexpectedly.
|
||||||
|
|
||||||
config ITRACE_COND
|
config ITRACE_COND
|
||||||
depends on ITRACE
|
depends on ITRACE
|
||||||
|
@ -158,7 +161,7 @@ config ITRACE_BUFFER
|
||||||
|
|
||||||
config MTRACE
|
config MTRACE
|
||||||
depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
|
depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
|
||||||
bool "Enable memory tracer"
|
bool "Enable memory tracing"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
config MTRACE_RANGE
|
config MTRACE_RANGE
|
||||||
|
@ -176,7 +179,7 @@ config MTRACE_RANGE_MAX
|
||||||
|
|
||||||
config FTRACE
|
config FTRACE
|
||||||
depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
|
depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER
|
||||||
bool "Enable function tracer"
|
bool "Enable function tracing"
|
||||||
default y
|
default y
|
||||||
|
|
||||||
config FTRACE_STACK_SIZE
|
config FTRACE_STACK_SIZE
|
||||||
|
|
|
@ -35,9 +35,9 @@ void init_elf(const char *path) {
|
||||||
func_table = (func_t *)calloc(func_table_size, sizeof(func_t));
|
func_table = (func_t *)calloc(func_table_size, sizeof(func_t));
|
||||||
assert(func_table);
|
assert(func_table);
|
||||||
|
|
||||||
FAILED_GOTO(failed_nosym, fread(&header, sizeof(Elf32_Ehdr), 1, elf_file) <= 0);
|
FAILED_GOTO(failed_header, 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_header, 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(section_header, header.e_shentsize, header.e_shnum, elf_file) <= 0);
|
||||||
|
|
||||||
char *shstrtab = calloc(1, section_header[header.e_shstrndx].sh_size);
|
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);
|
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);
|
int sym_length = symtab->sh_size / sizeof(Elf32_Sym);
|
||||||
Elf32_Sym *sym = calloc(sym_length, sizeof(Elf32_Sym));
|
Elf32_Sym *sym = calloc(sym_length, sizeof(Elf32_Sym));
|
||||||
assert(sym);
|
assert(sym);
|
||||||
FAILED_GOTO(failed, fseek(elf_file, symtab->sh_offset, SEEK_SET) != 0);
|
FAILED_GOTO(failed_funcname, 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, fread(sym, sizeof(Elf32_Sym), sym_length, elf_file) <= 0);
|
||||||
|
|
||||||
for(int j = 0; j < sym_length; j++) {
|
for(int j = 0; j < sym_length; j++) {
|
||||||
if(ELF32_ST_TYPE(sym[j].st_info) != STT_FUNC) continue;
|
if(ELF32_ST_TYPE(sym[j].st_info) != STT_FUNC) continue;
|
||||||
// Only read function type symbol
|
// Only read function type symbol
|
||||||
func_t *f = &func_table[func_table_len];
|
func_t *f = &func_table[func_table_len];
|
||||||
char *func = (char *)malloc(30);
|
char *func = (char *)malloc(30);
|
||||||
FAILED_GOTO(failed, fseek(elf_file, strtab->sh_offset + sym[j].st_name, SEEK_SET) != 0);
|
FAILED_GOTO(failed_funcname, 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, fgets(func, 30, elf_file) <= 0);
|
||||||
f->start = sym[j].st_value;
|
f->start = sym[j].st_value;
|
||||||
f->len = sym[j].st_size;
|
f->len = sym[j].st_size;
|
||||||
f->name = func;
|
f->name = func;
|
||||||
|
@ -85,11 +85,11 @@ success:
|
||||||
free(shstrtab);
|
free(shstrtab);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
failed:
|
failed_funcname:
|
||||||
free(sym);
|
free(sym);
|
||||||
failed_shstrtab:
|
failed_shstrtab:
|
||||||
free(shstrtab);
|
free(shstrtab);
|
||||||
failed_nosym:
|
failed_header:
|
||||||
for(int i = 0; i < func_table_len; i++) {
|
for(int i = 0; i < func_table_len; i++) {
|
||||||
func_t *f = &func_table[i];
|
func_t *f = &func_table[i];
|
||||||
if(f->name) { free(f->name); }
|
if(f->name) { free(f->name); }
|
||||||
|
|
Loading…
Reference in a new issue