如何在 python/pybinder 中捕获 corefile

发布于 2025-01-17 15:40:41 字数 1552 浏览 3 评论 0原文

上下文:我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有伤那来痛 2025-01-24 15:40:41

错误发生在

f.write(r"kernel.core_pattern=/tmp/test_coredump/corefile.%e.%p")

该错误应该是

f.write(r"/tmp/test_coredump/corefile.%e.%p")

The error happens at

f.write(r"kernel.core_pattern=/tmp/test_coredump/corefile.%e.%p")

which should be

f.write(r"/tmp/test_coredump/corefile.%e.%p")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文