简体   繁体   中英

Does pantheios catch segfault?

I'm using the pantheios log library in C++, i didn't find if pantheios can catch a segfault, and then, force to print the buffer data before exiting.

I can catch the segfault, but i didn't found a way to eventually print the buffer that contain my logs.

Rgds,

I'm pretty certain it would be bad practise for a library to try and register a signal handler, so I would be surprised if pantheios did this.

You should catch the signal yourself if you think you could handle it usefully. Are you certain that there is a pending log buffer to be emptied, and that it wasn't the action of trying to log some data that triggered the segfault in the first place?

There is a terrible misunderstanding here I fear: do you understand what causes a segfault ?

In the trivial case, a segfault is caused by a null dereference. It's easy to fix because the issue is generally easy to spot.

However, in the nasty cases, a segfault is triggered by a memory corruption which wrote garbage where you would expect a regular pointer and led you to try and reach into memory you should not have.

Now, imagine that you register a handler for the segfault. Obviously, you cannot distinguish whether you are in the trivial or nasty case, so you should assume the memory is corrupted and that you cannot trust it...

What makes you think that the log messages would not be corrupted ?

No sane library should try and handle a segfault.

In case of segfault, dump the memory state into a core-dump file and crash hard. If you cannot trust memory, you cannot take any meaningful action anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM