Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem with mxCreatedoublematrix(), using MATLAB in NS-2

Subject: Problem with mxCreatedoublematrix(), using MATLAB in NS-2

From: saba

Date: 6 Nov, 2012 18:51:08

Message: 1 of 5

Dear all,
I am trying to use MATLAB in NS2 following this website:
http://www.cse.msu.edu/~wangbo1/ns2/nshowto3.html

I have to make some minor changes to make it work with my version of MATLAB(R2007a).
everything compiles with no error. The problem is that when I call mxCreatedoublematrix() anywhere in my code, I receive SegFault. Backtrace on the error returns:

#0 0x0000000000000000 in ?? ()
#1 0x00002aaaaaf160f1 in mxCreateDoubleMatrix () from /usr/local/Matlab74/bin/glnxa64/libmwmclmcrrt.so.7.6
.
.

I investigated a little further by examining the stack and RIP values, right after the SegFault:
(gdb) x/2xg $rsp
0x7fffda869fb8: 0x00002aaaaaf160f1 0x0000000000000002
(gdb) print /x $rip
$1 = 0x0
and looking at the top of the stack address:

(gdb) disassemble 0x00002aaaaaf160f1
Dump of assembler code for function mxCreateDoubleMatrix:
0x00002aaaaaf160d0 <mxCreateDoubleMatrix+0>: push %rbp
0x00002aaaaaf160d1 <mxCreateDoubleMatrix+1>: mov %rsp,%rbp
0x00002aaaaaf160d4 <mxCreateDoubleMatrix+4>: mov %rbx,0xffffffffffffffe8(%rbp)
0x00002aaaaaf160d8 <mxCreateDoubleMatrix+8>: mov %r12,0xfffffffffffffff0(%rbp)
0x00002aaaaaf160dc <mxCreateDoubleMatrix+12>: mov %edx,%ebx
0x00002aaaaaf160de <mxCreateDoubleMatrix+14>: mov %r13,0xfffffffffffffff8(%rbp)
0x00002aaaaaf160e2 <mxCreateDoubleMatrix+18>: mov %rsi,%r12
0x00002aaaaaf160e5 <mxCreateDoubleMatrix+21>: mov %rdi,%r13
0x00002aaaaaf160e8 <mxCreateDoubleMatrix+24>: sub $0x20,%rsp
0x00002aaaaaf160ec <mxCreateDoubleMatrix+28>: callq 0x2aaaaaef9070 <mclAcquireMutex@plt>
0x00002aaaaaf160f1 <mxCreateDoubleMatrix+33>: mov %ebx,%edx
0x00002aaaaaf160f3 <mxCreateDoubleMatrix+35>: mov %r12,%rsi
0x00002aaaaaf160f6 <mxCreateDoubleMatrix+38>: mov %r13,%rdi
0x00002aaaaaf160f9 <mxCreateDoubleMatrix+41>: callq *1182601(%rip) # 0x2aaaab036c88
0x00002aaaaaf160ff <mxCreateDoubleMatrix+47>: mov %rax,%rbx
0x00002aaaaaf16102 <mxCreateDoubleMatrix+50>: callq 0x2aaaaaef8f90 <mclReleaseMutex@plt>
---Type <return> to continue, or q <return> to quit---
0x00002aaaaaf16107 <mxCreateDoubleMatrix+55>: mov %rbx,%rax
0x00002aaaaaf1610a <mxCreateDoubleMatrix+58>: mov 0xfffffffffffffff0(%rbp),%r12
0x00002aaaaaf1610e <mxCreateDoubleMatrix+62>: mov 0xffffffffffffffe8(%rbp),%rbx
0x00002aaaaaf16112 <mxCreateDoubleMatrix+66>: mov 0xfffffffffffffff8(%rbp),%r13
0x00002aaaaaf16116 <mxCreateDoubleMatrix+70>: leaveq
0x00002aaaaaf16117 <mxCreateDoubleMatrix+71>: retq
0x00002aaaaaf16118 <mxCreateDoubleMatrix+72>: mov %rax,%rbx
0x00002aaaaaf1611b <mxCreateDoubleMatrix+75>: callq 0x2aaaaaef8f90 <mclReleaseMutex@plt>
0x00002aaaaaf16120 <mxCreateDoubleMatrix+80>: mov %rbx,%rdi
0x00002aaaaaf16123 <mxCreateDoubleMatrix+83>: callq 0x2aaaaaef9180 <_Unwind_Resume@plt>

Any ideas why RIP pointer is taking invalid value, and how I can fix it?

Subject: Problem with mxCreatedoublematrix(), using MATLAB in NS-2

From: James Tursa

Date: 6 Nov, 2012 20:08:08

Message: 2 of 5

