From 45341a843068f2c4160fd26741d455bf42077557 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Tue, 27 Apr 2021 17:41:46 +0100 Subject: [PATCH] base: Add DPRINTFV macro This macro is directly expecting a Debug::Flag instance as a first argument instead of simply the name of the debug flag, and it is forwarding it with no preprocessing to the underlying logic (dprintf_flag). This is different from the common DPRINTF, which is converting the first argument into a flag and into a string literal. This is useful if we want to pass the DebugFlag from the subclass to the superclass. This makes it possible to set tracepoints in the Base class logic, and let the Derived classes define the flag which will enable the tracepoint class Base { Base(const Debug::SimpleFlag &_flag) : flag(_flag) {} void baseLogic() { DPRINTFV(flag, "..."); } const Debug::SimpleFlag flag; } class Derived1 : public Base { Derived1() : Base(Debug::Derived1) {} } class Derived2 : public Base { Derived2() : Base(Debug::Derived2) {} } A more concrete example is Arm Table Walker, which is using a DmaPort. If we want to log the table walker port activity, we are using the --debug-flags=DMA, which is unconvenient as it will contain the logs from every DMA device in the simulation Change-Id: I793cf1521303fd0a3bbea2059a9447386f83661e Signed-off-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44967 Tested-by: kokoro Reviewed-by: Daniel Carvalho Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power --- src/base/trace.hh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/base/trace.hh b/src/base/trace.hh index 36fcee4217..be8476b828 100644 --- a/src/base/trace.hh +++ b/src/base/trace.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2019 ARM Limited + * Copyright (c) 2014, 2019, 2021 Arm Limited * All rights reserved * * Copyright (c) 2001-2006 The Regents of The University of Michigan @@ -154,10 +154,17 @@ const std::string &name(); * If you desire that the automatic printing not occur, use DPRINTFR * (R for raw) * + * With DPRINTFV it is possible to pass a Debug::SimpleFlag variable + * as first argument. Example: + * + * Debug::Flag some_flag = Debug::DMA; + * DPRINTFV(some_flag, ...); + * * \def DDUMP(x, data, count) * \def DPRINTF(x, ...) * \def DPRINTFS(x, s, ...) * \def DPRINTFR(x, ...) + * \def DPRINTFV(x, ...) * \def DPRINTFN(...) * \def DPRINTFNR(...) * \def DPRINTF_UNCONDITIONAL(x, ...) @@ -195,6 +202,13 @@ const std::string &name(); } \ } while (0) +#define DPRINTFV(x, ...) do { \ + if (M5_UNLIKELY(x)) { \ + Trace::getDebugLogger()->dprintf_flag( \ + curTick(), name(), x.name(), __VA_ARGS__); \ + } \ +} while (0) + #define DPRINTFN(...) do { \ Trace::getDebugLogger()->dprintf(curTick(), name(), __VA_ARGS__); \ } while (0) @@ -214,6 +228,7 @@ const std::string &name(); #define DPRINTF(x, ...) do {} while (0) #define DPRINTFS(x, ...) do {} while (0) #define DPRINTFR(...) do {} while (0) +#define DPRINTFV(...) do {} while (0) #define DPRINTFN(...) do {} while (0) #define DPRINTFNR(...) do {} while (0) #define DPRINTF_UNCONDITIONAL(x, ...) do {} while (0)