how do i debug dll generated from compiler

3 ビュー (過去 30 日間)
rafael
rafael 2016 年 3 月 28 日
コメント済み: Walter Roberson 2016 年 3 月 29 日
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?

回答 (1 件)

Walter Roberson
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 件のコメント
rafael
rafael 2016 年 3 月 29 日
thanks. i will try your advice. i was hoping of an easier way of checking. its just whenever i recompile my code it takes 5 mins.
Walter Roberson
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by