-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
[flang][debuginfo] Inconsistent debugger behavior when processing executables emitted by flang-new #97476
Comments
@llvm/issue-subscribers-flang-ir Author: Paul Osmialowski (pawosm-arm)
Consider simple program:
```
PROGRAM allocatable
IMPLICIT NONE
INTEGER, ALLOCATABLE, TARGET :: alloc2d(:, :)
ALLOCATE(alloc2d(-1:1, -2:2))
(gdb) b allocatable.f90:5 Breakpoint 1, allocatable () at allocatable.f90:5
(gdb) b allocatable.f90:5 Breakpoint 1, _QQmain () at allocatable.f90:5
PROGRAM minimal ALLOCATE(alloc2d(-1:1, -2:2))
(gdb) b minimal.f90:10 Breakpoint 1, minimal () at minimal.f90:10
(gdb) b minimal.f90:10 Breakpoint 1, _QQmain () at minimal.f90:10
|
@llvm/issue-subscribers-debuginfo Author: Paul Osmialowski (pawosm-arm)
Consider simple program:
```
PROGRAM allocatable
IMPLICIT NONE
INTEGER, ALLOCATABLE, TARGET :: alloc2d(:, :)
ALLOCATE(alloc2d(-1:1, -2:2))
(gdb) b allocatable.f90:5 Breakpoint 1, allocatable () at allocatable.f90:5
(gdb) b allocatable.f90:5 Breakpoint 1, _QQmain () at allocatable.f90:5
PROGRAM minimal ALLOCATE(alloc2d(-1:1, -2:2))
(gdb) b minimal.f90:10 Breakpoint 1, minimal () at minimal.f90:10
(gdb) b minimal.f90:10 Breakpoint 1, _QQmain () at minimal.f90:10
|
Thanks for reporting this @pawosm-arm. We have an issue that when a local variable is pointing to a global storage, LLVM's drops such local variables. This was the reason debugger did not show you If you move these variables to a module, then you should be able to evaluate them correctly. For example, here is how my debug session looked when I moved them to a module (see example program below). Although if you look at the output of ptype command, you noticed that flang confused upper bound with count in case of allocatable arrays. I will fix that.
|
Thanks @abidh for looking into it. The minimalist reproducer that I've prepared wasn't based on my code, I have no power to shift things around into modules. |
I understand. My example was just to make clear what exactly is not working. |
This PR fixes 2 similar issues. 1. As reported in llvm#97476, flang generated executable has inconsistent behavior regarding values of the local array variables. 2. Variable with save attribute would not show up in debugger. The reason behind is same for both cases. If a local variable has storage which extends beyond function lifetime, the way to represent it in the debug info is through a global variable whose scope is limited to the function. This is what is used for static local variable in C. Previously local array worked in cases they were on stack. But will not show up if they had a global storage. To fix this, if we can get a corresponding GlobalOp for a variable while processing DeclareOp, we treat it as a global variable.
One more comment. You should see all the local variables with |
@pawosm-arm I posted a fix for it in #98661. If you could kindly test that it works for you then it would be great. |
It is better and the tests I've quoted above are now passing. Yet still I have a test case that is failing, see:
If you set breakpoint at the line 7 (
That is the case when you build the code with gfortran or the old classic flang. Sadly, not with the new flang:
|
Thanks for checking. The problem you described is known. At the moment, we have to qualify the module member with its name. So if you try |
Do you know if there was a bug report opened for that? |
|
This PR fixes 2 similar issues. 1. As reported in llvm#97476, flang generated executable has inconsistent behavior regarding values of the local array variables. 2. Variable with save attribute would not show up in debugger. The reason behind is same for both cases. If a local variable has storage which extends beyond function lifetime, the way to represent it in the debug info is through a global variable whose scope is limited to the function. This is what is used for static local variable in C. Previously local array worked in cases they were on stack. But will not show up if they had a global storage. To fix this, if we can get a corresponding `GlobalOp` for a variable while processing `DeclareOp`, we treat it the variable as global with scope set appropriately. A new FIR test is added. A previous Integration test has been adjusted as to not expect local variables for local arrays. With this fix in place, all the issues described in llvm#97476 go away. It also fixes a lot of fails in GDB's fortran testsuite. Fixes llvm#97476.
Summary: This PR fixes 2 similar issues. 1. As reported in #97476, flang generated executable has inconsistent behavior regarding values of the local array variables. 2. Variable with save attribute would not show up in debugger. The reason behind is same for both cases. If a local variable has storage which extends beyond function lifetime, the way to represent it in the debug info is through a global variable whose scope is limited to the function. This is what is used for static local variable in C. Previously local array worked in cases they were on stack. But will not show up if they had a global storage. To fix this, if we can get a corresponding `GlobalOp` for a variable while processing `DeclareOp`, we treat it the variable as global with scope set appropriately. A new FIR test is added. A previous Integration test has been adjusted as to not expect local variables for local arrays. With this fix in place, all the issues described in #97476 go away. It also fixes a lot of fails in GDB's fortran testsuite. Fixes #97476. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250985
Consider simple program:
I've tried to compile it with gfortran and the old classic flang (each time with the
-O0 -g
flags), and I've observed (more or less) the same effect in gdb (after setting breakpoint at the ALLOCATE statement):When compiled with flang-new, I can observe a different behavior:
Apparently, gdb can't figure out that the array was not allocated yet.
This has some nasty implications as I extended the program a bit:
When compiled with gfortran (and more or less the same when compiled with the old classic flang):
Notice, that uninitialized variables are not present.
When compiled with flang-new:
Now, some (but only some) of the uninitialized variables are shown, all of them with random values, and
alloc2d
has gone completely to the moon. Note that when doing experiments (adding more variables, some of them with user defined types) I've managed to make the information aboutalloc2d
completely lost, which is the most unfortunate.The text was updated successfully, but these errors were encountered: