DEBUGGING YOUR PLUGINS - A DevC++ guide.
Since the release of IanM’s Interface library, this has opened up a whole new area for development using DarkBASIC Professional, which in my eyes, is an excellent tool on it’s own. But developing fast image manipulation or mesh deforming functions in C does have it’s advantages.
Ok, I posted earlier asking the question about debugging DLLs. Finally, with a few emails to Lee, I’ve got a fairly good method of debugging DLLs using DevC++. Although the principle works identically with Visual Studio as well. This method of debugging allows you to place breakpoints in your DLL source code and trace through the code when your DarkBASIC application calls any of the DLL exported functions.
Unfortunately, the only way this can be done is by using the TPC SDK method. This means that your DLL must export it’s functions as addon DarkBASIC commands via a string table and that the DLL is compiled directly into the Plugins-User directory of your DarkBASIC Professional installation.
Although I have not tried this, I have been told that the above method is the only way that the DLL can be debugged. In otherwords, you can’t use Dynamic loading of the DLL using the LOAD DLL command from your DB application.
So, what’s first:
1. Well, start off as normal by creating your DLL, using the technical document that comes with DarkBASIC Pro’s help for adding user defined commands to the DLL via a string table. If you’re using C++, you’ll notice that the exported function definitions are mangled, but never the less, still work the same as normal C exported functions. Note that normal expansion plugins and plugins or DLLs that use IanM’s interface library work the same way.
2. When you’re ready to begin debugging your DLL, in DevCpp, select ‘Project Options’ and select the ‘Build Options’ tab.
3. Here, you must specify the Executable Output directory. Normally this is blank so it’s compiled to the project folder. You need to change this to the Program Files/Dark Basic Professional/Compiler/Plugins-User folder. **BUT** it needs to be in the Short hand form of the path, i.e. not using long name paths. So for example, on my machinee, it’s ../../../PROGRA~1/DARKBA~1/DARKBA~1/COMPILER/PLUGIN~1. Also note that although I’ve used forward slashs here, it needs to be the normal slash notation (Left key). I only did this here because of HTML tags.
4. Also under Project Options – Compiler tab, select the Linker options and enable compiling debugging information. By default, this is off.
5. Now do a complete rebuild of your DLL. The DLL will now be built into the Plugins-User directory.
6. Once your DLL is compiled, you must now compile your DarkBASIC Professional application. Doing so will automatically enbed the DLL with debugging information into your EXE. You must ALWAYS rebuild the DarkBASIC application after any changes to your DLL otherwise you will experience erratic errors from your DB program.
7. Ok, after your DB app is built, switch back to DevCpp and bring down the Debug menu. Select ‘Parameters’ option and ensure that ‘Host Application’ contains the full path and filename of your DB executable.
8. Now hit F8 to begin debugging. At first, your application will start but it will then pause. Switch to DevCpp and find the initial function that your DB application will call. I’ve found that debugging is temperamental when trying to get the debugger to stop, but the only way I could get it to do this was to place the Cursor in your source, onto the first executed line of the function. Do not place on variable declarations as these are precompiled. Maybe on a variable assignment or a function call. Anything!
9. Using the debugging tab at the bottom, select the ‘Run To Cursor’ button. Now, if you’re lucky and the breakpoint is valid, a breakpoint with a tick will appear in the gutter. If it does, select the Continue button on the debugging tab. You’re process line should hit this line and you can use the normal debugging keys to trace through your DLL code.
10. You’ll need to experiment with this but it does eventually work. What I will say though is that you can’t startup your debugging session if you’ve actually placed Breakpoints using Ctrl+F5. If you have, you’ll find that your DB application won’t startup. I think this is something to do with where the breakpoint is placed. If you have luck working this out, let us know.
Happy dabuggin.
Paul
Home of the Cartography Shop - DarkBASIC Professional map importer