-
Notifications
You must be signed in to change notification settings - Fork 139
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] Array debugging support with upgraded DISubrange #952
Conversation
Hi @kiranchandramohan, I have closed other subset PRs. This PR should be ready to review. Additional commit is made to make the array debugging work for current version 9 (which should be valid after backport PRs to 9 and 10 are merged). |
b0eec73
to
5fb4c50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have two internal tests that fail after applying this set of changes. We'll send you the short test cases and the errors we see when running them (related to generated debtg metadata). We see these with LLVM 9 and LLVM 10.
Other internal tests pass, so I am approving this pull request while perhaps we investigate this in the background.
5fb4c50
to
67f9180
Compare
Thanks @gklimowicz , The fix is pushed, can you please check now ? |
If we do not use LLVM_FLANG_EXTENSIONS, then string will go back to using DIBasicType instead of DIString. I see that @SouraVX introduced DIStringType in https://reviews.llvm.org/D86305. Is there a corresponding Flang change? |
@alokkrsharma I reran our tests and they do indeed pass now with your latest change. |
Debug for allocatable variables in modules seem to be missing. Can that be handled?
|
It's present @kiranchandramohan. Debuggers like GDB skips parsing/reading if line and file info is not present in a FORTRAN module as a result when an end user issues command |
67f9180
to
2aa3bc2
Compare
Can you please check the printing of variable now ? |
Thanks @alokkrsharma. I can see the debug emitted for the "patch_count" variable. But I do not see it working in gdb. Consider the program and gdb session below. It can be seen that the value of patch_count cannot be printed.
The IR and debug generated is as follows. As can be seen, the debug for @mod_vars_0 is pointing to !13 (patch_count$sd) instead of !7 (patch_count). If I make this correction then I can print patch_count.
|
2aa3bc2
to
335c4d2
Compare
Thanks for pointing this out. It is fixed in latest patch. Please try. |
tools/flang2/flang2exe/lldebug.cpp
Outdated
INLINE static void | ||
init_subrange_bound(LL_DebugInfo *db, ISZ_T *cb, LL_MDRef *bound_sptr, | ||
SPTR sptr, ISZ_T defVal, int findex) | ||
INLINE static void init_subrange_bound_pre11(LL_DebugInfo *db, ISZ_T *cb, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, the PGI coding standard was to keep the function names starting in column 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. I have corrected this.
Now I realize it is due to tool "git-clang-format" which I use, is there any equivalent tool for PGI coding style ?
error: '%p$sd1_317' defined with type '[16 x i64]*' but expected '[16 x i64]'
|
335c4d2
to
5e075fd
Compare
Thanks for pointing this out. Can you please check with updated sources ? |
I built this branch with flang-compiler/classic-flang-llvm-project#8 successfully, but the
Running this test by itself seems okay, but running the whole |
I tried with gdb-10.1 and it worked. Is the patch present in 10.1? |
Yes, GDB fix should be present in 10.1 and to include Flang fix for prologue #940 I have re-based the current PR. |
@alokkrsharma Can you rebase the PR to run the CI? I think once it passes we can merge it. |
ba5d2c9
to
343ff52
Compare
@alokkrsharma Assuming the test fails since some of the relevant patches are not in llvm-11. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work. Thanks for your patience.
Unfortunately, I do not have sufficient time to review this properly. At the same time we have delayed this PR for too long. Since we have tested it fairly well we will go ahead with this now.
If you get time please add all the macros that you used for arrays to the documentation in some page.
What can we do about the release_11x branch? Would cherry-picking the relevant debug commits there be too much work? Apologies for this, a timely review would have avoided the need for this.
Yes, release_11x test fail due to this. Errors like these suggest this. |
Thanks a lot for your quality time on this. |
This is fixed. |
Hi @bryanpkc , do you have any more comment on this ? |
@alokkrsharma Thanks. Is this a big change? I could not make out from the last commit. Could you add a small description? |
Please consider the change in (debug) IR for newly added test assumed_shape_noopt.f90
After fix:
There is a minor change in statement B1(before fix) and B2(after fix) as after fix, this artificial variable is marked as an "arg:". Looking at the statement A, this is correct and helps in not getting optimized out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @bryanpkc , do you have any more comment on this ?
I had some problems merging this patch into our internal repo, but the vanilla Flang build seemed okay to me. I agree with Kiran, with the amount of review and testing already done, we should go ahead with it.
@alokkrsharma can you push to trigger a fresh run of the CI? If it is green I will merge. |
Note: This modification makes use of recent upgrade to DISubrange https://reviews.llvm.org/rGd20bf5a7258d4b6a7f017a81b125275dac1aa166 Currently flang generates 0 sized DISubrange metadata for assumed sahpe arrays. --------- test case --------- subroutine sub(assume,n1,n2) dimension assume(n1,n2) end subroutine sub ------- LLVM IR ------- !29 = !DILocalVariable(name: "assume", arg: 1, scope: !26, file: !3, type: !30) !30 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 32, align: 32, elements: !31) !31 = !{!32, !32} !32 = !DISubrange(count: 0, lowerBound: 1) ------- This is fixed by upgrading DISubrange as it is upgraded in LLVM to be able to dump proper DISubrange for assumed shape array. ------- !29 = !DILocalVariable(name: "assume", arg: 1, scope: !26, file: !3, type: !30) !30 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 32, align: 32, elements: !31) !31 = !{!32, !36} !32 = !DISubrange(lowerBound: 1, upperBound: !33) !33 = distinct !DILocalVariable(scope: !34, file: !3, type: !35, flags: DIFlagArtificial) !36 = !DISubrange(lowerBound: 1, upperBound: !37) !37 = distinct !DILocalVariable(scope: !34, file: !3, type: !35, flags: DIFlagArtificial) -------
Note: This modification makes use of recent upgrade to DISubrange https://reviews.llvm.org/rGd20bf5a7258d4b6a7f017a81b125275dac1aa166 Now, below testcase gives desired results with debugger. -------------- program main integer, allocatable :: arr(:) allocate (arr(2:10)) arr(3) = 9 end program main -------------- (gdb) pt arr type = integer (2:10) (gdb) p arr $1 = (0, 9, 0, 0, 0, 0, 0, 0, 0) -------------- And below case works as well -------------- program main type dt integer :: var1 integer :: var2 integer, allocatable :: arr1 (:,:) integer :: var3 end type dt type(dt) :: dvar1 dvar1%var1 = 21 dvar1%var2 = 22 dvar1%var3 = 23 allocate (dvar1%arr1(2:9, 3:11)) dvar1%arr1(5,4) = 11 end program main -------------- (gdb) pt dvar1 type = Type dt integer :: var1 integer :: var2 integer :: arr1(2:9,3:11) integer :: var3 End Type dt (gdb) p dvar1%arr1 $2 = (( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 11, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ) ---------------
This patch makes use of commited llvm patch [DebugInfo] Support for DW_AT_associated and DW_AT_allocated. https://reviews.llvm.org/rG2d10258a31a6d05368dfd4442c4aaa7b54614f1e This fix is needed for allocatable/pointer arrays. for pointer array (before allocation/association) Before fix ------ (gdb) pt ptr type = integer (140737345375288:140737354129776) (gdb) p ptr value requires 35017956 bytes, which is more than max-value-size ------ After fix ------ (gdb) pt ptr type = integer (:) (gdb) p ptr $1 = <not associated> ------ for allocatable array (before allocation) Before fix ------ (gdb) pt arr type = integer (140737345375288:140737354129776) (gdb) p arr value requires 35017956 bytes, which is more than max-value-size ------ After fix ------ (gdb) pt arr type = integer, allocatable (:) (gdb) p arr $1 = <not allocated> ------ Testing: - check-flang
This commit is valid only after below PRs are merged. LLVM10: flang-compiler/classic-flang-llvm-project#8 LLVM9: flang-compiler/llvm#86
…ocatable attribute
…d away Base address of assumed shape array is marked as 'dataLocation' field of array type, this is an artifical variable earlier mentioned as DW_TAG_variable. With below options this artificial variable is optimized out. %flang -g -S -emit-llvm test/debug_info/assumed_shape_noopt.f90 %llc -O0 -fast-isel=false -global-isel=false -filetype=obj assumed_shape_noopt.ll Marking this variable as DW_TAG_formal_parameter is a right thing to do and also avoids optimization.
24a34a8
to
788459a
Compare
All checks have passed. Thanks in advance. |
Thanks @bryanpkc for your quality time review. It helped a lot. |
@alokkrsharma is the following gdb patch required for allocation status to work correctly? commit 9cdf98207c5bab668e3734d11d5a24d6b5375b54
|
Yes. |
This PR supports general array debugging (adjustable array, assumed shape array, assumed size array, allocatable and pointer array and assumed rank array).
It uses multiple upgrades to upstream LLVM which are backported to flang-LLVM as
LLVM11: flang-compiler/classic-flang-llvm-project#14
LLVM10: flang-compiler/classic-flang-llvm-project#8
LLVM9: flang-compiler/llvm#86
Please note that this PR should be able to replace existing flang-LLVM DIFortranSubrage .