OK, the dynamically loading of the dll and calling the function also works.
To do this, I have:
1, change the main.cpp (the code to generate the exe file) like below:
#include <stdio.h>
#include <stdlib.h>
#include "exchndl.h"
typedef void (*SomeFunctionPtr)(const LPCSTR);
int main() {
ExcHndlInit();
HMODULE h = LoadLibrary("plugin/test-drmingw-dll.dll");
SomeFunctionPtr f = reinterpret_cast<SomeFunctionPtr>(GetProcAddress(h, "SomeFunction"));
f("abc");
return 0;
}
and separate the debug symbol of this exe file by calling:
objcopy --only-keep-debug test-drmingw.exe test-drmingw.debug
strip --strip-debug --strip-unneeded test-drmingw.exe
objcopy --add-gnu-debuglink test-drmingw.debug test-drmingw.exe
2, now I move the two files "test-drmingw-dll.dll" and "test-drmingw-dll.debug" to a sub-folder "bin/Debug/plugin".
Since those two files were already debug symbol separated files, I do not need to rebuild the dlls.
3, run the exe file, it will crash inside the dll function call, now see whether the "test-drmingw.RPT" in the root folder (the "bin/Debug" folder).
Yes, it does show the correct call stack with source code lines.