S-Function && MS Visual Studio C/C++: Segmenation Violation -> how to find error?
Ältere Kommentare anzeigen
Hi,
how can I show the location of a Segmentation violation when coding a C S-Function with MS Visual Studio 2010 (and Matlab R2010b). If I run the code in debugging mode and the problem occurs, Visual Studio stops the run with the message "Matlab.exe has triggered a breakpoint", but it is unable to show the source code and thereby the location of the error. It displays the disassembly instead. When I continue the run, Matlab closes down with the "Matlab System Error" Window and the message "Segmentation violation detected".
In a previous bug of my code, Visual Studio was able to show the source code, which made debugging easier.
Anyone has a hint on this?
Cheers,
m
Akzeptierte Antwort
Weitere Antworten (4)
Jarrod Rivituso
am 22 Apr. 2011
0 Stimmen
I've never heard of anything like this. However, before I knew about debugging S-functions properly, I used to use printf statements everywhere to see how far the code got. I know it isn't ideal, but I made it work in the past.
I think if this problem persists you should contact MathWorks technical support and inform them of the issue.
Good luck!
Kaustubha Govind
am 22 Apr. 2011
0 Stimmen
It is likely that the SegV is getting caught in a MathWorks binary (does MSVC show you a stack trace that points to a line number in your S-function?).
Have you tried setting a breakpoint in your S-function and stepping through it line-by-line? This could help you finding the exact line that is causing the SegV.
Uday M
am 22 Apr. 2011
0 Stimmen
If you are using the right C MEX S-Function debugging mechanism, as listed in the following tech-note, http://www.mathworks.com/support/tech-notes/1800/1819.html, you should be able to execute the Simulink model containing the S-Function, which should in turn allow you to step through your S-Function code.
However, if you are unable to diagnose the issue even after following the steps listed in tech-note, it may be useful to contact MathWorks technical support.
MIchael
am 20 Mai 2011
3 Kommentare
Kaustubha Govind
am 20 Mai 2011
If you are able to post your S-function code, someone might be able to point out errors.
MIchael
am 21 Mai 2011
Kaustubha Govind
am 21 Mai 2011
Ah! Then you might want to go over your code carefully to see if you're not handling memory correctly. Besides allocations and de-allocations, you also must check that you are not reading out-of-bounds memory. Also, if you are work vectors in your S-function, ensure that you are using them correctly.
Finally, if you are able to post the stack trace, that might point to some clues about where the segv is occurring.
Kategorien
Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!