在gem5中,我如何知道课程的具体位置?

问题描述

这个问题让人觉得很愚蠢,但这确实使我感到困惑。当我查看gem5的源代码时,总是遇到typedef typename cpuPol::IQ IQ; typedef typename Impl::DynInstPtr DynInstPtr;之类的类。我想看看这些类中有什么功能。但是在vscode中,我无法跳转到它们的定义位置。我什至找不到他们。我也没有找到一些文件名与类名相似的文件

解决方法

gem5在某些方面使用了这种可怕的impl模板模式,而不是虚拟方法。有人向我解释了原因,但我忘了。

然后我经过测试的IDE(例如Eclipse)无法解析“已使用的模板列表” here's a minimal test for that

typedef typename Impl::DynInstPtr DynInstPtr的特定情况下,我设法找到了如下的定义in Eclipse。这可能也适用于vscode。

从其中一个typedef开始:

template <class Impl>
class BaseDynInst : public ExecContext,public RefCounted
{
  public:
    typedef typename Impl::DynInstPtr DynInstPtr;

搜索BaseDynInst的用法(Ctrl + Alt + G)。幸运的是,第一种用法是:

// Explicit instantiation
template class BaseDynInst<O3CPUImpl>;

explicit template instantiation

所以现在我只跳到O3CPUImpl的定义,就可以了:

struct O3CPUImpl
{
    /** The DynInst type to be used. */
    typedef RefCountingPtr<DynInst> DynInstPtr;

是的,在这种情况下,我很幸运。如果没有显式的实例化,我将不得不搜索构建对象的构造函数的所有用法,以查找模板上设置的类型。

此外,事后看来,我们可能早先注意到,在搜​​索DynInstPtr(Ctrl + Shift + T)的定义时,名为*Impl的类中的任何结果都将是有趣的是,由于使用了gem5命名模式。

最后,您可以使用的另一种游击技巧是:

nm -C gem5/build/ARM/gem5.opt | grep BaseDynInst

这会将我们指向O3CPUImpl,其中包含以下几种类型的条目:

00000000016cda30 W BaseDynInst<O3CPUImpl>::armMonitor(unsigned long)                                                                    
00000000016cf0e0 W BaseDynInst<O3CPUImpl>::clearInROB() 

其中一些是briefly mentioned here

在gem5 0d5a80cb469f515b95e03f23ddaf70c9fd2ecbf2上进行了测试。