"saba" wrote in message <k7bm6s$pd$1@newscl01ah.mathworks.com>...
> Dear all,
> I am trying to use MATLAB in NS2 following this website:
> http://www.cse.msu.edu/~wangbo1/ns2/nshowto3.html
>
> I have to make some minor changes to make it work with my version of MATLAB(R2007a).
> everything compiles with no error. The problem is that when I call mxCreatedoublematrix() anywhere in my code, I receive SegFault.

(snip)

Can you post your source code? Or a small subset of it that reproduces the problem? I am assuming that mxCreatedoublematrix is a typo for mxCreateDoubleMatrix. True?

James Tursa

Subject: Problem with mxCreatedoublematrix(), using MATLAB in NS-2

From: saba

Date: 7 Nov, 2012 18:55:08

Message: 3 of 5

Hi James,
You are correct , the function name was a typo, I was referring to mxCreateDoubleMatrix(). This is the part of the code that generate the error, I have put an arrow next to the line that generates the error:
Matlab::testmatrix(const double matrix1[], const int matrix1_r, const int matrix1_c,
                  double *result, int *result_r, int *result_c ){
mxArray *in1, *in2;
mxArray *out = NULL;
double *data;
int i, j;
-->in1 = mxCreateDoubleMatrix(matrix1_r, matrix1_c, mxREAL);
...
}
where "matrix1_r" and "matrix1_c" input to the main function as "const int matrix1_r" and "const int matrix1_c", and their values are equal to one in this case. It does not really matter where in my NS-2 code I call the "testmatrix" function, I always get the same error.

I would really appreciate your help,
-SB

"James Tursa" wrote in message <k7bqn8$iqo$1@newscl01ah.mathworks.com>...
> "saba" wrote in message <k7bm6s$pd$1@newscl01ah.mathworks.com>...
> > Dear all,
> > I am trying to use MATLAB in NS2 following this website:
> > http://www.cse.msu.edu/~wangbo1/ns2/nshowto3.html
> >
> > I have to make some minor changes to make it work with my version of MATLAB(R2007a).
> > everything compiles with no error. The problem is that when I call mxCreatedoublematrix() anywhere in my code, I receive SegFault.
>
> (snip)
>
> Can you post your source code? Or a small subset of it that reproduces the problem? I am assuming that mxCreatedoublematrix is a typo for mxCreateDoubleMatrix. True?
>
> James Tursa

Subject: Problem with mxCreatedoublematrix(), using MATLAB in NS-2

From: James Tursa

Date: 8 Nov, 2012 01:35:14

Message: 4 of 5

"saba" wrote in message <k7eaqc$rnl$1@newscl01ah.mathworks.com>...
> Hi James,
> You are correct , the function name was a typo, I was referring to mxCreateDoubleMatrix(). This is the part of the code that generate the error, I have put an arrow next to the line that generates the error:
> Matlab::testmatrix(const double matrix1[], const int matrix1_r, const int matrix1_c,
> double *result, int *result_r, int *result_c ){
> mxArray *in1, *in2;
> mxArray *out = NULL;
> double *data;
> int i, j;
> -->in1 = mxCreateDoubleMatrix(matrix1_r, matrix1_c, mxREAL);
> ...
> }
> where "matrix1_r" and "matrix1_c" input to the main function as "const int matrix1_r" and "const int matrix1_c", and their values are equal to one in this case. It does not really matter where in my NS-2 code I call the "testmatrix" function, I always get the same error.
>
> I would really appreciate your help,
> -SB

Q1: Are you on a 64-bit system?
Q2: Do you have the correct prototype for mxCreateDoubleMatrix?

E.g., maybe the arguments to mxCreateDoubleMatrix are supposed to be 64-bit integers (long long) but it is being passed ints (32-bit) because of an incorrect prototype.

James Tursa

Subject: Problem with mxCreatedoublematrix(), using MATLAB in NS-2

From: saba

Date: 8 Nov, 2012 16:59:12

Message: 5 of 5


> Q1: Are you on a 64-bit system?

Yes it is a 64-bit system, Fedora 7, x86-64 GNU/Linux

> Q2: Do you have the correct prototype for mxCreateDoubleMatrix?

I am including the "matrix.h" from "MatlabDir/extern/include" which has the following prototype for mxCreateDoubleMatrix:
EXTERN_C mxArray *mxCreateDoubleMatrix(mwSize m, mwSize n, mxComplexity flag);

> E.g., maybe the arguments to mxCreateDoubleMatrix are supposed to be 64-bit integers (long long) but it is being passed ints (32-bit) because of an incorrect prototype.

I do not see how I might be using the wrong prototype when prototype is provided by MCR/Matlab? Would you please give me some hints how I can fix this?

Thank you,
Sanaz

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us