Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
CommonProgrammingBugs
Edit
PageHistory
Diff
Info
LikePages
!!! My program causes a SegmentationFault in malloc(3) or <tt>new</tt> It's common for a program to cause a SegmentationFault in <tt>new</tt> or malloc(3) if you have previously corrupted memory by using a pointer incorrectly. To diagnose this problem, compile everything with __-g__ (and probably [-Wall] as well) and link it all with electric fence using <tt>-lefence</tt>, eg: <pre> __gcc -g -Wall broken.cc -o broken.o__ __gcc -lefence broken.o -o broken__ </pre> Check your ulimit(1) is not set to 0 (this is the default on most recent distros, use <tt>ulimit -c unlimited</tt> to allow your program to dump core), then run your program: <pre> __./broken__ Segmentation Fault (core dumped) </pre> If you don't get the <tt>(core dumped)</tt> bit, then your ulimit is wrong, or you don't have write access to the current working directory, or the disk is full etc. Now that you have the program and the core file, use it to figure out where your program cored <pre> __gdb ./broken ./core__ ''lots of chatter...'' (gdb) __bt full__ </pre> If it says <tt>(no symbols)</tt> then you didn't compile with <tt>-g</tt> above. <tt>bt full</tt> will take the __b__ack__t__race of the core file and if you specify "full" it'll show you all the variables along the way. The first line should be the place where your bug occured. If you look at this line you'll probably find you're doing something silly (like addressing past the end of an array, or using a pointer that has been free(3)d). See DeBugging for more details. !!! <tt>ld: ''name'': hidden symbol `__dso_handle' in foo.o is referenced by DSO</tt> You are linking against a shared library that was created incorrectly. With [GCC] 3.x this might happen if you create a SharedLibrary directly using <tt>ld -shared -o libfoo.so ...</tt>. Instead, use <tt>g++ -shared -Wl,-soname,libfoo.so.1 -o libfoo.so ...</tt> ---- CategoryProgrammingBugs
5 pages link to
CommonProgrammingBugs
:
UserSubmittedNotes
MALLOC_CHECK_
SIGSEGV
DeBugging
LD_DEBUG