Tomas Aschan
Tomas Aschan

Reputation: 60574

Debugging Fortran with gdb: Display names of all variables, but not their contents

I'm debugging a Fortran program with gdb, and when, at a breakpoint, I try to print an element of a 2-dimensional array with p/d cs(ii,inti+1) I get the message No symbol cs in current context. However, cs is clearly available in the current scope - the line I just stepped over used it - although not declared thare, but on module level (in the same module).

I tried to find out what variables are available, to see if I could figure out why gdb wouldn't let me view the contents of this one. info locals didn't do me much good, since I'm not after a local variable, and info variables takes forever to complete, because I have a couple of matrices with 10 000 rows and it prints not only the names, but also the contents, of each variable.

Is there a way to print only the names (and possibly dimensions) of all variables available in the current scope? And while I'm asking - is there something obvious I've missed here that explains why I can't view the contents of cs(ii,inti+1)?

Upvotes: 2

Views: 703

Answers (1)

scottt
scottt

Reputation: 7228

For the original "No symbol cs in current context" problem, I'd take a quick peak at the disassembly to see if the function is being inlined.

Just printing the names and types of global variables can be achieved with Python scripting.

Save this to list-globals.py

import gdb
block = gdb.block_for_pc(long(gdb.parse_and_eval('$pc'))).global_block
for symbol in block:
    gdb.write('%s: %s\n' % (symbol.print_name, symbol.type))

Then run:

$ gdb /bin/true
(gdb) start
(gdb) source list-globals.py

Your gdb needs to be compiled with Python scripting enabled though.

Upvotes: 1

Related Questions