[Lldb-commits] [lldb] [lldb][FreeBSDKernel] Supply values for CS/SS registers (PR #192207)

Minsoo Choo via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 15 01:18:53 PDT 2026


https://github.com/mchoo7 created https://github.com/llvm/llvm-project/pull/192207

These two values ensure that CPU was in kernel privilege at the time of crash. This change is from KGDB's `amd64fbsd-kern.c`.

>From deb506d5e68073c8e3ad9360bdb4c316dbc710cb Mon Sep 17 00:00:00 2001
From: Minsoo Choo <minsoochoo0122 at proton.me>
Date: Wed, 15 Apr 2026 17:05:31 +0900
Subject: [PATCH] [lldb][FreeBSDKernel] Supply values for CS/SS registers

Signed-off-by: Minsoo Choo <minsoochoo0122 at proton.me>
---
 .../RegisterContextFreeBSDKernelCore_x86_64.cpp       | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_x86_64.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_x86_64.cpp
index 8f833aa47e486..a0cb53526d331 100644
--- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_x86_64.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/RegisterContextFreeBSDKernelCore_x86_64.cpp
@@ -58,6 +58,9 @@ bool RegisterContextFreeBSDKernelCore_x86_64::ReadRegister(
     llvm::support::ulittle64_t rip;
   } pcb;
 
+  constexpr unsigned short CODE_SEL = 4 << 3;
+  constexpr unsigned short DATA_SEL = 5 << 3;
+
 #if defined(__FreeBSD__) && defined(__amd64__)
   static_assert(offsetof(struct pcb, pcb_r15) == offsetof(decltype(pcb), r15));
   static_assert(offsetof(struct pcb, pcb_r14) == offsetof(decltype(pcb), r14));
@@ -90,9 +93,13 @@ bool RegisterContextFreeBSDKernelCore_x86_64::ReadRegister(
     REG(rsp);
     REG(rbx);
     REG(rip);
-
 #undef REG
-
+  case lldb_cs_x86_64:
+    value.SetUInt(CODE_SEL, reg_info->byte_size);
+    break;
+  case lldb_ss_x86_64:
+    value.SetUInt(DATA_SEL, reg_info->byte_size);
+    break;
   default:
     return false;
   }



More information about the lldb-commits mailing list