From 553e4f3df17f484f409f59b99d1489ecc6c5c217 Mon Sep 17 00:00:00 2001 From: zzy <2450266535@qq.com> Date: Tue, 27 Aug 2024 09:23:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(debug):=20=E7=A1=AE=E4=BF=9D=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E6=9D=A1=E4=BB=B6=E6=AD=A3=E7=A1=AE=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E6=96=AD=E8=A8=80=E5=92=8C=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=20```=20=E4=BF=AE=E6=94=B9Assert=E5=92=8CLog=E5=AE=8F=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E4=BE=BF=E6=A0=B9=E6=8D=AE=5F=5FDEBUG=5FLEVEL=5F=5F?= =?UTF-8?q?=E7=9A=84=E5=80=BC=E6=AD=A3=E7=A1=AE=E5=A4=84=E7=90=86=E6=96=AD?= =?UTF-8?q?=E8=A8=80=E5=92=8C=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E3=80=82?= =?UTF-8?q?=E4=BB=A5=E5=89=8D=EF=BC=8C=E6=9F=90=E4=BA=9B=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E6=96=AD=E8=A8=80=E4=B8=8D=E4=BC=9A=E6=8C=89=E9=A2=84?= =?UTF-8?q?=E6=9C=9F=E8=A7=A6=20=E5=8F=91=EF=BC=8C=E8=80=8C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95=E5=9C=A8=5F=5FDEBUG=5FLEVEL=5F=5F?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA1=E6=97=B6=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=A2=AB=E6=AD=A3=E7=A1=AE=E7=A6=81=E7=94=A8=E3=80=82=E7=8E=B0?= =?UTF-8?q?=E5=9C=A8=EF=BC=8CAssert=E5=B0=86=E5=9C=A8=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=E5=A4=A7=E4=BA=8E=E7=AD=89=E4=BA=8E1?= =?UTF-8?q?=E6=97=B6=E5=90=AF=E7=94=A8=EF=BC=8CLog=20=E5=B0=86=E5=9C=A8?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E7=BA=A7=E5=88=AB=E4=B8=BA2=E6=97=B6?= =?UTF-8?q?=E5=90=AF=E7=94=A8=E3=80=82=E6=84=9F=E8=B0=A2[@yourname]?= =?UTF-8?q?=E7=9A=84=E8=B4=A1=E7=8C=AE=E3=80=82=20```?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debug.h | 18 ++++++++++++++++++ main.c | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/debug.h b/debug.h index 0aeed2f..4dec59a 100644 --- a/debug.h +++ b/debug.h @@ -20,6 +20,16 @@ #include #include +#ifdef __DEBUG_LEVEL__ +#undef __DEBUG_LEVEL__ +#endif +/* You can change the debug level here + * 0: no log + * 1: Assert + * 2: Assert + Log + */ +#define __DEBUG_LEVEL__ 9 + // ----------- log ----------- #define ANSI_FG_BLACK "\33[1;30m" @@ -52,10 +62,15 @@ printf(__VA_ARGS__); \ } while (0) +#if __DEBUG_LEVEL__ >= 2 #define Log(format, ...) \ _Log(ANSI_FMT("[%s:%d %s] " format, ANSI_FG_BLUE) "\n", \ __FILE__, __LINE__, __func__, ## __VA_ARGS__) +#else +#define Log(format, ...) (NULL) +#endif +#ifdef __DEBUG_LEVEL__ >= 1 #define Assert(cond, format, ...) \ do { \ if (!(cond)) { \ @@ -64,6 +79,9 @@ assert(cond); \ } \ } while (0) +#else +#define Assert(cond, format, ...) (NULL) +#endif #define panic(format, ...) Assert(0, format, ## __VA_ARGS__) diff --git a/main.c b/main.c index dacd6fe..0b8df29 100644 --- a/main.c +++ b/main.c @@ -45,7 +45,7 @@ static struct { } cmd_table [] = { { "help", "Display information about all supported commands", cmd_help }, { "p", "p EXPR: To evaluate an expression EXPR and output the result", cmd_p }, - { "q", "Exit NEMU", cmd_q }, + { "q", "Exit EXPR", cmd_q }, /* TODO: Add more commands */