Jump to content

Seg fault when port is bound to dummay signal in before_end_of_elaboration


rahuljn

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

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);
}
};
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

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...