how do i debug dll generated from compiler
3 次查看(过去 30 天)
显示 更早的评论
i created a c++ dll using matlab compiler. i am able to use the dll in my application. my problem is i can't debug the dll. once i send a bad value the program crashes. i would like to be able to step through the matlab code and see where it is failing. any advice on how to do this?
0 个评论
回答(1 个)
Walter Roberson
2016-3-28
MATLAB Compiler generates encrypted data structures without the actual MATLAB code. It is not debuggable at the MATLAB level.
If you were to use MATLAB Coder then the resulting code could be debugged by any suitable debugger, at the C/C++ level.
Basically with the Compiler you need to fall back to disp() and fprintf() and the like. Any code that interacts with the user should be checking input and explicitly checking file existence. Every fopen() should have its result checked. Toss in try/catch to detect and report on errors.
2 个评论
Walter Roberson
2016-3-29
Add an extra argument to your function that is the debugging level. Code debugging checks in lots of places that check the current debugging level to determine whether to dump information. Then leave those checks in place permanently (unless they are really interfering with performance.) As long as you do not have an error that interferes with all execution paths, you can then do multiple testing with the same .exe.
Command line arguments to .exe are passed as strings no matter what characters are in them (e.g., numeric-looking things are not made into numbers unless you convert it in the code) so you can use section names with a separator. For example,
MyExe fopen,handle_paranoia
function MyExe(debugopts)
debugflags = struct();
if nargin > 0
flagnames = strsplit(debugopts, ',');
for K = 1 : length(flagnames)
debugflags.(flagnames{K}) = true;
end
end
...
[fid, message] = fopen(filename)
if isfield(debugflags,'fopen')
fprintf('Result of open of "%s" was %d with message "%s"\n', filename, fid, message);
end
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!