简体   繁体   English

尝试解析CORBA引用时出现C ++分段错误

[英]C++ segmentation fault when trying to resolve a CORBA reference

When im trying to resolve a CORBA reference I receive a segmentation fault. 当我尝试解析CORBA引用时,出现分段错误。 Either im blind or I have done something really stupid for this not work. 我是盲目的还是我做了一些愚蠢的事情,以解决这个问题。 Im using ACE 5.7.9 TAO 1.7.9 for CORBA. 我在CORBA中使用ACE 5.7.9 TAO 1.7.9。 Wondering if anyone can help me please ??? 想知道是否有人可以帮助我?

The segmentation fault seems to be happening on the line "serverRef = Corba::Orb::getOrb().resolveObjectReference (myIOR.c_str());" 分段错误似乎发生在“ serverRef = Corba :: Orb :: getOrb()。resolveObjectReference(myIOR.c_str());”行上 as commenting this line will cause the application to run fine. 因为注释此行将导致应用程序正常运行。

I have copied all the dependan code below. 我已经复制了下面的所有dependan代码。

bool ClsSend::ServerObject::resolveServerRef()
{
  clssendlog << debug << "In ClsSend::ServerObject::resolveServerRef 1" << endl;
 bool referenceIsUsable = true;
 ostringstream errMsg;

 // Are we dealing with a new reference?
 if (CORBA::is_nil (serverRef.in()))
 {
   try {
     Monitor crit (mutexCoreRef);

     if (CORBA::is_nil (serverRef.in()))
     {
       // Step 1: Resolve the object reference
       serverRef = Corba::Orb::getOrb().resolveObjectReference <GenericServerWithTransport> (myIOR.c_str());

       // Step 2: Ping to check connectivity if reference is not null
       if (!CORBA::is_nil (serverRef.in()))
         serverRef->ping();
       else
       {
         errMsg << "Not registered in naming server.";
         referenceIsUsable = false;
       }
     }
   } catch (const CORBA::COMM_FAILURE &exc) {
     errMsg << "CORBA::COMM_FAILURE";
     referenceIsUsable = false;
     setRefNil();
   } catch (const NamingException &exc) {
     errMsg << exc;
     referenceIsUsable = false;
     setRefNil();
   } catch (...) {
     errMsg << "Unknown exception";
     referenceIsUsable = false;
     setRefNil();
   }
 }
 return referenceIsUsable;

} }

///////////////////////////////////////////////////////////////// ////////////////////////////////////////////////// ///////////////

resolveObjectReference outline, resolveObjectReference大纲,

// Resolve a reference to an object, return a nil object reference if none is bound
// Specify the name with a delimited string
template<class T> typename T::_var_type resolveObjectReference(const string &name,
    char delimiter = '/')
{
  return Corba::resolveObjectReference<T> (orb_.in(), name, delimiter);
}

// Resolve a reference to an object, return a nil object reference if none is bound
// Specify the name with a delimited c-style string
template<class T>
typename T::_var_type resolveObjectReference(const CORBA::ORB_ptr & orb, const string &name, char delimiter = '/')
{
  return resolveObjectReference<T> (orb, convertToCosName(name, delimiter));
}

// Resolve a reference to an object, return a nil object reference if none is bound
// Specify the name with a CosNaming::Name object
template<class T>
typename T::_var_type resolveObjectReference(const CORBA::ORB_ptr & orb, const CosNaming::Name &name)
{
  typename T::_var_type typedObj;
  CORBA::Object_var obj;

  // Check it is a valid name
  assert_throw(name.length() > 0);

  // Try to resolve the object reference
  try
  {
    obj = getNamingContext(orb)->resolve(name);

    // If the object reference was bound to nil emit a warning but return nil, do not throw
    if (CORBA::is_nil(obj.in()))
    {
      liblog << warning << "Object reference " << toString(name)
          << " bound to nil in naming service" << endl;
    }
    else
    {
      typedObj = T::_narrow(obj.in());

      // If the object reference narrowed to nil this indicates the object was of the wrong type
      if (CORBA::is_nil(typedObj.in()))
      {
        liblog << error << "Object reference " << toString(name)
            << " is not of the expected type " << typeid(T).name() << endl;
        throw NamingException("Object reference narrows to a nil");
      }
    }
  }
  catch (const CosNaming::NamingContext::NotFound &exc)
  {
    // Object not bound - return nil
  }
  return typedObj;
}

///////////////////////////////////////////////////////////////////////////
// Local function - getNamingContext
///////////////////////////////////////////////////////////////////////////
CosNaming::NamingContext_var getNamingContext(CORBA::ORB_ptr orb)
{
  // Get the initial reference to the naming service
  CORBA::Object_var nameService;

  // Try to get a reference to the naming service
  nameService = orb->resolve_initial_references("NameService");
  if (CORBA::is_nil(nameService.in()))
  {
    liblog << error << "Name service reference bound to nil" << endl;
    throw NamingException("Naming service reference bound to nil");
  }

  // cerr << "Name service IOR: " << getORB()->object_to_string (nameService) << endl;

  // Narrow the reference to the root naming context
  CosNaming::NamingContext_var rootContext =
      CosNaming::NamingContext::_narrow(nameService.in());
  if (CORBA::is_nil(rootContext.in()))
  {
    liblog << error << "Name service reference resolved to nil" << endl;
    throw NamingException("Naming service reference resolves to nil");
  }
  return rootContext;
}

///////////////////////////////////////////////////////////////////////////
// Local function - convertToCosName
///////////////////////////////////////////////////////////////////////////
CosNaming::Name convertToCosName(const string &strname, char delimiter)
{
  const char *name = strname.c_str();

  CosNaming::Name cosName;
  cosName.length(count(name, name + strlen(name), delimiter) + 1);

  size_t index = 0;
  const char *next = strchr(name, delimiter);
  if (next == NULL)
  {
    next = name + strlen(name);
  }
  while (next != NULL)
  {
    cosName[index].id = string(name, next).c_str();
    cosName[index++].kind = CORBA::string_dup("");
    if (*next)
    {
      name = next + 1;
      next = strchr(name, delimiter);
      if (next == NULL)
      {
        next = name + strlen(name);
      }
    }
    else
    {
      next = NULL;
    }
  }
  return cosName;
}

Dang, that's a lot of code in a question... 亲爱的,这是很多问题中的代码...

My next look in a case like this would be to split that offending line: 在这种情况下,我的下一个目标是拆分该违规行:

serverRef = Corba::Orb::getOrb().resolveObjectReference (myIOR.c_str());

Into as many parts as possible, and try to see which part is crashing. 放入尽可能多的零件,并尝试查看哪个零件崩溃了。 After that, try to see what is wrong with that one part. 在那之后,尝试看看那一部分出了什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM