Move gDebuggerPresent to libRS.so, and fix up driver after split.

Now that libRS.so has been split into public/private libraries, we must
also move gDebuggerPresent into the public side. lldb uses this as a
flag to indicate that the driver can proceed (after waiting for the
debugger to attach).

Change-Id: I4c8f5c466644a51d50368ac8dd91f0bfd699302d
diff --git a/libRS.map b/libRS.map
index c288bf1..b6a2d82 100644
--- a/libRS.map
+++ b/libRS.map
@@ -1,5 +1,6 @@
 libRS {
   global:
+    gDebuggerPresent;
     rsaAllocationGetType;
     rsaContextSetNativeLibDir;
     rsaElementGetNativeData;
diff --git a/rsApiContext.cpp b/rsApiContext.cpp
index a5c7c3f..8cb2993 100644
--- a/rsApiContext.cpp
+++ b/rsApiContext.cpp
@@ -24,8 +24,19 @@
 using namespace android;
 using namespace android::renderscript;
 
+/*
+ * This global will be found by the debugger and will have its value flipped.
+ * It's independent of the Context class to allow the debugger to do the above
+ * without knowing the type makeup. This allows the debugger to be attached at
+ * an earlier stage.
+ */
+extern "C" int gDebuggerPresent = 0;
+
 extern "C" RsContext rsContextCreate(RsDevice vdev, uint32_t version, uint32_t sdkVersion,
                                       RsContextType ct, uint32_t flags) {
+    if (!gInternalDebuggerPresent) {
+        gInternalDebuggerPresent = &gDebuggerPresent;
+    }
     //ALOGV("rsContextCreate dev=%p", vdev);
     Device * dev = static_cast<Device *>(vdev);
     Context *rsc = Context::createContext(dev, nullptr, ct, flags);
diff --git a/rsContext.cpp b/rsContext.cpp
index 3eb7216..fae48b7 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -45,7 +45,7 @@
 #include "rsCompatibilityLib.h"
 #endif
 
-int gDebuggerPresent = 0;
+int *gInternalDebuggerPresent = nullptr;
 
 #ifdef RS_SERVER
 // Android exposes gettid(), standard Linux does not
@@ -483,7 +483,9 @@
 }
 
 void Context::waitForDebugger() {
-    while (!gDebuggerPresent) {
+    // Wait until this symbol has been properly set up, and the flag itself is
+    // set to a non-zero value.
+    while (!gInternalDebuggerPresent || !*gInternalDebuggerPresent) {
         sleep(0);
     }
 }
diff --git a/rsContext.h b/rsContext.h
index 890459d..fce22b5 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -46,12 +46,11 @@
 #endif
 
 /*
- * This global will be found by the debugger and will have its value flipped.
- * It's independent of the Context class to allow the debugger to do the above
- * without knowing the type makeup. This allows the debugger to be attached at
- * an earlier stage.
+ * This is a pointer to the gDebuggerPresent global from libRS.so. The
+ * debugger will use this to signal that it is attached, and thus the
+ * driver can wait appropriately.
 */
-extern "C" int gDebuggerPresent;
+extern int *gInternalDebuggerPresent;
 
 // ---------------------------------------------------------------------------
 namespace android {