chiark / gitweb /
fishdescriptor: debugging
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 18 Oct 2017 17:25:57 +0000 (18:25 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Wed, 18 Oct 2017 17:25:57 +0000 (18:25 +0100)
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
fishdescriptor/py/fishdescriptor/fish.py
fishdescriptor/py/fishdescriptor/indonor.py

index 9c7fca839e44ae5c3c923952ee5019be1617d2f2..4739feb845e4e7ad4b5a507eb5161fe953d33779 100644 (file)
@@ -24,11 +24,11 @@ class Donor():
         )            
 
     def _eval_integer(d, expr):
-        l = d._sp.stdin.readline()
-        if l != '!\n': raise RuntimeError("indonor said %s" % repr(l))
-        d._sp.stdout.write(expr + '\n')
-        d._sp.stdout.flush()
-        l = d._sp.stdin.readline().rstrip('\n')
+        l = d._sp.stdout.readline()
+        if l != b'!\n': raise RuntimeError("indonor said %s" % repr(l))
+        d._sp.stdin.write(expr.encode('utf-8') + b'\n')
+        d._sp.stdin.flush()
+        l = d._sp.stdout.readline().rstrip(b'\n')
         return int(l)
 
     def _eval_success(d, expr):
index 1f3c68994feabe4715f89b8de51dfc7ffe15cd14..12f8c685e01cf4651f5b53bd163acce4f9bfe2d1 100644 (file)
@@ -4,6 +4,7 @@
 import gdb
 import copy
 import os
+import sys
 
 def _string_escape_for_c(s):
     out = ''
@@ -43,9 +44,16 @@ def _make_lit(v):
     else:
         return v # should already be an integer
 
+def parse_eval(expr):
+    sys.stderr.write("##  EVAL %s\n" % repr(expr))
+    x = gdb.parse_and_eval(expr)
+    sys.stderr.write('##  => %s\n' % x)
+    sys.stderr.flush()
+    return x
+
 class DonorStructLayout():
     def __init__(l, typename):
-        x = gdb.parse_and_eval('(%s){ }' % typename)
+        x = parse_eval('(%s){ }' % typename)
         l._typename = typename
         l._template = [ ]
         l._posns = { }
@@ -54,6 +62,7 @@ class DonorStructLayout():
             try: f.type.fields(); blank = '{ }'
             except AttributeError: blank = '0'
             l._template.append(blank)
+
     def substitute(l, values):
         build = copy.deepcopy(l._template)
         for (k,v) in values.items():
@@ -85,14 +94,15 @@ class DonorImplementation():
 
     def _func(di, functype, funcname, realargs):
         expr = '((%s) %s) %s' % (functype, funcname, realargs)
-        return gdb.parse_and_eval(expr)
+        return parse_eval(expr)
 
     def _must_func(di, functype, funcname, realargs):
         retval = di._func(functype, funcname, realargs)
         if retval < 0:
-            errnoval = gdb.parse_and_eval('errno')
+            errnoval = parse_eval('errno')
             raise RuntimeError("%s gave errno=%d `%s'" %
                                (funcname, errnoval, os.strerror(errnoval)))
+        return retval
 
     # wrappers for the syscalls that do what we want
 
@@ -146,7 +156,7 @@ class DonorImplementation():
             '("%s", %d)' % (_string_escape_for_c(path), mode)
         )
         if r < 0:
-            errnoval = gdb.parse_and_eval('errno')
+            errnoval = parse_eval('errno')
             if errnoval != os.errno.EEXIST:
                 raise RuntimeError("mkdir %s failed: `%s'" %
                                    (repr(path), os.strerror(errnoval)))
@@ -154,19 +164,20 @@ class DonorImplementation():
         return 1
 
     def _errno_save(di):
-        di._saved_errno = gdb.parse_and_eval('errno')
+        di._saved_errno = parse_eval('errno')
 
     def _errno_restore(di):
         to_restore = di._saved_errno
         di._saved_errno = None
         if to_restore is not None:
-            gdb.parse_and_eval('errno = %d' % to_restore)
+            parse_eval('errno = %d' % to_restore)
 
-    # main entrypoints
+    def _result(di, output):
+        sys.stderr.write("#> %s" % output)
+        di._result_stream.write(output)
+        di._result_stream.flush()
 
-    def result(di, output):
-        di._result_stram.write(output)
-        di._result_stram.flush()
+    # main entrypoints
 
     def donate(di, path, control_msg):
         # control_msg is an array of integers being the ancillary data
@@ -201,14 +212,16 @@ class DonorImplementation():
     def mkdir(di, path):
         try:
             di._errno_save()
-            val = di._mkdir(path, '0700')
+            val = di._mkdir(path, int('0700', 8))
         finally:
             di._errno_restore()
 
         di._result('%d\n' % val)
 
     def _protocol_read(di):
-        return sys.stdin.readline().rstrip('\n')
+        input = sys.stdin.readline().rstrip('\n')
+        sys.stderr.write("#< %s\n" % input)
+        return input
 
     def eval_loop(di):
         while True: