Ejemplo n.º 1
0
char __cdecl CToJavaCallHandler(DCCallback* callback, DCArgs* args, DCValue* result, void* userdata)
{
	CallTempStruct* call;
	jthrowable exc;
	NativeToJavaCallbackCallInfo* info = (NativeToJavaCallbackCallInfo*)userdata;
	JNIEnv *env = GetEnv();
	initCallHandler(NULL, &call, env, &info->fInfo);
	
	call->pCallIOs = info->fInfo.fCallIOs;
	
	BEGIN_TRY(env, call);
	
	CToJavaCallHandler_Sub(call, info, args, result);
	
	END_TRY(info->fInfo.fEnv, call);

	exc = (*env)->ExceptionOccurred(env);
	if (exc) {
		(*env)->ExceptionDescribe(env);
        printStackTrace(env, exc);
		//(*env)->ExceptionClear(env);
	}
	
	cleanupCallHandler(call);
	
	return info->fInfo.fDCReturnType;
	
}
Ejemplo n.º 2
0
void StackTraceNoHeap::log(const char *errorType, const char *tracefn,
                           const char *pid, const char *buildId,
                           int debuggerCount) const {
  int fd = ::open(tracefn, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
  if (fd < 0) return;

  dprintf(fd, "Host: %s\n",Process::GetHostName().c_str());
  dprintf(fd, "ProcessID: %s\n", pid);
  dprintf(fd, "ThreadID: %" PRIx64"\n", (int64_t)Process::GetThreadId());
  dprintf(fd, "ThreadPID: %u\n", Process::GetThreadPid());
  dprintf(fd, "Name: %s\n", Process::GetAppName().c_str());
  dprintf(fd, "Type: %s\n", errorType ? errorType : "(unknown error)");
  dprintf(fd, "Runtime: hhvm\n");
  dprintf(fd, "Version: %s\n", buildId);
  dprintf(fd, "DebuggerCount: %d\n", debuggerCount);
  dprintf(fd, "\n");

  for (auto const& pair : StackTraceLog::s_logData->data) {
    dprintf(fd, "%s: %s\n", pair.first.c_str(), pair.second.c_str());
  }
  dprintf(fd, "\n");

  printStackTrace(fd);

  ::close(fd);
}
Ejemplo n.º 3
0
static void signal_handler(int sig) {
    char *name;

    switch (sig) {
        case SIGILL:
            name = "SIGILL";
            break;
        case SIGABRT:
            name = "SIGABRT";
            break;
        case SIGBUS:
            name = "SIGBUS";
            break;
        case SIGSEGV:
            name = "SIGSEGV";
            break;
        default:
            name = "??";
    }
    fprintf(stdout, "received signal %s\n", name);
    printStackTrace();
    printProfileInfo();

    signal(SIGILL,  NULL);
    signal(SIGABRT, NULL);
    signal(SIGBUS,  NULL); 
    signal(SIGSEGV, NULL); 

    abort();
}
Ejemplo n.º 4
0
 void assertAlreadyDeclared(void *p, int len) {
     if( commitJob.wi()._debug[p] >= len )
         return;
     log() << "assertAlreadyDeclared fails " << (void*)p << " len:" << len << ' ' << commitJob.wi()._debug[p] << endl;
     printStackTrace();
     abort();
 }
Ejemplo n.º 5
0
void StackTraceNoHeap::log(const char *errorType, const char *tracefn,
                           const char *pid) const {
  int fd = ::open(tracefn, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
  if (fd < 0) return;

  dprintf(fd, "Host: %s\n",Process::GetHostName().c_str());
  dprintf(fd, "ProcessID: %s\n", pid);
  dprintf(fd, "ThreadID: %llx\n", (int64)Process::GetThreadId());
  dprintf(fd, "ThreadPID: %u\n", Process::GetThreadPid());
  dprintf(fd, "Name: %s\n", Process::GetAppName().c_str());
  dprintf(fd, "Type: %s\n", errorType ? errorType : "(unknown error)");
  dprintf(fd, "Runtime: %s\n", hhvm ? "hhvm" : "hphp");
  dprintf(fd, "Version: %s\n", COMPILER_ID);
  dprintf(fd, "\n");

  hphp_string_map<std::string> &extra = StackTraceLog::s_logData->data;
  for (hphp_string_map<std::string>::const_iterator iter = extra.begin();
       iter != extra.end(); ++iter) {
    dprintf(fd, "%s: %s\n", iter->first.c_str(), iter->second.c_str());
  }
  dprintf(fd, "\n");

  printStackTrace(fd);

  ::close(fd);
}
Ejemplo n.º 6
0
void signalHandler(int signum)
{
  // associate each signal with a signal name string.
  const char* name = NULL;
  switch(signum)
  {
    case SIGABRT: name = "SIGABRT";  break;
    case SIGSEGV: name = "SIGSEGV";  break;
    case SIGILL:  name = "SIGILL";   break;
    case SIGFPE:  name = "SIGFPE";   break;
    default:  break;
  }
  // Dump a stack trace to a file.
  QFile stackTraceFile;
  QString& tmpPath = OpenModelica::tempDirectory();
  stackTraceFile.setFileName(QString("%1openmodelica.stacktrace.%2").arg(tmpPath).arg(Helper::OMCServerName));
  if (stackTraceFile.open(QIODevice::WriteOnly | QIODevice::Text))
  {
    printStackTrace(&stackTraceFile, signum, name);
    stackTraceFile.close();
  }
  if (name)
    fprintf(stderr, "Caught signal %d", signum);
  else
    fprintf(stderr, "Caught signal %d (%s)", signum, name);
  CrashReportDialog *pCrashReportDialog = new CrashReportDialog;
  pCrashReportDialog->exec();

  // If you caught one of the above signals, it is likely you just
  // want to quit your program right now.
  exit(signum);
}
Ejemplo n.º 7
0
        void FatalError(const std::string & errorMessage)
        {

            std::cerr << "\n\n\nSparCraft Fatal Error: \n\n\n      " << errorMessage << "\n\n";
        	printStackTrace(1);
            throw(SPARCRAFT_FATAL_ERROR);
        }
Ejemplo n.º 8
0
// TODO: if we get a segfault while saving, what then?
void sigbadHandler ( int x , siginfo_t *info , void *y ) {

	log("loop: sigbadhandler. disabling handler from recall.");
	// . don't allow this handler to be called again
	// . does this work if we're in a thread?
	struct sigaction sa;
	sigemptyset (&sa.sa_mask);
	sa.sa_flags = SA_SIGINFO ; //| SA_ONESHOT;
	sa.sa_sigaction = NULL;
	sigaction(SIGSEGV, &sa, NULL);
	sigaction(SIGILL, &sa, NULL);
	sigaction(SIGFPE, &sa, NULL);
	sigaction(SIGBUS, &sa, NULL);
	sigaction(SIGQUIT, &sa, NULL);
	sigaction(SIGSYS, &sa, NULL);
	// if we've already been here, or don't need to be, then bail
	if ( g_loop.m_shutdown ) {
		log("loop: sigbadhandler. shutdown already called.");
		return;
	}

	// unwind
	printStackTrace();

	// if we're a thread, let main process know to shutdown
	g_loop.m_shutdown = 2;
	log("loop: sigbadhandler. trying to save now. mode=%" PRId32, (int32_t)g_process.m_mode);

	// . this will save all Rdb's
	// . if "urgent" is true it will dump core
	// . if "urgent" is true it won't broadcast its shutdown to all hosts
	g_process.shutdown ( true );
}
Ejemplo n.º 9
0
 // takes an entry that was written _logTransactionOps
 // and applies them to collections
 //
 // TODO: possibly improve performance of this. We create and destroy a
 // context for each operation. Find a way to amortize it out if necessary
 //
 void applyTransactionFromOplog(BSONObj entry) {
     bool transactionAlreadyApplied = entry["a"].Bool();
     if (!transactionAlreadyApplied) {
         Client::Transaction transaction(DB_SERIALIZABLE);
         if (entry.hasElement("ref")) {
             applyRefOp(entry);
         } else if (entry.hasElement("ops")) {
             applyOps(entry["ops"].Array());
         } else {
             verify(0);
         }
         // set the applied bool to true, to let the oplog know that
         // this entry has been applied to collections
         BSONElementManipulator(entry["a"]).setBool(true);
         {
             LOCK_REASON(lockReason, "repl: setting oplog entry's applied bit");
             Lock::DBRead lk1("local", lockReason);
             writeEntryToOplog(entry, false);
         }
         // If this code fails, it is impossible to recover from
         // because we don't know if the transaction successfully committed
         // so we might as well crash
         // There is currently no known way this code can throw an exception
         try {
             // we are operating as a secondary. We don't have to fsync
             transaction.commit(DB_TXN_NOSYNC);
         }
         catch (std::exception &e) {
             log() << "exception during commit of applyTransactionFromOplog, aborting system: " << e.what() << endl;
             printStackTrace();
             logflush();
             ::abort();
         }
     }
 }
void abortHandler( int signum )
#endif
{
	// associate each signal with a signal name string.
	const char * name = NULL;
	switch ( signum )
	{
		case SIGABRT: name = "SIGABRT" ; break ;
		case SIGSEGV: name = "SIGSEGV" ; break ;
#ifndef	WIN32
		case SIGBUS: name = "SIGBUS" ; break ;
#endif
		case SIGILL: name = "SIGILL" ; break ;
		case SIGFPE: name = "SIGFPE" ; break ;
	}
	// Notify the user which signal was caught. We use printf, because this is the
	// most basic output function. Once you get a crash, it is possible that more
	// complex output systems like streams and the like may be corrupted. So we
	// make the most basic call possible to the lowest level, most
	// standard print function.
	if ( name )
		fprintf ( stderr, "Caught signal %d(%s)\n" , signum, name );
	else
		fprintf ( stderr, "Caught signal %d\n" , signum );

	// Dump a stack trace.	Will do Windows/Cygwin later.  Randy
#ifdef	UNIX_BACKTRACE_OK
	printStackTrace();
#else
	// StackDump();
#endif
	// If you caught one of the above signals, it is likely you just
	// want to quit your program right now.
	exit ( signum );
}
Ejemplo n.º 11
0
extern void printMemoryLeaks()
{
    // Dump general heap memory leaks
    if (__memoryAllocationCount == 0)
    {
        gameplay::print("[memory] All HEAP allocations successfully cleaned up (no leaks detected).\n");
    }
    else
    {
        gameplay::print("[memory] WARNING: %d HEAP allocations still active in memory.\n", __memoryAllocationCount);
        MemoryAllocationRecord* rec = __memoryAllocations;
        while (rec)
        {
#ifdef WIN32
            if (rec->trackStackTrace)
            {
                gameplay::print("[memory] LEAK: HEAP allocation leak at address %#x of size %d:\n", rec->address, rec->size);
                printStackTrace(rec);
            }
            else
                gameplay::print("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.\n", rec->address, rec->size, rec->line, rec->file);
#else
            gameplay::print("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.\n", rec->address, rec->size, rec->line, rec->file);
#endif
            rec = rec->next;
        }
    }
}
Ejemplo n.º 12
0
void repl(Interpreter &interpreter, const Settings &settings)
{
	std::cout << "Enter some code, or type \'exit\' when finished:\n";
	std::string line;
	int count = 0;
	while((std::cout << " > ") && std::getline(std::cin, line) && !(line == "quit" || line == "exit"))
	{
		++count;
		try
		{
			Token token = lex("repl(" + str(count) + ")", line);
			Declarations declarations = interpreter.declarations();
			InstructionList instructions = parse(token, declarations, settings);
			if (!instructions.empty())
			{
				Value result = interpreter.exec(instructions);
				std::cout << " < " << result << std::endl;
			}
		}
		catch(const LexError &e)
		{
			std::cerr << "Lex error at " << e.sourceLocation() << " " << e.what() << '\n';
			printStackTrace(std::cerr, e);
		}
		catch(const ParseError &e)
		{
			std::cerr << "Parse error at " << e.sourceLocation() << " " << e.what() << '\n';
			printStackTrace(std::cerr, e);
		}
		catch(const ExecutionError &e)
		{
			std::cerr << "Execution error at " << e.sourceLocation() << " " << e.what() << '\n';
			printStackTrace(std::cerr, e);
		}
		catch(const RaspError &e)
		{
			std::cerr << "General error: " << e.what() << '\n';
			printStackTrace(std::cerr, e);
		}
		catch(const std::exception &error)
		{
			std::cerr << "Internal Error: " << error.what() << std::endl;
		}
	}
	// If you use CTRL-D, nice to output a newline...
	std::cout << '\n';
}
Ejemplo n.º 13
0
 NOINLINE_DECL void msgasserted(int msgid, const char *msg) {
     assertionCount.condrollover( ++assertionCount.warning );
     tlog() << "Assertion: " << msgid << ":" << msg << endl;
     raiseError(msgid,msg && *msg ? msg : "massert failure");
     breakpoint();
     printStackTrace();
     throw MsgAssertionException(msgid, msg);
 }
Ejemplo n.º 14
0
    WriteConflictException::WriteConflictException()
        : DBException( "WriteConflict", ErrorCodes::WriteConflict ) {

        if ( trace ) {
            printStackTrace();
        }

    }
Ejemplo n.º 15
0
/* The given object 'sobj' must have a void println(char[]) method */
JNIEXPORT void JNICALL Java_java_lang_Throwable_printStackTrace0
  (JNIEnv *env, jobject thisobj, jobject sobj) {
  StackTrace tr;
  tr = (StackTrace)FNI_GetJNIData(env, thisobj);
  if (printStackTrace(env, sobj, tr) != 0)
      printNumericStackTrace(env, sobj, tr);
  return;
}
Ejemplo n.º 16
0
/**
 * Prints stack trace to stdout
 */
extern SERVER_DECL void printStackTrace()
{
#if defined(WIN32) && defined(_DEBUG)
    char buffer[6400];
    printStackTrace(&buffer[0], 6400);
    printf("%s", buffer);
#endif
}
Ejemplo n.º 17
0
 void msgasserted(int msgid, const char *msg) {
     assertionCount.condrollover( ++assertionCount.warning );
     tlog() << "Assertion: " << msgid << ":" << msg << endl;
     lastAssert[2].set(msg, getDbContext().c_str(), "", 0);
     raiseError(msgid,msg && *msg ? msg : "massert failure");
     breakpoint();
     printStackTrace();
     throw MsgAssertionException(msgid, msg);
 }
Ejemplo n.º 18
0
/**
 * Used for assertions
 */
extern SERVER_DECL void arcAssertFailed(const char* fname, int line, const char* expr)
{
    printf("Assertion Failed: (%s)\n", expr);
    printf("Location: %s(%i)\n", fname, line);
    //printf( "Expression: %s\n", expr );
#if defined(WIN32) && defined(_DEBUG)
    printf("Stack trace:\n");
    printStackTrace();
#endif
}
Ejemplo n.º 19
0
void Abort(const char* error, ...) {
  va_list argptr;
  va_start (argptr, error);
  fprintf(stderr,"Abort: ");
  vfprintf(stderr,error,argptr);
  fprintf(stderr,"\n");
  va_end (argptr);
  printStackTrace();
  throw;
}
Ejemplo n.º 20
0
void abortHandler ( int signum )
{
#ifdef GNUC
	FILE* outfile = OpenStackFile ();

	FILE* out;
	if( outfile == nullptr )
	{
		printf( "Unable to open !stacktrace.txt\n" );
		out = stdout;
	}
	else
	{
		out = outfile;
	}

	// associate each signal with a signal name string.
	const char* name = NULL;
	switch( signum )
	{
		case SIGABRT: name = "SIGABRT";  break;
		case SIGSEGV: name = "SIGSEGV";  break;
		case SIGBUS:  name = "SIGBUS";   break;
		case SIGILL:  name = "SIGILL";   break;
		case SIGFPE:  name = "SIGFPE";   break;
		default:  name = "Unknown signum"; break;
	}

	// Notify the user which signal was caught. We use printf, because this is the 
	// most basic output function. Once you get a crash, it is possible that more 
	// complex output systems like streams and the like may be corrupted. So we 
	// make the most basic call possible to the lowest level, most 
	// standard print function.
	if( name )
		fprintf ( out, "Caught signal %d (%s)\n\n", signum, name );
	else
		fprintf ( out, "Caught signal %d\n\n", signum );

	// Dump a stack trace.
	// This is the function we will be implementing next.
	printStackTrace ( out );

	// If you caught one of the above signals, it is likely you just 
	// want to quit your program right now.

	if( outfile )
		fclose ( outfile );

	exit(signum);
#else
	throw signum; // Just use C++ UnhandledException filters on windows.
				 // This allows us to get current thread context without
				 // the need to use assembly code.
#endif
}
Ejemplo n.º 21
0
 static MongoMMF* findMMF_inlock(void *ptr, size_t &ofs) {
     MongoMMF *f = privateViews.find_inlock(ptr, ofs);
     if( f == 0 ) {
         error() << "findMMF_inlock failed " << privateViews.numberOfViews_inlock() << endl;
         printStackTrace(); // we want a stack trace and the assert below didn't print a trace once in the real world - not sure why
         stringstream ss;
         ss << "view pointer cannot be resolved " << hex << (size_t) ptr;
         journalingFailure(ss.str().c_str()); // asserts, which then abends
     }
     return f;
 }
Ejemplo n.º 22
0
void Assert(int assertion, const char* error, ...) {
  va_list argptr;
  if(!assertion) {
    va_start (argptr, error);
    fprintf(stderr,"Assertion Failed: ");
    vfprintf(stderr,error,argptr);
    fprintf(stderr,"\n");
    va_end (argptr);
    printStackTrace();
    throw;
  }
}
Ejemplo n.º 23
0
void printStackTrace(JNIEnv* env, jthrowable ex) {
	jthrowable cause;
	jclass thClass = (*env)->FindClass(env, "java/lang/Throwable");
	jmethodID printMeth = (*env)->GetMethodID(env, thClass, "printStackTrace", "()V");
	jmethodID causeMeth = (*env)->GetMethodID(env, thClass, "getCause", "()Ljava/lang/Throwable;");
	if (!ex) {
		jclass exClass = (*env)->FindClass(env, "java/lang/RuntimeException");
		jmethodID initMeth = (*env)->GetMethodID(env, exClass, "<init>", "()V");
		ex = (jthrowable)(*env)->NewObject(env, exClass, initMeth);
	}
	(*env)->CallVoidMethod(env, (jobject)ex, printMeth);
	cause = (jthrowable)(*env)->CallObjectMethod(env, ex, causeMeth);
	if (cause)
		printStackTrace(env, cause);
}
Ejemplo n.º 24
0
Archivo: db.cpp Proyecto: zhuk/mongo
    void abruptQuit(int x) {
        ostringstream ossSig;
        ossSig << "Got signal: " << x << " (" << strsignal( x ) << ")." << endl;
        rawOut( ossSig.str() );

        ostringstream ossOp;
        ossOp << "Last op: " << currentOp.infoNoauth() << endl;
        rawOut( ossOp.str() );

        ostringstream oss;
        oss << "Backtrace:" << endl;
        printStackTrace( oss );
        rawOut( oss.str() );
        dbexit( EXIT_ABRUBT );
    }
Ejemplo n.º 25
0
char __cdecl CToJavaCallHandler(DCCallback* callback, DCArgs* args, DCValue* result, void* userdata)
{
	CallTempStruct* call;
	jthrowable exc;
	NativeToJavaCallbackCallInfo* info = (NativeToJavaCallbackCallInfo*)userdata;
	JNIEnv *env = GetEnv();
	initCallHandler(NULL, &call, env);
	BEGIN_TRY(env, call);
	
	call->pCallIOs = info->fInfo.fCallIOs;
	
	dcMode(call->vm, JNI_CALL_MODE);
	
	if (!info->fCallbackInstance)
	{
		throwException(env, "Trying to call a null callback instance !");
		cleanupCallHandler(call);
		return info->fInfo.fDCReturnType;
	}

	if (0) {
		float value = dcbArgFloat(args);
		float ret = (*call->env)->CallFloatMethod(call->env, info->fCallbackInstance, info->fMethod, value);
		result->f = ret;
	} else {
	dcArgPointer(call->vm, (DCpointer)call->env);
	dcArgPointer(call->vm, info->fCallbackInstance);
	dcArgPointer(call->vm, info->fMethod);
	
	if (info->fIsGenericCallback) {
		followArgsGenericJavaCallback(call, args, info->fInfo.nParams, info->fInfo.fParamTypes)
		&&
		followCallGenericJavaCallback(call, info->fInfo.fReturnType, result, (void*)(*env)->CallObjectMethod);
	} else {
		followArgs(call, args, info->fInfo.nParams, info->fInfo.fParamTypes, JNI_TRUE, JNI_TRUE)
		&&
		followCall(call, info->fInfo.fReturnType, result, info->fJNICallFunction, JNI_TRUE, JNI_FALSE);
	}
	
	exc = (*env)->ExceptionOccurred(env);
	if (exc) {
		(*env)->ExceptionDescribe(env);
        printStackTrace(env, exc);
		//(*env)->ExceptionClear(env);
	}
	}
	cleanupCallHandler(call);
	END_TRY_BASE(info->fInfo.fEnv, call, cleanupCallHandler(call););
Ejemplo n.º 26
0
void CBattlegroundManager::DeleteBattleground(CBattleground* bg)
{
    try
    {
        uint32 i = bg->GetType();
        uint32 j = bg->GetLevelGroup();
        Player* plr;

        m_instanceLock.Acquire();
        m_queueLock.Acquire();
        m_instances[i].erase(bg->GetId());

        /* erase any queued players */
        list<uint32>::iterator itr = m_queuedPlayers[i][j].begin();
        list<uint32>::iterator it2;
        for (; itr != m_queuedPlayers[i][j].end();)
        {
            it2 = itr++;
            plr = objmgr.GetPlayer(*it2);
            if (!plr)
            {
                m_queuedPlayers[i][j].erase(it2);
                continue;
            }

            if (plr && plr->m_bgQueueInstanceId == bg->GetId())
            {
                sChatHandler.SystemMessageToPlr(plr, plr->GetSession()->LocalizedWorldSrv(54), bg->GetId());
                SendBattlefieldStatus(plr, BGSTATUS_NOFLAGS, 0, 0, 0, 0, 0);
                plr->m_bgIsQueued = false;
                m_queuedPlayers[i][j].erase(it2);
            }
        }

        m_queueLock.Release();
        m_instanceLock.Release();

        //LOG_DETAIL("Deleting battleground from queue %u, instance %u", bg->GetType(), bg->GetId());
        delete bg;
    }
    catch (...)  // for Win32 Debug
    {
        LOG_ERROR("Exception: CBattlegroundManager::DeleteBattleground");
        printStackTrace();
        throw;
    }

}
Ejemplo n.º 27
0
    void WriteBackManager::queueWriteBack( const string& remote , const BSONObj& o ) {
        static mongo::mutex xxx( "WriteBackManager::queueWriteBack tmp" );
        static OID lastOID;

        scoped_lock lk( xxx );
        const BSONElement& e = o["id"];

        if ( lastOID.isSet() ) {
            if ( e.OID() < lastOID ) {
                log() << "this could fail" << endl;
                printStackTrace();
            }
        }
        lastOID = e.OID();
        getWritebackQueue( remote )->queue.push( o );
    }
Ejemplo n.º 28
0
Archivo: etest.c Proyecto: knaka/src
int
main (
  int argc,
  char * * argv ) {
  int i;
    init_exception_handler(argv[0]);
    for (i = -3; i < 3; i ++) {
      int e;
        try {
            foo(i);
            throw(UnknownException);
        } catch (e) {
            e_getMessage(e, __func__);
            printStackTrace();
        }
    }
    return (0);
}
Ejemplo n.º 29
0
static void *threadLooper(void *x)
{
    int runTime = 0;
    size_t lastStrokeSeen = sWatchdogStrokeCount;
    /* allow to run for up to 2 minutes */
    while (runTime < sWatchdogTimeout) {
        safeSleep(5);
        runTime += 5;
        if (lastStrokeSeen == sWatchdogStrokeCount) {
            msg("Watchdog not stroked for a while, printing stack: \n");
            printStackTrace();
        }
        lastStrokeSeen = sWatchdogStrokeCount;
    }
    msg("Watchdog about to abort with a timeout after %d\n", runTime);
    _exit(20);
    return NULL;
}
Ejemplo n.º 30
0
        DBClientBase * get( const string& addr , const string& ns, bool ignoreDirect = false ) {
            _check( ns );

            // Determine if non-shard conn is RS member for warning
            // All shards added to _hosts if not present in _check()
            if( ( logLevel >= 1 || ! printedShardConnWarning ) && ! ignoreDirect && _hosts.find( addr ) == _hosts.end() ){

                vector<Shard> all;
                Shard::getAllShards( all );

                bool isRSMember = false;
                string parentShard;
                for ( unsigned i = 0; i < all.size(); i++ ) {
                    string connString = all[i].getConnString();
                    if( connString.find( addr ) != string::npos && connString.find( '/' ) != string::npos ){
                        isRSMember = true;
                        parentShard = connString;
                        break;
                    }
                }

                if( isRSMember ){
                    printedShardConnWarning = true;
                    warning() << "adding shard sub-connection " << addr << " (parent " << parentShard << ") as sharded, this is safe but unexpected" << endl;
                    printStackTrace();
                }
            }


            Status* &s = _hosts[addr];
            if ( ! s )
                s = new Status();

            if ( s->avail ) {
                DBClientBase* c = s->avail;
                s->avail = 0;
                shardConnectionPool.onHandedOut( c );
                return c;
            }

            s->created++;
            return shardConnectionPool.get( addr );
        }