From nobody Sun Nov 23 17:50:21 2025 X-Original-To: dev-commits-src-main@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 4dDxLk1LXtz6HNjM for ; Sun, 23 Nov 2025 17:50:22 +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 4dDxLk0jFjz3J5N for ; Sun, 23 Nov 2025 17:50:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763920222; 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=eANX/OukS8R6BxmjJPma+nCre+EE7XXsjj3UQZ0GuN8=; b=mtaIZP8BS4dU6jiERymgY6FgOs43X96RXjPphTLxq7BYgeaz3W31wLdXRcmwUmVUanAiJW IaVFNPWIaJv8zbrXFq5JCBT1u3IKCTFk1zjnyk//OG+4WPlwfEUnTAAcaS7T6o9qXulRg7 qVgpOVUAom/srlJ1FSyFbQ9WUUSobjkyQIHHQuR4JgYUfSfe/sAkiTYPDydQR4EnVjD6eP I/g3aHuNlwEXOHaf2y/rmIv5ujWlVCWp+4FHbhjgCIpdeqXhYoiWb0zZHGGGoriX3yk6t2 0FnfqupvDwrUUE91bRD2V8L7yIha7GorW87TFTmsurEmS+zlDd5Ofkl+hFdZVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763920222; 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=eANX/OukS8R6BxmjJPma+nCre+EE7XXsjj3UQZ0GuN8=; b=m5GQpTe95Yp2k63ciGKHsVExqRvIXC3JCNVvVjS6xDerzPlCGf9NZfysiclfsY6RdyCZlN 22jGby8IeecHTcw/MlxXE9wH4v7I0KIVR0LCov1q11huLfBArz3/wScFAAWfZiij7EqwTs 6ImzUuqWUntNeeXC+BptNmweZvHeHVzyUooZnKAyug0Rp+GAk4my+neGefTM2iO8V+YLb1 N9HuhOftex+rubt1/cXhbXm6HQOVcbOJt+7effvoy2WOlLO6NyMTXaYtnCZeF7sD02oY6X eJIWB5P/azkaQ53s9i5Kl3VSXbkAfsQOqkFqPvmqUQZAV4mXFpIQqmrRNknyhg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763920222; a=rsa-sha256; cv=none; b=d/QqRcKL5+pJBNY4QIospf2tCYBP5qj3ZuKu8uquYo7E8EiQz6YqZW08kufmGB919hiPu9 ZksKdqHCSLwdxuAQCiINK5cCbeCe5buZi2elkooViIzQGZX/E1tE/4/3zZCmzvibanxU/W /uVKKAk7FILTu9UcVsQ7ykNFRDIqnL7lKoMzP1QDR1dAEJcGRt94hig83JDsoYEkoGDDMJ qEgmFvYWTtrfNra7+URM4qVXmFapMuZlYQL8BwEISHG0oDesvKmaMojT5FPf6EVVNfRWmw 1VLptxdZBSkjoaxIpvYikHD2Tzu2AsIIZ6QQtNNvqvf0oJfWWFjh3h/mz2oQmA== 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 4dDxLj71kMzfGW for ; Sun, 23 Nov 2025 17:50:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id e0f0 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 23 Nov 2025 17:50:21 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: ShengYi Hung From: Ed Maste Subject: git: fa1c56b3affa - main - lldb: Fix Architecture parsing by reading the ELF header. (#162811) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: fa1c56b3affaab7be6ece43070b36da2e75787cb Auto-Submitted: auto-generated Date: Sun, 23 Nov 2025 17:50:21 +0000 Message-Id: <6923495d.e0f0.40fefec9@gitrepo.freebsd.org> The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=fa1c56b3affaab7be6ece43070b36da2e75787cb commit fa1c56b3affaab7be6ece43070b36da2e75787cb Author: ShengYi Hung AuthorDate: 2025-11-21 18:28:25 +0000 Commit: Ed Maste CommitDate: 2025-11-23 17:49:51 +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 --- .../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; }