Why adding a DPRINTF(XXX debug flag fails with "error:'XXX' was not declared in this scope" in gem5?

Why adding a DPRINTF(XXX debug flag fails with "error:'XXX' was not declared in this scope" in gem5?

我想知道执行替换算法时的缓存信息。所以我在最新版的gem5中做了如下修改。我在 /home/cuiyujie/workspace/workGem5/gem5/src/mem/cache/replacement_policies/SConscript 文件中添加了一行 DebugFlag('ReplacementInfo') 命令。然后我在/home/cuiyujie/workspace/workGem5/gem5/build/X86/params/RandomRP.cc文件中添加了头文件#include "debug/ReplacementInfo.hh"。然后我在这个文件中使用了 DPRINTF(ReplacementInfo, "candidates"); 命令。但是在编译过程中出现了错误。

build/X86/mem/cache/replacement_policies/random_rp.cc: In member function'virtual ReplaceableEntry* RandomRP::getVictim(const ReplacementCandidates&) const':
build/X86/mem/cache/replacement_policies/random_rp.cc:82:13: error:'ReplacementInfo' was not declared in this scope
     DPRINTF(ReplacementInfo, "candidates");
             ^
build/X86/mem/cache/replacement_policies/random_rp.cc:82:13: note: suggested alternative:
In file included from build/X86/mem/cache/replacement_policies/random_rp.cc:44:0:
build/X86/debug/ReplacementInfo.hh:18:19: note:'Debug::ReplacementInfo'
 extern SimpleFlag ReplacementInfo;
                   ^
build/X86/mem/cache/replacement_policies/random_rp.cc:82:42: error:'DPRINTF' was not declared in this scope
     DPRINTF(ReplacementInfo, "candidates");
                                          ^
scons: *** [build/X86/mem/cache/replacement_policies/random_rp.o] Error 1
scons: building terminated because of errors.

第二个错误是:

build/X86/mem/cache/replacement_policies/random_rp.cc:82:42: error:'DPRINTF' was not declared in this scope
     DPRINTF(ReplacementInfo, "candidates");

这意味着您还需要:

#include "base/trace.hh"

这是定义 DPRINTF 的地方。

错误顺序有点混乱,因为 GCC 必须假设 DPRINTF 是一个函数,因为它没有看到宏定义,所以它首先尝试评估参数。但是 DPRINTF 是一个宏,并将缺少的 Debug:: 添加到 Debug::ReplacementInfo,它在第一个错误中抱怨:

#define DPRINTF(x, ...) do {                     \
    using namespace Debug;                       \
    if (M5_UNLIKELY(DTRACE(x))) {                \
        Trace::getDebugLogger()->dprintf_flag(   \
            curTick(), name(), #x, __VA_ARGS__); \
    }                                            \
} while (0)