[cogl/fosdem-2012: 5/19] shader: Print line numbers for COGL_DEBUG=show-source



commit afc39406b2a475f88d60a611de2d24c911eb6861
Author: Robert Bragg <robert linux intel com>
Date:   Sat Dec 31 19:12:01 2011 +0000

    shader: Print line numbers for COGL_DEBUG=show-source
    
    So that error messages with line numbers can quickly be mapped to source
    code we now write out line numbers when COGL_DEBUG=show-source is used.

 cogl/cogl-shader.c |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/cogl/cogl-shader.c b/cogl/cogl-shader.c
index 72d9541..e99c893 100644
--- a/cogl/cogl-shader.c
+++ b/cogl/cogl-shader.c
@@ -265,6 +265,8 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle,
   if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE)))
     {
       GString *buf = g_string_new (NULL);
+      gboolean skip_line_number = FALSE;
+      int line = 0;
       int i;
 
       g_string_append_printf (buf,
@@ -272,10 +274,35 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle,
                               shader_gl_type == GL_VERTEX_SHADER ?
                               "vertex" : "fragment");
       for (i = 0; i < count; i++)
-        if (lengths[i] != -1)
-          g_string_append_len (buf, strings[i], lengths[i]);
-        else
-          g_string_append (buf, strings[i]);
+        {
+          size_t length;
+          const char *string;
+          const char *eol;
+
+          if (lengths[i] != -1)
+            length = lengths[i];
+          else
+            length = strlen (strings[i]);
+
+          string = strings[i];
+          while (length && (eol = g_strstr_len (string, length, "\n")))
+            {
+              size_t line_length = (eol - string) + 1;
+              if (!skip_line_number)
+                g_string_append_printf (buf, "%4d %.*s", line++, line_length, string);
+              else
+                g_string_append_printf (buf, "%.*s", line_length, string);
+              string = eol + 1;
+              length -= line_length;
+            }
+          if (string[0])
+            {
+              g_string_append_printf (buf, "%4d %.*s", line++, length, string);
+              skip_line_number = TRUE;
+            }
+          else
+            skip_line_number = FALSE;
+        }
 
       g_message ("%s", buf->str);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]