1414#include " lldb/lldb-defines.h"
1515#include " lldb/lldb-types.h"
1616
17+ #include " lldb/Core/AddressRangeListImpl.h"
1718#include " lldb/Core/Debugger.h"
1819#include " lldb/Core/Module.h"
1920#include " lldb/Core/PluginManager.h"
2627#include " lldb/Target/Target.h"
2728#include " lldb/Target/Thread.h"
2829#include " lldb/Utility/Args.h"
30+ #include " lldb/Utility/LLDBLog.h"
2931#include " lldb/Utility/ProcessInfo.h"
3032#include " lldb/Utility/State.h"
3133#include " lldb/Utility/Stream.h"
@@ -320,8 +322,8 @@ void SBProcess::ReportEventState(const SBEvent &event, FileSP out) const {
320322 if (process_sp) {
321323 StreamFile stream (out);
322324 const StateType event_state = SBProcess::GetStateFromEvent (event);
323- stream.Printf (" Process %" PRIu64 " %s\n " ,
324- process_sp-> GetID (), SBDebugger::StateAsCString (event_state));
325+ stream.Printf (" Process %" PRIu64 " %s\n " , process_sp-> GetID (),
326+ SBDebugger::StateAsCString (event_state));
325327 }
326328}
327329
@@ -378,7 +380,6 @@ bool SBProcess::SetSelectedThreadByIndexID(uint32_t index_id) {
378380 ret_val = process_sp->GetThreadList ().SetSelectedThreadByIndexID (index_id);
379381 }
380382
381-
382383 return ret_val;
383384}
384385
@@ -546,7 +547,6 @@ ByteOrder SBProcess::GetByteOrder() const {
546547 if (process_sp)
547548 byteOrder = process_sp->GetTarget ().GetArchitecture ().GetByteOrder ();
548549
549-
550550 return byteOrder;
551551}
552552
@@ -558,7 +558,6 @@ uint32_t SBProcess::GetAddressByteSize() const {
558558 if (process_sp)
559559 size = process_sp->GetTarget ().GetArchitecture ().GetAddressByteSize ();
560560
561-
562561 return size;
563562}
564563
@@ -810,6 +809,55 @@ const char *SBProcess::GetBroadcasterClass() {
810809 return ConstString (Process::GetStaticBroadcasterClass ()).AsCString ();
811810}
812811
812+ lldb::SBAddressRangeList SBProcess::FindRangesInMemory (
813+ const void *buf, uint64_t size, const SBAddressRangeList &ranges,
814+ uint32_t alignment, uint32_t max_matches, SBError &error) {
815+ LLDB_INSTRUMENT_VA (this , buf, size, ranges, alignment, max_matches, error);
816+
817+ lldb::SBAddressRangeList matches;
818+
819+ ProcessSP process_sp (GetSP ());
820+ if (!process_sp) {
821+ error.SetErrorString (" SBProcess is invalid" );
822+ return matches;
823+ }
824+ Process::StopLocker stop_locker;
825+ if (!stop_locker.TryLock (&process_sp->GetRunLock ())) {
826+ error.SetErrorString (" process is running" );
827+ return matches;
828+ }
829+ std::lock_guard<std::recursive_mutex> guard (
830+ process_sp->GetTarget ().GetAPIMutex ());
831+ matches.m_opaque_up ->ref () = process_sp->FindRangesInMemory (
832+ reinterpret_cast <const uint8_t *>(buf), size, ranges.ref ().ref (),
833+ alignment, max_matches, error.ref ());
834+ return matches;
835+ }
836+
837+ lldb::addr_t SBProcess::FindInMemory (const void *buf, uint64_t size,
838+ const SBAddressRange &range,
839+ uint32_t alignment, SBError &error) {
840+ LLDB_INSTRUMENT_VA (this , buf, size, range, alignment, error);
841+
842+ ProcessSP process_sp (GetSP ());
843+
844+ if (!process_sp) {
845+ error.SetErrorString (" SBProcess is invalid" );
846+ return LLDB_INVALID_ADDRESS;
847+ }
848+
849+ Process::StopLocker stop_locker;
850+ if (!stop_locker.TryLock (&process_sp->GetRunLock ())) {
851+ error.SetErrorString (" process is running" );
852+ return LLDB_INVALID_ADDRESS;
853+ }
854+
855+ std::lock_guard<std::recursive_mutex> guard (
856+ process_sp->GetTarget ().GetAPIMutex ());
857+ return process_sp->FindInMemory (reinterpret_cast <const uint8_t *>(buf), size,
858+ range.ref (), alignment, error.ref ());
859+ }
860+
813861size_t SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len,
814862 SBError &sb_error) {
815863 LLDB_INSTRUMENT_VA (this , addr, dst, dst_len, sb_error);
0 commit comments