0

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,

salezica
  • 74,081
  • 25
  • 105
  • 166
Tristan Piron
  • 63
  • 1
  • 8

2 Answers2

1

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?

Rook
  • 5,734
  • 3
  • 34
  • 43
  • I have not yet had a segfault, but my question was, if in my program, I have a segfault, is that the informations logged just before the segfault, is that informations will remain in the buffer? If pantheios use a buffer ... but I have not found any information in pantheios documentation to print the buffer. – Tristan Piron Jun 20 '12 at 07:53
  • Ahh, so you don't know if you actually have a problem yet? Perhaps you should try writing a trivial test case where you generate a logmessage and then dereference a null pointer and see what happens. – Rook Jun 20 '12 at 07:56
1

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.

Matthieu M.
  • 287,565
  • 48
  • 449
  • 722