From nobody Tue Dec 9 15:49:32 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dQjw14LRCz6KpJf for ; Tue, 09 Dec 2025 15:49:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dQjw13qC3z42rJ for ; Tue, 09 Dec 2025 15:49:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765295377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QZdK/VB+fOmt8Q7B13+EdAZWWxIAUh9tWX7EmaLh5nE=; b=vkcpVDVBmc3D4tFNcMLxdwe4vK8H7L2GZp95w2qWAK2qn++F3oC1MMGYZuiH65wiBJlQjD ZuVBE0+F9l1PVHEJ6momoY8qCCROCuHfNWAXL1cPZycxOcOljduKIXpXf3GKWKbJgj/TZX mZxYOazwmJuOVE46jZ6a2IWOp5g2O5ZS1/sXbCRWNmw/R6r1vdEy+6rXSEWjVZ8AzbcjOn FXe40YguIR/Ki7RGBXiGJd1VFRYeLx44uYzyIi9A14+kgB/BTOjnu9nVczrVLXTbmGAfBe U/HymZrRWDInEGpZ2B5VcaeWz9GwlHLdgB42WNijtre3GUbUOcZvWFq+pW/aOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765295377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QZdK/VB+fOmt8Q7B13+EdAZWWxIAUh9tWX7EmaLh5nE=; b=bF7kUdWmAfeRRpRw8pTumPT+hk8Xy1zr7h5Jvch2+yxF0pleKqp522T7uco0uORmN1QvaT QuvQOplYj6Bdq9jaVUxRrS0aK/LVPnwEy7uVJiFCJmYKfYVv+f8uzWMtr2ui4bmvS8G8a5 vDbNHPH/thoUm46heSUv74lVBiAVVon+qDije3bMKTgiGg9FoOBHXjO7g3or/ZbGwj3+oP YtRisCvP+Ptukj3KTT8mYhyxV4eX409l2eDazgENG5AnZug6geJR6/GqZxkOzi9KwNarfq 4/QGSbHpvaEA15A/t1bT6IHOghiyDu/pEprRTbDBGMNT8VTvqMFMz0ePp1he2w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765295377; a=rsa-sha256; cv=none; b=OAe568oOjBumfzJoJhTQ1PeH9IJ31muyx7n2iRbYXS29mw076NtzeUrvkELhpioK8NP982 iTBEhBvLweki32uQyhAWFC3+fwqJJKQsI0VsV3qWwhGdJ34g2p4fxaArAMTzO3waDHlujt lR8Jx928sFV+5dC3QT4NrbAwA1LfqHGpKP+NdKnjcdtlKd+NAODCeK9DPeQkolCczRdZmF mBtj6B7J1Fy5Hqh5ikkf+zBpm2KsEvig4jXPrQVJ14avmVu6aFFVFJUFOFap0o9AsTeUFo rNSrYrcXNrVV+J67UfNgBYZUCXvp8E9M3q8pvCJBV/ojZth55o3/zlQOthKS8A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dQjw12rn8z14Sn for ; Tue, 09 Dec 2025 15:49:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 333cd by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 09 Dec 2025 15:49:32 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: ShengYi Hung From: Ed Maste Subject: git: 87fdc35e5869 - stable/15 - lldb: Fix Architecture parsing by reading the ELF header. (#162811) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 87fdc35e586930d9782efee4c0217d5e19b9274a Auto-Submitted: auto-generated Date: Tue, 09 Dec 2025 15:49:32 +0000 Message-Id: <6938450c.333cd.691606d4@gitrepo.freebsd.org> The branch stable/15 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=87fdc35e586930d9782efee4c0217d5e19b9274a commit 87fdc35e586930d9782efee4c0217d5e19b9274a Author: ShengYi Hung AuthorDate: 2025-11-21 18:28:25 +0000 Commit: Ed Maste CommitDate: 2025-12-09 15:49:10 +0000 lldb: Fix Architecture parsing by reading the ELF header. (#162811) Currently, LLDB in FreeBSD host sets the Process Architecture used by lldbserver as Default one. Which cause problem when trying to debug a 32bit binary on amd64 platform since the lldb itself will found mismatch architecture with lldbserver's return. Notice that this patch is only a partial fix for the debugging problem. We are still unable to debug x86 on x86_64 so that we don't provide testcase in this patch. PR: 289945 Obtained from: llvm-project 394e7ded8b6bcff1382468b407ca620a2837f41b (cherry picked from commit fa1c56b3affaab7be6ece43070b36da2e75787cb) --- .../llvm-project/lldb/source/Host/freebsd/Host.cpp | 41 +++++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/contrib/llvm-project/lldb/source/Host/freebsd/Host.cpp b/contrib/llvm-project/lldb/source/Host/freebsd/Host.cpp index 110e803b3354..0778eb320dcf 100644 --- a/contrib/llvm-project/lldb/source/Host/freebsd/Host.cpp +++ b/contrib/llvm-project/lldb/source/Host/freebsd/Host.cpp @@ -14,12 +14,13 @@ #include #include -#include - #include #include #include +#include "llvm/Object/ELF.h" + +#include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" #include "lldb/Utility/DataBufferHeap.h" @@ -101,17 +102,33 @@ GetFreeBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr, proc_args.AppendArgument(llvm::StringRef(cstr)); } - return true; -} - -static bool GetFreeBSDProcessCPUType(ProcessInstanceInfo &process_info) { - if (process_info.ProcessIDIsValid()) { - process_info.GetArchitecture() = - HostInfo::GetArchitecture(HostInfo::eArchKindDefault); + auto buffer_sp = FileSystem::Instance().CreateDataBuffer(pathname, 0x20, 0); + if (!buffer_sp) { + process_info.Clear(); return true; } - process_info.GetArchitecture().Clear(); - return false; + uint8_t exe_class = + llvm::object::getElfArchType( + {reinterpret_cast(buffer_sp->GetBytes()), + size_t(buffer_sp->GetByteSize())}) + .first; + + switch (exe_class) { + case llvm::ELF::ELFCLASS32: + process_info.SetArchitecture( + HostInfo::GetArchitecture(HostInfo::eArchKind32)); + break; + case llvm::ELF::ELFCLASS64: + process_info.SetArchitecture( + HostInfo::GetArchitecture(HostInfo::eArchKind64)); + break; + case llvm::ELF::ELFCLASSNONE: + process_info.SetArchitecture( + HostInfo::GetArchitecture(HostInfo::eArchKindDefault)); + break; + } + + return true; } static bool GetFreeBSDProcessUserAndGroup(ProcessInstanceInfo &process_info) { @@ -218,7 +235,6 @@ uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info, // Make sure our info matches before we go fetch the name and cpu type if (match_info_noname.Matches(process_info) && GetFreeBSDProcessArgs(&match_info, process_info)) { - GetFreeBSDProcessCPUType(process_info); if (match_info.Matches(process_info)) process_infos.push_back(process_info); } @@ -232,7 +248,6 @@ bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) { if (GetFreeBSDProcessArgs(NULL, process_info)) { // should use libprocstat instead of going right into sysctl? - GetFreeBSDProcessCPUType(process_info); GetFreeBSDProcessUserAndGroup(process_info); return true; }