Hello,
I have a strange beahavior of a systemC program caused by a debug function.
This function (called memItemExamine) allows to read a memory cell in a sub-module (memDev in the example) from the top level class (Model_top in the example).
The particularity of that error lies in the fact that I can read the memory cell (content is correctly displayed in terminal), but when later a process comes to read the memory cell again, the program fails with a segmentation fault.
Please find a simplified example of my codes hereunder, they illustrate the hierarchy of my program and the methodology I use to implement the memItemExamine function.
Any comment or feedback is welcome.
Do not hesitate to give me SystemC debug advices, I almost found nothing on internet about it (another topic could arrive on that subject regarding Eclipse CDT debug environment).
memDev.h :
One of the systemC thread implements an array of pointers which represent the memory cells. Initialisation of the pointers is not shown in the code but it is done.
SC_MODULE (memDev){ public : memItem** itemArray; void readmemItem(int address, memItem** ppReadItem); SC_HAS_PROCESS(memDev); memDev(sc_module_name instname) : sc_module(instname) { SC_THREAD(execute); itemArray = new memItem*[100]; // Memory initialization performed } };
memDev.cpp
void memDev::execute(){ while(true){ ... wait(20, SC_NS); }; void memDev::readmemItem(int address, memItem** ppReadItem){ *ppReadItem = itemArray[address]->content; };
Model_top.h :
memItemExamine function copy the memory cell content in the provided pointer readItem.
#include "memDev.h" #include "otherDev.h" // Not important here class Model_top { memDev my_memDev; // SystemC thread otherDev my_otherDev; //SystemC thread Model_top(); void memItemExamine(int address, memItem* readItem); }
Model_top.cpp
Model_top::Model_top(): my_memDev("my_memDev"), my_otherDev("my_otherDev"){ } void Model_top::memItemExamine(int address, memItem* readItem){ memItem** tempVal = new memItem*; my_memDev.readmemItem(address, tempVal); readItem->content = (*tempVal)->content; delete tempVal; }
main.cpp :
If the memItemExamine function is not executed, no segmentation fault occurs.
int sc_main(int argc, char* argv[]) { Model_top my_modelTop; // sc_start(30, SC_NS); // Possibility to start simulation before examine // Memory item examine (debug purpose) memItem* pmemItem = new memItem; modelTop.memItemExamine(1, pmemItem); cout << pmemItem->content << endl; // Content is displayed // Segmentation fault occurs here : sc_start(70, SC_NS); return 0; };
Thank you for your time!
Regards,
J-B