From: Ian Jackson Date: Tue, 24 Oct 2017 16:56:39 +0000 (+0100) Subject: fishdescriptor: fix error handling X-Git-Tag: archive/debian/6.0.0~1^2~8 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=commitdiff_plain;h=a30213491e687db44dbf5ee15f35932bf8b82394 fishdescriptor: fix error handling Signed-off-by: Ian Jackson --- diff --git a/fishdescriptor/fishdescriptor b/fishdescriptor/fishdescriptor index 20eddfe..7e95ed7 100755 --- a/fishdescriptor/fishdescriptor +++ b/fishdescriptor/fishdescriptor @@ -35,7 +35,10 @@ fdmap = { } # fdmap[nominal] = (actual, Donor, there) def implement_pending(): - actuals = donor.fish([pend[1] for pend in pending]) + try: actuals = donor.fish([pend[1] for pend in pending]) + except fishdescriptor.fish.Error as e: + print('fishdescriptor error: %s' % e, file=sys.stderr) + sys.exit(127) assert(len(actuals) == len(pending)) for (nominal, there), actual in zip(pending, actuals): overwriting_info = fdmap.get(nominal) diff --git a/fishdescriptor/py/fishdescriptor/fish.py b/fishdescriptor/py/fishdescriptor/fish.py index a506938..56a562d 100644 --- a/fishdescriptor/py/fishdescriptor/fish.py +++ b/fishdescriptor/py/fishdescriptor/fish.py @@ -13,6 +13,8 @@ def _shuffle_fd3(): os.dup2(1,3) os.dup2(2,1) +class Error(Exception): pass + class Donor(): def __init__(d, pid, debug=None): d.pid = pid @@ -35,6 +37,7 @@ class Donor(): def _eval_integer(d, expr): try: l = d._sp.stdout.readline() + if not len(l): raise Error('gdb process donor python repl quit') 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() diff --git a/fishdescriptor/py/fishdescriptor/indonor.py b/fishdescriptor/py/fishdescriptor/indonor.py index c538baa..dcd447a 100644 --- a/fishdescriptor/py/fishdescriptor/indonor.py +++ b/fishdescriptor/py/fishdescriptor/indonor.py @@ -1,6 +1,8 @@ # class for use inside gdb which is debugging the donor process +from __future__ import print_function + import gdb import copy import os @@ -260,6 +262,9 @@ class DonorImplementation(): return input def eval_loop(di): + if not gdb.selected_inferior().was_attached: + print('gdb inferior not attached', file=sys.stderr) + sys.exit(0) while True: di._result('!\n') cmd = di._protocol_read()