From: Chris Turnes on
I've been working on some C++ code for awhile that interfaces with MATLAB through Mex. I get a segmentation fault 90% of the time when I run the code (with the exact same inputs), but the stack trace with gdb tells me extremely little in terms of what's going on. I've even added mexPrintf statements to try to figure out where this thing is going wrong, but it seems to make it all the way through the code.

I've even determine which line I can comment out to get the code to run properly. In one subroutine, I make an instance of a class (which at this point I don't even use, I've commented so much of the code out). If I don't make that class instance, the program runs fine. But the constructor and destructor for that class seem fine.

I am at a total loss here, and am hoping someone can help me figure out what's going on. Here's the stack trace (what is this awake() function?):
Program received signal SIGSEGV, Segmentation fault.
0xaed7d11d in awake () from /sffttrafo.mexglx
Current language: auto; currently asm
(gdb) bt
#0 0xaed7d11d in awake () from /sffttrafo.mexglx
#1 0x0bf16bb8 in ?? ()
#2 0xaec98e8a in mexFunction (nlhs=2, plhs=0xb2dab6bc, nrhs=2, prhs=0xb2dab71c) at sffttrafo.cpp:73
#3 0xb65a9421 in mexRunMexFile () from /media/matlab/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libmex.so
#4 0xb65a62ff in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libmex.so
#5 0xb65a6ea7 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libmex.so
#6 0xb72accc8 in Mfh_file::dispatch_fh () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_dispatcher.so
#7 0xb6db8a81 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#8 0xb6d4c9b1 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#9 0xb6d67d7a in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#10 0xb6d6b6ec in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#11 0xb6d6a56e in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#12 0xb6d6af49 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#13 0xb6dccbb2 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#14 0xb6da5920 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#15 0xb6da47be in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#16 0xb72accc8 in Mfh_file::dispatch_fh () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_dispatcher.so
#17 0xb6dadfcb in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#18 0xb6d5dc6c in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#19 0xb6d6258e in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#20 0xb6d62f47 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#21 0xb6d2a158 in inEvalCmdWithLocalReturn () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwm_interpreter.so
#22 0xb73287d8 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwbridge.so
#23 0xb73297a5 in mnParser () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwbridge.so
#24 0xb72ecc23 in mcrInstance::mnParser_on_interpreter_thread () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#25 0xb72f4800 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#26 0xb72d8c5e in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#27 0xb72d8d41 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#28 0xb72d33c1 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#29 0xb56f0b50 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libmwuix.so
#30 0xb56eb5ff in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libmwuix.so
#31 0xb56f2135 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libmwuix.so
#32 0xb73dcf2f in svWS_ProcessPendingEvents () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwservices.so
#33 0xb72d5c5e in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#34 0xb72d6299 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#35 0xb72d6650 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#36 0xb72d91de in mcr::runtime::InterpreterThreadFactory::runThreadFunction () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#37 0xb72d9217 in mcr::runtime::InterpreterThreadFactory::ThreadFunctionRunner::operator() () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#38 0xb72d96d9 in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#39 0x0804b569 in ?? ()
#40 0x0804a347 in ?? ()
#41 0xb72ff9dc in ?? () from /media/matlab/bin/glnx86/../../bin/glnx86/libmwmcr.so
#42 0xb6b6d4fb in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#43 0xb6aeff5e in clone () from /lib/tls/i686/cmov/libc.so.6
From: James Tursa on
"Chris Turnes" <cturnes(a)gmail.com> wrote in message <huosbm$qf5$1(a)fred.mathworks.com>...
> I've been working on some C++ code for awhile that interfaces with MATLAB through Mex. I get a segmentation fault 90% of the time when I run the code (with the exact same inputs), but the stack trace with gdb tells me extremely little in terms of what's going on. I've even added mexPrintf statements to try to figure out where this thing is going wrong, but it seems to make it all the way through the code.
>
> I've even determine which line I can comment out to get the code to run properly. In one subroutine, I make an instance of a class (which at this point I don't even use, I've commented so much of the code out). If I don't make that class instance, the program runs fine. But the constructor and destructor for that class seem fine.
>
> I am at a total loss here, and am hoping someone can help me figure out what's going on. Here's the stack trace (what is this awake() function?):

No one is going to be able to help you without seeing your source code.

James Tursa