From 5f3581ad47395583accc3ed76de85dc8afe830fa Mon Sep 17 00:00:00 2001 From: tracer-ysyx Date: Thu, 8 Feb 2024 19:05:19 +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.1.75=20#1-Nix?= =?UTF-8?q?OS=20SMP=20PREEMPT=5FDYNAMIC=20Thu=20Jan=2025=2023:27:52=20UTC?= =?UTF-8?q?=202024=20x86=5F64=20GNU/Linux=20=2019:05:19=20=20up=201=20day?= =?UTF-8?q?=20=204:41,=20=202=20users,=20=20load=20average:=201.09,=200.92?= =?UTF-8?q?,=200.82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nemu/src/monitor/sdb/sdb.c | 6 ------ nemu/src/monitor/sdb/watchpoint.c | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/nemu/src/monitor/sdb/sdb.c b/nemu/src/monitor/sdb/sdb.c index 7d27d0f..4a1804e 100644 --- a/nemu/src/monitor/sdb/sdb.c +++ b/nemu/src/monitor/sdb/sdb.c @@ -185,12 +185,6 @@ static int cmd_info_w(char *args) { static int cmd_w(char *args) { char *expr = strtok(NULL, " "); - bool success = false; - parse_expr(expr, &success); - if (!success) { - Error("Failed to parse given expression `%s`", expr); - return 0; - } wp_add(expr); return 0; } diff --git a/nemu/src/monitor/sdb/watchpoint.c b/nemu/src/monitor/sdb/watchpoint.c index 8bd7bfd..5362ecd 100644 --- a/nemu/src/monitor/sdb/watchpoint.c +++ b/nemu/src/monitor/sdb/watchpoint.c @@ -56,7 +56,7 @@ static WP *wp_new() { } static void wp_delete(WP *wp) { - assert(wp); + Assert(wp, "Failed to delete watchpoint from pool."); wp->next = free_; free_ = wp; } @@ -65,7 +65,7 @@ int wp_add(char * expr) { WP *wp = wp_new(); if (wp == NULL) { Error("watchpoint: Failed to add watchpoint, pool is full."); - return 1; + goto failed_create; } wp->NO = wp_count++; @@ -76,15 +76,27 @@ int wp_add(char * expr) { tail->next = wp; tail = wp; } + + bool success = false; + wp->val = parse_expr(expr, &success); + if (!success) { + Error("Failed to parse given expression `%s`", expr); + goto failed_create; + } + int len = strlen(expr); wp->expr = malloc((len + 1) * sizeof(char)); if (wp->expr == NULL) { Error("Failed to allocate memory for expression"); - return 1; + goto failed_create; } strncpy(wp->expr, expr, len + 1); wp->expr[len] = '\0'; return 0; + +failed_create: + wp_delete(wp); + return 1; } int wp_remove_by_number(int number) {