summaryrefslogtreecommitdiffstats
path: root/opengl/libs/GLES2_dbg/generate_MessageFormatter_java.py
diff options
context:
space:
mode:
authorDavid Li <davidxli@google.com>2011-03-01 16:08:10 -0800
committerDavid Li <davidxli@google.com>2011-03-03 18:28:43 -0800
commit28ca2abb1ab92b2cc3a5c9119ec2f697ec3401b2 (patch)
treef6bcb82ff2a68a5bd30218326def0f95fb6734f2 /opengl/libs/GLES2_dbg/generate_MessageFormatter_java.py
parente5f823ccf1cce4cab5699f1a07c1ee2290a69169 (diff)
downloadframeworks_base-28ca2abb1ab92b2cc3a5c9119ec2f697ec3401b2.zip
frameworks_base-28ca2abb1ab92b2cc3a5c9119ec2f697ec3401b2.tar.gz
frameworks_base-28ca2abb1ab92b2cc3a5c9119ec2f697ec3401b2.tar.bz2
Initial commit of GLESv2 debugger server
Use debug.egl.debug_proc property to match process cmdline. Binds to TCP:5039 and waits for client connection. Sends function call parameters, textures and shaders using Protobuf. Java Eclipse client plug-in is next. Change-Id: I183b755263663f87e86dde1ad12f527d0445fd57 Signed-off-by: David Li <davidxli@google.com>
Diffstat (limited to 'opengl/libs/GLES2_dbg/generate_MessageFormatter_java.py')
-rwxr-xr-xopengl/libs/GLES2_dbg/generate_MessageFormatter_java.py239
1 files changed, 239 insertions, 0 deletions
diff --git a/opengl/libs/GLES2_dbg/generate_MessageFormatter_java.py b/opengl/libs/GLES2_dbg/generate_MessageFormatter_java.py
new file mode 100755
index 0000000..81272e6
--- /dev/null
+++ b/opengl/libs/GLES2_dbg/generate_MessageFormatter_java.py
@@ -0,0 +1,239 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+
+def RemoveAnnotation(line):
+ if line.find(":") >= 0:
+ annotation = line[line.find(":"): line.find(" ", line.find(":"))]
+ return line.replace(annotation, "*")
+ else:
+ return line
+
+if __name__ == "__main__":
+ externs = []
+ lines = open("gl2_api_annotated.in").readlines()
+ i = 0
+ print """// auto generated by generate_MessageFormatter_java.py"
+package GLESv2Debugger;
+
+public class MessageFormatter {
+
+\tstatic String FormatFloats(int count, byte [] data)
+\t{
+\t\tString ret = "[";
+\t\tfor (int i = 0; i < count; i++)
+\t\t{
+\t\t\tint bits = (data[i* 4 + 0] & 0xff) << 24;
+\t\t\tbits |= (data[i* 4 + 1] & 0xff) << 16;
+\t\t\tbits |= (data[i* 4 + 2] & 0xff) << 8;
+\t\t\tbits |= (data[i* 4 + 3] & 0xff) << 0;
+\t\t\tret += Float.intBitsToFloat(bits);
+\t\t\tif (i < count - 1)
+\t\t\t\tret += ", ";
+\t\t}
+\t\treturn ret + "]";
+\t}
+\t
+\tstatic String FormatInts(int count, byte [] data)
+\t{
+\t\tString ret = "[";
+\t\tfor (int i = 0; i < count; i++)
+\t\t{
+\t\t\tint bits = (data[i* 4 + 3] & 0xff) << 24;
+\t\t\tbits |= (data[i* 4 + 2] & 0xff) << 16;
+\t\t\tbits |= (data[i* 4 + 1] & 0xff) << 8;
+\t\t\tbits |= (data[i* 4 + 0] & 0xff) << 0;
+\t\t\tret += bits;
+\t\t\tif (i < count - 1)
+\t\t\t\tret += ", ";
+\t\t}
+\t\treturn ret + "]";
+\t}
+\t
+\tstatic String FormatUints(int count, byte [] data)
+\t{
+\t\tString ret = "[";
+\t\tfor (int i = 0; i < count; i++)
+\t\t{
+\t\t\tlong bits = (data[i* 4 + 3] & 0xff) << 24;
+\t\t\tbits |= (data[i* 4 + 2] & 0xff) << 16;
+\t\t\tbits |= (data[i* 4 + 1] & 0xff) << 8;
+\t\t\tbits |= (data[i* 4 + 0] & 0xff) << 0;
+\t\t\tret += bits;
+\t\t\tif (i < count - 1)
+\t\t\t\tret += ", ";
+\t\t}
+\t\treturn ret + "]";
+\t}
+\t
+\tstatic String FormatMatrix(int columns, int count, byte [] data)
+\t{
+\t\tString ret = "[";
+\t\tfor (int i = 0; i < count; i++)
+\t\t{
+\t\t\tint bits = (data[i* 4 + 0] & 0xff) << 24;
+\t\t\tbits |= (data[i* 4 + 1] & 0xff) << 16;
+\t\t\tbits |= (data[i* 4 + 2] & 0xff) << 8;
+\t\t\tbits |= (data[i* 4 + 3] & 0xff) << 0;
+\t\t\tret += Float.intBitsToFloat(bits);
+\t\t\tif (i % columns == columns - 1)
+\t\t\t\tret += '\\n';
+\t\t\telse if (i < count - 1)
+\t\t\t\tret += ", ";
+\t\t}
+\t\treturn ret + "]";
+\t}
+
+\tpublic static String Format(final DebuggerMessage.Message msg)
+\t{
+\t\tString str;
+\t\tswitch (msg.getFunction())
+\t\t{"""
+
+ for line in lines:
+ if line.find("API_ENTRY(") >= 0: # a function prototype
+ returnType = line[0: line.find(" API_ENTRY(")].replace("const ", "")
+ functionName = line[line.find("(") + 1: line.find(")")] #extract GL function name
+ parameterList = line[line.find(")(") + 2: line.find(") {")]
+ # print "\t\tcase %s:" % (functionName)
+ # print "\t\t\t//return MessageFormatterCustom.Format(msg);"
+ # print "\t\t\tstr = msg.toString(); break;"
+ # #extern = "%s Format_%s(%s);" % (returnType, functionName, parameterList)
+ # extern = functionName
+ # externs.append(extern)
+ # continue
+
+ parameters = parameterList.split(',')
+ paramIndex = 0
+
+ formatString = "%s "
+ formatArgs = ""
+ if returnType != "void":
+ if returnType == "GLenum":
+ formatArgs += "GLEnum.valueOf(msg.getRet())"
+ elif returnType.find("*") >= 0:
+ formatArgs += '"0x" + Integer.toHexString(msg.getRet())'
+ else:
+ formatArgs += "msg.getRet()"
+ else:
+ formatArgs += '"void"'
+
+ #formatString += "%s(" % (functionName)
+ formatString += "("
+
+ if parameterList == "void":
+ parameters = []
+
+ paramTypes = []
+ paramNames = []
+ paramAnnotations = []
+
+ for parameter in parameters:
+ parameter = parameter.replace("const","")
+ parameter = parameter.strip()
+ paramType = parameter.split(' ')[0]
+ paramName = parameter.split(' ')[1]
+ annotation = ""
+
+ formatString += paramName + "=%s"
+
+ if parameter.find(":") >= 0:
+ assert paramIndex == len(parameters) - 1 # only last parameter should be annotated
+ inout = paramType.split(":")[2]
+ annotation = paramType.split(":")[1]
+ paramType = paramType.split(":")[0]
+ assert paramType.find("void") < 0
+ count = 1
+ countArg = ""
+ if annotation.find("*") >= 0:
+ count = int(annotation.split("*")[0])
+ countArg = annotation.split("*")[1]
+ assert countArg in paramNames
+ elif annotation in paramNames:
+ count = 1
+ countArg = annotation
+ elif annotation == "GLstring":
+ annotation = annotation
+ else:
+ count = int(annotation)
+ dataFormatter = ""
+ if paramType == "GLfloat":
+ dataFormatter = "FormatFloats"
+ elif paramType == "GLint":
+ dataFormatter = "FormatInts"
+ elif paramType == "GLuint":
+ dataFormatter = "FormatUints"
+ elif annotation == "GLstring":
+ assert paramType == "GLchar"
+ else:
+ assert 0
+ if functionName.find("Matrix") >= 0:
+ columns = int(functionName[functionName.find("fv") - 1: functionName.find("fv")])
+ assert columns * columns == count
+ assert countArg != ""
+ assert paramType == "GLfloat"
+ formatArgs += ", FormatMatrix(%d, %d * msg.getArg%d(), msg.getData().toByteArray())" % (columns, count, paramNames.index(countArg))
+ elif annotation == "GLstring":
+ formatArgs += ", msg.getData().toStringUtf8()"
+ elif countArg == "":
+ formatArgs += ", %s(%d, msg.getData().toByteArray())" % (dataFormatter, count)
+ else:
+ formatArgs += ", %s(%d * msg.getArg%d(), msg.getData().toByteArray())" % (dataFormatter, count, paramNames.index(countArg))
+ else:
+ #formatArgs += ', "%s"' % (paramName)
+ if paramType == "GLfloat" or paramType == "GLclampf":
+ formatArgs += ", Float.intBitsToFloat(msg.getArg%d())" % (paramIndex)
+ elif paramType == "GLenum":
+ formatArgs += ", GLEnum.valueOf(msg.getArg%d())" % (paramIndex)
+ elif paramType.find("*") >= 0:
+ formatArgs += ', "0x" + Integer.toHexString(msg.getArg%d())' % (paramIndex)
+ else:
+ formatArgs += ", msg.getArg%d()" % (paramIndex)
+ if paramIndex < len(parameters) - 1:
+ formatString += ", "
+ paramTypes.append(paramType)
+ paramNames.append(paramName)
+ paramAnnotations.append(annotation)
+ paramIndex += 1
+
+
+ formatString += ")"
+
+ print "\t\tcase %s:" % (functionName)
+ if line.find("*") >= 0 and (line.find("*") < line.find(":") or line.find("*") > line.rfind(":")):
+ sys.stderr.write(line)
+ print "\t\t\t// FIXME: this function uses pointers, debugger may send data in msg.data"
+ print '\t\t\tstr = String.format("%s", %s); break;' % (formatString, formatArgs)
+
+
+ print """\t\tdefault:
+\t\t\tstr = msg.toString();
+\t\t}
+\t\treturn str;
+\t}
+}"""
+
+ print """/*
+package GLESv2Debugger;
+
+public class MessageFormatterCustom {
+
+\tpublic static String Format(final DebuggerMessage.Message msg) {
+\t\tString str;
+\t\tswitch (msg.getFunction()) {"""
+
+ for extern in externs:
+ print "\t\tcase %s" % (extern)
+ print "\t\t\t// TODO:"
+
+print """\t\tdefault:
+\t\t\tstr = msg.toString();
+\t\t}
+\t\treturn str;
+\t}
+}
+*/"""
+
+