can开发者_高级运维 anybody tell me if there is a way we can force a segfault with certain specific information in it. Forcing a segfault can be done through abort(), call. But i need something like abort(ptr), where ptr is a pointer that tells the actual memory where some corruption started.
thanks, Kapil Upadhayay
Your question is very unclear. Core dump contains a memory snapshot of your entire process, so it already contains the info you want it to contain.
If you want to make finding that info easier, you can introduce a global, e.g.
void *a_corrupt_ptr; // global
void some_func() {
...
if (the_pointer_has_been_corrupted(ptr)) {
a_corrupt_ptr = ptr;
abort();
}
and then examine a_corrupt_ptr
in your debugger.
Or you can simply print the value before calling abort()
.
精彩评论