add an option to EGL to dump stack traces on errors

enable by setting debug.egl.callstack to 1

Change-Id: I7fad9ce71b4c4c5ece97d4f9d139348eab742a3c
diff --git a/opengl/libs/EGL/egl_tls.cpp b/opengl/libs/EGL/egl_tls.cpp
index 961a61e..f3c8d2c 100644
--- a/opengl/libs/EGL/egl_tls.cpp
+++ b/opengl/libs/EGL/egl_tls.cpp
@@ -14,9 +14,13 @@
  ** limitations under the License.
  */
 
+#include <stdlib.h>
 #include <pthread.h>
 
 #include <cutils/log.h>
+#include <cutils/properties.h>
+
+#include <utils/CallStack.h>
 
 #include <EGL/egl.h>
 
@@ -69,6 +73,13 @@
     if (tls->error != error) {
         LOGE("%s:%d error %x (%s)", caller, line, error, egl_strerror(error));
         tls->error = error;
+        char value[PROPERTY_VALUE_MAX];
+        property_get("debug.egl.callstack", value, "0");
+        if (atoi(value)) {
+            CallStack stack;
+            stack.update();
+            stack.dump();
+        }
     }
 }