@Ekopalypse said in New cross-platform plugin template for Delphi developers:
that sounds strange if halt is supposed to terminate the running process […]
Like @klaus101 observed, it does not kill the notepad++.exe process because the Free Pascal version of the template does not own the main application handle (the way the Delphi version — unfortunately — does, for reasons that go back to Delphi’s history as the precursor to .NET, as .NET plugins likewise share the notepad++ process ID).
@klaus101 said in New cross-platform plugin template for Delphi developers:
i’m now still unsure about debugging it.
That’s a problem with DLLs in general and with plugin DLLs in particular. For example, the getFuncsArray function is called by notepad++.exe through a function pointer, i.e., a memory address pointing to where the compiled Pascal code is sitting in the DLL. I don’t know if the Lazarus IDE’s debugger can even trace that; you would have to first of all attach it to the running notepad++.exe process, and the function call happens so early you will miss it.
In general, the stuff in the template’s DllExports unit should be considered read-only, except for the DLL_ATTACH hook where you construct your plugin object.
As for tooling, I suggest using GNU Debug if you want to monitor every step of the DLL lifecycle. My personal setup uses VS Code with the C++ Tools extension. All I do is create a launch profile based on the cppdbg template, e.g.,
{ "version": "0.2.0", "configurations": [ { "name": "Notepad++", "request": "launch", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "type": "cppdbg", "MIMode": "gdb", "miDebuggerPath": "${env:LAZARUS_DIR}\\mingw\\x86_64-win64\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "Set Disassembly Flavor to Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ], "logging": { "moduleLoad": true }, "program": "${full_path_to}\\notepad++.exe" } ] }Save this as .vscode/launch.json and open the root source folder in VS Code. Replace "${full_path_to}\\notepad++.exe" to the one where the plugin is installed. Every Lazarus toolchain comes with a compatible version of gdb, so replace ${env:LAZARUS_DIR}\\mingw\\x86_64-win64\\bin\\gdb.exe with the actual path on your PC.
After that, you should be able to set breakpoints (by clicking on the line number margin) and start the editor with the F5 key.