[lldb][Process/FreeBSDKernelCore] Fix RegisterContext for arm64#183947
[lldb][Process/FreeBSDKernelCore] Fix RegisterContext for arm64#183947
Conversation
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
|
@llvm/pr-subscribers-lldb Author: Minsoo Choo (mchoo7) ChangesThis commit address two issues with arm64 RegisterContext on FreeBSDKernelCore. Since LR in pcb structure stores LR for normal threads and PC for crashed thread, both Full diff: https://github.com/llvm/llvm-project/pull/183947.diff 1 Files Affected:
diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm64.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm64.cpp
index afd60a64a6365..442fa9b12460f 100644
--- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm64.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_arm64.cpp
@@ -101,7 +101,7 @@ bool RegisterContextFreeBSDKernelCore_arm64::ReadRegister(
// 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];
+ value = pcb.x[gpr_lr_arm64 - gpr_x19_arm64];
break;
case gpr_sp_arm64:
value = pcb.sp;
@@ -151,13 +151,14 @@ bool RegisterContextFreeBSDKernelCore_arm64::ReadRegister(
"nonconsecutive arm64 register numbers");
value = pcb13.x[reg - gpr_x0_arm64];
break;
- case gpr_sp_arm64:
- value = pcb13.sp;
- break;
+ case gpr_lr_arm64:
case gpr_pc_arm64:
// The pc of crashing thread is stored in lr.
value = pcb13.lr;
break;
+ case gpr_sp_arm64:
+ value = pcb13.sp;
+ break;
default:
return false;
}
|
This is a bit confusing given we expose LR as PC. Otherwise the diff itself looks good to me (I had also not noticed PC was missing for the <14 case). |
I thought thread crashed threads store their pc in |
They do, but that's not because they're different, it's to make them look the same as if it had called cpu_switch at that point in time. Really, pcb_lr is the PC, it's just that normally you get the PC calling cpu_switch and reading LR. To be honest, I'm not sure why we even return pcb_lr for LR, it's useless (like any other call-clobbered register, which isn't saved, and so we don't show), but I guess KGDB does that. |
I just verified that KGDB doesn't expose LR at all. I'll update the diff and description. |
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) lldb-apilldb-api.tools/lldb-dap/breakpoint/TestDAP_logpoints.pyIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
…#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>
Since
pcb.lralways contains the value of pc,gpr_lr_arm64should be unavailable. This also fixes the case wheregpr_pc_arm64displays sp not lr field in pcb.Reported by: jrtc27
Fixes: 4f0eb3d (#180222)