S-Function && MS Visual Studio C/C++: Segmenation Violation -> how to find error?
显示 更早的评论
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
采纳的回答
更多回答(4 个)
Jarrod Rivituso
2011-4-22
0 个投票
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
2011-4-22
0 个投票
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
2011-4-22
0 个投票
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
2011-5-20
3 个评论
Kaustubha Govind
2011-5-20
If you are able to post your S-function code, someone might be able to point out errors.
MIchael
2011-5-21
Kaustubha Govind
2011-5-21
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!