Jump to content

I got an seg fault and i don't arrive to fix it yet


Recommended Posts

Hello all, i really your help. I'm getting an segmentation fault (Erreur de segmentation (core dumped) ) and i do not understand how to fix it.

when i do the gdb i git thie one as error.

Quote

Erreur de segmentation (core dumped)
chaka@chaka-VirtualBox:~/Bureau/systemC/framework_development/code_framework_network/network_chaka_v1$ gdb
(gdb) file ./simul
Reading symbols from ./simul...done.
(gdb) run
Starting program: /home/chaka/Bureau/systemC/framework_development/code_framework_network/network_chaka_v1/simul
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

        SystemC 2.3.1-Accellera --- Feb  5 2016 15:49:14
        Copyright (c) 1996-2014 by all Contributors,
        ALL RIGHTS RESERVED

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b0ac1d in sc_core::sc_port_base::complete_binding() () from /usr/lib/libsystemc-2.3.1.so

(gdb) bt
#0  0x00007ffff7b0ac1d in sc_core::sc_port_base::complete_binding() () from /usr/lib/libsystemc-2.3.1.so
#1  0x00007ffff7b0adf9 in sc_core::sc_port_registry::complete_binding() () from /usr/lib/libsystemc-2.3.1.so
#2  0x00007ffff7b0ae1c in sc_core::sc_port_registry::elaboration_done() () from /usr/lib/libsystemc-2.3.1.so
#3  0x00007ffff7af1a92 in sc_core::sc_simcontext::elaborate() () from /usr/lib/libsystemc-2.3.1.so
#4  0x00007ffff7af3057 in sc_core::sc_simcontext::initialize(bool) () from /usr/lib/libsystemc-2.3.1.so
#5  0x00007ffff7af31bc in sc_core::sc_simcontext::simulate(sc_core::sc_time const&) ()
   from /usr/lib/libsystemc-2.3.1.so
#6  0x00007ffff7af3612 in sc_core::sc_start(sc_core::sc_time const&, sc_core::sc_starvation_policy) ()
   from /usr/lib/libsystemc-2.3.1.so
#7  0x00007ffff7af3786 in sc_core::sc_start() () from /usr/lib/libsystemc-2.3.1.so
#8  0x0000000000409157 in sc_main (argc=1, argv=0x6accb0) at main_archEmotica.cpp:183
#9  0x00007ffff7ae1674 in sc_elab_and_sim () from /usr/lib/libsystemc-2.3.1.so
#10 0x00007ffff6e9cf45 in __libc_start_main (main=0x408700 <main@plt>, argc=1, argv=0x7fffffffdf18,
    init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdf08)
    at libc-start.c:287
#11 0x0000000000409039 in _start ()

 

i understand that the error occurred on sc_start and the the problem is with libsystemc-2.3.1.so. i need your help to fix it.

Thanks in advance,

bellow, tou have my source code.

#include <iostream>
 #include <string>
 #include <vector>
 #include "math.h"

#define SC_INCLUDE_DYNAMIC_PROCESSES

#include "systemc.h"


#include "tlm.h"
#include "tlm_utils/simple_initiator_socket.h"
#include "tlm_utils/simple_target_socket.h"

#include "pthread.h"


#include "timer_counter_sc.cpp"

#include <inttypes.h>

#include "genMcu.h"
#include "sensors.h"
#include "genRadio.h"
#include "genbattery.h" 

#include "alldef.h"

using namespace sc_core;
using namespace sc_dt;
using namespace std;

GenMcu*	o_genericMcu[numberOfSensorNode]= {NULL};
GenSensor* o_genericSensor[numberOfSensorNode]= {NULL}; 
Transceiver_hc05* o_genericRadio[numberOfSensorNode]= {NULL}; 
GenBattery* o_genericBattery[numberOfSensorNode]= {NULL};
SCTimerCounter* o_genericTimer[numberOfSensorNode]= {NULL};
SCTimerCounter* o_genericTimer_rf[numberOfSensorNode]= {NULL};

sc_signal<unsigned int,SC_MANY_WRITERS> sizeDataInRam[numberOfSensorNode];
sc_signal< bool ,SC_MANY_WRITERS> radioINT[numberOfSensorNode];
sc_signal< bool,SC_MANY_WRITERS > sig_radioCS[numberOfSensorNode];
sc_signal< bool ,SC_MANY_WRITERS> mcuInt[numberOfSensorNode];
sc_signal< bool,SC_MANY_WRITERS > sig_allPacketsTransmitted[numberOfSensorNode];
sc_signal<float,SC_MANY_WRITERS>  sigMcuHC05[numberOfSensorNode];

sc_core::sc_signal<int,SC_MANY_WRITERS> identSensor_io[numberOfSensorNode];
sc_core::sc_signal<bool,SC_MANY_WRITERS> syncSensorsMcu[numberOfSensorNode];
sc_signal<bool,SC_MANY_WRITERS> paquetToTransmit_io[numberOfSensorNode];
sc_signal< bool,SC_MANY_WRITERS > init_simul_i[numberOfSensorNode];
sc_signal< bool,SC_MANY_WRITERS>  commandMode_CMD[numberOfSensorNode];
sc_signal< double,SC_MANY_WRITERS> timeElapsed_mcu[numberOfSensorNode];
sc_signal< double,SC_MANY_WRITERS> timeElapsed_radio[numberOfSensorNode];
sc_signal< char,SC_MANY_WRITERS >  batt_mcuState[numberOfSensorNode];
sc_signal<char,SC_MANY_WRITERS>  batt_radioState[numberOfSensorNode];

sc_core::sc_signal<float,SC_MANY_WRITERS>  sensorData[numberOfSensorNode][fsampling];

std::string s;
sc_event ev_activeNode_1;
const int indexNode =0;
SC_MODULE (emotica)
{
	//sc_in<int> indexNode{"indexNode_emoticaM"};
	
  SC_CTOR(emotica) 
  {
    int HC05 = HC;
	int mcuType   = MCU_t;
	int radioType = HC05; 
	int selectSensor[3] = {1,2,4};
	
	sc_time period_clk(period_mcu, SC_SEC); //0.125=1/8 @freq_mcu= 8 
	sc_clock clk("clk", period_clk, 0.5, SC_ZERO_TIME, true);
	
	sc_time period_clk_hc05(period_radio, SC_SEC); // @freq_hc05= 1 megabit/s
	sc_clock clk_hc05("clk_hc05", period_clk_hc05, 0.5, SC_ZERO_TIME, true);
	
	  std::stringstream stream;
		stream << indexNode;
		stream >> s;
		paquetToTransmit_io[indexNode]  = false;
	  commandMode_CMD[indexNode]= false;
	  	
		o_genericMcu[indexNode]	= new GenMcu	(("mcu"+s).c_str());

		o_genericSensor[indexNode] = new GenSensor	(("sensor"+s).c_str(),selectSensor[indexNode]); 
		
    o_genericRadio[indexNode] = new Transceiver_hc05	(("radio"+s).c_str()); 
    
		o_genericBattery[indexNode] = new GenBattery	(("battery"+s).c_str(), mcuType,radioType,freq_mcu,SUPPLY_VOLTAGE_V);
		
		o_genericTimer[indexNode] = new SCTimerCounter	(("timer"+s).c_str());
		
		o_genericTimer_rf[indexNode] = new SCTimerCounter	(("timer_rf"+s).c_str());
		
		
		o_genericTimer[indexNode]->ClockTC(clk);
		o_genericTimer_rf[indexNode]->ClockTC(clk_hc05);
	
		o_genericMcu[indexNode]->clk(clk);
		o_genericMcu[indexNode]->allPacketsTransmitted(sig_allPacketsTransmitted[indexNode]);
		o_genericMcu[indexNode]->identSensor(identSensor_io[indexNode]);
		init_simul_i[indexNode].write(true);
		o_genericMcu[indexNode]->init_simul(init_simul_i[indexNode]);
		o_genericMcu[indexNode]->tc_reg_access.bind(o_genericTimer[indexNode]->reg_access_socket);
		o_genericMcu[indexNode]->tc_irq_socket.bind(o_genericTimer[indexNode]->irq);
		o_genericMcu[indexNode]->timeElapsed_mcu(timeElapsed_mcu[indexNode]);
		o_genericBattery[indexNode]->timeElapsed_mcu(timeElapsed_mcu[indexNode]);
		o_genericBattery[indexNode]->timeElapsed_radio(timeElapsed_radio[indexNode]);
		o_genericMcu[indexNode]->readSensorData(syncSensorsMcu[indexNode]);
		o_genericSensor[indexNode]->readSensorData(syncSensorsMcu[indexNode]);
		o_genericSensor[indexNode]->identSensor(identSensor_io[indexNode]);
		identSensor_io[indexNode]=0;
	
		for (int i=0; i< nbSensors; i++)
		{
			for (int j=0;j<fsampling;j++)
			{
				o_genericMcu[indexNode]->analogInput[i][j](sensorData[indexNode][j]);
				o_genericSensor[indexNode]->sensorAnalogOut[i][j](sensorData[indexNode][j]);
			}
		}
		
		o_genericMcu[indexNode]->paquetToTransmit(paquetToTransmit_io[indexNode]);
		o_genericMcu[indexNode]->batt_mcuState(batt_mcuState[indexNode]);
		o_genericBattery[indexNode]->batt_mcuState(batt_mcuState[indexNode]);
		o_genericBattery[indexNode]->batt_radioState(batt_radioState[indexNode]);
	
	  o_genericMcu[indexNode]->radioINT(radioINT[indexNode]);
		o_genericMcu[indexNode]->sizeDataInRam(sizeDataInRam[indexNode]);
 		o_genericMcu[indexNode]->radioCS(sig_radioCS[indexNode]);
		o_genericMcu[indexNode]->mcuInt(mcuInt[indexNode]);
	
		o_genericRadio[indexNode]->clk(clk_hc05);
		o_genericRadio[indexNode]->radioINT(radioINT[indexNode]);
		o_genericRadio[indexNode]->sizeDataInRam(sizeDataInRam[indexNode]);
 		o_genericRadio[indexNode]->radioCS(sig_radioCS[indexNode]);
		o_genericRadio[indexNode]->mcuInt(mcuInt[indexNode]); 
		o_genericRadio[indexNode]->sigFifoIn(sigMcuHC05[indexNode]);
		o_genericRadio[indexNode]->batt_radioState(batt_radioState[indexNode]);
		o_genericRadio[indexNode]->timeElapsed_radio(timeElapsed_radio[indexNode]);
		o_genericRadio[indexNode]->tc_reg_access.bind(o_genericTimer_rf[indexNode]->reg_access_socket);
		o_genericRadio[indexNode]->tc_irq_socket.bind(o_genericTimer_rf[indexNode]->irq);
	

		o_genericMcu[indexNode]->commandMode_CMD(commandMode_CMD[indexNode]);
		o_genericRadio[indexNode]->commandMode_CMD(commandMode_CMD[indexNode]);
  }
  
  ~emotica()
  {
  	delete o_genericMcu[indexNode];
  	delete o_genericSensor[indexNode];
  	delete o_genericRadio[indexNode];
  	delete o_genericBattery[indexNode];
  }
};


SC_MODULE (signal_bind) {
  //sc_signal<int> indexNode;
 
  emotica *archEmotica_1 = NULL;
  SC_CTOR(signal_bind) 
  {
    archEmotica_1 = new emotica("archEmotica_1");
    //indexNode.write(1);
    //archEmotica_1->indexNode (indexNode);
  }
  ~signal_bind()
  {
  	delete archEmotica_1;
  }
}; 

int sc_main(int argc, char *argv[])
{
	signal_bind archEmotica("SIGNAL_BIND");

  sc_start();
  return 0;
}

 

Link to comment
Share on other sites

Looks to me like you are declaring sc_clock objects inside the constructor on the stack, which will then be immediately destroyed at the end of construction. They should be class members.

Also, you appear to have the intent of using PHREADs; however, SystemC is not thread-safe unless you take special precautions.

I would also suggest you consider using std::unique_ptr<> instead managing pointers yourself. Safety first.

 

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