[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)
Miro Bucko via lldb-commits
lldb-commits at lists.llvm.org
Wed Jun 12 09:05:39 PDT 2024
================
@@ -810,6 +809,65 @@ const char *SBProcess::GetBroadcasterClass() {
return ConstString(Process::GetStaticBroadcasterClass()).AsCString();
}
+lldb::SBAddressRangeList
+SBProcess::FindRangesInMemory(const void *buf, uint64_t size,
+ SBAddressRangeList &ranges, uint32_t alignment,
+ uint32_t max_matches, SBError &error) {
+ LLDB_INSTRUMENT_VA(this, buf, size, ranges, alignment, max_matches, error);
+
+ Log *log = GetLog(LLDBLog::Process);
+ lldb::SBAddressRangeList matches;
+
+ ProcessSP process_sp(GetSP());
+ if (!process_sp) {
+ LLDB_LOGF(log, "SBProcess::%s SBProcess is invalid.", __FUNCTION__);
+ return matches;
+ }
+ Process::StopLocker stop_locker;
+ if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
+ LLDB_LOGF(
+ log,
+ "SBProcess::%s Cannot find process in memory while process is running.",
+ __FUNCTION__);
+ return matches;
+ }
+ std::lock_guard<std::recursive_mutex> guard(
+ process_sp->GetTarget().GetAPIMutex());
+ matches.m_opaque_up->ref() = process_sp->FindRangesInMemory(
+ reinterpret_cast<const uint8_t *>(buf), size, ranges.m_opaque_up->ref(),
+ alignment, max_matches, error.ref());
+ return matches;
+}
+
+lldb::addr_t SBProcess::FindInMemory(const void *buf, uint64_t size,
+ SBAddressRange &range, uint32_t alignment,
+ SBError &error) {
+ LLDB_INSTRUMENT_VA(this, buf, size, range, alignment, error);
+
+ if (!range.IsValid()) {
+ error.SetErrorStringWithFormat("range is invalid");
+ return LLDB_INVALID_ADDRESS;
+ }
+
----------------
mbucko wrote:
I'm calling `*range.m_opaque_up` further down so I left this check here
https://github.com/llvm/llvm-project/pull/95007
More information about the lldb-commits
mailing list