Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DebugInfo] Flang should generate debug location for limited instructions in prolog #940

Merged
merged 2 commits into from
Jan 13, 2021

Conversation

alokkrsharma
Copy link
Collaborator

Due to this wrong debug_line section entry is created with wrong instruction
marked as 'prologue_end'. More details in committed test cases.
This causes debugger not skipping prologue when inserting break-point with
function/subroutine name.
To make breakpoint work as expected, some debugger (GDB) changes were
also required which are already committed as
commit c2fd7faea8f2c3a267f276ceb6a95f9f537ea7c1
Author: Alok Kumar Sharma [email protected]
Date: Thu Aug 20 10:35:27 2020 +0530

Due to this wrong debug_line section entry is created with wrong instruction
marked as 'prologue_end'. More details in commited test cases.
@alokkrsharma alokkrsharma changed the title Flang should generate limited debug location for instructions in prolog [DebugInfo] Flang should generate limited debug location for instructions in prolog Oct 24, 2020
@gklimowicz gklimowicz requested a review from jieljiel October 24, 2020 21:15
@alokkrsharma alokkrsharma changed the title [DebugInfo] Flang should generate limited debug location for instructions in prolog [DebugInfo] Flang should generate debug location for limited instructions in prolog Oct 26, 2020
@gklimowicz gklimowicz self-requested a review November 18, 2020 18:38
Copy link
Contributor

@gklimowicz gklimowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This passes our tests on OpenPOWER for LLVM 9 and LLVM 10.

@alokkrsharma
Copy link
Collaborator Author

Hi @jiel-nv , @bryanpkc , @kiranchandramohan , do you have any comments ?

Comment on lines +2731 to +2732
return (!strncmp(name_str, "@fort_init", strlen("@fort_init")) ||
!strncmp(name_str, "@f90_", strlen("@f90_")));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about fortran statements like allocate which in turn generate runtime calls, @f90_alloc*. Will this patch disable generation of line-numbers for these runtime calls also?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generation of debug info is suppressed only for the statements in prologue, other occurrences would have debug location.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about fortran statements like allocate which in turn generate runtime calls, @f90_alloc*. Will this patch disable generation of line-numbers for these runtime calls also?

Generation of debug info is suppressed only for the statements in prologue, other occurrences would keep having debug location.

@bryanpkc
Copy link
Collaborator

bryanpkc commented Dec 1, 2020

I tested this patch on our AArch64 server. I didn't see any failure but also didn't see any improvement; I had thought that this patch would make gdb skip the prologue when stepping. Running the debugger on a Fortran "hello, world", I see the following behaviour:

$ gdb -q ./hello
Reading symbols from ./hello...done.
(gdb) b MAIN_
Breakpoint 1 at 0x400990
(gdb) r
Starting program: /home/bryanpkc/hello
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x0000000000400990 in hello ()
(gdb) list
1       <built-in>: No such file or directory.
(gdb) step
Single stepping until exit from function hello,
which has no line number information.
0x0000fffff7d304ec in fort_init (n=0x8020080280200802) from ./flang/install/lib/libflang.so
(gdb) finish
Run till exit from #0  0x0000fffff7d304ec in fort_init (n=0x8020080280200802) from ./flang/install/lib/libflang.so
0x00000000004009ac in hello () at hello.f90:1
1       program hello
(gdb) step
4           print *, "hello"
(gdb) 

@bryanpkc
Copy link
Collaborator

bryanpkc commented Dec 1, 2020

Running the test case failed for me:

FAIL: Flang :: debug_info/dwarfdump_prolog.f90 (1 of 1)
******************** TEST 'Flang :: debug_info/dwarfdump_prolog.f90' FAILED ********************
Script:
--
: 'RUN: at line 1';    /home/b00375952/src/cpu/llvm-project/install/bin/flang  -g /home/b00375952/src/cpu/llvm-project/flang/test/debug_info/dwarfdump_prolog.f90 -o /home/b00375952/src/cpu/llvm-project/build/flang/test/debug_info/Output/dwarfdump_prolog.f90.tmp
: 'RUN: at line 2';   llvm-dwarfdump  --debug-line /home/b00375952/src/cpu/llvm-project/build/flang/test/debug_info/Output/dwarfdump_prolog.f90.tmp -o - | /home/b00375952/src/cpu/llvm-project/build/flang/bin/FileCheck /home/b00375952/src/cpu/llvm-project/flang/test/debug_info/dwarfdump_prolog.f90
--
Exit Code: 1

