#include "DebugAndroid.hpp"

#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <cutils/properties.h>

void AndroidEnterDebugger()
{
    ALOGE(__FUNCTION__);
#ifndef NDEBUG
    static volatile int * const makefault = nullptr;
    char value[PROPERTY_VALUE_MAX];
    property_get("debug.db.uid", value, "-1");
    int debug_uid = atoi(value);
    if ((debug_uid >= 0) && (geteuid() < static_cast<uid_t>(debug_uid)))
    {
        ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u. Look for thread %u", getpid(), gettid());
        volatile int waiting = 1;
        while (waiting) {
            sleep(1);
        }
    } else {
        ALOGE("No debugger");
    }
#endif
}

void trace(const char *format, ...)
{
    va_list vararg;
    va_start(vararg, format);
    android_vprintLog(ANDROID_LOG_VERBOSE, NULL, LOG_TAG, format, vararg);
    va_end(vararg);
}

#include "DebugAndroid.hpp"

#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <cutils/properties.h>

void AndroidEnterDebugger()
{
    ALOGE(__FUNCTION__);
#ifndef NDEBUG
    static volatile int * const makefault = nullptr;
    char value[PROPERTY_VALUE_MAX];
    property_get("debug.db.uid", value, "-1");
    int debug_uid = atoi(value);
    if ((debug_uid >= 0) && (geteuid() < static_cast<uid_t>(debug_uid)))
    {
        ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u", gettid());
        while (1) {
            pause();
        }
    } else {
        ALOGE("No debugger");
    }
#endif
}

void trace(const char *format, ...)
{
    va_list vararg;
    va_start(vararg, format);
    android_vprintLog(ANDROID_LOG_VERBOSE, NULL, LOG_TAG, format, vararg);
    va_end(vararg);
}

--- 
+++ 
@@ -15,9 +15,10 @@
     int debug_uid = atoi(value);
     if ((debug_uid >= 0) && (geteuid() < static_cast<uid_t>(debug_uid)))
     {
-        ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u", gettid());
-        while (1) {
-            pause();
+        ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u. Look for thread %u", getpid(), gettid());
+        volatile int waiting = 1;
+        while (waiting) {
+            sleep(1);
         }
     } else {
         ALOGE("No debugger");
Improve advice for attaching the debugger

Change-Id: I6ca5697a8b672a1e20bcb7999cf4d9ba544f9558
Reviewed-on: https://swiftshader-review.googlesource.com/3117
Reviewed-by: Nicolas Capens <0612353e1fcebbfd4b302d9337447ca0cdfa9122@google.com>
Tested-by: Greg Hartman <1491e78df1ea2169b62fa2ceaf1a32538792aab8@google.com>
