Maltab throws segmentation fault when debugging mex function

8 views (last 30 days)
Hello,
I'm trying to debug a s-function in a simlulink model. However, when i attach to the matlab process, before running any models, I get a segmentation fault event.
I'm attaching the the matlab.exe process using visual studio code with the gdb from the matlab installation. Here is my launch.json snippet:
{
"name": "(gdb) attach",
"type": "cppdbg",
"request": "attach",
"program": "C:\\Program Files\\MATLAB\\R2019b\\bin\\matlab.exe",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"miDebuggerPath": "C:\\ProgramData\\MATLAB\\SupportPackages\\R2019b\\3P.instrset\\mingw_w64.instrset\\bin\\gdb.exe",
"symbolLoadInfo": {
"loadAll": true,
"exceptionList": ""
},
"setupCommands": [
{
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
This is the debugger output:
Thread 53 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 7672.0x2de8]
0x000001f4 in ?? ()
How can matlab throw SIGSEGV segmentation fault without crasing?
As I said, I did not execute any scripts yet in matlab, only started matlab and attached to the process.
The SIGSEGV comes multiple times, even after I continue
Is this a faulty matlab installataion/configuration/debugging configuration?
I've noticed that the adress is displayed in 32 bit, even though I'm running 64 bit
This is the thread information I can see:
[Unknown/Just-In-Time compiled code] (Unknown Source:0)
jvm.dll!jvm!??_7SpeculativeTrapData@@6B@ (Unknown Source:0)
[Unknown/Just-In-Time compiled code] (Unknown Source:0)

Answers (2)

Image Analyst
Image Analyst on 20 Dec 2021
Did you send in the error report? Did it even ask you about the error report when you restarted MATLAB?
Otherwise, see the FAQ:
and do what it says.
  3 Comments
Image Analyst
Image Analyst on 20 Dec 2021
Well I don't know. If it's a problem with your code, or your mex source code or DLL, or Visual Studio, not with MATLAB itself, you probably won't get any or much help from Mathworks, and you'd be on your own.
Steve Oswald
Steve Oswald on 20 Dec 2021
Edited: Steve Oswald on 4 Jan 2022
I stated that it was not matlab crashing,
but thanks for the input :)

Sign in to comment.


Gunter Nitzsche
Gunter Nitzsche on 16 Mar 2023
Even though, the question is quite old I post the answer, because while looking around how to do debugging with VS Code I came across a possible solution:
There it is mentioned, that Matlab internally throws SIGSEGVs but catches and handles them. When you run the debugger, it stops there. That is also the reason, why you do not see Matlab crash. It handles the SIGSEGV and carrys on.
However, I currently have the issue, that gdb cannot intercept Matlab and install the breakpoints. So I am quite happy about the SIGSEGV to cause a first interrupt, which then enables by breakpoints. This is only necessary when debugging via VS Code. When running gdb in a terminal I do not need this workaround.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!