[lldb][Process/FreeBSDKernel] Fix broken debugging on aarch64#180222
[lldb][Process/FreeBSDKernel] Fix broken debugging on aarch64#180222
Conversation
|
@llvm/pr-subscribers-lldb Author: Minsoo Choo (mchoo7) Changes
Full diff: https://github.com/llvm/llvm-project/pull/180222.diff 1 Files Affected:
diff --git a/lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp b/lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
index 11843ddc82d97..68944418b9a83 100644
--- a/lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
+++ b/lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
@@ -43,9 +43,10 @@ bool RegisterContextFreeBSDKernel_arm64::ReadRegister(
return false;
struct {
- llvm::support::ulittle64_t x[30];
- llvm::support::ulittle64_t lr;
- llvm::support::ulittle64_t _reserved;
+#define PCB_FP 10
+#define PCB_LR 11
+
+ llvm::support::ulittle64_t x[12];
llvm::support::ulittle64_t sp;
} pcb;
@@ -57,25 +58,6 @@ bool RegisterContextFreeBSDKernel_arm64::ReadRegister(
uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
switch (reg) {
- case gpr_x0_arm64:
- case gpr_x1_arm64:
- case gpr_x2_arm64:
- case gpr_x3_arm64:
- case gpr_x4_arm64:
- case gpr_x5_arm64:
- case gpr_x6_arm64:
- case gpr_x7_arm64:
- case gpr_x8_arm64:
- case gpr_x9_arm64:
- case gpr_x10_arm64:
- case gpr_x11_arm64:
- case gpr_x12_arm64:
- case gpr_x13_arm64:
- case gpr_x14_arm64:
- case gpr_x15_arm64:
- case gpr_x16_arm64:
- case gpr_x17_arm64:
- case gpr_x18_arm64:
case gpr_x19_arm64:
case gpr_x20_arm64:
case gpr_x21_arm64:
@@ -87,16 +69,19 @@ bool RegisterContextFreeBSDKernel_arm64::ReadRegister(
case gpr_x27_arm64:
case gpr_x28_arm64:
case gpr_fp_arm64:
- static_assert(gpr_fp_arm64 - gpr_x0_arm64 == 29,
+ static_assert(gpr_fp_arm64 - gpr_x19_arm64 == PCB_FP,
"nonconsecutive arm64 register numbers");
- value = pcb.x[reg - gpr_x0_arm64];
- break;
- case gpr_sp_arm64:
- value = pcb.sp;
+ value = pcb.x[reg - gpr_x19_arm64];
break;
+ case gpr_lr_arm64:
case gpr_pc_arm64:
// The pc of crashing thread is stored in lr.
- value = pcb.lr;
+ static_assert(gpr_lr_arm64 - gpr_x19_arm64 == PCB_LR,
+ "nonconsecutive arm64 register numbers");
+ value = pcb.x[reg - gpr_x19_arm64];
+ break;
+ case gpr_sp_arm64:
+ value = pcb.sp;
break;
default:
return false;
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
kevans91
left a comment
There was a problem hiding this comment.
This is fine, though I note that it might be nice to avoid breaking pre-14.0 kernel debugging? If for nothing else but to establish the infrastructure to grab a __FreeBSD_version from the target (if it doesn't exist) and use that for runtime compat. I realize that it's a tough sell with 13.5 going out of support in just a few short months, though.
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
Although dropping stable/13 support was approved #179587, @emaste approved because it was text-only approval (not actually breaking stable/13). This change definitely breaks stable/13 so I need approval from him again. |
If we can do so without too much work I think it's worth doing. That said, I'd much rather have 14.x+ fixed than have 13.x support, so I would be fine with this change going in and then adding 13.x backwards compat in a followup. |
I think it's better to add fixes for both post-14 and 13 in this PR and backport to LLVM 22. |
3a4317a to
746831a
Compare
|
@kevans91 could you test this on arm64? |
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
Sure, but probably won't have time until Monday at least. |
No problem. I'll get a dump from Ampere on Sunday. |
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.h
Outdated
Show resolved
Hide resolved
d5f1858 to
1f04ae0
Compare
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
|
@DavidSpickett This change is now tested natively on aarch64. I updated the PR description for results. |
|
Is this subject to last minute backporting for llvm 22? |
DavidSpickett
left a comment
There was a problem hiding this comment.
Is this subject to last minute backporting for llvm 22?
The final RC of 22 was just released so there is still time for a backport. This must be approved and known to not have caused problems, before a backport can happen.
For future reference the process for a backport is https://llvm.org/docs/GitHub.html#backporting.
This seems like a significant fix for lldb users, so I suggest including a release note in the backport. If the backport is rejected, then we can add said release note to main instead, in a separate PR.
As FreeBSD related people raised concerns here about the version handling (@kevans91), I want to see an approval from at least one of them, even if it's only on that topic.
I have left some comments but it's just style at this point. If a FreeBSD reviewer is happy with it, then I am.
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Show resolved
Hide resolved
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
Outdated
Show resolved
Hide resolved
DavidSpickett
left a comment
There was a problem hiding this comment.
LGTM but this can only be merged when there is also a FreeBSD approval.
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
| // The pc of crashing thread is stored in lr. | ||
| static_assert(gpr_lr_arm64 - gpr_x19_arm64 == PCB_LR, | ||
| "nonconsecutive arm64 register numbers"); | ||
| value = pcb.x[reg - gpr_x19_arm64]; |
There was a problem hiding this comment.
This does the wrong thing for gpr_pc_arm64, it's one past the end, so reads sp. Presumably this is meant to be always gpr_lr_arm64 - gpr_x19_arm64, i.e. PCB_LR?
…#183947) Since `pcb.lr` always contains the value of pc, `gpr_lr_arm64` should be unavailable. This also fixes the case where `gpr_pc_arm64` displays sp not lr field in pcb. Reported by: jrtc27 Fixes: 4f0eb3d (llvm#180222) --------- Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
…#183947) Since `pcb.lr` always contains the value of pc, `gpr_lr_arm64` should be unavailable. This also fixes the case where `gpr_pc_arm64` displays sp not lr field in pcb. Reported by: jrtc27 Fixes: 4f0eb3d (llvm#180222) --------- Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
struct pcbfor arm64 has changed In freebsd/freebsd-src@1c1f31a#diff-d07b4e228ca340857a90658e328d65f8dea9c5063e99197fbaaa046d97ae927c, which broke kernel debugging on AArch64. Add support for FreeBSD 14 and later by findingosreldate.Until FreeBSD 13 (previous
struct pcbcontained information for all registers):Since FreeBSD 14 (these are defined in the new
struct pcb):