Command Output (stderr):
--
/home/b00375952/src/cpu/llvm-project/flang/test/debug_info/dwarfdump_prolog.f90:6:9: error: CHECK: expected string not found in input
!CHECK: {{0x[0-9a-f]+}} 13 1 1 0 0 is_stmt prologue_end
        ^
<stdin>:35:1: note: scanning from here
------------------ ------ ------ ------ --- ------------- -------------
^
<stdin>:37:10: note: possible intended match here
0x0000000000400a14 0 0 1 0 0 is_stmt prologue_end
         ^

--

For some reason, llvm-dwarfdump reports a lot of weird "line 0, column 0" entries:

           name: "dwarfdump_prolog.f90"
      dir_index: 1
       mod_time: 0x00000000
         length: 0x00000000

Address            Line   Column File   ISA Discriminator Flags
------------------ ------ ------ ------ --- ------------- -------------
0x0000000000400a0c      9      0      1   0             0  is_stmt
0x0000000000400a14      0      0      1   0             0  is_stmt prologue_end
0x0000000000400a5c     13      1      1   0             0  is_stmt
0x0000000000400a60      0      0      1   0             0
0x0000000000400a7c     13      1      1   0             0
0x0000000000400a80      0      0      1   0             0
0x0000000000400a88     13      1      1   0             0
0x0000000000400a8c      0      0      1   0             0
0x0000000000400a90     13      1      1   0             0
0x0000000000400a9c      0      0      1   0             0
0x0000000000400ab0     13      1      1   0             0
0x0000000000400ac0      0      0      1   0             0
0x0000000000400acc     13      1      1   0             0
0x0000000000400adc      0      0      1   0             0
0x0000000000400af0     14      1      1   0             0  is_stmt
0x0000000000400b18      0      0      1   0             0
0x0000000000400b20     14      1      1   0             0
0x0000000000400b30     16      1      1   0             0  is_stmt
0x0000000000400b3c     18      0      1   0             0  is_stmt
0x0000000000400bec      0      0      1   0             0  is_stmt prologue_end
0x0000000000400c08     29      1      1   0             0  is_stmt
0x0000000000400c0c     30      1      1   0             0  is_stmt
0x0000000000400c18     30      1      1   0             0  is_stmt end_sequence

@alokkrsharma
Copy link
Collaborator Author

I tested this patch on our AArch64 server. I didn't see any failure but also didn't see any improvement; I had thought that this patch would make gdb skip the prologue when stepping. Running the debugger on a Fortran "hello, world", I see the following behaviour:

$ gdb -q ./hello
Reading symbols from ./hello...done.
(gdb) b MAIN_
Breakpoint 1 at 0x400990
(gdb) r
Starting program: /home/bryanpkc/hello
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x0000000000400990 in hello ()
(gdb) list
1       <built-in>: No such file or directory.
(gdb) step
Single stepping until exit from function hello,
which has no line number information.
0x0000fffff7d304ec in fort_init (n=0x8020080280200802) from ./flang/install/lib/libflang.so
(gdb) finish
Run till exit from #0  0x0000fffff7d304ec in fort_init (n=0x8020080280200802) from ./flang/install/lib/libflang.so
0x00000000004009ac in hello () at hello.f90:1
1       program hello
(gdb) step
4           print *, "hello"
(gdb) 

This would need an updated gdb containing below commit. Can you please confirm whether required gdb is being used ?

commit c2fd7faea8f2c3a267f276ceb6a95f9f537ea7c1
Author: Alok Kumar Sharma [email protected]
Date: Thu Aug 20 10:35:27 2020 +0530

@bryanpkc
Copy link
Collaborator

bryanpkc commented Dec 4, 2020

@alokkrsharma Thanks, I built GDB 10.1 which contains that commit, and it does work fine on a binary built with this branch (rebased on master), and classic-flang-llvm-project/release_100.

@bryanpkc bryanpkc self-requested a review January 3, 2021 20:51
Copy link
Collaborator

