def set_donor(pid):
global donor
if donor is not None: donor.detach()
- donor = fishdescriptor.fish.Donor(pid)
+ donor = fishdescriptor.fish.Donor(pid, debug=ov.debug)
def ocb_set_donor(option, opt, value, parser):
set_donor(value)
op.disable_interspersed_args()
op.add_option('-p','--pid', type='int', action='callback',
callback=ocb_set_donor)
+ op.add_option('-D','--debug', action='store_const',
+ dest='debug', const=sys.stderr)
+ ov.debug = None
args = sys.argv[1:]
last_nominal = None # None or (nominal,) ie None or (None,) or (int,)
if not len(args): break
arg = args.pop(0)
- print("ARG %s" % arg, file=sys.stderr)
if donor is None:
- print("SET_DONOR", file=sys.stderr)
set_donor(int(arg))
elif arg_matches(r'^(?:(\d+)=)?(\d+)?$'):
(nominal, there) = m.groups()
import os
import pwd
import struct
+import tempfile
+import shutil
+import sys
def _shuffle_fd3():
os.dup2(1,3)
os.dup2(2,1)
class Donor():
- def __init__(d, pid):
+ def __init__(d, pid, debug=None):
d.pid = pid
+ if debug is None:
+ d._stderr = tempfile.TemporaryFile(mode='w+')
+ else:
+ d._stderr = None
d._sp = subprocess.Popen(
preexec_fn = _shuffle_fd3,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
+ stderr = d._stderr,
close_fds = False,
args = ['gdb', '-p', str(pid), '-batch', '-ex',
'python import fishdescriptor.indonor as id;'+
)
def _eval_integer(d, expr):
- 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)
+ try:
+ 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)
+ except Exception as e:
+ if d._stderr is not None:
+ d._stderr.seek(0)
+ shutil.copyfileobj(d._stderr, sys.stderr)
+ d._stderr.seek(0)
+ d._stderr.truncate()
+ raise e
def _eval_success(d, expr):
r = d._eval_integer(expr)