From 2209c26dce3019ad63bd1b8cef094a7c5f84f7b9 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Tue, 26 Mar 2024 12:43:03 +0800 Subject: [PATCH] nemu: fix some memory bug --- nemu/Kconfig | 4 ++-- nemu/src/cpu/cpu-exec.c | 2 +- nemu/src/utils/ftrace.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nemu/Kconfig b/nemu/Kconfig index ae1921f..2b316a5 100644 --- a/nemu/Kconfig +++ b/nemu/Kconfig @@ -180,12 +180,12 @@ config MTRACE_RANGE_MAX config FTRACE depends on TRACE && TARGET_NATIVE_ELF && ENGINE_INTERPRETER bool "Enable function tracing" - default y + default n config FTRACE_STACK_SIZE depends on FTRACE int "Max function track stack size" - default 100 + default 256 config FTRACE_LOG depends on FTRACE diff --git a/nemu/src/cpu/cpu-exec.c b/nemu/src/cpu/cpu-exec.c index 1e402ab..d2b1f98 100644 --- a/nemu/src/cpu/cpu-exec.c +++ b/nemu/src/cpu/cpu-exec.c @@ -52,7 +52,7 @@ static void exec_once(Decode *s, vaddr_t pc) { #ifdef CONFIG_ITRACE logbuf_rear = (logbuf_rear + 1) % CONFIG_ITRACE_BUFFER; char *p = logbuf[logbuf_rear]; - p += snprintf(p, sizeof(logbuf), FMT_WORD ":", s->pc); + p += snprintf(p, sizeof(logbuf[logbuf_rear]), FMT_WORD ":", s->pc); int ilen = s->snpc - s->pc; int i; uint8_t *inst = (uint8_t *)&s->isa.inst.val; diff --git a/nemu/src/utils/ftrace.c b/nemu/src/utils/ftrace.c index ea2f2b6..a522be7 100644 --- a/nemu/src/utils/ftrace.c +++ b/nemu/src/utils/ftrace.c @@ -104,7 +104,7 @@ void ftrace_call(vaddr_t pc, vaddr_t addr) { "FTRACE_STACK_SIZE."); ftrace_stack[ftrace_stack_len] = pc + 4; Trace("%*s0x%x call 0x%x <%s+0x%x>", ftrace_stack_len, "", pc, addr, - f == NULL ? "???" : f->name, addr - f->start); + f == NULL ? "???" : f->name, f == NULL ? addr : addr - f->start); ftrace_stack_len++; } @@ -115,10 +115,10 @@ void ftrace_return(vaddr_t pc, vaddr_t addr) { vaddr_t tco_addr = ftrace_stack[ftrace_stack_len]; func_t *f = get_func(tco_addr); Trace("%*s0x%x ret 0x%x <%s+0x%x> (TCO)", ftrace_stack_len, "", pc, tco_addr, - f == NULL ? "???" : f->name, tco_addr - f->start); + f == NULL ? "???" : f->name, f == NULL ? addr : addr - f->start); } func_t *f = get_func(addr); Trace("%*s0x%x ret 0x%x <%s+0x%x>", ftrace_stack_len, "", pc, addr, - f == NULL ? "???" : f->name, addr - f->start); + f == NULL ? "???" : f->name, f == NULL ? addr : addr - f->start); } #endif