3

How can I call Fortran intrinsics from within gdb? For example, given an array, I want to do

call size(array)

but I get No symbol "size" in current context. Is it necessary to define them in gdb first, or is there some way of calling them directly?

Yossarian
  • 5,226
  • 1
  • 37
  • 59

1 Answers1

3

Intrinsics are implemented by compiler in some vendor specific library. For example, Intel compiler implements size intrinsic by inlined code, that placed stored array length to a given variable, and as a result there is no function that can be called.

Technically, GDB/IILDB can evaluate any function implemented in given binary file (you can find all of them using nm utility on most of the Unix based systems). For example, if program defines following function:

function get_pi() result(pi)
    real pi

     pi = 3.1415926
end function

it's possible to invoke it by following statement in debugger:

p (float) get_pi()

Please keep in mind, that real name of this function (provided by nm) will be different. Usually it starts and ends by underscore character, like '_gdb_array_module_mp_get_pi_'.

But you are always is able to use any functions from core C library, like size that returns amount of memory allocated for a given variable. And to determine array size in Fortran program it's possible to use following statement:

p sizeof(array)/sizeof(*array)
syscreat
  • 553
  • 1
  • 7
  • 16
  • So does that mean that you cannot call intrinsic functions like `maxval` or `minval`. Also, would you mind elaborating your comment about "core C library"? I suspect that means libc, `` is in libc so with that logic we should be able to call from GDB `sin(x)` but that does not seem to be the case. – gnikit Sep 21 '21 at 10:08