'How to capture corefile in python/pybinder
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
apportcommand
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.
Solution 1:[1]
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")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dentiny |
