如何在 python/pybinder 中捕获 corefile
上下文:我有一个 python 脚本,调用用 C++ 实现的接口,并由 pybinder 公开。
据我了解,拥有 corefile 需要:
- 将 corefile 大小设置为无限制,默认为 0
- (可选) 在核心模式文件中设置 corefile 路径,或
apport
命令
这是我的程序,
# Enable process to corefile size.
resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
# Core pattern file indicates the destination of corefile, which could be a command to calculate destination (if starting with '|'), or a path.
f = open("/proc/sys/kernel/core_pattern", "w")
f.write(r"kernel.core_pattern=/tmp/test_coredump/corefile.%e.%p")
f.close()
# Print to make sure it's correct.
f = open("/proc/sys/kernel/core_pattern", "r")
print(f.readlines())
f.close()
print("main function invoked")
obj: coredump_pybind.CoredumpObject
obj = coredump_pybind.GetObject()
obj.Run()
print("main function finishes, begin destructing")
# CoredumpObject is implemented in C++ and intentionally segfaults to test the script
我确实遇到了段错误
['kernel.core_pattern=/tmp/test_coredump/corefile.%e.%p\n']
main function invoked
WARNING: Logging before InitGoogleLogging() is written to STDERR
I20220329 00:07:21.942946 3537696 coredump.cc:10] construction
I20220329 00:07:21.942981 3537696 coredump_pybind.cc:10] CoredumpObject
I20220329 00:07:21.943009 3537696 coredump_pybind.cc:14] ~CoredumpObject
I20220329 00:07:21.943020 3537696 coredump.cc:18] destruction
Segmentation fault
我期望的是我可以在 /tmp/test_coredump/
中找到 corefile(这是预先创建的),但在那里什么也没找到。
Context: I have a python script calling interfaces implemented in C++, and exposed by pybinder.
From what I understand, having the corefile needs:
- set corefile size to unlimited, which is default 0
- (optional) set the corefile path in core pattern file, or
apport
command
This is my program
# Enable process to corefile size.
resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
# Core pattern file indicates the destination of corefile, which could be a command to calculate destination (if starting with '|'), or a path.
f = open("/proc/sys/kernel/core_pattern", "w")
f.write(r"kernel.core_pattern=/tmp/test_coredump/corefile.%e.%p")
f.close()
# Print to make sure it's correct.
f = open("/proc/sys/kernel/core_pattern", "r")
print(f.readlines())
f.close()
print("main function invoked")
obj: coredump_pybind.CoredumpObject
obj = coredump_pybind.GetObject()
obj.Run()
print("main function finishes, begin destructing")
# CoredumpObject is implemented in C++ and intentionally segfaults to test the script
I do get segfault
['kernel.core_pattern=/tmp/test_coredump/corefile.%e.%p\n']
main function invoked
WARNING: Logging before InitGoogleLogging() is written to STDERR
I20220329 00:07:21.942946 3537696 coredump.cc:10] construction
I20220329 00:07:21.942981 3537696 coredump_pybind.cc:10] CoredumpObject
I20220329 00:07:21.943009 3537696 coredump_pybind.cc:14] ~CoredumpObject
I20220329 00:07:21.943020 3537696 coredump.cc:18] destruction
Segmentation fault
What I expect is I could find the corefile in /tmp/test_coredump/
(which is pre-created beforehand), but nothing find there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误发生在
该错误应该是
The error happens at
which should be