MEX file debugging with MS Visual Studio

조회 수: 40 (최근 30일)
junaid . 2012년 3월 1일
답변: 埃博拉酱 . 2023년 2월 13일
Hi all,
I have been working with this project for some time now, which involves creating and using a MEX file within a much larger MATLAB project. Unfortunately the MEX file is pretty big and it is becoming a pain to debug just by inspection, especially since the MEX file works with pointers and gives segmentation errors upon running. This causes MATLAB to crash upon an error as well.
I tried using the MS Visual Studio 2010 and 2008 with MATLAB to debug the file.
I haven't managed to do it. I can attach the Visual Studio to the MATLAB process but when I open the C file in Visual Studio, and try to set a breakpoint, it tells me that "no symbols have been loaded for this file".
(You can see even in the link of the Mathworks site that I have posted above, upon setting the breakpoint the symbols are not loaded as shown by the "empty" breakpoint symbol) :P
I have given it a bit of hit and try for sometime now but still no success. If anyone has any experience please share, coz I am at my wits end. :(
(I remember once I tried debugging in Linux using gdb but that was also impossible, but anyways that is another story ! for the moment I just want to be able to debug in windows )
Thank you very much !
All replies greatly appreciated ... :)

채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 3월 1일
When you compile the MEX-file, did you use the mex -g option so that a debuggable binary is built? If using Visual Studio, you should see a PDB (eg. myfile.mexw64.pdb) file created.
  댓글 수: 4
junaid 2012년 3월 2일
Well I will be damned ... it DOES actually WORK ... Thank you very much Friedrich ... muchas gracias ... much appreciated ...
OMG !!! I wasted so much time trying to debug mex files without a debugger !!! and OMG !!! it really works ...
I think I tried this once before like last July and back then for some reason it didn't work. (I think I was doing everything similar except MAYBE back then I had an express version of Microsoft Visual C++ compiler and now I have the full Visual Studio 2008 ...)
Thanks again guys ...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

埃博拉酱 2023년 2월 13일
As @Friedrich said, MEX file functions are loaded dynamically, so the function needs to be called once in MATLAB to load symbols. In most cases, the breakpoint can still be hit.
However, there are exceptions. Sometimes the breakpoint cannot be hit, and even after calling the function in MATLAB, the symbol is still displayed as not loaded. In my experience, this is because you chose the wrong process in Visual Studio because sometimes there are multiple processes called MATLAB in the system, and only one of them is correct.
If you don't know which is correct, it is recommended to close MATLAB, use Task Manager to end all MATLAB processes, then reopen them, and reselect the process in Visual Studio (don't use VS's "reattach to process" feature, it will help you select the wrong process again).


Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by