[flang-commits] [flang] [flang] Add design document for debug info generation. (PR #86939)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Thu Apr 11 10:10:22 PDT 2024


================
@@ -0,0 +1,451 @@
+# Debug Generation
+
+Application developers spend a significant time debugging the applications that
+they create. Hence it is important that a compiler provide support for a good
+debug experience. DWARF[1] is the standard debugging file format used by
+compilers and debuggers. The LLVM infrastructure supports debug info generation
+using metadata[2]. Support for generating debug metadata is present
+in MLIR by way of MLIR attributes. Flang can leverage these MLIR attributes to
+generate good debug information.
+
+We can break the work for debug generation into two separate tasks:
+1) Line Table generation
+2) Full debug generation
+The support for Fortran Debug in LLVM infrastructure[3] has made great progress
+due to many Fortran frontends adopting LLVM as the backend as well as the
+availability of the Classic Flang compiler.
+
+## Driver Flags
+By default, Flang will not generate any debug or linetable information.
+Debug information will be generated if the following flags are present.
+
+-gline-tables-only, -g1 : Emit debug line number tables only  
+-g : Emit full debug info
+
+## Line Table Generation
+
+There is existing AddDebugFoundationPass which add `FusedLoc` with a
+`SubprogramAttr` on FuncOp. This allows MLIR to generate LLVM IR metadata
+for that function. However, following values are hardcoded at the moment. These
+will instead be passed from the driver.
+
+- Details of the compiler (name and version and git hash).
+- Language Standard. We can set it to Fortran95 for now and periodically
+revise it when full support for later standards is available.
+- Optimisation Level.
+- Type of debug generated (linetable/full debug).
+- Calling Convention: `DW_CC_normal` by default and `DW_CC_program` if it is
+the main program.
+
+`DISubroutineTypeAttr` currently has a fixed type. This will be changed to
+match the signature of the actual function/subroutine.
----------------
kiranchandramohan wrote:

As discussed in https://reviews.llvm.org/D138534, for the following program, what would be the `ptype` for the function foo?
```
 program mn
  integer :: arr(10), cnt
  call foo(arr, cnt)
contains
  subroutine foo( a, n)
    integer  :: a(:), n
  end subroutine foo
end program
```
gfortran (Actual signature)
```
ptype foo
type = void (integer(kind=4) (:), integer(kind=4))
```
Classic Flang (LLVM IR signature)
```
(gdb) ptype foo
type = void (integer*8, integer, integer (187651372366496), uinteger*8)
```

https://github.com/llvm/llvm-project/pull/86939


More information about the flang-commits mailing list