• Advertisement
Sign in to follow this  

Are segfaults normal when project hasn't been cleaned for a while?

This topic is 1830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone,

I'm working on a project from three machines, using one machine most of the time.
Yesterday, after adding a new member variable to a class, the project compiled but then crashed.
Usually, I wouldn't hesitate to take the blame.

It's very-very rare I make the compiler or environment behave wrong.
I code stupid, make things easy for myself when possible.

I tried debugging to find the source of the segfault. I found that it seemingly occurred in std::map::insert(val, key), and traced upwards. Everything had been initialized. Val referenced something created elsewhere, I thought it looked good. Key was a copy since the parameter. I hadn't touched this area of my code for over two months...
There were no dangling pointers (no pointers, even) to be found in my main units, so I thought it had something to do with the member variable. (Being the last change I committed, this should be the prime suspect)

The class that I added the variable to contained an object which in turn contained the std::map, so I thought to myself, that maybe the change in the header file didn't trigger a build of new .os that should depend on it. When I created my own build tool, I didn't check the headers for modifications, and unless I changed the implementation file too, I'd often end up with having to clean build, or everything would crash.

Sure enough, a clean build fixed the error. But is Netbeans supposed to miss a significant change like a new member variable, without recompiling the unit+dependent units?

Do you guys experience this too from time to time? It's been weeks since I last encountered a segfault,
and now I'm worried that perhaps I'm doing something wrong. Edited by SuperVGA

Share this post


Link to post
Share on other sites
Advertisement

In my experience, IDE:s in general are far from perfect.

I always do a clean and recompile as a first measure when I encounter a strange bug.

Share this post


Link to post
Share on other sites

Anything with an "edit and continue" type feature I've found will sometimes miss-patch the partial build.  It's rather flaky as to when I've seen this type of thing happen, but it's very annoying when it does.

Share this post


Link to post
Share on other sites

in my experience, a seg-fault cropping up/disappearing with a clean is resonate of a much deeper problem in the code base.

 

This is not to say it very well might be an issue with a bad build, but in general, i've almost always discovered their to be an actual flaw in my code somewhere after heavy analyzing(something that only cropped up because the compiler didn't null all my pointers(and i forgot to explicity set a pointer to null) for me for some reason, or was allowing buffer-overflow's that didn't cause immidiate crash's)

 

edit after L. Spiro's/Karsten_'s posts, i'd like to point out that i only use a single machine for compilation, and i use VS 2010, which auto-detects header changes, and appropriately re-compiles the obj's that include the headers, which is probably why i more often experience such things in form of actual bugs, than bad build's.

Edited by slicer4ever

Share this post


Link to post
Share on other sites

That’s not been my experience (to slicer4ever).

 

Doing a clean build removes .OBJ files from different versions of compilers and this can have a profound effect on the stability of the resulting .EXE.

I even have the same compiler on both my Windows XP and Windows 7 installs, same service packs, etc.  But when I switch between Windows XP and Windows 7 I really have to do a clean or I am guaranteed to get segment faults and other strange behavior.

Many times in the most isolated areas I have been able to prove the code was correct.  A clean rebuild became part of my routine and I no longer suspect any underlying issues with the code.

 

As for the original poster, if you work with your code between different machines, save yourself some hassle and get into the habit of cleaning each time you copy the code and project to a new machine.  Once again, for me, failure to do so always results in some kind of crazy run-time crash that makes no sense.

 

 

L. Spiro

Edited by L. Spiro

Share this post


Link to post
Share on other sites

Usually IDEs deal with this sort of thing using .d files.

 

Basically when you change a header and add something like an std::string to it, you really should compile every unit (.cpp file) that has a dependence on that header.

 

I believe this is because otherwise the space for the new variable is not reserved properly from those objects.

 

I have this issue when using Makefiles but rather than fix the issue (making the build system quite a bit more complex), I just detect whether a header has changed and rebuild the whole thing.

Share this post


Link to post
Share on other sites

I'm with LSpiro here, have frequently had issues that were nothing to do with code and simply due to the IDE/Build System failing to rebuild an object file that it should have.

 

Qt's PRO system suffers from this quite often. Guess it is hard to get a dependency system right.

Share this post


Link to post
Share on other sites
Thanks for your input everyone. Actually, LSpiro and Aaardvajk,
I don't even have my obj/ shared. The only thing I did of those sorts was to not clean build for a long time.
On my repo, i only have src, doc and bin/ (for scripts and assets)
And thus no obj + dist files are shared.
I have my makefiles, .nbproject (and perhaps d files as well), though.

Perhaps it tends to be a makefile-related thing?
Slicer4Evers use of MSVC could support this...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement