From 60d267acf1967f894530f1fbb7ae7c28b433e5cd Mon Sep 17 00:00:00 2001 From: ShengYi Hung Date: Sat, 11 Oct 2025 01:07:36 +0800 Subject: [PATCH] [LLDB, FreeBSD, x86] Fix empty register set when trying to get size of register info The register set information is stored as a singleton in GetRegisterInfo_i386. However, it is later use by other function which assume it stores in GetSharedRegisterInfoVector. Therefore, we copy the data to GetSharedRegisterInfoVector directly so that LLDB won't get panic. Also, reorder the header order and provide a test for debugging 32bit binary on 64bit platform. This test is just a copy paste from dummy-target.test but change the target as -m32. --- lldb/source/Host/freebsd/Host.cpp | 3 +-- .../Utility/RegisterContextFreeBSD_x86_64.cpp | 6 +++-- .../Breakpoint/debug_x86_over_amd64.test | 26 +++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 lldb/test/Shell/Breakpoint/debug_x86_over_amd64.test diff --git a/lldb/source/Host/freebsd/Host.cpp b/lldb/source/Host/freebsd/Host.cpp index fa7efad466bad..dfdbfea0c3c0a 100644 --- a/lldb/source/Host/freebsd/Host.cpp +++ b/lldb/source/Host/freebsd/Host.cpp @@ -18,8 +18,6 @@ #include #include -#include "llvm/Object/ELF.h" - #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" @@ -32,6 +30,7 @@ #include "lldb/Utility/Status.h" #include "lldb/Utility/StreamString.h" +#include "llvm/Object/ELF.h" #include "llvm/TargetParser/Host.h" namespace lldb_private { diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.cpp index e0f3971c6e272..b55a5c595d3ca 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.cpp @@ -76,8 +76,7 @@ static std::vector &GetSharedRegisterInfoVector() { static const RegisterInfo * GetRegisterInfo_i386(const lldb_private::ArchSpec &arch) { - static std::vector g_register_infos( - GetSharedRegisterInfoVector()); + static std::vector g_register_infos; // Allocate RegisterInfo only once if (g_register_infos.empty()) { @@ -93,6 +92,9 @@ GetRegisterInfo_i386(const lldb_private::ArchSpec &arch) { #define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS #include "RegisterInfos_x86_64.h" #undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS + std::vector &shared_regs = + GetSharedRegisterInfoVector(); + shared_regs = g_register_infos; } return &g_register_infos[0]; diff --git a/lldb/test/Shell/Breakpoint/debug_x86_over_amd64.test b/lldb/test/Shell/Breakpoint/debug_x86_over_amd64.test new file mode 100644 index 0000000000000..90d4748e5fa51 --- /dev/null +++ b/lldb/test/Shell/Breakpoint/debug_x86_over_amd64.test @@ -0,0 +1,26 @@ +# REQUIRES: target-x86_64 +# XFAIL: system-windows + +# RUN: mkdir -p %t +# RUN: cd %t +# RUN: %clang_host -m32 %p/Inputs/dummy-target.c -o dummy.out +# RUN: %lldb -b -s %s dummy.out | FileCheck %s + +breakpoint set -D -n main +# CHECK: Breakpoint {{[0-9]}}: no locations (pending). +# CHECK: Breakpoint set in dummy target + +breakpoint list +# CHECK: No breakpoints currently set + +breakpoint list -D +# CHECK: name = 'main', locations = 0 (pending) + +target delete +# CHECK: 1 targets deleted + +target create dummy.out +# CHECK: Current executable set to {{.*}}dummy.out + +breakpoint list +# CHECK: name = 'main', locations = {{[1-9]}}