|XP is just a number|
Binary search the cause of a Segmentation Fault (searching automatically the cause of a segfault)by spx2 (Chaplain)
|on Apr 02, 2013 at 04:29 UTC||Need Help??|
spx2 has asked for the
wisdom of the Perl Monks concerning the following question:
Hello dear monks,
It's been a while, but I'm back :)
I'm working on a C utility which parses log files. The C utility has some segfaults caused by the fact that it needs more safety checks on length of fields and some other things.
So basically I'm trying to iron out the bugs. It segfaults now more and more rarely.
Btw, I'm talking 500mb log gzipped log files, so processing takes some time.
Anyway, so sometimes I have a segfault and I want to find out exactly the log line that caused that segfault, so I wrote something that does binary search.
Everything works well, except I have a hackish way of finding out that it segfaulted. So I came here to ask what's the best way to do that.
So in order to check if one of the halves of the input segfaulted is that I check $? to see if it's 139. This is the value I should get but for a different binary called filter I get 35584 upon SEGFAULT. So what should I check for ? Maybe just $? > 0 ?
So my question is: What return value should I expect upon a segfault ? How do I robustly check if a segmentation fault occured.
tl;dr => How do I robustly and properly check in Perl, for a segfault that occured upon running a child process ?
Let me show you a small C program that I wrote that takes 2 parameters and intentionally segfaults if 30 is in the interval of these 2 parameters:
So compile this with gcc f.c
Now you get an `a.out` which you can use below in the script.
Now here's the script which is the binary search that I wrote: