Search code examples
c++tcpgdbns-3mptcp

Debugging using GDB


I am trying to get a bug out of my ns-3 (networking simulation software) program.

I run it under gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff4850195 in ns3::MpTcpBulkSendApplication::StartApplication (this=0x706850) at ../src/applications/model/mp-tcp-bulk-send-application.cc:170
170       m_socket->Bind();
(gdb) bt
#0  0x00007ffff4850195 in ns3::MpTcpBulkSendApplication::StartApplication (this=0x706850) at ../src/applications/model/mp-tcp-bulk-send-application.cc:170
#1  0x00007ffff09f9b45 in ns3::EventImpl* ns3::MakeEvent<void (ns3::Application::*)(), ns3::Application*>(void (ns3::Application::*)(), ns3::Application*)::EventMemberImpl0::Notify() (this=0x62f440) at ./ns3/make-event.h:94
#2  0x00007ffff02e90ef in ns3::EventImpl::Invoke (this=0x62f440) at ../src/core/model/event-impl.cc:45
#3  0x00007ffff02ee3a9 in ns3::DefaultSimulatorImpl::ProcessOneEvent (this=0x6d2d00) at ../src/core/model/default-simulator-impl.cc:141
#4  0x00007ffff02ee7ac in ns3::DefaultSimulatorImpl::Run (this=0x6d2d00) at ../src/core/model/default-simulator-impl.cc:194
#5  0x00007ffff02e9ff5 in ns3::Simulator::Run () at ../src/core/model/simulator.cc:161
#6  0x0000000000410640 in main (argc=1, argv=0x7fffffffdc58) at ../scratch/doordi3.cc:188

I can't understand what is happening, what gives the error. Any help would be welcome.

Thanks.

This function is the place from where error is coming:

// Application Methods
void MpTcpBulkSendApplication::StartApplication (void) // Called at time specified by Start
{
  NS_LOG_FUNCTION (this);
  //NS_LOG_UNCOND(Simulator::Now().GetSeconds() << " StartApplication -> Node-FlowId: {" << GetNode()->GetId() <<"-" << m_flowId<< "} MaxBytes: " << m_maxBytes << " F-Type: " << m_flowType << " S-Time: " << m_simTime);
  // Create the socket if not already
  if (!m_socket)
     { cout<<"Going to Bind"<<endl;
      //m_socket = CreateObject<MpTcpSocketBase>(GetNode()); //m_socket = Socket::CreateSocket (GetNode (), m_tid);
      m_socket = DynamicCast<MpTcpSocketBase>(Socket::CreateSocket (GetNode (), m_tid));
      m_socket->Bind();
      //m_socket->SetMaxSubFlowNumber(m_subflows);
      m_socket->SetFlowType(m_flowType);
      m_socket->SetOutputFileName(m_outputFileName);
      int result = m_socket->Connect(m_peer);
      if (result == 0)
        {
          m_socket->SetFlowId(m_flowId);
          m_socket->SetDupAckThresh(m_dupack);
          m_socket->SetConnectCallback(MakeCallback(&MpTcpBulkSendApplication::ConnectionSucceeded, this),MakeCallback(&MpTcpBulkSendApplication::ConnectionFailed, this));
          m_socket->SetDataSentCallback(MakeCallback(&MpTcpBulkSendApplication::DataSend, this));
          m_socket->SetCloseCallbacks (MakeCallback (&MpTcpBulkSendApplication::HandlePeerClose, this),MakeCallback (&MpTcpBulkSendApplication::HandlePeerError, this));
          //m_socket->SetSendCallback(MakeCallback(&MpTcpBulkSendApplication::DataSend, this));
        }
      else
        {
          NS_LOG_UNCOND("Connection is failed");
        }
    }
  if (m_connected)
    { 
      SendData ();
    }
}

Solution

  • In the comments you indicated that printing out the value of the pointer produces a 0. So that's pretty much your answer. The code is attempting to dereference a null pointer.

    You obtained this pointer from some library function whose purpose, based on the context, is to create a socket. If you were to check the documentation of your library function, you will find an explanation that a null pointer gets returned if the socket cannot be created for some reason.

    So, you have two follow-up courses of action:

    1) Investigate why the socket could not be created.

    2) Take this as a lesson learned: whenever you are calling a library function, you must check its documentation. If the library function indicates that it could possibly fail in its mission, and return a value, or some indication of some sorts that the operation has failed, your code must check for it, and take the appropriate action. You cannot assume that the library function will always succeed. Otherwise your code will fail in some mysterious fashion, and you will be forced to go to some web site and ask strangers to help you. And you don't obviously want to do that. You want to be able to figure out your bugs all by yourself.