SegFault in scratchFile

48 views
Skip to first unread message

Osama Gazali

unread,
Sep 22, 2014, 6:08:24 AM9/22/14
to ns-3-...@googlegroups.com

Concerning scratch file, I want to output the statistic of Packet InterReceptionTime of nested map. first map is consist of a key (receptionID) and irtMap and the second one hole SourceID and receptiontime (rxTime).
I got segmentation fault in the second for loop and exactly in the line below
      for (std::map<uint64_t, std::vector<uint64_t>*>::iterator j=irtMap->begin(); j!=irtMap->end(); ++j)

I used gdb which help to pinpoint the problem but i could not find where is the problem. Could you help please?

void ComputeStatistics() 
{
 
 std::vector<uint64_t>::iterator vi;
 //int k =0;
 int k;
 uint64_t tmp_RxTime;
 uint64_t sum_RxTime = 0;
 
  //file_log2<<" RX_ID "<<"     "<<" TX_ID "<<"     "<<" average IRT "<<"     "<<" variance IRT "<<"     "<<" std_dev IRT "<<"     "<<std::endl;

  std::cout<<" CALLED33 Trace "<<std::endl;
 
  if (globalIrtMap == NULL) {
      return;
  std::cout<<" CALLED44 Trace "<<std::endl;
  }
 
 
  for (std::map<uint64_t, std::map<uint64_t, std::vector<uint64_t>*>*>::iterator i=globalIrtMap->begin(); i!=globalIrtMap->end(); ++i)
  {
      std::cout<<" CALLED55 Trace "<<std::endl;
        std::cout <<" rxId "<< i->first << " IrtMap " << i->second <<endl;
        
        std::map<uint64_t, std::vector<uint64_t>*>* irtMap = (*i).second;
      std::cout<<" CALLED66 Trace "<<std::endl;
 
    if (irtMap == NULL) { // we should never enter here but just in case
             std::cout<<" CALLED77 Trace "<<std::endl;
        continue;     
       }
 
      for (std::map<uint64_t, std::vector<uint64_t>*>::iterator j=irtMap->begin(); j!=irtMap->end(); ++j)
      {
          std::cout<<" CALLED88 Trace "<<std::endl;
            
                std::vector<uint64_t>* rxTime = (*j).second;
               //if (rxTime == NULL) { // we should never enter here but just in case
             //    std::cout<<" CALLED99 Trace "<<std::endl;
        //    continue;     
           //}
 
           for (vi = rxTime->begin()+1; vi<rxTime->end(); ++vi)
           {
            std::cout<<" CALLED1010 Trace "<<std::endl;
                        tmp_RxTime = *vi - *(vi-1);             
            rxTime->insert(vi-1, tmp_RxTime);
 
            //I want to keep this in a vector to use it for variance calculation  
                        std::cout<<"Inter-ReceptionTime to calculate the variance"<<tmp_RxTime<<std::endl;
 
             sum_RxTime += tmp_RxTime; 
             
 
           }
        //*1* To compute the average irt*****************************************************************************
 
        uint64_t av_RxTime = sum_RxTime/(rxTime->size()-1);
 
        std::cout<<" Average_Inter-ReceptionTime for each dedicated bi-directional communication "<<av_RxTime<<std::endl;
 
        //*2* To compute the variance of irt**************************************************************************
        uint64_t sample_variance = 0;
 
        for (k = 1; k < rxTime->size()-1 ; ++k)
           {
          //variance[k-1]= rxTime->at(k) - rxTime->at(k-1);
          sample_variance += ( ((rxTime->at(k) - rxTime->at(k-1)) - av_RxTime)*((rxTime->at(k) - rxTime->at(k-1)) - av_RxTime) / rxTime->size()-2) ;
 
              std::cout<<" CALLED1111 Trace "<<std::endl;  
 
           }
 
        //*3* To compute the variance of irt**************************************************************************
 
        uint64_t stdDeviation = sqrt (sample_variance);   

                        std::cout<<" standard deviation of the inter-reception time of packets"<<stdDeviation<<std::endl;
 
        //*4* To plot the statistics of irt**************************************************************************
 
file_log2<<" RX_ID "<<(*i).first<<" TX_ID "<<(*j).first<<" average IRT "<<av_RxTime<<" variance IRT "<<sample_variance<<" std_dev IRT "<<stdDeviation<<std::endl;
      }
          std::cout<<" CALLED1212 Trace "<<std::endl;
  }
          std::cout<<" CALLED1313 Trace "<<std::endl;
}
 
 
void ActivateCamTxon(PacketManager* packetManager, uint32_t nodeId)
{
  TechnologyList techList;
 
  techList.push_back("WaveVehicle");
 
//this is the frequency of CAM correspond to maximum allowable CAM could be transmit per second from DCC prespective 
  packetManager->ActivateCamTxon(nodeId, 10.0, 400);
}

Konstantinos

unread,
Sep 22, 2014, 6:32:53 AM9/22/14
to ns-3-...@googlegroups.com
Hi,

With only this information we can not help you. 
What was the error/backtrace you got from gdb? 
Check the individual variables such as irtMap to identify how many entries it has. 
It might have only one entry and by using pre-increment in the loop (http://stackoverflow.com/a/484492), you are getting the segfault.
How many times do you get in the loop? E.g. print the size of the map before you enter the loop and then check the loops you actually do.

Osama Gazali

unread,
Sep 22, 2014, 11:33:32 AM9/22/14
to ns-3-...@googlegroups.com
This is the backtrace and the first two stack frame does not give me any meaning. stack frame number 2 is the problem
the segFault occur in a line where there is no execution. it is a bit confusing for me.

Breakpoint 1, ComputeStatistics () at ../scratch/den.cc:95
95     std::vector<uint64_t>::iterator vi;
(gdb) next
99     uint64_t sum_RxTime = 0;
(gdb)
103      std::cout<<" CALLED33 Trace "<<std::endl;
(gdb)
 CALLED33 Trace
105      if (globalIrtMap == NULL) {
(gdb)
111      for (std::map<uint64_t, std::map<uint64_t, std::vector<uint64_t>*>*>::iterator i=globalIrtMap->begin(); i!=globalIrtMap->end(); ++i)
(gdb)
113          std::cout<<" CALLED55 Trace "<<std::endl;
(gdb)
 CALLED55 Trace
115            std::map<uint64_t, std::vector<uint64_t>*>* irtMap = (*i).second;
(gdb)
117            std::cout <<" rxId "<< (*i).first << " IrtMap " << (*i).second <<endl;
(gdb)
 rxId 15642270892032 IrtMap 0x11d700000000
118            //std::cout << "irtMap.size() is " << irtMap->size() <<endl;
(gdb)

Program received signal SIGSEGV, Segmentation fault.
0x000000000042a698 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, std::vector<unsigned long, std::allocator<unsigned long> >*>, std::_Select1st<std::pair<unsigned long const, std::vector<unsigned long, std::allocator<unsigned long> >*> >, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, std::vector<unsigned long, std::allocator<unsigned long> >*> > >::size (this=0x11d700000000)
    at /usr/include/c++/4.8/bits/stl_tree.h:728
728          { return _M_impl._M_node_count; }
(gdb) backtrace
#0  0x000000000042a698 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, std::vector<unsigned long, std::allocator<unsigned long> >*>, std::_Select1st<std::pair<unsigned long const, std::vector<unsigned long, std::allocator<unsigned long> >*> >, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, std::vector<unsigned long, std::allocator<unsigned long> >*> > >::size (
    this=0x11d700000000) at /usr/include/c++/4.8/bits/stl_tree.h:728
#1  0x0000000000428c24 in std::map<unsigned long, std::vector<unsigned long, std::allocator<unsigned long> >*, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, std::vector<unsigned long, std::allocator<unsigned long> >*> > >::size (this=0x11d700000000)
    at /usr/include/c++/4.8/bits/stl_map.h:435
#2  0x000000000040db46 in ComputeStatistics () at ../scratch/den.cc:118
#3  0x0000000000423b3b in main (argc=1, argv=0x7fffffffe2c8) at ../scratch/den.cc:2180
(gdb) up
#1  0x0000000000428c24 in std::map<unsigned long, std::vector<unsigned long, std::allocator<unsigned long> >*, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, std::vector<unsigned long, std::allocator<unsigned long> >*> > >::size (this=0x11d700000000)
    at /usr/include/c++/4.8/bits/stl_map.h:435
435          { return _M_t.size(); }
(gdb) up
#2  0x000000000040db46 in ComputeStatistics () at ../scratch/den.cc:118
118            //std::cout << "irtMap.size() is " << irtMap->size() <<endl;
(gdb)


One thing i want to reply concerning how to print the size of the map and identify how many entries it has.


--
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/s9wdMmB2nIM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages