Im compiling the source code of an old game server, the compilation runs without errors, but when I try to execute the output I get a segmentation fault.
I recompiled with -g flag and executed gdb with the following
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000414004 in boost::simple_segregated_storage<unsigned long>::segregate (block=0xeaf3d0, sz=0, partition_sz=8, end=0x0)
at /usr/local/include/boost-1_55/boost/pool/simple_segregated_storage.hpp:304
304 nextof(iter) = old;
I tried to change the boost's version from 1_65_1 to 1_55 but still getting that error.
Any idea?
I am also getting same error. within segregate method its trying to get next pointer address somehow the iterator position and partition size is not in sync , which causes to access invalid address (Segmentation Fault.)
Related
I have recently started using std::filesystem, and I have faced an issue that I could not fix. I have a class with a function that periodically iterates over some directories and in case new files are found, it adds its name and size to a map container. But I constantly either received segmentation fault or std::bad_alloc. I therefore wrote a simple test to see if it works out of my relatively large and complex make file project. But I still receive segmentation fault.
I simply get the number of files in a directory this way:
int main(){
const fs::path Path = fs::current_path();
for (const auto& p:fs::directory_iterator(Path)){
count++;
}
return count;
}
the error is somehow connected to path object destructor. The debugger throws the following error:
Program received signal SIGSEGV, Segmentation fault.
0x0000555555556693 in std::vector<std::filesystem::__cxx11::path::_Cmpt, >std::allocatorstd::filesystem::__cxx11::path::_Cmpt >::~vector (this=0x20, >__in_chrg=) at /usr/include/c++/8/bits/stl_vector.h:567
567 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
Program terminated with signal SIGSEGV, Segmentation fault.
Now, I've seen few posts about g++ issue with filesystem, like this one:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90050
I use g++ 8.4.0 on an Ubuntu 18.4 machine. I tried in my makefile project to add -lstdc++fs to linker flags, but it did not make a difference.
So the question is what is the root cause of this error? Is it really caused by g++?
thanks in advance for helping!
I am compiling the unit tests (via GoogleTests) for my program and whenever I try to compile in DEBUG mode on Solaris 11.3 with Eigen 3.2.x, I'm getting this SIGSEGV error then core dump when running the program in gdb:
(gdb) r
...
[Thread debugging using libthread_db enabled] [New Thread 1 (LWP 1)]
Program received signal SIGSEGV, Segmentation fault. [Switching to
Thread 1 (LWP 1)] 0x0830fc30 in
Eigen::internal::ploadu (
from=0xfeffe5a0) at ./eigen/Eigen/src/Core/arch/SSE/Complex.h:307 307 {
EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu((const
double*)from)); }
(gdb)
When print from in gdb this is what I'm getting:
gdb p from: (const std::complex< double > *) 0xfeffe5a0
This SIGSEGV only on Solaris, and only when compiling with -Og. I've compiled and tested it on multiple other OSes and there are no issues whatsoever. Is this a known issue? It looks it has to do with some SSE optimizations and alignments, however I cannot pinpoint what exactly is going on.
I am unable to move forward in getting to see the core dumped.
I have got this when i typed
gdb normal_estimation core
Reading symbols from /home/sai/Documents/pcl_learning/normal_estimation/build/normal_estimation...(no debugging symbols found)...done.
warning: core file may not match specified executable file.
[New LWP 11816]
warning: Can't read pathname for load map: Input/output error.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
Core was generated by `./normal_estimation'.
Program terminated with signal 11, Segmentation fault.
#0 0xb53101d6 in free () from /lib/i386-linux-gnu/libc.so.6
(gdb)
Please let me know what should i do?
Program terminated with signal 11, Segmentation fault.
#0 0xb53101d6 in free () from /lib/i386-linux-gnu/libc.so.6
The first command you need to learn is backtrace (or its synonym: where).
This will tell you which code invoked the free, which crashed.
However, it is possible that that code has nothing to do with the actual problem: any crash in free is always caused by heap corruption of some sort (freeing un-allocated memory, freeing the same memory twice, writing to memory that has already been freed, or overflowing an allocated buffer).
The most useful tools to diagnose heap corruption on Linux are Valgrind and AddressSanitizer. Chances are either of these tools will tell you exactly what you are doing wrong.
I'm getting this:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7580d75 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
Can I know why the seg fault is occuring?
I am currently printing the content of a C++ map in a file when this error occurs. The map size would be in MBs, could that be a problem?
Try installing debugging symbols for libc, they should be available as a package. In ubuntu they can be found in the package libc-dbg. Gdb should produce better output for you then.
How do I debug a segmentation fault?
Basically this is what happens:
I run my server in background: ./server &
then I run my client: ./client
When I try to login to my server, on correct username and password, everything is okay, but when I type invalid user and password, it results in a segmentation fault.
How do I make the compiler/debugger able to output what error its actually see that causes segmentation core dump.
I know gdb but I try using gdb client but it doesn't seem to work.
A good idea with segmentation faults is to run the program with valgrind for debugging. That way, you'll often get more detailed information about what caused your segmentation fault. For example, it will tell you if you are reading from uninitialized memory.
If you are using g++ first compile your program using the -g option. Then use
gdb name_of_program core
to run gdb on the core dump you get (name_of_program is the name of the executable file you just built with g++).
This link is useful for how to use gdb.
http://www.ibm.com/developerworks/library/l-gdb/
this ads annotations to the code. it's helpful only if you have a lot of function calls and you don't know the call path.