0

I am trying to debug and profile (ideally line-by-line time spent) Fortran code on an M1 Mac. Most commands I tried don't seem to work for Fortran and/or M1.

  • gdb seems outdated and won't run
  • lldb complains that it does not work on M1.
  • I tried Time Profiler within Instruments, but I cannot make any sense of the recorded output.

If someone could tell me which commands or flags are needed or show and example, that'd be greatly appreciated!

Context: I'm trying to find some bottlenecks for optimization of serial code and in addition, an OpenMP version of my subroutine just stops with "Illegal instruction: 4", so I'm trying to find out why this is happening (stack and OMP_STACKSIZE is large).


EDIT - To give some more details:

I am compiling with gfortran (Homebrew GCC 13.1.0). So wanted to compile with -p -pg option and run gdb ./a.out, but installing gdb fails with

"gdb: The x86_64 architecture is required for this software."

also adding the -pg option during compilation does not seem to work. It complains that "ld: library not found for -lgcrt1.o" but this file is nowhere to be found (neither in homebrew nor on the Xcode SDK packages) and brew install glibc (of which gcrt1.o seems to be part of) also does not work ("glibc: Linux is required for this software.").

I managed to start lldb ./a.out, but this seems useless to me. I can set a break point, but if I try to print out a variable (e.g. p (int) ix, I get "error: Could not find type system for language fortran95: TypeSystem for language fortran95 doesn't exist".

So in summary just stepping through any simple little fortran program in a debugger does not work for me on an M1 Mac. If someone knows how to make this work or where to find those missing libraries, that would greatly be appreciated. Extra credit would be a line-by-line-time-spent output to help me find where the bottleneck is.

John Smith
  • 1,059
  • 1
  • 13
  • 35
  • This is a quite vague question. First, which compiler/version are you using? – PierU Aug 29 '23 at 08:10
  • `gfortran` from `Homebrew GCC 13.1.0`, mostly. Sorry about the vagueness, but it is a problem not specific to a particular code and most related answers are outdated (other architecture or languages), so I hope this will be useful not only for me. Let me know if I can be more specific on some aspects. – John Smith Aug 29 '23 at 09:01
  • Is your code compiled for ARM? An illegal instruction hints that it might not be the case. Show the specific versions of the software you are using and the exact error messages. No "complains that", just copy the message. Plese note that software recommendations are off-topic here and should be asked at https://softrec.stackexchange.com – Vladimir F Героям слава Aug 29 '23 at 12:34
  • Remember, all software that you try **must be compiled for Apple M1-2**. Trying some version downloaded somewhere that is compiled for x86-64 is hopeless. When asking to solve a specific problem you must indicate the exact versions you have. – Vladimir F Героям слава Aug 30 '23 at 08:20
  • Yes, I am compiling for on the M1 Mac for the M1 Mac – John Smith Aug 30 '23 at 08:38
  • 1
    There are a million questions asking for "how can I do X" and people recommend command line tools. I don't see why this is closed for asking for a recommendation. – John Smith Aug 30 '23 at 08:42
  • @JohnSmith Because the answer for "how to debug" is: use a debugger. You say that the usual debuggers do not work for you and asking for a different one. But you should first try to find out why the usual ones do not work. I and others have asked for details how those debuggers you mentioned do not work for you, because they should. The main point is that tools like GDB really **should work** on ARM just fine. If they do not work for you, you must show some details. You probably have some incorrect version. Alas, you did not even indicate what version you have! – Vladimir F Героям слава Aug 30 '23 at 14:40
  • *"Yes, I am compiling for on the M1 Mac for the M1 Mac"* Yes, But I wrote that all the software you are trying to use must be the correct M1 version as well. Show us the specific versions of the software you tried. Tell us where you got them. – Vladimir F Героям слава Aug 30 '23 at 14:44
  • Regarding your last comment, though, remember, you did NOT ask "how can I do X", you asked "I am looking for tools to debug and profile" and only made the edit later. I am not voting for reopen because they are other reasons for the closer, explained in my previois two comments. The solution is simple, just provide the necessary details. You yourself wrote "Let me know if I can be more specific on some aspects". I spent a lot of time explaining how you can be. Please spend at least some time being more specific. – Vladimir F Героям слава Aug 31 '23 at 05:19
  • @VladimirFГероямслава at some point `gbd` was not working on Mac M1/M2. I don't know if it has changed since then. A common workaround was to install ARM Linux in a virtual machine and develop under Linux instead. – PierU Aug 31 '23 at 06:28
  • @PierU It still seems to be the case. Then we still have lldb which should be available, at least for certain optimization levels. But as I commented in my first comment, "complains that it does not work on M1" really says way too little. I would also note that there are plenty of separate SO questions and answers about those individual tools at M1 MacOS which tell a lot. – Vladimir F Героям слава Aug 31 '23 at 06:34
  • Another point where to be more specific: *"Most commands I tried don't seem to work for Fortran and/or M1."* Does it mean that some of those commands do not work for Fortran but do work for C or other languages or compilers? Please explain in detail. Is this really specific to Fortran? Which exact compiler? – Vladimir F Героям слава Aug 31 '23 at 06:43
  • I agree that the question is missing a lot of informations and details. – PierU Aug 31 '23 at 07:15
  • Added more details, let me know what other 'information and details' are missing. – John Smith Aug 31 '23 at 08:19
  • Looks like the `-pg` option of `gcc` won't work on macOS (there are several SO questions that report that). That said there is some confusion between debugging and profiling: `lldb` is a debugger, not a profiler, so in itself it doesn't require the `-pg` option but rather the `-g` option. – PierU Aug 31 '23 at 08:43
  • I have no suggestion for profiling the code, though... it would be `gprof`, but without `-pg` at compile/link time it's useless. – PierU Aug 31 '23 at 08:45
  • ok, thanks for the clarification. I managed to step through the code with `lldb` but it cannot show me the variables, edited the question. – John Smith Aug 31 '23 at 09:23
  • lldb may not support Fortran, unless it has changed recently: https://stackoverflow.com/a/44993207/14778592 https://stackoverflow.com/a/37999672/14778592 – PierU Aug 31 '23 at 12:16
  • so are there any other options I could try on an M1-Mac? – John Smith Aug 31 '23 at 12:17
  • I don't know... You may try asking on this forum, which is probably better suited than SO for extended discussions and recommendations : https://fortran-lang.discourse.group/ (this is kind of the "official unofficial" forum of the Fortran community) – PierU Aug 31 '23 at 12:20

0 Answers0