-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Clang adds incorrect frame base information. #64390
Comments
@llvm/issue-subscribers-debuginfo |
Ping, has anyone been able to take a look at this? |
My understanding of this area is that LLVM sets the epilogue_begin flag on the 113d instruction, indicating that past that point the stack frame isn't valid, and then doesn't attempt to maintain variable location information past that point. There's a few different ways we could try to describe variable locations during frame-destruction, however I don't believe there's a strong motivation to pursue any because developers typically don't step on any instructions in the epilogue. Does gdb put a breakpoint on the "ret" instruction instead of "pop %rbp" if you try to put a breakpoint on on any of the lines in the function? |
The issue is not a breakpoint, but a software watchpoint. With the location as described (4 bytes off of %rbp), when the pop instruction happens, the value of the variable seems to change, because we start analysing a new area of memory. But also, the information that is being produces around the CFA is good enough, it just isn't used because in the DWARF information the CFA is never specified, instead it says that the location "4 bytes off of rbp" is valid for the whole block. that is, it sets |
I filed a similar issue a while back #49629. You can see in the comments that there was an attempt to use I'm going to close this as a duplicate (but I agree that it'd be good to get that fixed). |
Duplicate of #49629 |
I understand that this is blocked by #49629, but I don't think this is a duplicate. That issue refers to LLDB's inability to deal with the CFA, while this one talk about clang not referring back to it when producing a binary. IMHO, this issue should remain open until clang is doing that. |
The fix mentioned in #49629 (to the compiler) couldn't be applied due to issues with LLDB (because it caused LLDB tests to fail in strange ways). The linked ticket summary reports missing variable locations due to some compiler internal details, but the reason I thought to mark this ticket as duplicate is because the solution to that problem (mentioned in the first comment) is the same as what you're asking for: have the compiler emit
That said, #49629's fix has additional requirements, which may be unneeded additional work for your purposes. In addition, although unlikely and undesirable, the compiler issue mentioned ticket could technically be resolved in other ways. Re-opening, sorry for the additional noise! |
Ah, I get it, gdb breaks-in when something affects a variable location, which here includes rbp, The difficulty here is that (AFAIUI) we don't want to force all consumers to have to support an extra part of DWARF, i.e. loading
I think this is possible with the epilogue_begin flag, which is signalling where frame-based variable locations cease to be valid because we're destroying the frame. Regardless: LLVM does support producing CFA-based call frames, support was added in https://reviews.llvm.org/D143463, we just usually don't choose to describe stack variables with CFA. Perhaps we can adjust the |
Well, the point is to change when the value is changed, but if how GDB calculates the location is changed, it is likely (though not necessary) that the new location has a different value, so it is likely that GDB will think the value is changed, thus breaking.
Ah, yeah, that makes sense.
Oh, I haven't seen that flag anywhere so I imagined you were talking about something internal to clang. Where is that stored?
debugger-tuning sounds like a great option to work around the "forcing other consumers to support this" issue. I think this would be enough for me to close this bug, if it isn't stopped by those internal compiler problems that OCHyams mentioned. |
@Billionai Hi, I have the same problem as yours. |
@JunningWu I'm not familiar with the assembly you posted, but from what I can understand, it seems to be a different issue? It looks like you are stopping when the variable is being changed, but the line is being reported incorrectly. My issue is that the stack pointer being changed causes GDB to think the variable's value has been changed. If it is the same issue, I'm tying to add a workaround in GDB, that I expect to make it in for GDB 15, so it will work with it... it would just be better if |
Let me make it more clear.
I want to set one breakpoint to |
I see. I think I misread your original comment, then, sorry about that. That said, I don't think GDB should be worrying about CFA when you try to set a breakpoint on a given line, and I think there's something else different wrong, either with LLVM debug info or GDB's reading of it. To avoid spamming LLVM developers while we work this out, I'll email you so we can work on diagnosing what's up with this (or if I'm just missing something in GDB) |
Thanks a lot for reaching out.
This may be a common issue for RISC-V targets. I will dig into it, and
hopefully may get more useful information.
…On Fri, Dec 1, 2023 at 6:46 PM billionai ***@***.***> wrote:
I see. I think I misread your original comment, then, sorry about that.
That said, I don't think GDB should be worrying about CFA when you try to
set a breakpoint on a given line, and I think there's something else
different wrong, either with LLVM debug info or GDB's reading of it.
To avoid spamming LLVM developers while we work this out, I'll email you
so we can work on diagnosing what's up with this (or if I'm just missing
something in GDB)
—
Reply to this email directly, view it on GitHub
<#64390 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFTWZNGW35O2GG4HIIOBIDYHGYQJAVCNFSM6AAAAAA3C7X5XOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZVHA3TENZVG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
The following code:
when compiled with
clang -O0 -g3
gives the following debug information and assembly:As you can see, the CFA information regarding frame bases is completely correct and perfectly usable, but the DIE for the main function says that the frame information should be obtained from rbp.
This is a problem because when you set a watchpoint (at least in GDB with software watchpoints), when we reach instruction 113e, the difference in rbp makes it look like the variable was changed, because there's no way for the debugger to know that the frame base is no longer valid, and we get a spurious warning of a value change. GCC handles it by making the frame base be
DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
instead.The text was updated successfully, but these errors were encountered: