summaryrefslogtreecommitdiff
path: root/sys/src/liboventi/debug.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/liboventi/debug.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/liboventi/debug.c')
-rwxr-xr-xsys/src/liboventi/debug.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/sys/src/liboventi/debug.c b/sys/src/liboventi/debug.c
new file mode 100755
index 000000000..496860458
--- /dev/null
+++ b/sys/src/liboventi/debug.c
@@ -0,0 +1,78 @@
+#include <u.h>
+#include <libc.h>
+#include <oventi.h>
+#include "session.h"
+
+void vtDumpSome(Packet*);
+
+void
+vtDebug(VtSession *s, char *fmt, ...)
+{
+ va_list arg;
+
+ if(!s->debug)
+ return;
+
+ va_start(arg, fmt);
+ vfprint(2, fmt, arg);
+ va_end(arg);
+}
+
+void
+vtDebugMesg(VtSession *z, Packet *p, char *s)
+{
+ int op;
+ int tid;
+ int n;
+ uchar buf[100], *b;
+
+
+ if(!z->debug)
+ return;
+ n = packetSize(p);
+ if(n < 2) {
+ fprint(2, "runt packet%s", s);
+ return;
+ }
+ b = packetPeek(p, buf, 0, 2);
+ op = b[0];
+ tid = b[1];
+
+ fprint(2, "%c%d[%d] %d", ((op&1)==0)?'R':'Q', op, tid, n);
+ vtDumpSome(p);
+ fprint(2, "%s", s);
+}
+
+void
+vtDumpSome(Packet *pkt)
+{
+ int printable;
+ int i, n;
+ char buf[200], *q, *eq;
+ uchar data[32], *p;
+
+ n = packetSize(pkt);
+ printable = 1;
+ q = buf;
+ eq = buf + sizeof(buf);
+ q = seprint(q, eq, "(%d) '", n);
+
+ if(n > sizeof(data))
+ n = sizeof(data);
+ p = packetPeek(pkt, data, 0, n);
+ for(i=0; i<n && printable; i++)
+ if((p[i]<32 && p[i] !='\n' && p[i] !='\t') || p[i]>127)
+ printable = 0;
+ if(printable) {
+ for(i=0; i<n; i++)
+ q = seprint(q, eq, "%c", p[i]);
+ } else {
+ for(i=0; i<n; i++) {
+ if(i>0 && i%4==0)
+ q = seprint(q, eq, " ");
+ q = seprint(q, eq, "%.2X", p[i]);
+ }
+ }
+ seprint(q, eq, "'");
+ fprint(2, "%s", buf);
+}