From 709c4ee97784b3489c36ed81578a0c0ab3181622 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 24 Oct 2017 17:19:27 +0100 Subject: [PATCH] fishdescriptor: hideous errno workaround Signed-off-by: Ian Jackson --- fishdescriptor/py/fishdescriptor/indonor.py | 34 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/fishdescriptor/py/fishdescriptor/indonor.py b/fishdescriptor/py/fishdescriptor/indonor.py index f01f9eb..c538baa 100644 --- a/fishdescriptor/py/fishdescriptor/indonor.py +++ b/fishdescriptor/py/fishdescriptor/indonor.py @@ -82,6 +82,7 @@ class DonorImplementation(): di._structs = { } di._saved_errno = None di._result_stream = os.fdopen(3, 'w') + di._errno_workaround = None # assembling structs # sigh, we have to record the order of the arguments! @@ -97,6 +98,31 @@ class DonorImplementation(): fields = di._find_fields(typename) return fields.substitute(values) + # hideous workaround + + def _parse_eval_errno(di, expr_pat): + # evaluates expr_pat % 'errno' + if di._errno_workaround is not True: + try: + x = parse_eval(expr_pat % 'errno') + di._errno_workaround = False + return x + except gdb.error as e: + if di._errno_workaround is False: + raise e + di._errno_workaround = True + # Incomprehensibly, gdb.parse_and_eval('errno') can sometimes + # fail with + # gdb.error: Cannot find thread-local variables on this target + # even though plain gdb `print errno' works while `print errno = 25' + # doesn't. OMG. This may be related to: + # https://github.com/cloudburst/libheap/issues/24 + # although I can't find it in the gdb bug db (which is half-broken + # in my browser). Also the error is very nonspecific :-/. + # This seems to happen on jessie, and is fixed in stretch. + # Anyway: + return parse_eval(expr_pat % '(*((int (*)(void))__errno_location)())') + # calling functions (need to cast the function name to the right # type in case maybe gdb doesn't know the type) @@ -107,7 +133,7 @@ class DonorImplementation(): def _must_func(di, functype, funcname, realargs): retval = di._func(functype, funcname, realargs) if retval < 0: - errnoval = parse_eval('errno') + errnoval = di._parse_eval_errno('%s') raise RuntimeError("%s gave errno=%d `%s'" % (funcname, errnoval, os.strerror(errnoval))) return retval @@ -164,7 +190,7 @@ class DonorImplementation(): '("%s", %d)' % (_string_escape_for_c(path), mode) ) if r < 0: - errnoval = parse_eval('errno') + errnoval = di._parse_eval_errno('%s') if errnoval != os.errno.EEXIST: raise RuntimeError("mkdir %s failed: `%s'" % (repr(path), os.strerror(errnoval))) @@ -172,13 +198,13 @@ class DonorImplementation(): return 1 def _errno_save(di): - di._saved_errno = parse_eval('errno') + di._saved_errno = di._parse_eval_errno('%s') def _errno_restore(di): to_restore = di._saved_errno di._saved_errno = None if to_restore is not None: - parse_eval('errno = %d' % to_restore) + di._parse_eval_errno('%%s = %d' % to_restore) def _result(di, output): sys.stderr.write("#> %s" % output) -- 2.30.2