Jump to content
rahuljn

Seg fault when port is bound to dummay signal in before_end_of_elaboration

Recommended Posts

Hello

 

In the following example I am tying to connect the unconnected port to dummy channel in before_end_of_elaboration callback. But it gives me seg fault

 

#include "systemc.h"

class test : public sc_module {
    public:
    sc_in<bool> in1;
    SC_HAS_PROCESS(test);
    test(sc_module_name name){
        SC_THREAD(fun);
    }

    void fun(){
    }

    void before_end_of_elaboration(){
        sc_signal<bool> sig;
        in1.bind(sig);
    }
};

int sc_main(int, char**){
    test t("t");
    sc_start();
    return 0;
}

 

Can you please help.

 

Also the standard says that @page 122 that the time at which deferred port binding is complete is implementation defined, so where I shoudl check my unconnected ports in the module"

 

Thanks

RahulJn

Share this post


Link to post
Share on other sites

Well, in my case your simulation does not produces segfault. But obviously you have a problem your code:

 

The problem is that you create your signal on call stack.  Basically it is local to before_end_of_elaboration function.

Once control returns from before_end_of_elaboration, signal sig is destroyed. 

 

So if you will try to read from port in1 you will have a segfault:

void fun(){
in1.read();
}

Solution is to make your signal a member of module:

class test : public sc_module {
public:
sc_in<bool> in1;
sc_signal<bool> sig;

SC_HAS_PROCESS(test);
test(sc_module_name name){
SC_THREAD(fun);
}

void fun(){
in1.read();
}

void before_end_of_elaboration(){
in1.bind(sig);
}
};

Share this post


Link to post
Share on other sites

Hello

 

Thanks for your comments. But in my case I am not interested in reading that port value during the simulation as I am explicitly stubing that.

Can you confirm you are not getting seg fault with my example(without any change) ?

 

In my env I am using Ubuntu, gcc 4.8.4 and SystemC 2.3.1 and I am getting the seg fault.

 

 

 

Thanks

RJ

Share this post


Link to post
Share on other sites

I've checked on Windows now,

yes it's segfaults when tries to dereference pointer to sig during deferred biding. Unfortunately there is no mechanism in C++ to check if pointer is valid, so SystemC kernel can't save us from this type of mistakes. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×