Track the process of python scripts calling C++

Hi Juan.
When the devsim python scripts is running, it will call the devsim_py3.pyd library. For example, when execuating

create_gmsh_mesh(mesh="diode3d", file="gmsh_diode3d.msh")

I’m trying to track the process as it calls the CmdDispatch() function and others in C++. Unfortunately, despite my efforts over the past few days, I haven’t made any progress. I would greatly appreciate it if you could share any methods or guidance that might help me.

Much appreciated.

Please look in src/pythonapi/CommandTable.cc and look for the comand you are interested in:

DS_FUNCTION_TABLE(create_gmsh_mesh, dsCommand::createGmshMeshCmd)

which means you should set a breakpoint in dsCommand::createGmshMeshCmd, which is located in src/commands/MeshingCommands.cc.

void createGmshMeshCmd(CommandHandler &data)

note that an optimized build may lose the debugging information, so I recommend compiling a debug version of the code, which you can do with:

cmake --build . --config Debug -- //m //nologo //verbosity:minimal

inside the win64 directory and then use the debugger in Visual Studio.

Unfortunately, building a debug version on windows is difficult and I have not done that in a long time, because it requires python debug dll, which has a name like python3X_d.dll, where X is your version number. If you have this file, it needs to be referenced in cmake/appveyor.cmake

SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB:python3")

but I have had a difficult time getting this to work.

For this reason, I recommend using Linux with a debugger.

If you do a manual debug build of devsim_py3.so or devsim_py3.pyd, it then needs to replace the optimized one in your conda or virtual environment installation directory.

an additional note is that this line will need to be adjusted in
scripts/build_appveyor.sh

export PYTHON3_ARCHIVE=$(cygpath -w ${CONDA_PREFIX}/libs/python3.lib)

Thanks Juan.
I have been trying to build a debug version but failed. It seems like the problems lie in link of symdiff library.
However, I can refer to CommandTable.cc to continue my work. If the opportunity arises in the future, I’ll attempt to build a debug version on Linux.
I really appreciate it—your response was extremely helpful!

Hi @Wong,

I think attempting a debug build on Windows is difficult, because each component, (symdiff, umfpack) also needs to be compiled in debug build for this to work.

It may be easier to change the Release compile flags to reduce the optimization, so it is easier to debug. For example, you may be able to use the Zo flag, and also reduce the other optimizatino level flags.

WIth Linux, each library can still be compiled release, and devsim can be compiled as debug.

Thanks! I will try it.