Using GDB to test for a variable condition

Firstly, I am aware that this is a Fortran forum and NOT a GDB one; but it appears there is some experience in using this debugging tool within this community. If, however, this is an invalid question, I will delete it - just let me know.

I have successfully run my program, that uses commandline arguments, within GDB using the following commands:

gdb -ex=r --args dummymain -s35000 -t10 -f'mass10.lst'

What the arguments do is not relevant, but I run this within WSL on my Windows command system (WSL being a Linux emulation(?)) and GDB successfully runs my code - all the way to a very clear fault point.

I have been able to identify that a particular value is becoming negative; a value that should not be negative.

Though this particular variable is local to the subroutine, it is actually passed to the subroutine from another subroutine as an argument; and this argument is a global array.

So, I know that, at some point, the global array variable vx becomes negative.

vx is defined within one of my modules as vx(mj, mh), with mj and mh being defined as parameters and equal to 4000 and 4, respectively.

I know that this always happens when the 2nd dimension is 3, but the first dimension could be anything within a set range of values.

If I ran my code, as above and, once it crashed, set a watch as watch vx(mj, 3) < 0 then the system informs me that a watchpoint has been set. So far so good.

However, if I try to run the code now, inside GDB, (run --args dummymain s35000 t10 f'mass10.lst') I get The program being debugged has been started already; despite the fact it crashed (with error messages) within GDB.

If I, instead, quit GDB, rerun it with gdb dummymain, then set the watch (getting the message Reading symbols from dummymain...), I get No symbol "vx" in current context.

Long and short of it. How do I set a watch for this global, then run the code?

Can you set a breakpoint in a routine that references the global variable before the error happens, and then when the program stops for the breakpont, set a watchpoint for the variable befoere continuing? Since the watchpoint is set for a hardware location, it should still be effective even if the error happens in a different routine. Or maybe I am imagining things - I haven’t been able to locate much information about gdb of fortran programs.