Mesa (master): util/u_debug: add description field to debug_named_value

Joakim Sindholt jsindholt at kemper.freedesktop.org
Thu Jun 3 11:45:29 UTC 2010


Module: Mesa
Branch: master
Commit: fbeab4cbcea98db161aa5067c0bcef9ea44cb0de
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fbeab4cbcea98db161aa5067c0bcef9ea44cb0de

Author: Joakim Sindholt <opensource at zhasha.com>
Date:   Tue Jun  1 20:11:02 2010 +0200

util/u_debug: add description field to debug_named_value

---

 src/gallium/auxiliary/util/u_debug.c |   20 ++++++++++++++++----
 src/gallium/auxiliary/util/u_debug.h |    6 ++++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index 86db2c2..3d913be 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -42,6 +42,7 @@
 #include "util/u_tile.h" 
 #include "util/u_prim.h" 
 
+#include <limits.h> /* CHAR_BIT */
 
 void _debug_vprintf(const char *format, va_list ap)
 {
@@ -173,6 +174,12 @@ debug_get_num_option(const char *name, long dfault)
    return result;
 }
 
+static INLINE int
+max( int a,
+     int b )
+{
+    return (a > b) ? a : b;
+}
 
 unsigned long
 debug_get_flags_option(const char *name, 
@@ -181,16 +188,21 @@ debug_get_flags_option(const char *name,
 {
    unsigned long result;
    const char *str;
+   const struct debug_named_value *orig = flags;
+   int namealign = 0;
    
    str = os_get_option(name);
    if(!str)
       result = dfault;
    else if (!util_strcmp(str, "help")) {
       result = dfault;
-      while (flags->name) {
-         debug_printf("%s: help for %s: %s [0x%lx]\n", __FUNCTION__, name, flags->name, flags->value);
-         flags++;
-      }
+      debug_printf("%s: help for %s:\n", __FUNCTION__, name);
+      for (; flags->name; ++flags)
+         namealign = max(namealign, strlen(flags->name));
+      for (flags = orig; flags->name; ++flags)
+         debug_printf("| %*s [0x%0*lx]%s%s\n", namealign, flags->name,
+                      sizeof(unsigned long)*CHAR_BIT/4, flags->value,
+                      flags->desc ? " " : "", flags->desc ? flags->desc : "");
    }
    else {
       result = 0;
diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
index e8ff277..1c9624e 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -230,6 +230,7 @@ struct debug_named_value
 {
    const char *name;
    unsigned long value;
+   const char *desc;
 };
 
 
@@ -252,8 +253,9 @@ struct debug_named_value
  *    ...
  * @endcode
  */
-#define DEBUG_NAMED_VALUE(__symbol) {#__symbol, (unsigned long)__symbol} 
-#define DEBUG_NAMED_VALUE_END {NULL, 0} 
+#define DEBUG_NAMED_VALUE(__symbol) DEBUG_NAMED_VALUE_WITH_DESCRIPTION(__symbol, NULL)
+#define DEBUG_NAMED_VALUE_WITH_DESCRIPTION(__symbol, __desc) {#__symbol, (unsigned long)__symbol, __desc}
+#define DEBUG_NAMED_VALUE_END {NULL, 0, NULL}
 
 
 /**




More information about the mesa-commit mailing list