I would like to follow how some variables are changing during an OpenMolcas calculation, and adding WRITE statements has become too tedious. I've compiled with the -DCMAKE_BUILD_TYPE=Debug option:

cmake ../OpenMolcas_HPQC_LEVEL -DCMAKE_BUILD_TYPE=Debug
make -j8

I've set the PATH accordingly:

> MOLCAS has been found at /home/nike/build_OpenMolcas_HPQC_LEVEL_Debug

Attempts to use gdb have failed, for example:

gdb --args pymolcas
> "/home/nike/build_OpenMolcas_HPQC_LEVEL_Debug/pymolcas": not in executable format: file format not recognized

When searching the word "debug" on the Molcas forum I got about 29 results, but most of them were about running calculations in parallel (I am not), or just had the word debug in the post because it was part of the CMAKE output, even if the post had nothing to do with debugging. The most relevant results that I found there were:

  • The -D DEBUG_DEFS=_DEVEL_ was recommended here but that was in the context of turning errors into warnings (which is not what I'm trying to do).
  • This post) includes an output file that says "To debug your program, run it with the --sync command line option", but it's in the context of LUSCUS and pymolcas -h suggests that --sync isn't an option for pymolcas.

I also searched the documentation, and found that there's a MOLCAS_DEBUGGER environment variable but running export MOLCAS_DEBUGGER=gdb before the above gdb command leads to the same error (and I assume this environment variable affects the running of molcas rather than pymolcas). The word "debug" shows up a few times in the Documentation PDF (18 times to be exact) but mainly in the context of printing more output, in addition to the afformentioned CMAKE build type and the MOLCAS_DEBUGGER variable

The word debug appears another 71 times in the CMakeLists file but rather than going through every possibility there, if there's perhaps a set of instructions on how to use gdb with OpenMolcas (perhaps in the documentation), it would be helpful if you could let me know them!


2 Answers 2


pymolcas runs each program as a separate process, so you need to insert gdb before each individual program call, and not before pymolcas. This is what MOLCAS_DEBUGGER is supposed to achieve. Try:

MOLCAS_DEBUGGER=gdb pymolcas ...

PS: For OpenMolcas-specific questions you can use https://openmolcas.zulipchat.com/

  • $\begingroup$ Thanks! I've now tried export MOLCAS_DEBUGGER=gdb pymolcas but am not sure what the ... is supposed to represent? Also, this sounds like I shouldn't call gdb with gdb --args pymolcas. Do you have any recommendation how I should run it? $\endgroup$ Dec 12, 2022 at 17:20
  • $\begingroup$ The ... means whatever arguments you'd normally pass to pymolcas. $\endgroup$
    – Jellby
    Dec 12, 2022 at 20:52
  • $\begingroup$ I generally just do pymolcas 800.input -f, but doing export MOLCAS_DEBUGGER=gdb pymolcas 800.input -f would give -bash: export: -f': not a valid identifier. Also if I just do export MOLCAS_DEBUGGER=gdb pymolcas` then gdb followed by r < 800.input or r pymolcas 800.input -f gdb complains about not knowing what to execute. So I wonder how to get pymolcas 800.input -f running in debug mode? $\endgroup$ Dec 12, 2022 at 21:11
  • 1
    $\begingroup$ -f redirects the output to a file, so you don't want to use it for interactive debugging. Try simply MOLCAS_DEBUGGER=gdb pymolcas 800.input (and without export). $\endgroup$
    – Jellby
    Dec 13, 2022 at 11:34
  • $\begingroup$ Beautiful, it worked! $\endgroup$ Dec 13, 2022 at 16:02

The following eventually worked for me, especially after Jellby's most recent comment:


cmake ../OpenMolcas_HPQC_LEVEL -DCMAKE_BUILD_TYPE=Debug
make -j8
export PATH=$PATH:/home/nike/build_OpenMolcas_HPQC_LEVEL


MOLCAS_DEBUGGER=gdb pymolcas inputFile.input

Unlike some programs, in which you might run something like gdb --args ~/path/to/program/level.exe followed by run < inputFile.input to have level.exe run with the input file inputFile.input, the run command is not used at this stage because the above command involving MOLCAS_DEBUGGER will invoke Molcas to start running immediately with the input file inputFileinput. After parsing the input file it will start running gdb before running the "module" or "program" within Molcas that your input file wishes to invoke. In my case the first line of the input file was &LEVEL so after parsing and printing (in the command window) the input file, it printed:

--- Start Module: level at Tue Dec 13 07:19:04 2022 ---
GNU gdb (Gentoo 9.1 vanilla) 9.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/nike/build_OpenMolcas_HPQC_LEVEL_Debug/bin/level.exe...

At the gdb prompt I was able to set my breakpoint and to run the "module" or "program":

(gdb) b level.f:10
(gdb) r

This was the output:

Starting program: /home/nike/build_OpenMolcas_HPQC_LEVEL_Debug/bin/level.exe 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/cvmfs/soft.computecanada.ca/gentoo/2020/lib64/libthread_db.so.1".



                                   only a single process is used
                       available to each process: 2.0 GB of memory, 1 thread?
                                             pid: 34832

Breakpoint 1, level (rc=7844255429672472576) at /home/nike/OpenMolcas_HPQC_LEVEL/src/level/level.f:76
76        NLEV2= -1

which is exactly what I was hoping to achieve 🙂


Compile with the above commands, then debug/run with MOLCAS_DEBUGGER=gdb pymolcas inputFile.input and you should then be able to use gdb in the way that you're familiar.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .