https://github.com/aokblast created
https://github.com/llvm/llvm-project/pull/195809
All native ELF process implementations (Linux, FreeBSD, NetBS) use
m_mem_region_cache to cache mmap regions. Move this cache object into the
generic ELF layer to eliminate duplication.
Also, implement DoStopIDBumped in the generic ELF layer, since all
implementations require flushing the cache on stop.
>From 14259a447a78432ee1a2b4fa2c00474c65c7edc5 Mon Sep 17 00:00:00 2001
From: ShengYi Hung <[email protected]>
Date: Mon, 4 May 2026 23:25:57 +0800
Subject: [PATCH 1/3] [LLDB][FreeBSD] Implement DoStopIDBumped on FreeBSD
When stopping, we should clear the mmap cache and repopulate all regions
to properly handle new mmap syscalls. Without this, binaries loaded via
dlopen or user-initiated mmap calls will not be recognized as valid
memory regions.
Fixes: https://github.com/llvm/llvm-project/issues/180445
---
.../Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp | 8 ++++++++
.../source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h | 2 ++
2 files changed, 10 insertions(+)
diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
index 46e9ac1cfd6fa..fc215d1bb7ef5 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
@@ -1089,3 +1089,11 @@ NativeProcessFreeBSD::SaveCore(llvm::StringRef
path_hint) {
"PT_COREDUMP not supported in the FreeBSD version used to build LLDB");
#endif
}
+
+void NativeProcessFreeBSD::DoStopIDBumped(uint32_t newBumpId) {
+ Log *log = GetLog(POSIXLog::Process);
+ LLDB_LOG(log, "newBumpId={0}", newBumpId);
+ LLDB_LOG(log, "clearing {0} entries from memory region cache",
+ m_mem_region_cache.size());
+ m_mem_region_cache.clear();
+}
diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
index fb7372817265d..46e1f6564d3fb 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
@@ -92,6 +92,8 @@ class NativeProcessFreeBSD : public NativeProcessELF,
llvm::Expected<std::string> SaveCore(llvm::StringRef path_hint) override;
+ void DoStopIDBumped(uint32_t newBumpId) override;
+
protected:
llvm::Expected<llvm::ArrayRef<uint8_t>>
GetSoftwareBreakpointTrapOpcode(size_t size_hint) override;
>From 0a9a4f0d0216bc9e924306b9085c8e14fe2176e7 Mon Sep 17 00:00:00 2001
From: ShengYi Hung <[email protected]>
Date: Tue, 5 May 2026 16:28:05 +0800
Subject: [PATCH 2/3] fixup! [LLDB][FreeBSD] Implement DoStopIDBumped on
FreeBSD
---
lldb/test/Shell/Breakpoint/Inputs/break_stepout.c | 2 ++
lldb/test/Shell/Breakpoint/step-out.test | 10 ++++++++++
2 files changed, 12 insertions(+)
create mode 100644 lldb/test/Shell/Breakpoint/Inputs/break_stepout.c
create mode 100644 lldb/test/Shell/Breakpoint/step-out.test
diff --git a/lldb/test/Shell/Breakpoint/Inputs/break_stepout.c
b/lldb/test/Shell/Breakpoint/Inputs/break_stepout.c
new file mode 100644
index 0000000000000..b7ae5db6e77bf
--- /dev/null
+++ b/lldb/test/Shell/Breakpoint/Inputs/break_stepout.c
@@ -0,0 +1,2 @@
+#include <stdio.h>
+int main() { printf("Hello World\n"); }
diff --git a/lldb/test/Shell/Breakpoint/step-out.test
b/lldb/test/Shell/Breakpoint/step-out.test
new file mode 100644
index 0000000000000..101dbe6eac1e7
--- /dev/null
+++ b/lldb/test/Shell/Breakpoint/step-out.test
@@ -0,0 +1,10 @@
+# RUN: cp %p/Inputs/break_stepout.c %t.c
+# RUN: %clang_host -g -o %t %t.c
+# RUN: rm %t.c
+# RUN: %lldb -b -o "br set -n vfprintf" -o run -o "thread step-out" -o "thread
step-out" %t 2>&1 | FileCheck %s
+
+## Check if we step-out twice sucessfully
+
+CHECK: stop reason = step out
+CHECK: stop reason = step out
+
>From f9332d8cf8d520bb6f97ffcd81cb9ba3d1b86906 Mon Sep 17 00:00:00 2001
From: ShengYi Hung <[email protected]>
Date: Tue, 5 May 2026 16:49:50 +0800
Subject: [PATCH 3/3] [LLDB][PosixELF] Move m_mem_region_cache to generic ELF
layer
All native ELF process implementations (Linux, FreeBSD, NetBS) use
m_mem_region_cache to cache mmap regions. Move this cache object into
the generic ELF layer to eliminate duplication.
Also, implement DoStopIDBumped in the generic ELF layer, since all
implementations require flushing the cache on stop.
---
.../Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp | 8 --------
.../source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h | 3 ---
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp | 8 --------
lldb/source/Plugins/Process/Linux/NativeProcessLinux.h | 3 ---
lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h | 1 -
lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp | 8 ++++++++
lldb/source/Plugins/Process/POSIX/NativeProcessELF.h | 4 ++++
7 files changed, 12 insertions(+), 23 deletions(-)
diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
index fc215d1bb7ef5..46e9ac1cfd6fa 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
@@ -1089,11 +1089,3 @@ NativeProcessFreeBSD::SaveCore(llvm::StringRef
path_hint) {
"PT_COREDUMP not supported in the FreeBSD version used to build LLDB");
#endif
}
-
-void NativeProcessFreeBSD::DoStopIDBumped(uint32_t newBumpId) {
- Log *log = GetLog(POSIXLog::Process);
- LLDB_LOG(log, "newBumpId={0}", newBumpId);
- LLDB_LOG(log, "clearing {0} entries from memory region cache",
- m_mem_region_cache.size());
- m_mem_region_cache.clear();
-}
diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
index 46e1f6564d3fb..4a3da9e987e3c 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
@@ -92,8 +92,6 @@ class NativeProcessFreeBSD : public NativeProcessELF,
llvm::Expected<std::string> SaveCore(llvm::StringRef path_hint) override;
- void DoStopIDBumped(uint32_t newBumpId) override;
-
protected:
llvm::Expected<llvm::ArrayRef<uint8_t>>
GetSoftwareBreakpointTrapOpcode(size_t size_hint) override;
@@ -103,7 +101,6 @@ class NativeProcessFreeBSD : public NativeProcessELF,
ArchSpec m_arch;
MainLoop &m_main_loop;
LazyBool m_supports_mem_region = eLazyBoolCalculate;
- std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
// Private Instance Methods
NativeProcessFreeBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 2dabae4eb8d3d..1ad57bd0c19e1 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -1313,14 +1313,6 @@ Status NativeProcessLinux::PopulateMemoryRegionCache() {
return Status();
}
-void NativeProcessLinux::DoStopIDBumped(uint32_t newBumpId) {
- Log *log = GetLog(POSIXLog::Process);
- LLDB_LOG(log, "newBumpId={0}", newBumpId);
- LLDB_LOG(log, "clearing {0} entries from memory region cache",
- m_mem_region_cache.size());
- m_mem_region_cache.clear();
-}
-
llvm::Expected<uint64_t>
NativeProcessLinux::Syscall(llvm::ArrayRef<uint64_t> args) {
PopulateMemoryRegionCache();
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
index d345f165a75d8..936d690e42ae7 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -122,8 +122,6 @@ class NativeProcessLinux : public NativeProcessELF,
Status RemoveBreakpoint(lldb::addr_t addr, bool hardware = false) override;
- void DoStopIDBumped(uint32_t newBumpId) override;
-
Status GetLoadedModuleFileSpec(const char *module_path,
FileSpec &file_spec) override;
@@ -177,7 +175,6 @@ class NativeProcessLinux : public NativeProcessELF,
ArchSpec m_arch;
LazyBool m_supports_mem_region = eLazyBoolCalculate;
- std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
lldb::tid_t m_pending_notification_tid = LLDB_INVALID_THREAD_ID;
diff --git a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
index f3d07651384fe..976d48e74854e 100644
--- a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+++ b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -97,7 +97,6 @@ class NativeProcessNetBSD : public NativeProcessELF {
ArchSpec m_arch;
MainLoop& m_main_loop;
LazyBool m_supports_mem_region = eLazyBoolCalculate;
- std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
// Private Instance Methods
NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
diff --git a/lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp
b/lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp
index 23e94a5f55e21..29aaf4752d57a 100644
--- a/lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp
+++ b/lldb/source/Plugins/Process/POSIX/NativeProcessELF.cpp
@@ -186,4 +186,12 @@ void NativeProcessELF::NotifyDidExec() {
m_shared_library_info_addr.reset();
}
+void NativeProcessELF::DoStopIDBumped(uint32_t newBumpId) {
+ Log *log = GetLog(POSIXLog::Process);
+ LLDB_LOG(log, "newBumpId={0}", newBumpId);
+ LLDB_LOG(log, "clearing {0} entries from memory region cache",
+ m_mem_region_cache.size());
+ m_mem_region_cache.clear();
+}
+
} // namespace lldb_private
diff --git a/lldb/source/Plugins/Process/POSIX/NativeProcessELF.h
b/lldb/source/Plugins/Process/POSIX/NativeProcessELF.h
index 937def94436be..b5a9a26b4ea8d 100644
--- a/lldb/source/Plugins/Process/POSIX/NativeProcessELF.h
+++ b/lldb/source/Plugins/Process/POSIX/NativeProcessELF.h
@@ -9,8 +9,10 @@
#ifndef liblldb_NativeProcessELF_H_
#define liblldb_NativeProcessELF_H_
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "Plugins/Process/Utility/AuxVector.h"
#include "lldb/Host/common/NativeProcessProtocol.h"
+#include "lldb/Target/MemoryRegionInfo.h"
#include "llvm/BinaryFormat/ELF.h"
#include <optional>
@@ -24,6 +26,7 @@ class NativeProcessELF : public NativeProcessProtocol {
public:
std::optional<uint64_t> GetAuxValue(enum AuxVector::EntryType type);
+ void DoStopIDBumped(uint32_t newBumpId) override;
protected:
template <typename T> struct ELFLinkMap {
@@ -50,6 +53,7 @@ class NativeProcessELF : public NativeProcessProtocol {
std::unique_ptr<AuxVector> m_aux_vector;
std::optional<lldb::addr_t> m_shared_library_info_addr;
+ std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
};
// Explicitly declare the two 32/64 bit templates that NativeProcessELF.cpp
will
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits