So, my main goal is to modify a MIPS simulator to display the contents of the register file during run time. I searched around in the simulator's cpp files and this is what I've determined:

There is a file called "ThreadContext.h" which contains the lines:

typedef long ValueGPR;
...
class ThreadContext {
    ...
    public:
        ValueGPR reg[33];
        ...
    ...
}
...

And "reg[]" is what I need to access in the following file called "ExecutionFlow.cpp":

...
#include ".../ThreadContext.h"
...
long ExecutionFlow::exeInst(void) {
    ...
    //ADD PRINTF OF reg[1] - reg[32] HERE
    ...
}
...

How do I access reg in ExecutionFlow.cpp? Do I make a global pointer in the ThreadContext object? How do I do that and where do I look for said object?

Recommended Answers

All 3 Replies

You need access to the specific instance of ThreadContext.

As your variable of interest, reg, is a part of a class, it will differ depending on the instance of the class.

Find out where an instance is made, could look like:

ThreadContext* tc = new ThreadContext(???);
or: ThreadContext tc(???);

Then provide a pointer to your ExecutionFlow class.
Eg:

long ExecutionFlow::exeInst(const ThreadContext* tc)
{
    std::cout << tc->reg << std::endl;
}

Then you provide the pointer to your function.

Eg:

ThreadContext* tc = new ThreadContext(???);
myExecutionFlow->exeInst(tc);
or: ThreadContext tc(???);
myExecutionFlow->exeInst(&tc);

Let me emphasis this :

How do I access reg in ExecutionFlow.cpp?

Excitized: You need access to the specific instance of ThreadContext

Let me emphasis this :


Excitized: You need access to the specific instance of ThreadContext

Yes, that's why I told him he had to provide a pointer to his ThreadContext instance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.