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 comment
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 comment
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 comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...