+ # 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)())')
+