@bryanpkc bryanpkc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

- to match coding style of newly added functions to rest of the file.
- to reduce optimization option to -O0 in test case.
@alokkrsharma
Copy link
Collaborator Author

LGTM.

Thanks @bryanpkc for approving this.

@alokkrsharma
Copy link
Collaborator Author

Hi @kiranchandramohan , do you have any comment on this ?

Copy link
Collaborator

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@shivaramaarao shivaramaarao merged commit 2eab099 into flang-compiler:master Jan 13, 2021
@kiranchandramohan
Copy link
Collaborator

Running the test case failed for me:

FAIL: Flang :: debug_info/dwarfdump_prolog.f90 (1 of 1)
******************** TEST 'Flang :: debug_info/dwarfdump_prolog.f90' FAILED ********************
Script:
--
: 'RUN: at line 1';    /home/b00375952/src/cpu/llvm-project/install/bin/flang  -g /home/b00375952/src/cpu/llvm-project/flang/test/debug_info/dwarfdump_prolog.f90 -o /home/b00375952/src/cpu/llvm-project/build/flang/test/debug_info/Output/dwarfdump_prolog.f90.tmp
: 'RUN: at line 2';   llvm-dwarfdump  --debug-line /home/b00375952/src/cpu/llvm-project/build/flang/test/debug_info/Output/dwarfdump_prolog.f90.tmp -o - | /home/b00375952/src/cpu/llvm-project/build/flang/bin/FileCheck /home/b00375952/src/cpu/llvm-project/flang/test/debug_info/dwarfdump_prolog.f90
--
Exit Code: 1

Command Output (stderr):
--
/home/b00375952/src/cpu/llvm-project/flang/test/debug_info/dwarfdump_prolog.f90:6:9: error: CHECK: expected string not found in input
!CHECK: {{0x[0-9a-f]+}} 13 1 1 0 0 is_stmt prologue_end
        ^
<stdin>:35:1: note: scanning from here
------------------ ------ ------ ------ --- ------------- -------------
^
<stdin>:37:10: note: possible intended match here
0x0000000000400a14 0 0 1 0 0 is_stmt prologue_end
         ^

--

For some reason, llvm-dwarfdump reports a lot of weird "line 0, column 0" entries:

           name: "dwarfdump_prolog.f90"
      dir_index: 1
       mod_time: 0x00000000
         length: 0x00000000

Address            Line   Column File   ISA Discriminator Flags
------------------ ------ ------ ------ --- ------------- -------------
0x0000000000400a0c      9      0      1   0             0  is_stmt
0x0000000000400a14      0      0      1   0             0  is_stmt prologue_end
0x0000000000400a5c     13      1      1   0             0  is_stmt
0x0000000000400a60      0      0      1   0             0
0x0000000000400a7c     13      1      1   0             0
0x0000000000400a80      0      0      1   0             0
0x0000000000400a88     13      1      1   0             0
0x0000000000400a8c      0      0      1   0             0
0x0000000000400a90     13      1      1   0             0
0x0000000000400a9c      0      0      1   0             0
0x0000000000400ab0     13      1      1   0             0
0x0000000000400ac0      0      0      1   0             0
0x0000000000400acc     13      1      1   0             0
0x0000000000400adc      0      0      1   0             0
0x0000000000400af0     14      1      1   0             0  is_stmt
0x0000000000400b18      0      0      1   0             0
0x0000000000400b20     14      1      1   0             0
0x0000000000400b30     16      1      1   0             0  is_stmt
0x0000000000400b3c     18      0      1   0             0  is_stmt
0x0000000000400bec      0      0      1   0             0  is_stmt prologue_end
0x0000000000400c08     29      1      1   0             0  is_stmt
0x0000000000400c0c     30      1      1   0             0  is_stmt
0x0000000000400c18     30      1      1   0             0  is_stmt end_sequence

@bryanpkc @alokkrsharma @shivaramaarao : This failure happened in the postcommit CI on an aarch64 machine. Did this finally work for you?

@alokkrsharma
Copy link
Collaborator Author

Running the test case failed for me:

