Re: [Intel-gfx] [PATCH igt v2] tools/error_decode: Print ASCII user buffers

2017-11-16 Thread Tvrtko Ursulin


On 16/11/2017 14:35, Chris Wilson wrote:

Look at the first 16 characters of the user buffer and if they are all
printable, assume that user buffer contains ASCII data (e.g. a debug log)
that we want to simply print out. Otherwise, we treat it as a binary data
and hexdump as before.

Tvrtko: you know you could just write this as a printf (d'oh)

Signed-off-by: Chris Wilson 
Reviewed-by: Tvrtko Ursulin 
---
  tools/intel_error_decode.c | 13 +
  1 file changed, 13 insertions(+)

diff --git a/tools/intel_error_decode.c b/tools/intel_error_decode.c
index cdef3b18..8924026a 100644
--- a/tools/intel_error_decode.c
+++ b/tools/intel_error_decode.c
@@ -51,6 +51,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #include "intel_chipset.h"

  #include "intel_io.h"
@@ -434,6 +435,16 @@ print_fault_data(unsigned devid, uint32_t data1, uint32_t 
data0)
  
  #define MAX_RINGS 10 /* I really hope this never... */
  
+static bool maybe_ascii(const void *data, int check)

+{
+   const char *c = data;
+   while (check--) {
+   if (!isprint(*c++))
+   return false;
+   }
+   return true;
+}
+
  static void decode(struct drm_intel_decode *ctx,
   const char *buffer_name,
   const char *ring_name,
@@ -458,6 +469,8 @@ static void decode(struct drm_intel_decode *ctx,
drm_intel_decode_set_batch_pointer(ctx, data, gtt_offset,
   *count);
drm_intel_decode(ctx);
+   } else if (maybe_ascii(data, 16)) {
+   printf("%*s\n", 4 * *count, (char *)data);
} else {
for (int i = 0; i + 4 <= *count; i += 4)
printf("[%04x] %08x %08x %08x %08x\n",



My r-b on the previous version was one of the disappeared e-mails from 
yesterday. Anyway, this is even better.


Reviewed-by: Tvrtko Ursulin 

Regards,

Tvrtko
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH igt v2] tools/error_decode: Print ASCII user buffers

2017-11-16 Thread Chris Wilson
Look at the first 16 characters of the user buffer and if they are all
printable, assume that user buffer contains ASCII data (e.g. a debug log)
that we want to simply print out. Otherwise, we treat it as a binary data
and hexdump as before.

Tvrtko: you know you could just write this as a printf (d'oh)

Signed-off-by: Chris Wilson 
Reviewed-by: Tvrtko Ursulin 
---
 tools/intel_error_decode.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/tools/intel_error_decode.c b/tools/intel_error_decode.c
index cdef3b18..8924026a 100644
--- a/tools/intel_error_decode.c
+++ b/tools/intel_error_decode.c
@@ -51,6 +51,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "intel_chipset.h"
 #include "intel_io.h"
@@ -434,6 +435,16 @@ print_fault_data(unsigned devid, uint32_t data1, uint32_t 
data0)
 
 #define MAX_RINGS 10 /* I really hope this never... */
 
+static bool maybe_ascii(const void *data, int check)
+{
+   const char *c = data;
+   while (check--) {
+   if (!isprint(*c++))
+   return false;
+   }
+   return true;
+}
+
 static void decode(struct drm_intel_decode *ctx,
   const char *buffer_name,
   const char *ring_name,
@@ -458,6 +469,8 @@ static void decode(struct drm_intel_decode *ctx,
drm_intel_decode_set_batch_pointer(ctx, data, gtt_offset,
   *count);
drm_intel_decode(ctx);
+   } else if (maybe_ascii(data, 16)) {
+   printf("%*s\n", 4 * *count, (char *)data);
} else {
for (int i = 0; i + 4 <= *count; i += 4)
printf("[%04x] %08x %08x %08x %08x\n",
-- 
2.15.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx