From nobody Tue Dec 9 15:52:54 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 4dQjzw4ZCwz6KpSh for ; Tue, 09 Dec 2025 15:53:00 +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 4dQjzw1zZYz444K for ; Tue, 09 Dec 2025 15:53:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765295580; 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=m0bmDatfToix1HSDtcB4eZCwOQnub6xaL+SeY6ie8Yk=; b=TQd+wq4h9w1uCnsJi9zfPBdxpyLM5quqEWgLGzBXGATu/8mkjSHsT5W7XRs/Yiy82Aizye YZNO+nyxfc2CIPTZNrZmpYKDmWjvWPVff9ASNw/98hy5eRUHhiLFXozVhG8lVjX7SJn1sC CvsdxK5lOZt+6wbbYbkeARfdE4zTt3ATXtzAJDeVKqDogne9SCM+2Sx4u2/MEXLvUCsHUY bKZVe0NyKW6hZhkvTS5CAhf05IHpr75IiOVzLDlQlpK3slxaX+BX045KrESCKSQH6jyCOF 1FnMHlbTtPTcIonenT0tmoTA70O5fjUVl1OFWDgOzV6ZQcCsRIYtOqNiij3axA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765295580; 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=m0bmDatfToix1HSDtcB4eZCwOQnub6xaL+SeY6ie8Yk=; b=qD5oesXjWCrZjmUpBjFTsXmvA7g+qjcBrSq2tbgiFebJP2Tdc0eS2dZRGasevLumS/OlAT /wNd+AdxzKHZoFTaT3XGnFugH2CYnO6yky4lMVz/IL/+VarrRA8idT7BkmEMNtHUkkG5qX 5mucGMBQwBjPQnW2uNYR2TtHlOsyf5dCxYYN5RmgaaL9Vns+ZLwWUKe9PgwiWfB05kaoGQ iU1Ekx4bzt3l7KpkELrwVSANo/OG4MwvzjDloMGnQYiR7TJXR/xxW3o6G3LElFGuIOHVIn FHN55bvR9+hqfFjQZ1pP94mAbxstGez9WxAI2pNwHSoX9B+L+2H6jdddi6rAhg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765295580; a=rsa-sha256; cv=none; b=lqL/+mW8FcIFmVd5R2MmhiSSowrHD8Q3m5iNI6FJL/HjqNh1B4F+/12NnCDbNk3z+Dj/AU vE2ZltwP0MJWwx80gPNOHBcnrsdSrzT/iims2RRl+dhS36DeuyW9mgGOU0sKcrdFLhxhkJ EWExnGVtY50es4TBIEb+DbcVk+VQMqge2BXhxHM7I044V0DcHt/fDeU6oG12Iw94rEYSiF l9QEuGFrdFrm8OD5nTjNxTE9g255j64R5qB2wKDI9SN+bMolJ2+/ITT92TlMDtIrK/McTC uKoCXi3KXrehjPAElrCGH65Y0r8oMBAjCtJh0MBTWgddeLalO3TN9aJs9KhzxQ== 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 4dQjzw0SQ7z14q0 for ; Tue, 09 Dec 2025 15:53:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 350a9 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 09 Dec 2025 15:52:54 +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: 58be4610c91f - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 58be4610c91f4ed1a6c29482ca555b2798f70b05 Auto-Submitted: auto-generated Date: Tue, 09 Dec 2025 15:52:54 +0000 Message-Id: <693845d6.350a9.68fe41f2@gitrepo.freebsd.org> The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=58be4610c91f4ed1a6c29482ca555b2798f70b05 commit 58be4610c91f4ed1a6c29482ca555b2798f70b05 Author: ShengYi Hung AuthorDate: 2025-11-21 18:28:25 +0000 Commit: Ed Maste CommitDate: 2025-12-09 15:52:31 +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) (cherry picked from commit 87fdc35e586930d9782efee4c0217d5e19b9274a) --- .../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; }