Jump to content

Seg fault when port is bound to dummay signal in before_end_of_elaboration


Recommended Posts

Posted

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

Posted

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

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

Posted

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. 

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...