S-Function && MS Visual Studio C/C++: Segmenation Violation -> how to find error?
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (4)
Jarrod Rivituso
le 22 Avr 2011
0 votes
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
le 22 Avr 2011
0 votes
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
le 22 Avr 2011
0 votes
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
le 20 Mai 2011
3 commentaires
Kaustubha Govind
le 20 Mai 2011
If you are able to post your S-function code, someone might be able to point out errors.
MIchael
le 21 Mai 2011
Kaustubha Govind
le 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.
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!