[Lldb-commits] [lldb] d610744 - [lldb] Speedup AppleObjCRuntimeV2 UpdateIfNeeded (#211774)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Jul 24 07:28:29 PDT 2026
Author: Felipe de Azevedo Piovezan
Date: 2026-07-24T15:28:24+01:00
New Revision: d610744c92b1edcf9330b2690cdb2e2053721a5f
URL: https://github.com/llvm/llvm-project/commit/d610744c92b1edcf9330b2690cdb2e2053721a5f
DIFF: https://github.com/llvm/llvm-project/commit/d610744c92b1edcf9330b2690cdb2e2053721a5f.diff
LOG: [lldb] Speedup AppleObjCRuntimeV2 UpdateIfNeeded (#211774)
This converts a loop calling Process::ReadMemory into a single call to
Process::ReadMemoryRanges.
Added:
Modified:
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index f1f71f7d7a451..79f7b4d82ba36 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -41,6 +41,7 @@
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
+#include "lldb/Utility/RangeMap.h"
#include "lldb/Utility/Scalar.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"
@@ -61,6 +62,7 @@
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/Sequence.h"
#include <cstdint>
#include <memory>
@@ -1819,23 +1821,35 @@ llvm::Error AppleObjCRuntimeV2::SharedCacheImageHeaders::UpdateIfNeeded() {
constexpr lldb::addr_t metadata_size =
sizeof(uint32_t) + sizeof(uint32_t); // count + entsize
- Status error;
+ /// Sanity check: m_count and m_entsize are external input, guard against
+ /// invalid values using an arbitrary 1GB maximum size.
+ const size_t memory_needed = static_cast<size_t>(m_count) * m_entsize;
+ if (memory_needed > 1024 * 1024 * 1024)
+ return llvm::createStringError(
+ "SharedCacheImageHeaders require too much memory");
+
const lldb::addr_t first_header_addr = m_headerInfoRWs_ptr + metadata_size;
- DataBufferHeap header_buffer(m_entsize, '\0');
- lldb::offset_t cursor = 0;
- for (uint32_t i = 0; i < m_count; i++) {
- const lldb::addr_t header_addr = first_header_addr + (i * m_entsize);
- process->ReadMemory(header_addr, header_buffer.GetBytes(), m_entsize,
- error);
- if (error.Fail())
+
+ llvm::SmallVector<Range<addr_t, size_t>> mem_ranges =
+ llvm::to_vector(llvm::map_range(llvm::seq(m_count), [&](uint32_t i) {
+ return Range<addr_t, size_t>(first_header_addr + (i * m_entsize),
+ m_entsize);
+ }));
+
+ llvm::SmallVector<uint8_t, 0> buffer(memory_needed, 0);
+ llvm::SmallVector<llvm::MutableArrayRef<uint8_t>> read_results =
+ process->ReadMemoryRanges(mem_ranges, buffer);
+
+ for (auto [i, header_data] : llvm::enumerate(read_results)) {
+ if (header_data.size() != m_entsize)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Failed to read memory from inferior when "
"populating SharedCacheImageHeaders");
- DataExtractor header_extractor(header_buffer.GetBytes(), m_entsize,
+ DataExtractor header_extractor(header_data.data(), m_entsize,
process->GetByteOrder(),
process->GetAddressByteSize());
- cursor = 0;
+ lldb::offset_t cursor = 0;
bool is_loaded = false;
if (m_entsize == 4) {
uint32_t header = header_extractor.GetU32_unchecked(&cursor);
More information about the lldb-commits
mailing list