Segmentation violation running C++ mex file R2012b on Ubuntu 12.04

1 view (last 30 days)
Details :
MATLAB crash file:/home/sandrefuego/matlab_crash_dump.20985-1:
------------------------------------------------------------------------
Segmentation violation detected at Mon Jan 21 19:13:23 2013
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Current Visual : 0x63 (class 4, depth 24)
Default Encoding: UTF-8
GNU C Library : 2.15 stable
MATLAB Root : /home/sandrefuego/MATLAB/R2012b
MATLAB Version : 8.0.0.783 (R2012b)
Operating System: Linux 3.2.0-31-generic #50-Ubuntu SMP Fri Sep 7 16:16:45 UTC 2012 x86_64
Processor ID : x86 Family 6 Model 42 Stepping 7, GenuineIntel
Virtual Machine : Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : The X.Org Foundation (11103000), display :0.0
Fault Count: 1
Abnormal termination:
Segmentation violation
Register State (from fault):
RAX = 00007fcb05112b40 RBX = 0000000000000000
RCX = 0000000000000000 RDX = 0000000000000100
RSP = 00007fcaf24bcf90 RBP = 0000000000000100
RSI = 0000000000000004 RDI = 00007fcaf24bd000
R8 = 00007fcaf24bd000 R9 = 0000000000000000
R10 = 00007fcaf24bcca0 R11 = 00007fcb04eb1330
R12 = 0000000000000400 R13 = 0000000000000004
R14 = 00007fcaf24bd830 R15 = 00007fcaf24bda40
RIP = 00007fcb0439a724 EFL = 0000000000010206
CS = 0033 FS = 0000 GS = 0000
Stack Trace (from fault):
[ 0] 0x00007fcb06f231de /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwfl.so+00516574 _ZN2fl4diag15stacktrace_base7captureERKNS0_14thread_contextEm+000158
[ 1] 0x00007fcb06f244b2 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwfl.so+00521394
[ 2] 0x00007fcb06f25ffe /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwfl.so+00528382 _ZN2fl4diag13terminate_logEPKcRKNS0_14thread_contextE+000174
[ 3] 0x00007fcb06212093 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00557203 _ZN2fl4diag13terminate_logEPKcPK8ucontext+000067
[ 4] 0x00007fcb0620eb9d /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00543645
[ 5] 0x00007fcb06210835 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00550965
[ 6] 0x00007fcb06210a55 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00551509
[ 7] 0x00007fcb062110fe /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00553214
[ 8] 0x00007fcb06211295 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00553621
[ 9] 0x00007fca596ee4f4 /home/sandrefuego/MATLAB/R2012b/sys/jxbrowser/glnxa64/lib/libjniwrap64.so+00034036 _Z11seh_handleriP7siginfoPv+000091
[ 10] 0x00007fcb046f9cb0 /lib/x86_64-linux-gnu/libpthread.so.0+00064688
[ 11] 0x00007fcb0439a724 /lib/x86_64-linux-gnu/libc.so.6+00456484 fread+000052
[ 12] 0x00007fca5a667bf6 /home/sandrefuego/Documents/MATLAB/mexfunction1.mexa64+00003062 mexFunction+000122
[ 13] 0x00007fcafcee369a /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmex.so+00112282 mexRunMexFile+000090
[ 14] 0x00007fcafcedf4e9 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmex.so+00095465
[ 15] 0x00007fcafcee033c /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmex.so+00099132
[ 16] 0x00007fcb05f60a4b /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00596555 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000539
[ 17] 0x00007fcb057f4e56 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02264662
[ 18] 0x00007fcb05780c1d /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01788957
[ 19] 0x00007fcb057a924e /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01954382
[ 20] 0x00007fcb057a60d3 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01941715
[ 21] 0x00007fcb057a6ed7 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01945303
[ 22] 0x00007fcb05812760 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02385760
[ 23] 0x00007fcb05f60a4b /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00596555 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000539
[ 24] 0x00007fcb057e197b /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02185595
[ 25] 0x00007fcb0579f21c /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01913372
[ 26] 0x00007fcb0579c24d /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01901133
[ 27] 0x00007fcb0579c685 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01902213
[ 28] 0x00007fcafd10e22e /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwbridge.so+00143918
[ 29] 0x00007fcafd10e391 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwbridge.so+00144273
[ 30] 0x00007fcafd10ef6d /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwbridge.so+00147309 _Z8mnParserv+000733
[ 31] 0x00007fcb061f7472 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00447602 _ZN11mcrInstance30mnParser_on_interpreter_threadEv+000034
[ 32] 0x00007fcb061d5b69 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00310121
[ 33] 0x00007fcb061d5d48 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00310600
[ 34] 0x00007fcafa175c36 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwuix.so+00474166
[ 35] 0x00007fcafa180cc2 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwuix.so+00519362
[ 36] 0x00007fcb06885a11 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01628689 _ZSt8for_eachIN9__gnu_cxx17__normal_iteratorIPN5boost8weak_ptrIN4sysq10ws_ppeHookEEESt6vectorIS6_SaIS6_EEEENS4_8during_FIS6_NS2_10shared_ptrIS5_EEEEET0_T_SH_SG_+000081
[ 37] 0x00007fcb06886aeb /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01633003 _ZN4sysq12ppe_for_eachINS_8during_FIN5boost8weak_ptrINS_10ws_ppeHookEEENS2_10shared_ptrIS4_EEEEEET_RKS9_+000251
[ 38] 0x00007fcb068845a2 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01623458 _ZN4sysq19ppePollingDuringFcnEb+000114
[ 39] 0x00007fcb06884969 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01624425 _ZN4sysq11ppeMainLoopEiib+000121
[ 40] 0x00007fcb06884b08 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01624840 _ZN4sysq11ppeLoopIfOKEiib+000152
[ 41] 0x00007fcb06884c63 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01625187 _ZN4sysq20processPendingEventsEiib+000147
[ 42] 0x00007fcb061d6664 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00312932
[ 43] 0x00007fcb061d6b3c /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00314172
[ 44] 0x00007fcb061d0592 /home/sandrefuego/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00288146
[ 45] 0x00007fcb046f1e9a /lib/x86_64-linux-gnu/libpthread.so.0+00032410
[ 46] 0x00007fcb0441ecbd /lib/x86_64-linux-gnu/libc.so.6+00998589 clone+000109
This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.
If this problem is reproducible, please submit a Service Request via:
http://www.mathworks.com/support/contact_us/
A technical support engineer might contact you with further information.
Thank you for your help.
  2 Comments
Walter Roberson
Walter Roberson on 21 Jan 2013
Have you used a debugger (or even just added I/O statements) to figure out what the mex file was trying to do at the time of the crash?
There are some causes of crashes that are relatively common and that usually reflect bugs in the C / C++ code, or going beyond limitations on what MATLAB can handle in C / C++ code. Narrowing down what the code was doing would help us be more accurate in telling what happened in this situation. Access to the C++ code would also help.
Ivan
Ivan on 23 Jan 2013
Thank you for the interest. The thing is, everything worked @ r2010a. This is the C++ code (it reads a binary file basicaly):
#include "mex.h"
#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;
static int mex_count=0;
void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
(void) prhs; (void) plhs;
int Stay;
Stay=0;
int S;
int S2;
mwSize Try1;
mwSize S3;
mwSize S4;
mwSize Try2;
S4=1;
struct headers {
int version,
nx,ny,
dx,dy,
specxgrid,specygrid,
vertpoints,
vertmandelay,
vertmangain;
float bias,current;
int imagesize,specgridsize,specgridchan,dummy[241];
}Param;
struct table {
float *Bias;
float *Z;
};
struct MAP {
float *Ch1,
*Ch2,
*Ch3,
*Ch4,
*Ch5,
*Ch6;
} ;
FILE *fp;
int N;
int i;
int K;
int L;
int y;
int n;
int m;
int o;
fp = fopen("/home/sandrefuego/MATLAB/A120904.162806.specgrid","r");
if (fp == NULL) cout << "Can't open file";
N=fread(&Param,sizeof(float),256,fp);
//cout << Param.nx << " " << Param.ny << " " << Param.specxgrid << " " << Param.specygrid << "\n";
S = Param.vertpoints;
S2=Param.vertpoints*(Param.nx/Param.specxgrid)*(Param.ny/Param.specygrid);
S3=(Param.nx/Param.specxgrid)*(Param.ny/Param.specygrid);
int const D1=Param.nx/Param.specxgrid;
int const D2=Param.ny/Param.specygrid;
table VZ;
VZ.Bias=new float[S];
VZ.Z=new float[S];
for (y=0;y<=Param.vertpoints;y++) {
K=fread(&VZ.Bias[y],sizeof(float),1,fp);
L=fread(&VZ.Z[y],sizeof(float),1,fp);
}
struct MAP Grid;
Grid.Ch1=new float[S2];
Grid.Ch2=new float[S2];
Grid.Ch3=new float[S2];
Grid.Ch4=new float[S2];
Grid.Ch5=new float[S2];
Grid.Ch6=new float[S2];
if (Grid.Ch1 == 0) {
//cout << "Error assigning memory\n" ; // error assign.ing memory. Take measures.
};
for (i=0;i<=S2;i++) {
fread(&Grid.Ch1[i],sizeof(float),1,fp);
fread(&Grid.Ch2[i],sizeof(float),1,fp);
fread(&Grid.Ch3[i],sizeof(float),1,fp);
fread(&Grid.Ch4[i],sizeof(float),1,fp);
fread(&Grid.Ch5[i],sizeof(float),1,fp);
fread(&Grid.Ch6[i],sizeof(float),1,fp);
}
//cout << (Param.nx/Param.specxgrid)*(Param.ny/Param.specygrid) << "\n";
//cout << Grid.Ch1[1000] << "\n" << Grid.Ch2[1000] << "\n" << Grid.Ch3[1000] << "\n" << Grid.Ch4[1000] << "\n" << Grid.Ch5[1000] << "\n" << (Grid.Ch6[1000])<< endl;
fclose(fp);
int status;
char array_name1[]="Spectra";
char array_name2[]="Bias";
mxArray *array_ptr1;
mxArray *array_ptr2;
array_ptr1 = mexGetVariable("global", array_name1);
array_ptr2 = mexGetVariable("global", array_name2);
/* Check status of MATLAB and MEX-file MEX-file variable */
if (array_ptr1 == NULL&&array_ptr2 == NULL ){
Try1=S3*512;
Try2=Param.vertpoints/2-128;
array_ptr1=mxCreateDoubleMatrix(Try1,1,mxREAL);
array_ptr2=mxCreateDoubleMatrix(Try2,1,mxREAL);
}
for (o=128;o<=S2;o+=1280) {
//printf("%i ",o);
for (n=o+1;n<=(o+512);n++) {
m=Stay;
mxGetPr(array_ptr1)[m]=Grid.Ch3[n];
//mex_count=(int)mxGetPr(array_ptr)[0];
//mexPrintf("mxArray = %i ", mex_count);
if (o==128) { mxGetPr(array_ptr2)[m]=VZ.Bias[n];
printf("%i ",n);
}
Stay=Stay+1;
}
}
status=mexPutVariable("global", array_name1, array_ptr1);
status=mexPutVariable("global", array_name2, array_ptr2);
if (status==1) {
mexPrintf("Variable %s\n", array_name1);
mexErrMsgTxt("Could not put variable in global workspace.\n");
}
mxDestroyArray(array_ptr1);
mxDestroyArray(array_ptr2);
/*double* Channel;
int Dim[2];
int Zero;
Zero=0;
Dim[0]=1;
Dim[1]=1;
out=plhs[0] = mxCreateNumericArray(1,Dim,mxSINGLE_CLASS,mxREAL);
Channel = (float*)mxGetData(out);
out=plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
Channel = mxGetPr(out);
printf("%f ",*Channel);
printf("%f ",Channel);
mxDestroyArray(plhs[0]);
*/
delete [] Grid.Ch1,Grid.Ch2,Grid.Ch3,Grid.Ch4,Grid.Ch5,Grid.Ch6, VZ.Bias;
}

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 23 Jan 2013
In C++ code, mexFunction needs to be declared within
extern "C"
or else it will have C++ linkage rather than C linkage as is required.
  3 Comments
Ivan
Ivan on 23 Jan 2013
Oh, sorry, i found the problem, it was in the binary file i tried to read!
James Tursa
James Tursa on 23 Jan 2013
Edited: James Tursa on 23 Jan 2013
@Walter: FYI the extern "C" for mexFunction is already part of mex.h ... the user doesn't need to manually include it in their C++ source code.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!