FAIL: Flang :: debug_info/dwarfdump_prolog.f90 (1 of 1)
******************** TEST 'Flang :: debug_info/dwarfdump_prolog.f90' FAILED ********************
Script:
--
: 'RUN: at line 1';    /home/b00375952/src/cpu/llvm-project/install/bin/flang  -g /home/b00375952/src/cpu/llvm-project/flang/test/debug_info/dwarfdump_prolog.f90 -o /home/b00375952/src/cpu/llvm-project/build/flang/test/debug_info/Output/dwarfdump_prolog.f90.tmp
: 'RUN: at line 2';   llvm-dwarfdump  --debug-line /home/b00375952/src/cpu/llvm-project/build/flang/test/debug_info/Output/dwarfdump_prolog.f90.tmp -o - | /home/b00375952/src/cpu/llvm-project/build/flang/bin/FileCheck /home/b00375952/src/cpu/llvm-project/flang/test/debug_info/dwarfdump_prolog.f90
--
Exit Code: 1

Command Output (stderr):
--
/home/b00375952/src/cpu/llvm-project/flang/test/debug_info/dwarfdump_prolog.f90:6:9: error: CHECK: expected string not found in input
!CHECK: {{0x[0-9a-f]+}} 13 1 1 0 0 is_stmt prologue_end
        ^
<stdin>:35:1: note: scanning from here
------------------ ------ ------ ------ --- ------------- -------------
^
<stdin>:37:10: note: possible intended match here
0x0000000000400a14 0 0 1 0 0 is_stmt prologue_end
         ^

--

For some reason, llvm-dwarfdump reports a lot of weird "line 0, column 0" entries:

           name: "dwarfdump_prolog.f90"
      dir_index: 1
       mod_time: 0x00000000
         length: 0x00000000

Address            Line   Column File   ISA Discriminator Flags
------------------ ------ ------ ------ --- ------------- -------------
0x0000000000400a0c      9      0      1   0             0  is_stmt
0x0000000000400a14      0      0      1   0             0  is_stmt prologue_end
0x0000000000400a5c     13      1      1   0             0  is_stmt
0x0000000000400a60      0      0      1   0             0
0x0000000000400a7c     13      1      1   0             0
0x0000000000400a80      0      0      1   0             0
0x0000000000400a88     13      1      1   0             0
0x0000000000400a8c      0      0      1   0             0
0x0000000000400a90     13      1      1   0             0
0x0000000000400a9c      0      0      1   0             0
0x0000000000400ab0     13      1      1   0             0
0x0000000000400ac0      0      0      1   0             0
0x0000000000400acc     13      1      1   0             0
0x0000000000400adc      0      0      1   0             0
0x0000000000400af0     14      1      1   0             0  is_stmt
0x0000000000400b18      0      0      1   0             0
0x0000000000400b20     14      1      1   0             0
0x0000000000400b30     16      1      1   0             0  is_stmt
0x0000000000400b3c     18      0      1   0             0  is_stmt
0x0000000000400bec      0      0      1   0             0  is_stmt prologue_end
0x0000000000400c08     29      1      1   0             0  is_stmt
0x0000000000400c0c     30      1      1   0             0  is_stmt
0x0000000000400c18     30      1      1   0             0  is_stmt end_sequence

@bryanpkc @alokkrsharma @shivaramaarao : This failure happened in the postcommit CI on an aarch64 machine. Did this finally work for you?

Things that can be done are...

  1. Mark the testcase as expected fail for aarch64 machines
  2. Limit test case only for x86 (!REQUIRES works on later version of LLVM but i guess not on current version of llvm-lit)
  3. We can completely remove the test case.

Let me explain why,

Another test prolog.f90 is sufficient to check the (fix) PR. The test case dwarfdump_prolog.f90 depends not only on how Flang (compiler frontend) behaves but also on how compiler backend works.
In case of optimizations (like combining two instructions from different locations), end result can have instructions with (0,0) line number info. which may lead to different output than what is expected in test case and we get on x86. Good news is that debug experience with gnu gdb does not depend on the "prologue_end" tag identified by dwarfdump. Same test case when debugged with latest gdb (having my fix) should behave as expected. The idea with existence of test case was more to demo than to check correctness of fix. If it creates problem we can get rid of it.

@bryanpkc
Copy link
Collaborator

That error didn't happen on my end, but I think that might have been thanks to an internal patch that prevented the (0, 0) lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants