我目前正在研究一个解析器,看起来我犯了一些错误,因为我不知道如何计算.所以我想知道是否有人知道计算跟随和第一组的好工具,所以我可以跳过/重新评估解析器构造中这个容易出错的部分.
我正在使用ctypes模块在 Linux 上执行一些 ptrace 系统调用,实际上效果很好。但如果我遇到错误,我想提供一些有用的信息。因此,我执行了get_errno()函数调用,它返回 errno 的值,但我没有找到任何函数或其他东西来解释 errno 值并给我相关的错误消息。
我错过了什么吗?有基于ctypes的解决方案吗?
这是我的设置:
import logging
from ctypes import get_errno, cdll
from ctypes.util import find_library, errno
# load the c lib
libc = cdll.LoadLibrary(find_library("c"), use_errno=True)
...
Run Code Online (Sandbox Code Playgroud)
例子:
return_code = libc.ptrace(PTRACE_ATTACH, pid, None, None)
if return_code == -1:
errno = get_errno()
error_msg = # here i wanna provide some information about the error
logger.error(error_msg)
Run Code Online (Sandbox Code Playgroud)