[omniORB] [Patch] Useful trace information

Eric Dumas edumas@tumbleweed.com
Tue, 2 May 2000 09:55:08 -0700


Hello.

You will find bellow a small patch in order to display more usefull
information when trying to release an object when the reference count
is <=0. 

The patch is for 2.6.1 - but could probably be applied for the next
release till 3.0. 

-- 
                        Iric Dumas (Eric.Dumas@tumbleweed.com)
   Tumbleweed Communications, 700 Saginaw Drive, Redwood City, CA 94063, USA
               http://www.tumbleweed.com    Tel: +1 650-216-2030

=-=-=

Index: objectRef.cc
===================================================================
RCS file: /opt/cvsroot/External/omniORB_2.6.1_http/src/lib/omniORB2/objectRef.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -a -u -r1.2 -r1.3
--- objectRef.cc	1999/12/23 01:17:25	1.2
+++ objectRef.cc	2000/05/02 15:52:37	1.3
@@ -29,6 +29,11 @@
 
 /*
   $Log: objectRef.cc,v $
+  Revision 1.3  2000/05/02 15:52:37  edumas
+
+  	When we try to release an object with an object count <=0,
+   	display the PID, ObjectId, Key and if this is from a proxy or not.
+
 
@@ -89,6 +94,10 @@
 #include <omniORB2/proxyFactory.h>
 #include <ropeFactory.h>
 
+#ifndef __WIN32__
+#include <unistd.h>
+#endif
+
 #if defined(HAS_Cplusplus_Namespace)
 using omniORB::operator==;
 #endif
@@ -274,7 +283,6 @@
 {
   omniObject::objectTableLock.lock();
   if (obj->getRefCount() <= 0) {
-    omniObject::objectTableLock.unlock();
     // This is most likely to be caused by the application code calling
     // CORBA::release() twice on an object reference.
     //
@@ -283,11 +291,43 @@
     // Therefore, just generate a warning message and returns.
     if (omniORB::traceLevel > 0) {
       omniORB::log << "Warning: try to release an object with reference count <= 0.\n"
-	   << "Has CORBA::release() been called more than once on an object reference?\n";
+		   << "Has CORBA::release() been called more than once on an object reference?\n";
+
+#ifndef __WIN32__
+      omniORB::log << "[PID=" << getpid() << "]: ";
+#endif
+
+      _CORBA_Octet 	*obj_key;
+      _CORBA_ULong 	kSize;
+      obj->getKey( obj_key, kSize );
+      
+      // Convertion code stolen from namectl... +- modifications.
+      char char_key[256];
+      int index=2;
+      char_key[0] = '0';
+      char_key[1] = 'x';
+      
+      for (int j=0; j < kSize; ++j) {
+	  int v = ((obj_key[j] & 0xf0) >> 4);
+	  char_key[index++] = (v < 10) ? (char)('0' + v) : (char)('a' + (v - 10));
+	  v = obj_key[j] & 0xf;
+	  char_key[index++] =  (v < 10) ? (char)('0' + v) : (char)('a' + (v - 10));
+      }	
+      char_key[index] = 0;
+    
+      if (obj->is_proxy()) {
+	  omniORB::log << "This object is Proxy.";
+      } else {
+	  omniORB::log << "This object is not a Proxy.";
+      }
+      omniORB::log << " ObjectID: "  << obj->NP_IRRepositoryId();
+      omniORB::log << " ObjectKey: " << char_key << "\n";
       omniORB::log.flush();
     }
+    // Unlock only at the end.
+    omniObject::objectTableLock.unlock();
     return;
-  }
+  } 
   obj->setRefCount(obj->getRefCount()-1);
   if (obj->getRefCount() == 0) {
     if (obj->is_proxy()) {