How do I debug DLL code in Visual Studio after using loadlibrary in MATLAB?
71 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a C++ code that I have compiled in Visual Studio 2022 as a DLL. I use MATLAB to call the DLL using the function loadlibrary. The code executes no problem. However, I want to enter the Visual Studio debugger to step through the code once MATLAB calls the DLL. Years ago in a previous version of Visual Studio and MATLAB, a friend showed me how to connect Visual Studio to MATLAB. In Visual Studio, I would select "Build->Attach to process" and pick the MATLAB process that would appear in the window. Then, I could add a breakpoint in the C code, and when MATLAB called the DLL, the Visual Studio debugger would stop code execution at the break point and let me step through the code. I'm unable to do that now for some reason. When I attach MATLAB to Visual Studio, the breakpoint turns to an empty red outline circle with a caution triangle on it. When I hover over it, the tooltip says "The breakpoint will not currently be hit. No symbols have been loaded for this document." The Symbol Status column of the Debug->Windows->Modules dialog says "Cannot find or open the PDB file." I'm unsure what to do here. I'm sure I'm just forgetting a step that I was shown years back. Any help would be appreciated. Note Visual Studio did create a pdb file along with the DLL and both are in the same directory. Also, I compiled in debug mode, not release mode.
2 Kommentare
Umar
am 22 Jun. 2024
Hi Joel, To debug a MATLAB DLL called from Visual Studio, ensure that the PDB file is correctly loaded. Check that the PDB file is in the same directory as the DLL and that Visual Studio can access it. You may need to set the symbol file location in Visual Studio to point to the directory containing the PDB file. Additionally, make sure that the DLL and MATLAB processes are running in the same architecture (32-bit or 64-bit) to enable debugging. Finally, rebuild the solution in Visual Studio to ensure that the latest symbols are generated and loaded correctly. By following these steps, you should be able to debug your MATLAB DLL code effectively in Visual Studio. Hope this will help resolve your issue.
Antworten (1)
aditi bagora
am 25 Jun. 2024
Hi Joel,
I understand that you are trying to debug a DLL using Visual Studio after loading and calling it from MATLAB. According to the issue, probably the Visual Studio is unable to find your pdb file.
It seems that Visual Studio is unable to load the pdb file. The issue is not related to MATLAB. However, in order to resolve the issue please refer to the following steps:
In the Modules Window in the Debugger:
- Go to Debug->Windows->Modules in the menu bar.
- Search for your dll file in the list. In the Symbol Status column it should read "Cannot find or open the PDB file".
- Right click the dll and choose Load Symbols from the context menu.
- Point it to the correct pdb file.
- The Symbol Status should now change to "Symbols Loaded".
The Symbol Status change shows that the symbols from pdb file are loaded and you can now debug the DLL using breakpoints
Hope this helps!
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!