In gem5, how do I know the specific location of the class?

216 views Asked by At

This question feels silly, but it really puzzles me. When I look at the source code of gem5, I always come across classes like typedef typename CPUPol::IQ IQ; typedef typename Impl::DynInstPtr DynInstPtr;. I want to see what functions are in these classes. But in vscode, I cannot jump to where they are defined. I can't even search for them. I also didn't find some files having similiar names with the class names.

1

There are 1 answers

0
Ciro Santilli On

gem5 uses in some points this horrible impl template pattern instead of virtual methods. Someone explained it to me why but I forgot.

Then IDEs such as Eclipse which I've tested with are not able to resolve "a list of templates used", here's a minimal test for that.

In the specific case of typedef typename Impl::DynInstPtr DynInstPtr I managed to find the definition as follows in Eclipse. This would likely also work on vscode.

Start from one of the typedefs e.g.:

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

Search for usages of BaseDynInst (Ctrl + Alt + G). The first usage luckily is:

// Explicit instantiation
template class BaseDynInst<O3CPUImpl>;

which is an explicit template instantiation.

So now I just jump to the definition of O3CPUImpl and there it is:

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

So yes, in this case I got lucky. If there was no explicit instantiation done, I would have had to search for all usages of the constructor that built the object to find what type was being set on the template.

Also, with the hindsight of the result, we could have noticed earlier that when searching for the definition of DynInstPtr (Ctrl + Shift + T), any results in a class named *Impl would be the interesting ones, due to the gem5 naming pattern used.

Finally, another guerrilla technique you could use you be to just:

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

which points us to O3CPUImpl with several entries of type:

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

Some of this had been briefly mentioned here.

Tested on gem5 0d5a80cb469f515b95e03f23ddaf70c9fd2ecbf2.