Jump to content

CallStack class

- - - - -

  • Please log in to reply
No replies to this topic

#1
Groogy

Groogy

    Programmer

  • Members
  • PipPipPipPip
  • 183 posts
Took me one day to complete this. These classes will let you walk trough the call stack with C++ and access local variables or arguments in other functions than the current one. I’m trying to follow the KISS(Keep-It-Simple-Stupid) method so it’s very straightforward to work with. The documentation can be found here. And here’s the GitHub repo.

Here’s a little example of it in use:

#include "CallStack.hpp"

#include <iostream>

 

using namespace std;

 

CallStackFrame mainFrame;

 

void CheckTestFunc() {

    CallStack stack(mainFrame);

    CallStackFrame frame = stack.GetStartFrame().Next();

    long * args = (long *) frame.GetArgumentData();

    long * vars = (long *) frame.GetVariableData();

    void * ret  =          frame.GetReturnAddress();

    cout << "TestFunc.arg=" << *args << endl;

    cout << "TestFunc.a="   << *vars << endl;

}

 

void TestFunc(int arg) {

    int a = 33;

    CheckTestFunc();

}

 

int main() {

    mainFrame = CallStack::CurrentFrame();

 

    TestFunc(55);

    return 0;

}



The output of this application will be:


TestFunc.arg=55

TestFunc.a=33


Original post
My Code Blog - My Github - Ascension Project - Madness Script Project - Simple-Garbage-Collector Project
There is bound to be something useful somewhere.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users