<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/117434>117434</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Suggestions for implementing flang's built-in functions "backtrace"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dty2
      </td>
    </tr>
</table>

<pre>
    I notice that gfortran's have a intrinsic function "abort" that can abort and print a backtrace when called.
flang also has it, but it only aborts without printing a backtrace.
So, I modified it for flang, and my implemention is different from gfortran's. So I would like to get some suggestions...
the source is
```
! L2 Norm of a vector
function vector_norm(n,vec) result(norm)
  implicit none
  integer, intent(in) :: n
  real, intent(in) :: vec(n)
  real :: norm

  norm = sqrt(sum(vec**2))
  call backtrace

end function vector_norm

! Print matrix A to screen
subroutine print_matrix(n,m,A)
  implicit none
  integer, intent(in) :: n
 integer, intent(in) :: m
  integer, intent(in) :: A(n, m)

  real :: v(9)
  real :: vector_norm
  integer :: i

  v(:) = 9

  do i = 1, n
    print *, A(i, 1:m)
  end do

  print *, 'Vector norm = ', vector_norm(9,v)
end subroutine print_matrix

program test_backtrace
  integer :: k(10, 10)
  k = 9
  call print_matrix(2, 3, k)
end program test_backtrace
```
And, gfortran's backtrace print like:
``` bash
#0  0x650cc12924a1 in vector_norm_
        at /home/hunter/plct/fortran/test.f90:10
#1  0x650cc12923ed in print_matrix_
        at /home/hunter/plct/fortran/test.f90:32
#2 0x650cc1292527 in test_backtrace
        at /home/hunter/plct/fortran/test.f90:40
#3  0x650cc1292577 in main
 at /home/hunter/plct/fortran/test.f90:41
```
And my implemention print like:
```
./test(_FortranABacktrace+0x32) [0x5b30328e1312]
./test(vector_norm_+0x129) [0x5b30328b38f9]
./test(print_matrix_+0x252) [0x5b30328b3b62]
./test(_QQmain+0x105) [0x5b30328b3c95]
./test(main+0x12) [0x5b30328b3cb2]
/usr/lib/libc.so.6(+0x25e08) [0x786915b75e08]
/usr/lib/libc.so.6(__libc_start_main+0x8c) [0x786915b75ecc]
./test(_start+0x25) [0x5b30328b36f5]
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVt1u4ygUfhpyczSRgTixL3KRtoo00mq1o5H2NsIY22xt6AJO27dfHezYcZPOjma3qpIY-H7ODxjhva6NUnuSPpD0aSX60Fi3L8M7WxW2fN9_BWODlgpCIwLUlXXBCUPYzkMjzgoEaBOcNl5LqHojg7YGCGOisC4QxgacFAbiCAhTwovTJoCAQsjn4IRU8NooA1K0rSrXJHkiyaFqhalBtN5CIzzoQNgjFH0AHcCa9n2g8_CqQ2P7MHBqhMy0I9V3i9iv0NlSV1qVSFFZB1ECp9BT9w66e2lVp0wMQXsodVUpp0yAytluEfsavlv4Cq-2b0to9bOCYKFWAbztFPi-rpVHGr9ejyZCo8Db3kkF2g9DZJuM_8Mjo_Abg9-t68BWIOCsZLBuTMcltcPgyVjXEZYZwh7PShKWg1O-bwOOxal8wEGMSksdwFijpkETVK0cBo8_DeK0QRrCD4QfwFxWOiXaz5dFbXSRX6-fSNDJENs4iyNA-BP4v7E7Mt9jFJHlQNiBIdHMhQ0xV_OaSZkS7qbkag3m84_YaZ0ITr_BAYvkpVNqjM73hbN90EYN7XMaFo557Qh7PPxvifzXhd1PUx5GgzCX-V72z4Rl-SeVuUnZJHtZoZfESIYz0cUTfJAtLeg4TtHW1Dsw7vRY3MfoW-MPSvjhukWxmqVdUi6QhO3-jI7nBiJshzPL7ZDjdpiIkfazEl9pvThbO9FBUD6cPnTbTVqeCctoEoNIriJ4vs7K2LgfWoohiOPH88Lhj-Q_nBAHUyJ-cQjPZ-iQMTyM0OsSD4XwzWVb8AQgedumiZSU5WwjKOjFLjrNBcQ_gXU4NrZT-NWbgM15fGllIOw4eTliAOsqTwg_0OlI43ShxfH0NYvU_GcxziYxdq2Vsh1q3S_rr4pt5sj4IrJ0F9U6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