[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-21 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From ad93faf460e37bd717dc0ab9070af774c24b1ade Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   4 +
 lldb/include/lldb/Target/Process.h|  14 ++
 lldb/source/API/SBProcess.cpp |  58 -
 lldb/source/Target/Process.cpp| 123 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 131 +++
 .../find_in_memory/TestFindRangesInMemory.py  | 221 ++
 .../find_in_memory/address_ranges_helper.py   |  73 ++
 .../API/python_api/find_in_memory/main.cpp|  27 +++
 11 files changed, 661 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..ceaf547ebddaf 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_matches,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,11 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  virtual void 

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-21 Thread Miro Bucko via lldb-commits


@@ -2007,6 +2007,135 @@ size_t Process::ReadMemory(addr_t addr, void *buf, 
size_t size, Status ) {
   }
 }
 
+void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+ const uint8_t *buf, size_t size,
+ AddressRanges , size_t alignment,
+ size_t max_matches) {
+  // Inputs are already validated in FindInMemory() functions.
+  assert(buf != nullptr);
+  assert(size > 0);
+  assert(alignment > 0);
+  assert(max_matches > 0);
+  assert(start_addr != LLDB_INVALID_ADDRESS);
+  assert(end_addr != LLDB_INVALID_ADDRESS);
+  assert(start_addr < end_addr);
+
+  lldb::addr_t start = start_addr;
+  if (alignment > 1) {
+// Align to an address alignment boundary
+const uint64_t align_offset = start % alignment;
+if (align_offset > 0)
+  start += alignment - align_offset;
+  }

mbucko wrote:

nice!

https://github.com/llvm/llvm-project/pull/95007
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-21 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 26e19d848937564ae74cf9c42e2ee51a224c3133 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   4 +
 lldb/include/lldb/Target/Process.h|  14 ++
 lldb/source/API/SBProcess.cpp |  58 -
 lldb/source/Target/Process.cpp| 129 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 131 +++
 .../find_in_memory/TestFindRangesInMemory.py  | 221 ++
 .../find_in_memory/address_ranges_helper.py   |  73 ++
 .../API/python_api/find_in_memory/main.cpp|  27 +++
 11 files changed, 667 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..ceaf547ebddaf 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_matches,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,11 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  virtual void 

[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)

2024-06-21 Thread Miro Bucko via lldb-commits

https://github.com/mbucko closed https://github.com/llvm/llvm-project/pull/95997
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)

2024-06-20 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95997

>From 3ba6a550cb4731b9754646665e18fcdc6e255bd4 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 18 Jun 2024 14:35:55 -0700
Subject: [PATCH] [lldb] Fix SBAddressRange validation checks.

---
 lldb/include/lldb/API/SBAddressRange.h|  6 
 lldb/include/lldb/API/SBAddressRangeList.h|  2 ++
 lldb/source/API/SBAddressRange.cpp| 29 +++
 lldb/source/API/SBAddressRangeList.cpp| 17 +++
 .../address_range/TestAddressRange.py |  2 +-
 5 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/lldb/include/lldb/API/SBAddressRange.h 
b/lldb/include/lldb/API/SBAddressRange.h
index 152bd82426af1..5c4d6b8c5683d 100644
--- a/lldb/include/lldb/API/SBAddressRange.h
+++ b/lldb/include/lldb/API/SBAddressRange.h
@@ -11,6 +11,10 @@
 
 #include "lldb/API/SBDefines.h"
 
+namespace lldb_private {
+class AddressRange;
+}
+
 namespace lldb {
 
 class LLDB_API SBAddressRange {
@@ -58,6 +62,8 @@ class LLDB_API SBAddressRange {
   friend class SBFunction;
   friend class SBProcess;
 
+  lldb_private::AddressRange () const;
+
   AddressRangeUP m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBAddressRangeList.h 
b/lldb/include/lldb/API/SBAddressRangeList.h
index a123287ef1b4f..5a4eeecf37dc9 100644
--- a/lldb/include/lldb/API/SBAddressRangeList.h
+++ b/lldb/include/lldb/API/SBAddressRangeList.h
@@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
   friend class SBBlock;
   friend class SBProcess;
 
+  lldb_private::AddressRangeListImpl () const;
+
   std::unique_ptr m_opaque_up;
 };
 
diff --git a/lldb/source/API/SBAddressRange.cpp 
b/lldb/source/API/SBAddressRange.cpp
index 9b1affdade439..5834ebe5e63c0 100644
--- a/lldb/source/API/SBAddressRange.cpp
+++ b/lldb/source/API/SBAddressRange.cpp
@@ -50,9 +50,7 @@ const SBAddressRange ::operator=(const 
SBAddressRange ) {
 bool SBAddressRange::operator==(const SBAddressRange ) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
-  if (!IsValid() || !rhs.IsValid())
-return false;
-  return m_opaque_up->operator==(*(rhs.m_opaque_up));
+  return ref().operator==(rhs.ref());
 }
 
 bool SBAddressRange::operator!=(const SBAddressRange ) {
@@ -64,40 +62,35 @@ bool SBAddressRange::operator!=(const SBAddressRange ) {
 void SBAddressRange::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
-  m_opaque_up.reset();
+  ref().Clear();
 }
 
 bool SBAddressRange::IsValid() const {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up && m_opaque_up->IsValid();
+  return ref().IsValid();
 }
 
 lldb::SBAddress SBAddressRange::GetBaseAddress() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return lldb::SBAddress();
-  return lldb::SBAddress(m_opaque_up->GetBaseAddress());
+  return lldb::SBAddress(ref().GetBaseAddress());
 }
 
 lldb::addr_t SBAddressRange::GetByteSize() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return 0;
-  return m_opaque_up->GetByteSize();
+  return ref().GetByteSize();
 }
 
 bool SBAddressRange::GetDescription(SBStream ,
 const SBTarget target) {
   LLDB_INSTRUMENT_VA(this, description, target);
 
-  Stream  = description.ref();
-  if (!IsValid()) {
-stream << "";
-return true;
-  }
-  m_opaque_up->GetDescription(, target.GetSP().get());
-  return true;
+  return ref().GetDescription((), target.GetSP().get());
+}
+
+lldb_private::AddressRange ::ref() const {
+  assert(m_opaque_up && "opaque pointer must always be valid");
+  return *m_opaque_up;
 }
diff --git a/lldb/source/API/SBAddressRangeList.cpp 
b/lldb/source/API/SBAddressRangeList.cpp
index 20660b3ff2088..957155d5125ef 100644
--- a/lldb/source/API/SBAddressRangeList.cpp
+++ b/lldb/source/API/SBAddressRangeList.cpp
@@ -37,40 +37,40 @@ SBAddressRangeList::operator=(const SBAddressRangeList 
) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
   if (this != )
-*m_opaque_up = *rhs.m_opaque_up;
+ref() = rhs.ref();
   return *this;
 }
 
 uint32_t SBAddressRangeList::GetSize() const {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up->GetSize();
+  return ref().GetSize();
 }
 
 SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
   LLDB_INSTRUMENT_VA(this, idx);
 
   SBAddressRange sb_addr_range;
-  (*sb_addr_range.m_opaque_up) = m_opaque_up->GetAddressRangeAtIndex(idx);
+  (*sb_addr_range.m_opaque_up) = ref().GetAddressRangeAtIndex(idx);
   return sb_addr_range;
 }
 
 void SBAddressRangeList::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
-  m_opaque_up->Clear();
+  ref().Clear();
 }
 
 void SBAddressRangeList::Append(const SBAddressRange _addr_range) {
   LLDB_INSTRUMENT_VA(this, sb_addr_range);
 
-  m_opaque_up->Append(*sb_addr_range.m_opaque_up);
+  ref().Append(*sb_addr_range.m_opaque_up);
 }
 
 void SBAddressRangeList::Append(const SBAddressRangeList _addr_range_list) {
   LLDB_INSTRUMENT_VA(this, sb_addr_range_list);
 
-  m_opaque_up->Append(*sb_addr_range_list.m_opaque_up);
+  

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-20 Thread Miro Bucko via lldb-commits


@@ -64,7 +64,7 @@ bool SBAddressRange::operator!=(const SBAddressRange ) {
 void SBAddressRange::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
-  m_opaque_up.reset();
+  m_opaque_up->Clear();

mbucko wrote:

correct

https://github.com/llvm/llvm-project/pull/95007
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-20 Thread Miro Bucko via lldb-commits


@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges ,
+  size_t alignment, size_t max_matches);
+

mbucko wrote:

Yeah possibly the FindRangesInMemory too. I was going to add that later once I 
know exactly how I'm going to override these.

https://github.com/llvm/llvm-project/pull/95007
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)

2024-06-20 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95997

>From ca4dcf373b0617ab588ee804e3d28f8d311da06a Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 18 Jun 2024 14:35:55 -0700
Subject: [PATCH] [lldb] Fix SBAddressRange validation checks.

---
 lldb/include/lldb/API/SBAddressRange.h|  6 
 lldb/include/lldb/API/SBAddressRangeList.h|  2 ++
 lldb/source/API/SBAddressRange.cpp| 29 +++
 lldb/source/API/SBAddressRangeList.cpp| 17 +++
 .../address_range/TestAddressRange.py |  2 +-
 5 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/lldb/include/lldb/API/SBAddressRange.h 
b/lldb/include/lldb/API/SBAddressRange.h
index 152bd82426af1..5c4d6b8c5683d 100644
--- a/lldb/include/lldb/API/SBAddressRange.h
+++ b/lldb/include/lldb/API/SBAddressRange.h
@@ -11,6 +11,10 @@
 
 #include "lldb/API/SBDefines.h"
 
+namespace lldb_private {
+class AddressRange;
+}
+
 namespace lldb {
 
 class LLDB_API SBAddressRange {
@@ -58,6 +62,8 @@ class LLDB_API SBAddressRange {
   friend class SBFunction;
   friend class SBProcess;
 
+  lldb_private::AddressRange () const;
+
   AddressRangeUP m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBAddressRangeList.h 
b/lldb/include/lldb/API/SBAddressRangeList.h
index a123287ef1b4f..5a4eeecf37dc9 100644
--- a/lldb/include/lldb/API/SBAddressRangeList.h
+++ b/lldb/include/lldb/API/SBAddressRangeList.h
@@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
   friend class SBBlock;
   friend class SBProcess;
 
+  lldb_private::AddressRangeListImpl () const;
+
   std::unique_ptr m_opaque_up;
 };
 
diff --git a/lldb/source/API/SBAddressRange.cpp 
b/lldb/source/API/SBAddressRange.cpp
index 9b1affdade439..5834ebe5e63c0 100644
--- a/lldb/source/API/SBAddressRange.cpp
+++ b/lldb/source/API/SBAddressRange.cpp
@@ -50,9 +50,7 @@ const SBAddressRange ::operator=(const 
SBAddressRange ) {
 bool SBAddressRange::operator==(const SBAddressRange ) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
-  if (!IsValid() || !rhs.IsValid())
-return false;
-  return m_opaque_up->operator==(*(rhs.m_opaque_up));
+  return ref().operator==(rhs.ref());
 }
 
 bool SBAddressRange::operator!=(const SBAddressRange ) {
@@ -64,40 +62,35 @@ bool SBAddressRange::operator!=(const SBAddressRange ) {
 void SBAddressRange::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
-  m_opaque_up.reset();
+  ref().Clear();
 }
 
 bool SBAddressRange::IsValid() const {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up && m_opaque_up->IsValid();
+  return ref().IsValid();
 }
 
 lldb::SBAddress SBAddressRange::GetBaseAddress() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return lldb::SBAddress();
-  return lldb::SBAddress(m_opaque_up->GetBaseAddress());
+  return lldb::SBAddress(ref().GetBaseAddress());
 }
 
 lldb::addr_t SBAddressRange::GetByteSize() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return 0;
-  return m_opaque_up->GetByteSize();
+  return ref().GetByteSize();
 }
 
 bool SBAddressRange::GetDescription(SBStream ,
 const SBTarget target) {
   LLDB_INSTRUMENT_VA(this, description, target);
 
-  Stream  = description.ref();
-  if (!IsValid()) {
-stream << "";
-return true;
-  }
-  m_opaque_up->GetDescription(, target.GetSP().get());
-  return true;
+  return ref().GetDescription((), target.GetSP().get());
+}
+
+lldb_private::AddressRange ::ref() const {
+  assert(m_opaque_up && "opaque pointer must always be valid");
+  return *m_opaque_up;
 }
diff --git a/lldb/source/API/SBAddressRangeList.cpp 
b/lldb/source/API/SBAddressRangeList.cpp
index 20660b3ff2088..957155d5125ef 100644
--- a/lldb/source/API/SBAddressRangeList.cpp
+++ b/lldb/source/API/SBAddressRangeList.cpp
@@ -37,40 +37,40 @@ SBAddressRangeList::operator=(const SBAddressRangeList 
) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
   if (this != )
-*m_opaque_up = *rhs.m_opaque_up;
+ref() = rhs.ref();
   return *this;
 }
 
 uint32_t SBAddressRangeList::GetSize() const {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up->GetSize();
+  return ref().GetSize();
 }
 
 SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
   LLDB_INSTRUMENT_VA(this, idx);
 
   SBAddressRange sb_addr_range;
-  (*sb_addr_range.m_opaque_up) = m_opaque_up->GetAddressRangeAtIndex(idx);
+  (*sb_addr_range.m_opaque_up) = ref().GetAddressRangeAtIndex(idx);
   return sb_addr_range;
 }
 
 void SBAddressRangeList::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
-  m_opaque_up->Clear();
+  ref().Clear();
 }
 
 void SBAddressRangeList::Append(const SBAddressRange _addr_range) {
   LLDB_INSTRUMENT_VA(this, sb_addr_range);
 
-  m_opaque_up->Append(*sb_addr_range.m_opaque_up);
+  ref().Append(*sb_addr_range.m_opaque_up);
 }
 
 void SBAddressRangeList::Append(const SBAddressRangeList _addr_range_list) {
   LLDB_INSTRUMENT_VA(this, sb_addr_range_list);
 
-  m_opaque_up->Append(*sb_addr_range_list.m_opaque_up);
+  

[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)

2024-06-20 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95997

>From 59c382f0b06d632c05baeb357c0390a2423932fc Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 18 Jun 2024 14:35:55 -0700
Subject: [PATCH] [lldb] Fix SBAddressRange validation checks.

---
 lldb/source/API/SBAddressRange.cpp| 25 ---
 lldb/source/API/SBAddressRangeList.cpp|  8 ++
 .../address_range/TestAddressRange.py |  2 +-
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/lldb/source/API/SBAddressRange.cpp 
b/lldb/source/API/SBAddressRange.cpp
index 9b1affdade439..44f2c15635d13 100644
--- a/lldb/source/API/SBAddressRange.cpp
+++ b/lldb/source/API/SBAddressRange.cpp
@@ -50,8 +50,8 @@ const SBAddressRange ::operator=(const 
SBAddressRange ) {
 bool SBAddressRange::operator==(const SBAddressRange ) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
-  if (!IsValid() || !rhs.IsValid())
-return false;
+  assert(m_opaque_up && "opaque pointer must always be valid");
+  assert(rhs.m_opaque_up && "opaque pointer must always be valid");
   return m_opaque_up->operator==(*(rhs.m_opaque_up));
 }
 
@@ -64,28 +64,28 @@ bool SBAddressRange::operator!=(const SBAddressRange ) {
 void SBAddressRange::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
-  m_opaque_up.reset();
+  assert(m_opaque_up && "opaque pointer must always be valid");
+  m_opaque_up->Clear();
 }
 
 bool SBAddressRange::IsValid() const {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up && m_opaque_up->IsValid();
+  assert(m_opaque_up && "opaque pointer must always be valid");
+  return m_opaque_up->IsValid();
 }
 
 lldb::SBAddress SBAddressRange::GetBaseAddress() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return lldb::SBAddress();
+  assert(m_opaque_up && "opaque pointer must always be valid");
   return lldb::SBAddress(m_opaque_up->GetBaseAddress());
 }
 
 lldb::addr_t SBAddressRange::GetByteSize() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return 0;
+  assert(m_opaque_up && "opaque pointer must always be valid");
   return m_opaque_up->GetByteSize();
 }
 
@@ -93,11 +93,6 @@ bool SBAddressRange::GetDescription(SBStream ,
 const SBTarget target) {
   LLDB_INSTRUMENT_VA(this, description, target);
 
-  Stream  = description.ref();
-  if (!IsValid()) {
-stream << "";
-return true;
-  }
-  m_opaque_up->GetDescription(, target.GetSP().get());
-  return true;
+  assert(m_opaque_up && "opaque pointer must always be valid");
+  return m_opaque_up->GetDescription((), target.GetSP().get());
 }
diff --git a/lldb/source/API/SBAddressRangeList.cpp 
b/lldb/source/API/SBAddressRangeList.cpp
index 20660b3ff2088..ddb5a0a8a3d0b 100644
--- a/lldb/source/API/SBAddressRangeList.cpp
+++ b/lldb/source/API/SBAddressRangeList.cpp
@@ -36,6 +36,8 @@ const SBAddressRangeList &
 SBAddressRangeList::operator=(const SBAddressRangeList ) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
+  assert(m_opaque_up && "opaque pointer must always be valid");
+  assert(rhs.m_opaque_up && "opaque pointer must always be valid");
   if (this != )
 *m_opaque_up = *rhs.m_opaque_up;
   return *this;
@@ -44,12 +46,14 @@ SBAddressRangeList::operator=(const SBAddressRangeList 
) {
 uint32_t SBAddressRangeList::GetSize() const {
   LLDB_INSTRUMENT_VA(this);
 
+  assert(m_opaque_up && "opaque pointer must always be valid");
   return m_opaque_up->GetSize();
 }
 
 SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
   LLDB_INSTRUMENT_VA(this, idx);
 
+  assert(m_opaque_up && "opaque pointer must always be valid");
   SBAddressRange sb_addr_range;
   (*sb_addr_range.m_opaque_up) = m_opaque_up->GetAddressRangeAtIndex(idx);
   return sb_addr_range;
@@ -58,18 +62,21 @@ SBAddressRange 
SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
 void SBAddressRangeList::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
+  assert(m_opaque_up && "opaque pointer must always be valid");
   m_opaque_up->Clear();
 }
 
 void SBAddressRangeList::Append(const SBAddressRange _addr_range) {
   LLDB_INSTRUMENT_VA(this, sb_addr_range);
 
+  assert(m_opaque_up && "opaque pointer must always be valid");
   m_opaque_up->Append(*sb_addr_range.m_opaque_up);
 }
 
 void SBAddressRangeList::Append(const SBAddressRangeList _addr_range_list) {
   LLDB_INSTRUMENT_VA(this, sb_addr_range_list);
 
+  assert(m_opaque_up && "opaque pointer must always be valid");
   m_opaque_up->Append(*sb_addr_range_list.m_opaque_up);
 }
 
@@ -77,6 +84,7 @@ bool SBAddressRangeList::GetDescription(SBStream ,
 const SBTarget ) {
   LLDB_INSTRUMENT_VA(this, description, target);
 
+  assert(m_opaque_up && "opaque pointer must always be valid");
   const uint32_t num_ranges = GetSize();
   bool is_first = true;
   Stream  = description.ref();
diff --git a/lldb/test/API/python_api/address_range/TestAddressRange.py 
b/lldb/test/API/python_api/address_range/TestAddressRange.py
index 

[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)

2024-06-20 Thread Miro Bucko via lldb-commits

mbucko wrote:

> This class behaves quite differently from other SB API classes. Normally, the 
> opaque pointer can be cleared to release the potentially more resource heavy 
> private counterpart. `AddressRange` is a pretty simple class, so I understand 
> that it makes things easier if we guarantee the pointer is always valid, but 
> it is somewhat of a surprise.
> 
> Personally, I think consistency beats the small advantage of not having to 
> check the pointer. If we want to stick to this approach, I'd like to see an 
> assert that makes it clear that in this class, we have a precondition that 
> the pointer is always valid:
> 
> ```
> assert(m_opaque_up && "opaque pointer must always be valid");
> ```

So you're ok with keeping the code as is plus adding the asserts?

https://github.com/llvm/llvm-project/pull/95997
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-20 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From bae5474315a8a9053033c90237e1eacd9e56e39c Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBAddressRange.h|   2 +
 lldb/include/lldb/API/SBAddressRangeList.h|   2 +
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   4 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBAddressRange.cpp|   4 +-
 lldb/source/API/SBAddressRangeList.cpp|   4 +
 lldb/source/API/SBProcess.cpp |  58 -
 lldb/source/Target/Process.cpp| 129 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 131 +++
 .../find_in_memory/TestFindRangesInMemory.py  | 221 ++
 .../find_in_memory/address_ranges_helper.py   |  73 ++
 .../API/python_api/find_in_memory/main.cpp|  27 +++
 15 files changed, 677 insertions(+), 7 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBAddressRange.h 
b/lldb/include/lldb/API/SBAddressRange.h
index 152bd82426af1..ef8ce9ba9977d 100644
--- a/lldb/include/lldb/API/SBAddressRange.h
+++ b/lldb/include/lldb/API/SBAddressRange.h
@@ -58,6 +58,8 @@ class LLDB_API SBAddressRange {
   friend class SBFunction;
   friend class SBProcess;
 
+  lldb_private::AddressRange () const;
+
   AddressRangeUP m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBAddressRangeList.h 
b/lldb/include/lldb/API/SBAddressRangeList.h
index a123287ef1b4f..9e4d747685e63 100644
--- a/lldb/include/lldb/API/SBAddressRangeList.h
+++ b/lldb/include/lldb/API/SBAddressRangeList.h
@@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
   friend class SBBlock;
   friend class SBProcess;
 
+  lldb_private::AddressRanges () const;
+
   std::unique_ptr m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   

[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)

2024-06-18 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/95997

None

>From 786e94dae236eafb71c2f001f48ed17651abd3e3 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 18 Jun 2024 14:35:55 -0700
Subject: [PATCH] [lldb] Fix SBAddressRange validation checks.

---
 lldb/source/API/SBAddressRange.cpp | 18 +++---
 .../address_range/TestAddressRange.py  |  2 +-
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/lldb/source/API/SBAddressRange.cpp 
b/lldb/source/API/SBAddressRange.cpp
index 9b1affdade439..0fba252979093 100644
--- a/lldb/source/API/SBAddressRange.cpp
+++ b/lldb/source/API/SBAddressRange.cpp
@@ -50,8 +50,6 @@ const SBAddressRange ::operator=(const 
SBAddressRange ) {
 bool SBAddressRange::operator==(const SBAddressRange ) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
-  if (!IsValid() || !rhs.IsValid())
-return false;
   return m_opaque_up->operator==(*(rhs.m_opaque_up));
 }
 
@@ -64,28 +62,24 @@ bool SBAddressRange::operator!=(const SBAddressRange ) {
 void SBAddressRange::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
-  m_opaque_up.reset();
+  m_opaque_up->Clear();
 }
 
 bool SBAddressRange::IsValid() const {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up && m_opaque_up->IsValid();
+  return m_opaque_up->IsValid();
 }
 
 lldb::SBAddress SBAddressRange::GetBaseAddress() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return lldb::SBAddress();
   return lldb::SBAddress(m_opaque_up->GetBaseAddress());
 }
 
 lldb::addr_t SBAddressRange::GetByteSize() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return 0;
   return m_opaque_up->GetByteSize();
 }
 
@@ -93,11 +87,5 @@ bool SBAddressRange::GetDescription(SBStream ,
 const SBTarget target) {
   LLDB_INSTRUMENT_VA(this, description, target);
 
-  Stream  = description.ref();
-  if (!IsValid()) {
-stream << "";
-return true;
-  }
-  m_opaque_up->GetDescription(, target.GetSP().get());
-  return true;
+  return m_opaque_up->GetDescription((), target.GetSP().get());
 }
diff --git a/lldb/test/API/python_api/address_range/TestAddressRange.py 
b/lldb/test/API/python_api/address_range/TestAddressRange.py
index 86ca4a62155f0..ae4b8c7c90ce4 100644
--- a/lldb/test/API/python_api/address_range/TestAddressRange.py
+++ b/lldb/test/API/python_api/address_range/TestAddressRange.py
@@ -166,7 +166,7 @@ def test_address_range_list_iterator(self):
 def test_address_range_print_invalid(self):
 """Make sure the SBAddressRange can be printed when invalid."""
 range = lldb.SBAddressRange()
-self.assertEqual(str(range), "")
+self.assertEqual(str(range), "[0x-0x)")
 
 def test_address_range_print_resolved(self):
 """Make sure the SBAddressRange can be printed when resolved."""

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-18 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From b9b8d8d918076ba9133103cb9ce7328d5e872d32 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBAddressRange.h|   2 +
 lldb/include/lldb/API/SBAddressRangeList.h|   2 +
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   4 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBAddressRange.cpp|   4 +-
 lldb/source/API/SBAddressRangeList.cpp|   4 +
 lldb/source/API/SBProcess.cpp |  58 -
 lldb/source/Target/Process.cpp| 123 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  64 ++
 .../API/python_api/find_in_memory/main.cpp|  13 ++
 15 files changed, 610 insertions(+), 7 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBAddressRange.h 
b/lldb/include/lldb/API/SBAddressRange.h
index 152bd82426af1..ef8ce9ba9977d 100644
--- a/lldb/include/lldb/API/SBAddressRange.h
+++ b/lldb/include/lldb/API/SBAddressRange.h
@@ -58,6 +58,8 @@ class LLDB_API SBAddressRange {
   friend class SBFunction;
   friend class SBProcess;
 
+  lldb_private::AddressRange () const;
+
   AddressRangeUP m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBAddressRangeList.h 
b/lldb/include/lldb/API/SBAddressRangeList.h
index a123287ef1b4f..9e4d747685e63 100644
--- a/lldb/include/lldb/API/SBAddressRangeList.h
+++ b/lldb/include/lldb/API/SBAddressRangeList.h
@@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
   friend class SBBlock;
   friend class SBProcess;
 
+  lldb_private::AddressRanges () const;
+
   std::unique_ptr m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges 

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-18 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 42e974f26798e013f13f75af164286ec2a69f539 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBAddressRange.h|   2 +
 lldb/include/lldb/API/SBAddressRangeList.h|   2 +
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   4 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBAddressRange.cpp|   4 +-
 lldb/source/API/SBAddressRangeList.cpp|   4 +
 lldb/source/API/SBProcess.cpp |  58 -
 lldb/source/Target/Process.cpp| 123 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 15 files changed, 605 insertions(+), 7 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBAddressRange.h 
b/lldb/include/lldb/API/SBAddressRange.h
index 152bd82426af1..ef8ce9ba9977d 100644
--- a/lldb/include/lldb/API/SBAddressRange.h
+++ b/lldb/include/lldb/API/SBAddressRange.h
@@ -58,6 +58,8 @@ class LLDB_API SBAddressRange {
   friend class SBFunction;
   friend class SBProcess;
 
+  lldb_private::AddressRange () const;
+
   AddressRangeUP m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBAddressRangeList.h 
b/lldb/include/lldb/API/SBAddressRangeList.h
index a123287ef1b4f..9e4d747685e63 100644
--- a/lldb/include/lldb/API/SBAddressRangeList.h
+++ b/lldb/include/lldb/API/SBAddressRangeList.h
@@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
   friend class SBBlock;
   friend class SBProcess;
 
+  lldb_private::AddressRanges () const;
+
   std::unique_ptr m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-18 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 71866d9a1f1b646021d56b576ddc74863ed3cb76 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBAddressRange.h|   2 +
 lldb/include/lldb/API/SBAddressRangeList.h|   2 +
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   4 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBAddressRange.cpp|   4 +-
 lldb/source/API/SBAddressRangeList.cpp|   4 +
 lldb/source/API/SBProcess.cpp |  58 -
 lldb/source/Target/Process.cpp| 117 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 15 files changed, 599 insertions(+), 7 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBAddressRange.h 
b/lldb/include/lldb/API/SBAddressRange.h
index 152bd82426af1..ef8ce9ba9977d 100644
--- a/lldb/include/lldb/API/SBAddressRange.h
+++ b/lldb/include/lldb/API/SBAddressRange.h
@@ -58,6 +58,8 @@ class LLDB_API SBAddressRange {
   friend class SBFunction;
   friend class SBProcess;
 
+  lldb_private::AddressRange () const;
+
   AddressRangeUP m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBAddressRangeList.h 
b/lldb/include/lldb/API/SBAddressRangeList.h
index a123287ef1b4f..9e4d747685e63 100644
--- a/lldb/include/lldb/API/SBAddressRangeList.h
+++ b/lldb/include/lldb/API/SBAddressRangeList.h
@@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
   friend class SBBlock;
   friend class SBProcess;
 
+  lldb_private::AddressRanges () const;
+
   std::unique_ptr m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-17 Thread Miro Bucko via lldb-commits


@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
,
+ uint32_t alignment, uint32_t max_matches, SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange , uint32_t alignment,

mbucko wrote:

We have gone back and forth between making it const/non-const. I have updated 
it. Tagging @clayborg for awareness.

https://github.com/llvm/llvm-project/pull/95007
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-17 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 6255aeca48a2ccd97d519a22632443f2f76d3773 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  63 +-
 lldb/source/Target/Process.cpp| 117 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 11 files changed, 591 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..a9840d889db89 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_matches,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges ,
+  size_t alignment, 

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 3a580b40d41575eb35c6fc3f465a628196299373 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  68 +-
 lldb/source/Target/Process.cpp| 118 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 11 files changed, 595 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..dc8cd116fd420 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
,
+ uint32_t alignment, uint32_t max_matches, SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..a9840d889db89 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_matches,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges ,
+  size_t alignment, size_t max_matches);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has
   /// removed non address bits from load_addr. Override this method in
   /// 

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 42ec0dd50ea037c832e38541204d3a911577cfab Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  68 ++-
 lldb/source/Target/Process.cpp| 116 
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +++
 .../find_in_memory/TestFindRangesInMemory.py  | 172 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +++
 .../API/python_api/find_in_memory/main.cpp|  11 ++
 11 files changed, 555 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..dc8cd116fd420 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
,
+ uint32_t alignment, uint32_t max_matches, SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..3ac19a74b8b99 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_count,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges ,
+  size_t alignment, size_t max_count);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has
   /// removed non address bits from load_addr. Override this method in
   

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 02345eaea4eab488234d0dccd437676279b065e6 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  64 +-
 lldb/source/Target/Process.cpp| 117 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 11 files changed, 590 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..dc8cd116fd420 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
,
+ uint32_t alignment, uint32_t max_matches, SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..a9840d889db89 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_matches,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges ,
+  size_t alignment, size_t max_matches);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has
   /// removed non address bits from load_addr. Override this method in
   /// 

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From a5335c87ed7e04b8b6d74cf5f166bfcdd9f723e6 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  64 +-
 lldb/source/Target/Process.cpp| 118 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 11 files changed, 591 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..dc8cd116fd420 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
,
+ uint32_t alignment, uint32_t max_matches, SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..a9840d889db89 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_matches,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges ,
+  size_t alignment, size_t max_matches);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has
   /// removed non address bits from load_addr. Override this method in
   /// 

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits


@@ -810,6 +809,65 @@ const char *SBProcess::GetBroadcasterClass() {
   return ConstString(Process::GetStaticBroadcasterClass()).AsCString();
 }
 
+lldb::SBAddressRangeList
+SBProcess::FindRangesInMemory(const void *buf, uint64_t size,
+  SBAddressRangeList , uint32_t alignment,
+  uint32_t max_matches, SBError ) {
+  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(_sp->GetRunLock())) {
+LLDB_LOGF(
+log,
+"SBProcess::%s Cannot find process in memory while process is 
running.",
+__FUNCTION__);
+return matches;
+  }
+  std::lock_guard guard(
+  process_sp->GetTarget().GetAPIMutex());
+  matches.m_opaque_up->ref() = process_sp->FindRangesInMemory(
+  reinterpret_cast(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 , uint32_t alignment,
+ SBError ) {
+  LLDB_INSTRUMENT_VA(this, buf, size, range, alignment, error);
+
+  if (!range.IsValid()) {
+error.SetErrorStringWithFormat("range is invalid");
+return LLDB_INVALID_ADDRESS;
+  }
+

mbucko wrote:

We are dereferencing the pointer though. If I don't do this check and someone 
passes in an invalid range, it will segfault.

https://github.com/llvm/llvm-project/pull/95007
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-12 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,31 @@
+import lldb
+
+SINGLE_INSTANCE_PATTERN = "there_is_only_one_of_me"
+DOUBLE_INSTANCE_PATTERN = "there_is_exactly_two_of_me"
+
+
+def GetAddressRanges(test_base):

mbucko wrote:

Why not just store them all on stack and only use one region to search through?

https://github.com/llvm/llvm-project/pull/95007
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-12 Thread Miro Bucko via lldb-commits


@@ -2007,6 +2007,124 @@ size_t Process::ReadMemory(addr_t addr, void *buf, 
size_t size, Status ) {
   }
 }
 
+void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+ const uint8_t *buf, size_t size,
+ AddressRanges , size_t alignment,
+ size_t max_count) {
+  // Inputs are already validated in FindInMemory() functions.
+  assert(buf != nullptr);
+  assert(size > 0);
+  assert(alignment > 0);
+  assert(max_count > 0);
+  assert(start_addr != LLDB_INVALID_ADDRESS);
+  assert(end_addr != LLDB_INVALID_ADDRESS);
+  assert(start_addr < end_addr);
+
+  lldb::addr_t start = start_addr;
+  while (matches.size() < max_count && (start + size) < end_addr) {
+const lldb::addr_t found_addr = FindInMemory(start, end_addr, buf, size);
+if (found_addr == LLDB_INVALID_ADDRESS)
+  break;
+matches.emplace_back(found_addr, size);
+start = found_addr + alignment;
+  }
+}
+
+AddressRanges Process::FindRangesInMemory(const uint8_t *buf, uint64_t size,
+  const AddressRanges ,
+  size_t alignment, size_t max_count,
+  Status ) {
+  AddressRanges matches;
+  if (buf == nullptr) {
+error.SetErrorStringWithFormat("buffer is null");
+return matches;
+  }
+  if (size == 0) {
+error.SetErrorStringWithFormat("size is zero");
+return matches;
+  }
+  if (ranges.empty()) {
+error.SetErrorStringWithFormat("ranges in empty");
+return matches;
+  }
+  if (alignment == 0) {
+error.SetErrorStringWithFormat(
+"invalid alignment %zu, must be greater than 0", alignment);
+return matches;
+  }
+  if (max_count == 0) {
+error.SetErrorStringWithFormat(
+"invalid max_count %zu, must be greater than 0", max_count);
+return matches;
+  }
+
+  Target  = GetTarget();
+  Log *log = GetLog(LLDBLog::Process);
+  for (size_t i = 0; i < ranges.size(); ++i) {
+if (matches.size() >= max_count) {
+  break;
+}
+const AddressRange  = ranges[i];
+if (range.IsValid() == false) {
+  LLDB_LOGF(log, "Process::%s range is invalid", __FUNCTION__);

mbucko wrote:

If we set the error but return successfully the ranges then the caller might 
discard the returned ranges no?

https://github.com/llvm/llvm-project/pull/95007
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-12 Thread Miro Bucko via lldb-commits


@@ -810,6 +809,65 @@ const char *SBProcess::GetBroadcasterClass() {
   return ConstString(Process::GetStaticBroadcasterClass()).AsCString();
 }
 
+lldb::SBAddressRangeList
+SBProcess::FindRangesInMemory(const void *buf, uint64_t size,
+  SBAddressRangeList , uint32_t alignment,
+  uint32_t max_matches, SBError ) {
+  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(_sp->GetRunLock())) {
+LLDB_LOGF(
+log,
+"SBProcess::%s Cannot find process in memory while process is 
running.",
+__FUNCTION__);
+return matches;
+  }
+  std::lock_guard guard(
+  process_sp->GetTarget().GetAPIMutex());
+  matches.m_opaque_up->ref() = process_sp->FindRangesInMemory(
+  reinterpret_cast(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 , uint32_t alignment,
+ SBError ) {
+  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
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)

2024-06-11 Thread Miro Bucko via lldb-commits

https://github.com/mbucko closed https://github.com/llvm/llvm-project/pull/94494
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)

2024-06-10 Thread Miro Bucko via lldb-commits

mbucko wrote:

> Thanks. LGTM!

Would you be able to Merge it in?

https://github.com/llvm/llvm-project/pull/94494
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)

2024-06-10 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/94494

>From 39c8c9aa1cc45fd4cfd16fe841f65a4d1cb08cf4 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Wed, 5 Jun 2024 09:03:38 -0700
Subject: [PATCH] Fix flaky TestDAP_console test.

Test Plan:
llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
---
 .../lldbsuite/test/tools/lldb-dap/dap_server.py   |  6 --
 .../test/tools/lldb-dap/lldbdap_testcase.py   |  6 --
 .../API/tools/lldb-dap/attach/TestDAP_attach.py   | 10 --
 .../tools/lldb-dap/commands/TestDAP_commands.py   | 15 ---
 .../API/tools/lldb-dap/console/TestDAP_console.py |  9 ++---
 .../API/tools/lldb-dap/launch/TestDAP_launch.py   | 10 --
 6 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index e2126d67a5fe7..a9eeec1840990 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -171,13 +171,15 @@ def get_output(self, category, timeout=0.0, clear=True):
 self.output_condition.release()
 return output
 
-def collect_output(self, category, duration, clear=True):
-end_time = time.time() + duration
+def collect_output(self, category, timeout_secs, pattern, clear=True):
+end_time = time.time() + timeout_secs
 collected_output = ""
 while end_time > time.time():
 output = self.get_output(category, timeout=0.25, clear=clear)
 if output:
 collected_output += output
+if pattern is not None and pattern in output:
+break
 return collected_output if collected_output else None
 
 def enqueue_recv_packet(self, packet):
diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index d56ea5dca14be..600dc2b5fe9bb 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -195,8 +195,10 @@ def get_stdout(self, timeout=0.0):
 def get_console(self, timeout=0.0):
 return self.dap_server.get_output("console", timeout=timeout)
 
-def collect_console(self, duration):
-return self.dap_server.collect_output("console", duration=duration)
+def collect_console(self, timeout_secs, pattern=None):
+return self.dap_server.collect_output(
+"console", timeout_secs=timeout_secs, pattern=pattern
+)
 
 def get_local_as_int(self, name, threadId=None):
 value = self.dap_server.get_local_variable_value(name, 
threadId=threadId)
diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py 
b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
index b3ba69749f673..1dbe00144f352 100644
--- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
+++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
@@ -200,7 +200,10 @@ def test_commands(self):
 # Get output from the console. This should contain both the
 # "exitCommands" that were run after the second breakpoint was hit
 # and the "terminateCommands" due to the debugging session ending
-output = self.collect_console(duration=1.0)
+output = self.collect_console(
+timeout_secs=1.0,
+pattern=terminateCommands[0],
+)
 self.verify_commands("exitCommands", output, exitCommands)
 self.verify_commands("terminateCommands", output, terminateCommands)
 
@@ -235,5 +238,8 @@ def test_terminate_commands(self):
 # Once it's disconnected the console should contain the
 # "terminateCommands"
 self.dap_server.request_disconnect(terminateDebuggee=True)
-output = self.collect_console(duration=1.0)
+output = self.collect_console(
+timeout_secs=1.0,
+pattern=terminateCommands[0],
+)
 self.verify_commands("terminateCommands", output, terminateCommands)
diff --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py 
b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
index 226b9385fe719..e4cf903fc0d11 100644
--- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
+++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
@@ -22,7 +22,10 @@ def test_command_directive_quiet_on_success(self):
 stopCommands=["?" + command_quiet, command_not_quiet],
 exitCommands=["?" + command_quiet, command_not_quiet],
 )
-full_output = self.collect_console(duration=1.0)
+full_output = self.collect_console(
+timeout_secs=1.0,
+pattern=command_not_quiet,
+)
 self.assertNotIn(command_quiet, 

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-10 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From e5b3bf115ff60e2892ccfae387877c205ec659f9 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 ++
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  68 -
 lldb/source/Target/Process.cpp| 118 +++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 100 +
 .../find_in_memory/TestFindRangesInMemory.py  | 136 ++
 .../find_in_memory/address_ranges_helper.py   |  31 
 .../API/python_api/find_in_memory/main.cpp|  21 +++
 11 files changed, 497 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index 8d4b740e5f35c..923a787e77c88 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..dc8cd116fd420 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
,
+ uint32_t alignment, uint32_t max_matches, SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..3ac19a74b8b99 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_count,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges ,
+  size_t alignment, size_t max_count);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has
   /// removed non address bits from load_addr. Override this method 

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-10 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,31 @@
+import lldb
+
+SINGLE_INSTANCE_PATTERN = "there_is_only_one_of_me"
+DOUBLE_INSTANCE_PATTERN = "there_is_exactly_two_of_me"
+
+
+def GetAddressRanges(test_base):
+mem_regions = test_base.process.GetMemoryRegions()
+test_base.assertTrue(len(mem_regions) > 0, "Make sure there are memory 
regions")
+addr_ranges = lldb.SBAddressRangeList()
+for i in range(mem_regions.GetSize()):
+region_info = lldb.SBMemoryRegionInfo()
+if not mem_regions.GetMemoryRegionAtIndex(i, region_info):
+continue
+if not (region_info.IsReadable() and region_info.IsWritable()):
+continue
+if region_info.IsExecutable():
+continue
+if not region_info.GetName() or region_info.GetName() != "[heap]":

mbucko wrote:

The above example doesn't have a name which also satisfies the condition so it 
should work. I mainly wanted to remove regions such as "[stack]" and 
"/some/path/lib.o" ...

https://github.com/llvm/llvm-project/pull/95007
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)

2024-06-10 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/94494

>From 5e92ee56b2b278b3ddad04cfdb1f440d3568389c Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Wed, 5 Jun 2024 09:03:38 -0700
Subject: [PATCH] Fix flaky TestDAP_console test.

Test Plan:
llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
---
 .../Python/lldbsuite/test/tools/lldb-dap/dap_server.py   | 6 --
 .../lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py| 6 --
 lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py| 4 ++--
 .../test/API/tools/lldb-dap/commands/TestDAP_commands.py | 6 +++---
 lldb/test/API/tools/lldb-dap/console/TestDAP_console.py  | 9 ++---
 lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py| 4 ++--
 6 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index e2126d67a5fe7..a9eeec1840990 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -171,13 +171,15 @@ def get_output(self, category, timeout=0.0, clear=True):
 self.output_condition.release()
 return output
 
-def collect_output(self, category, duration, clear=True):
-end_time = time.time() + duration
+def collect_output(self, category, timeout_secs, pattern, clear=True):
+end_time = time.time() + timeout_secs
 collected_output = ""
 while end_time > time.time():
 output = self.get_output(category, timeout=0.25, clear=clear)
 if output:
 collected_output += output
+if pattern is not None and pattern in output:
+break
 return collected_output if collected_output else None
 
 def enqueue_recv_packet(self, packet):
diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index d56ea5dca14be..600dc2b5fe9bb 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -195,8 +195,10 @@ def get_stdout(self, timeout=0.0):
 def get_console(self, timeout=0.0):
 return self.dap_server.get_output("console", timeout=timeout)
 
-def collect_console(self, duration):
-return self.dap_server.collect_output("console", duration=duration)
+def collect_console(self, timeout_secs, pattern=None):
+return self.dap_server.collect_output(
+"console", timeout_secs=timeout_secs, pattern=pattern
+)
 
 def get_local_as_int(self, name, threadId=None):
 value = self.dap_server.get_local_variable_value(name, 
threadId=threadId)
diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py 
b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
index b3ba69749f673..17a54d996cea6 100644
--- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
+++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
@@ -200,7 +200,7 @@ def test_commands(self):
 # Get output from the console. This should contain both the
 # "exitCommands" that were run after the second breakpoint was hit
 # and the "terminateCommands" due to the debugging session ending
-output = self.collect_console(duration=1.0)
+output = self.collect_console(timeout_secs=1.0)
 self.verify_commands("exitCommands", output, exitCommands)
 self.verify_commands("terminateCommands", output, terminateCommands)
 
@@ -235,5 +235,5 @@ def test_terminate_commands(self):
 # Once it's disconnected the console should contain the
 # "terminateCommands"
 self.dap_server.request_disconnect(terminateDebuggee=True)
-output = self.collect_console(duration=1.0)
+output = self.collect_console(timeout_secs=1.0)
 self.verify_commands("terminateCommands", output, terminateCommands)
diff --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py 
b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
index 226b9385fe719..313ae3685b91a 100644
--- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
+++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
@@ -22,7 +22,7 @@ def test_command_directive_quiet_on_success(self):
 stopCommands=["?" + command_quiet, command_not_quiet],
 exitCommands=["?" + command_quiet, command_not_quiet],
 )
-full_output = self.collect_console(duration=1.0)
+full_output = self.collect_console(timeout_secs=1.0)
 self.assertNotIn(command_quiet, full_output)
 self.assertIn(command_not_quiet, full_output)
 
@@ -47,7 +47,7 @@ def do_test_abort_on_error(
 postRunCommands=commands if use_post_run_commands else None,
   

[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)

2024-06-10 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/94494

>From ea050132f653a908eeefecd647431a0ed65e2cc0 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Wed, 5 Jun 2024 09:03:38 -0700
Subject: [PATCH] Fix flaky TestDAP_console test.

Test Plan:
llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
---
 .../Python/lldbsuite/test/tools/lldb-dap/dap_server.py  | 6 --
 .../lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py   | 4 ++--
 lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py   | 4 ++--
 lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py   | 6 +++---
 lldb/test/API/tools/lldb-dap/console/TestDAP_console.py | 5 ++---
 lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py   | 4 ++--
 6 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index e2126d67a5fe7..a9eeec1840990 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -171,13 +171,15 @@ def get_output(self, category, timeout=0.0, clear=True):
 self.output_condition.release()
 return output
 
-def collect_output(self, category, duration, clear=True):
-end_time = time.time() + duration
+def collect_output(self, category, timeout_secs, pattern, clear=True):
+end_time = time.time() + timeout_secs
 collected_output = ""
 while end_time > time.time():
 output = self.get_output(category, timeout=0.25, clear=clear)
 if output:
 collected_output += output
+if pattern is not None and pattern in output:
+break
 return collected_output if collected_output else None
 
 def enqueue_recv_packet(self, packet):
diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index d56ea5dca14be..e3796edb2291d 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -195,8 +195,8 @@ def get_stdout(self, timeout=0.0):
 def get_console(self, timeout=0.0):
 return self.dap_server.get_output("console", timeout=timeout)
 
-def collect_console(self, duration):
-return self.dap_server.collect_output("console", duration=duration)
+def collect_console(self, timeout_secs, pattern=None):
+return self.dap_server.collect_output("console", 
timeout_secs=timeout_secs, pattern=pattern)
 
 def get_local_as_int(self, name, threadId=None):
 value = self.dap_server.get_local_variable_value(name, 
threadId=threadId)
diff --git a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py 
b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
index b3ba69749f673..17a54d996cea6 100644
--- a/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
+++ b/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
@@ -200,7 +200,7 @@ def test_commands(self):
 # Get output from the console. This should contain both the
 # "exitCommands" that were run after the second breakpoint was hit
 # and the "terminateCommands" due to the debugging session ending
-output = self.collect_console(duration=1.0)
+output = self.collect_console(timeout_secs=1.0)
 self.verify_commands("exitCommands", output, exitCommands)
 self.verify_commands("terminateCommands", output, terminateCommands)
 
@@ -235,5 +235,5 @@ def test_terminate_commands(self):
 # Once it's disconnected the console should contain the
 # "terminateCommands"
 self.dap_server.request_disconnect(terminateDebuggee=True)
-output = self.collect_console(duration=1.0)
+output = self.collect_console(timeout_secs=1.0)
 self.verify_commands("terminateCommands", output, terminateCommands)
diff --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py 
b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
index 226b9385fe719..313ae3685b91a 100644
--- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
+++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
@@ -22,7 +22,7 @@ def test_command_directive_quiet_on_success(self):
 stopCommands=["?" + command_quiet, command_not_quiet],
 exitCommands=["?" + command_quiet, command_not_quiet],
 )
-full_output = self.collect_console(duration=1.0)
+full_output = self.collect_console(timeout_secs=1.0)
 self.assertNotIn(command_quiet, full_output)
 self.assertIn(command_not_quiet, full_output)
 
@@ -47,7 +47,7 @@ def do_test_abort_on_error(
 postRunCommands=commands if use_post_run_commands else None,
 

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-10 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From cfe6230a93d9689e465588f8c4a01fe06861501e Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 ++
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  11 ++
 lldb/source/API/SBProcess.cpp | 115 +++-
 lldb/source/Target/Process.cpp| 117 +
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py|  89 +
 .../find_in_memory/TestFindRangesInMemory.py  | 123 ++
 .../find_in_memory/address_ranges_helper.py   |  31 +
 .../API/python_api/find_in_memory/main.cpp|  21 +++
 11 files changed, 517 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index 8d4b740e5f35c..923a787e77c88 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..eb7441629108c 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches);
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange , uint32_t alignment);
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..176eb2b19f226 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,13 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  Status FindInMemory(AddressRanges , const uint8_t *buf, size_t size,
+  const AddressRanges , size_t alignment,
+  size_t max_count);
+
+  lldb::addr_t FindInMemory(const AddressRange , const uint8_t *buf,
+size_t size, size_t alignment);
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2807,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges ,
+  size_t alignment, size_t max_count);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has
   /// removed non address bits from load_addr. Override this method in
   /// subclasses of Process.

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-10 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/95007

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py 

Reviewers: clayborg

Tasks: lldb


>From da8f23bf675abbb6742987e41939710ccb1c18ac Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 ++
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  11 ++
 lldb/source/API/SBProcess.cpp | 115 -
 lldb/source/Target/Process.cpp| 117 +
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py|  85 +
 .../find_in_memory/TestFindRangesInMemory.py  | 120 ++
 .../find_in_memory/address_ranges_helper.py   |  30 +
 .../API/python_api/find_in_memory/main.cpp|  21 +++
 11 files changed, 509 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index 8d4b740e5f35c..923a787e77c88 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..eb7441629108c 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches);
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange , uint32_t alignment);
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..176eb2b19f226 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,13 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  Status FindInMemory(AddressRanges , const uint8_t *buf, size_t size,
+  const AddressRanges , size_t alignment,
+  size_t max_count);
+
+  lldb::addr_t FindInMemory(const AddressRange , const uint8_t *buf,
+size_t size, size_t alignment);
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2807,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges ,
+  

[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)

2024-06-05 Thread Miro Bucko via lldb-commits

mbucko wrote:

> Would this affect other calls to `collect_console` too? Do we usually look 
> for a particular string? If so, would it make sense to change the function 
> (rather than this particular call site) or have a little helper?

The problem is that the console hasn't had enough time to collect the logs 
after the process was terminated. This fix will keep collecting the logs until 
the "exited with status..." log has been collected so that we can check it. The 
caller could specify 10.0 seconds timeout instead of 1.0 second, but this way 
the caller can exit earlier rather than forcefully waiting on the timeout. 

https://github.com/llvm/llvm-project/pull/94494
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Fix flaky TestDAP_console test. (PR #94494)

2024-06-05 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/94494

Test Plan:
llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py

>From 0d1eb164ab12773cb574de6066b717fd4c4c9e31 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Wed, 5 Jun 2024 09:03:38 -0700
Subject: [PATCH] Fix flaky TestDAP_console test.

Test Plan:
llvm-lit llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
---
 lldb/test/API/tools/lldb-dap/console/TestDAP_console.py | 4 
 1 file changed, 4 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index e6345818bf087..fad4c31bb7658 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -141,6 +141,10 @@ def test_exit_status_message_sigterm(self):
 
 # Get the console output
 console_output = self.collect_console(1.0)
+n_reads = 0
+while n_reads < 10 and "exited with status" not in console_output:
+console_output += self.collect_console(1.0)
+n_reads += 1
 
 # Verify the exit status message is printed.
 self.assertIn(

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Fix formatter tests for clang version 15 (PR #93710)

2024-06-04 Thread Miro Bucko via lldb-commits

https://github.com/mbucko closed https://github.com/llvm/llvm-project/pull/93710
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Fix formatter tests for clang version 15 (PR #93710)

2024-06-04 Thread Miro Bucko via lldb-commits

mbucko wrote:

No longer needed, failing tests were due to local version override

https://github.com/llvm/llvm-project/pull/93710
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Fix failing test TestAddressRange.py (PR #93871)

2024-05-30 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/93871

>From afcd5a2524fc27cab2ff55ffba06cc19c62bbc4e Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Thu, 30 May 2024 13:04:17 -0700
Subject: [PATCH] [lldb][test] Fix failing test TestAddressRange.py

Summary:
Test llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py is 
failing on Windows due adding a carriage return character at the end of line.
Original PR is #93836.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers:

Tasks:

Tags:
---
 lldb/test/API/python_api/address_range/TestAddressRange.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/API/python_api/address_range/TestAddressRange.py 
b/lldb/test/API/python_api/address_range/TestAddressRange.py
index f8783260a2351..86ca4a62155f0 100644
--- a/lldb/test/API/python_api/address_range/TestAddressRange.py
+++ b/lldb/test/API/python_api/address_range/TestAddressRange.py
@@ -191,7 +191,7 @@ def test_address_range_print_resolved(self):
 interp.HandleCommand(script, result, False)
 self.assertTrue(result.Succeeded(), "script command succeeded")
 # [0x1000-0x2000] // Resolved with target or addresses without sections
-self.assertRegex(result.GetOutput(), "^\[0x[0-9a-f]+\-0x[0-9a-f]+\)$")
+self.assertRegex(result.GetOutput(), "^\[0x[0-9a-f]+\-0x[0-9a-f]+\)")
 process.Kill()
 
 def test_address_range_print_no_section_resolved(self):

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Fix failing test TestAddressRange.py (PR #93871)

2024-05-30 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/93871

Summary:
Test llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py is 
failing on Windows due adding a carriage return character at the end of line. 
Original PR is #93836.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py


Reviewers: clayborg

Subscribers:

Tasks:

Tags:

>From 61024a5fc1ca6130204e5fdb194f48af1bf3d8c5 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Thu, 30 May 2024 13:04:17 -0700
Subject: [PATCH] [lldb][test] Fix failing test TestAddressRange.py

Summary:
Test llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py is 
failing on Windows due adding a carriage return character at the end of line.
Original PR is #93836.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers:

Tasks:

Tags:
---
 lldb/test/API/python_api/address_range/TestAddressRange.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/API/python_api/address_range/TestAddressRange.py 
b/lldb/test/API/python_api/address_range/TestAddressRange.py
index f8783260a2351..70797784956cc 100644
--- a/lldb/test/API/python_api/address_range/TestAddressRange.py
+++ b/lldb/test/API/python_api/address_range/TestAddressRange.py
@@ -191,7 +191,7 @@ def test_address_range_print_resolved(self):
 interp.HandleCommand(script, result, False)
 self.assertTrue(result.Succeeded(), "script command succeeded")
 # [0x1000-0x2000] // Resolved with target or addresses without sections
-self.assertRegex(result.GetOutput(), "^\[0x[0-9a-f]+\-0x[0-9a-f]+\)$")
+self.assertRegex(result.GetOutput(), 
"^\[0x[0-9a-f]+\-0x[0-9a-f]+\)\r?$")
 process.Kill()
 
 def test_address_range_print_no_section_resolved(self):

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add AddressRange to SB API (PR #93836)

2024-05-30 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/93836

Summary:
This adds new SB API calls and classes to allow a user of the SB API to obtain 
an address range from SBFunction and SBBlock. This is a second attempt to land 
the reverted PR #92014.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:

>From 39e2add3c000c7953a19710bd66d133f9bcc842a Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.
This is a second attempt to land the reverted PR #92014.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |  11 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  29 ++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  66 +
 lldb/include/lldb/API/SBAddressRangeList.h|  54 
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/API/SBTarget.h  |   1 +
 lldb/include/lldb/Core/AddressRange.h |  14 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |  51 
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 103 +++
 lldb/source/API/SBAddressRangeList.cpp|  94 +++
 lldb/source/API/SBBlock.cpp   |  10 +
 lldb/source/API/SBFunction.cpp|  14 +
 lldb/source/Core/AddressRange.cpp |  43 +++
 lldb/source/Core/AddressRangeListImpl.cpp |  50 
 lldb/source/Core/CMakeLists.txt   |   1 +
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 262 ++
 .../API/python_api/address_range/main.cpp |   8 +
 31 files changed, 865 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/include/lldb/Core/AddressRangeListImpl.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/source/Core/AddressRangeListImpl.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index ffdc3c31ec883..c91504604b6ac 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..31bcfcb64590b
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1,11 @@
+%extend lldb::SBAddressRange {
+#ifdef SWIGPYTHON
+%pythoncode%{
+  def __repr__(self):
+import lldb
+stream = lldb.SBStream()
+self.GetDescription(stream, lldb.target if lldb.target else 
lldb.SBTarget())
+return stream.GetData()
+%}
+#endif
+}
diff --git 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-29 Thread Miro Bucko via lldb-commits

mbucko wrote:

If the a.out is not there then the address was not resolved, I will investigate.

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Fix formatter tests for clang version 15 (PR #93710)

2024-05-29 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/93710

Summary:

Test Plan:
ninja check-lldb

Reviewers:
clayborg

Subscribers:

Tasks:

Tags:

>From b6c70ac7b4c479fcdeb5d5c8b06da5a16ae468c4 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Wed, 29 May 2024 10:28:16 -0700
Subject: [PATCH] [lldb][test] Fix formatter tests for clang version 15

Summary:

Test Plan:
ninja check-lldb

Reviewers:
clayborg

Subscribers:

Tasks:

Tags:
---
 .../import-std-module/deque-basic/TestDequeFromStdModule.py   | 2 +-
 .../TestDbgInfoContentDequeFromStdModule.py   | 2 +-
 .../TestDbgInfoContentForwardListFromStdModule.py | 2 +-
 .../forward_list/TestForwardListFromStdModule.py  | 2 +-
 .../TestDbgInfoContentListFromStdModule.py| 2 +-
 .../import-std-module/list/TestListFromStdModule.py   | 2 +-
 .../non-module-type-separation/TestNonModuleTypeSeparation.py | 2 +-
 .../import-std-module/queue/TestQueueFromStdModule.py | 4 ++--
 .../retry-with-std-module/TestRetryWithStdModule.py   | 2 +-
 .../TestUniquePtrDbgInfoContent.py| 2 +-
 .../unique_ptr/TestUniquePtrFromStdModule.py  | 2 +-
 .../TestDbgInfoContentVectorFromStdModule.py  | 2 +-
 .../vector-of-vectors/TestVectorOfVectorsFromStdModule.py | 2 +-
 .../libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py | 2 +-
 .../libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py | 4 ++--
 15 files changed, 17 insertions(+), 17 deletions(-)

diff --git 
a/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
index 9e2fc17fa10b4..4168570f38c70 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
@@ -20,7 +20,7 @@ def test(self):
 self.runCmd("settings set target.import-std-module true")
 
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
-[">", "16.0"]
+[">", "14.0"]
 ):
 deque_type = "std::deque"
 else:
diff --git 
a/lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
index 24b1e00de67c7..cf11668290eee 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
@@ -21,7 +21,7 @@ def test(self):
 self.runCmd("settings set target.import-std-module true")
 
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
-[">", "16.0"]
+[">", "14.0"]
 ):
 deque_type = "std::deque"
 else:
diff --git 
a/lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
index 9b0ca8c49f003..1a146767cc1f8 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
@@ -20,7 +20,7 @@ def test(self):
 self.runCmd("settings set target.import-std-module true")
 
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
-[">", "16.0"]
+[">", "14.0"]
 ):
 list_type = "std::forward_list"
 else:
diff --git 
a/lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
index 10dd8ee01081c..c7382220883a9 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
@@ -20,7 +20,7 @@ def test(self):
 self.runCmd("settings set target.import-std-module true")
 
 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
-[">", "16.0"]
+[">", "14.0"]
 ):
 list_type = "std::forward_list"
 else:
diff --git 
a/lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
 

[Lldb-commits] [lldb] [nfc][lldb] Move FastSearch from CommandObjectMemoryFind to Process (PR #93688)

2024-05-29 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/93688

>From 6e461bef5a7f3bda3ff413168b3cc2a26b41cdb0 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Wed, 29 May 2024 06:38:22 -0700
Subject: [PATCH] [nfc][lldb] Move FastSearch from CommandObjectMemoryFind to
 Process

Summary:
Moving CommandObjectMemoryFind::FastSearch() to Process::FindInMemory().
Plan to expose FindInMemory as public API in SBProcess.

Test Plan:
ninja check-lldb

Reviewers:

Subscribers:

Tasks:
lldb

Tags:
---
 lldb/include/lldb/Target/Process.h   | 22 +++
 lldb/source/Commands/CommandObjectMemory.cpp | 61 +---
 lldb/source/Target/Process.cpp   | 54 +
 3 files changed, 78 insertions(+), 59 deletions(-)

diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 637d34c29715c..eec337c15f7ed 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2663,6 +2663,28 @@ void PruneThreadPlans();
 return m_source_file_cache;
   }
 
+  /// Find a pattern within a memory region.
+  ///
+  /// This function searches for a pattern represented by the provided buffer
+  /// within the memory range specified by the low and high addresses. It uses
+  /// a bad character heuristic to optimize the search process.
+  ///
+  /// \param[in] low The starting address of the memory region to be searched.
+  /// (inclusive)
+  ///
+  /// \param[in] high The ending address of the memory region to be searched.
+  /// (exclusive)
+  ///
+  /// \param[in] buf A pointer to the buffer containing the pattern to be
+  /// searched.
+  ///
+  /// \param[in] buffer_size The size of the buffer in bytes.
+  ///
+  /// \return The address where the pattern was found or LLDB_INVALID_ADDRESS 
if
+  /// not found.
+  lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
+const uint8_t *buf, size_t size);
+
 protected:
   friend class Trace;
 
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp 
b/lldb/source/Commands/CommandObjectMemory.cpp
index b78a0492cca55..1c13484dede64 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -977,35 +977,6 @@ class CommandObjectMemoryFind : public CommandObjectParsed 
{
   Options *GetOptions() override { return _option_group; }
 
 protected:
-  class ProcessMemoryIterator {
-  public:
-ProcessMemoryIterator(ProcessSP process_sp, lldb::addr_t base)
-: m_process_sp(process_sp), m_base_addr(base) {
-  lldbassert(process_sp.get() != nullptr);
-}
-
-bool IsValid() { return m_is_valid; }
-
-uint8_t operator[](lldb::addr_t offset) {
-  if (!IsValid())
-return 0;
-
-  uint8_t retval = 0;
-  Status error;
-  if (0 ==
-  m_process_sp->ReadMemory(m_base_addr + offset, , 1, error)) {
-m_is_valid = false;
-return 0;
-  }
-
-  return retval;
-}
-
-  private:
-ProcessSP m_process_sp;
-lldb::addr_t m_base_addr;
-bool m_is_valid = true;
-  };
   void DoExecute(Args , CommandReturnObject ) override {
 // No need to check "process" for validity as eCommandRequiresProcess
 // ensures it is valid
@@ -1106,8 +1077,8 @@ class CommandObjectMemoryFind : public 
CommandObjectParsed {
 found_location = low_addr;
 bool ever_found = false;
 while (count) {
-  found_location = FastSearch(found_location, high_addr, buffer.GetBytes(),
-  buffer.GetByteSize());
+  found_location = process->FindInMemory(
+  found_location, high_addr, buffer.GetBytes(), buffer.GetByteSize());
   if (found_location == LLDB_INVALID_ADDRESS) {
 if (!ever_found) {
   result.AppendMessage("data not found within the range.\n");
@@ -1144,34 +1115,6 @@ class CommandObjectMemoryFind : public 
CommandObjectParsed {
 result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
   }
 
-  lldb::addr_t FastSearch(lldb::addr_t low, lldb::addr_t high, uint8_t *buffer,
-  size_t buffer_size) {
-const size_t region_size = high - low;
-
-if (region_size < buffer_size)
-  return LLDB_INVALID_ADDRESS;
-
-std::vector bad_char_heuristic(256, buffer_size);
-ProcessSP process_sp = m_exe_ctx.GetProcessSP();
-ProcessMemoryIterator iterator(process_sp, low);
-
-for (size_t idx = 0; idx < buffer_size - 1; idx++) {
-  decltype(bad_char_heuristic)::size_type bcu_idx = buffer[idx];
-  bad_char_heuristic[bcu_idx] = buffer_size - idx - 1;
-}
-for (size_t s = 0; s <= (region_size - buffer_size);) {
-  int64_t j = buffer_size - 1;
-  while (j >= 0 && buffer[j] == iterator[s + j])
-j--;
-  if (j < 0)
-return low + s;
-  else
-s += bad_char_heuristic[iterator[s + buffer_size - 1]];
-}
-
-return LLDB_INVALID_ADDRESS;
-  }
-
   OptionGroupOptions m_option_group;
   

[Lldb-commits] [lldb] [nfc][lldb] Move FastSearch from CommandObjectMemoryFind to Process (PR #93688)

2024-05-29 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/93688

Summary:
Moving CommandObjectMemoryFind::FastSearch() to Process::FindInMemory(). Plan 
to expose FindInMemory as public API in SBProcess.

Test Plan:
ninja check-lldb

Reviewers: clayborg

Subscribers:

Tasks:
lldb

Tags:

>From b6ac1147a441d774c8a5ea4c2de620b72be151e2 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Wed, 29 May 2024 06:38:22 -0700
Subject: [PATCH] [nfc][lldb] Move FastSearch from CommandObjectMemoryFind to
 Process

Summary:
Moving CommandObjectMemoryFind::FastSearch() to Process::FindInMemory().
Plan to expose FindInMemory as public API in SBProcess.

Test Plan:
ninja check-lldb

Reviewers:

Subscribers:

Tasks:
lldb

Tags:
---
 lldb/include/lldb/Target/Process.h   | 22 +++
 lldb/source/Commands/CommandObjectMemory.cpp | 61 +---
 lldb/source/Target/Process.cpp   | 55 ++
 3 files changed, 79 insertions(+), 59 deletions(-)

diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 637d34c29715c1..f293d1e78494f7 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2663,6 +2663,28 @@ void PruneThreadPlans();
 return m_source_file_cache;
   }
 
+  /// Find a pattern within a memory region.
+  ///
+  /// This function searches for a pattern represented by the provided buffer
+  /// within the memory range specified by the low and high addresses. It uses
+  /// a bad character heuristic to optimize the search process.
+  ///
+  /// \param[in] low The starting address of the memory region to be searched.
+  /// (inclusive)
+  ///
+  /// \param[in] high The ending address of the memory region to be searched.
+  /// (exclusive)
+  ///
+  /// \param[in] buf A pointer to the buffer containing the pattern to be
+  /// searched.
+  ///
+  /// \param[in] buffer_size The size of the buffer in bytes.
+  ///
+  /// \return The address where the pattern was found or LLDB_INVALID_ADDRESS 
if
+  /// not found.
+  lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high, 
+const uint8_t *buf, size_t size);
+
 protected:
   friend class Trace;
 
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp 
b/lldb/source/Commands/CommandObjectMemory.cpp
index b78a0492cca558..1c13484dede648 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -977,35 +977,6 @@ class CommandObjectMemoryFind : public CommandObjectParsed 
{
   Options *GetOptions() override { return _option_group; }
 
 protected:
-  class ProcessMemoryIterator {
-  public:
-ProcessMemoryIterator(ProcessSP process_sp, lldb::addr_t base)
-: m_process_sp(process_sp), m_base_addr(base) {
-  lldbassert(process_sp.get() != nullptr);
-}
-
-bool IsValid() { return m_is_valid; }
-
-uint8_t operator[](lldb::addr_t offset) {
-  if (!IsValid())
-return 0;
-
-  uint8_t retval = 0;
-  Status error;
-  if (0 ==
-  m_process_sp->ReadMemory(m_base_addr + offset, , 1, error)) {
-m_is_valid = false;
-return 0;
-  }
-
-  return retval;
-}
-
-  private:
-ProcessSP m_process_sp;
-lldb::addr_t m_base_addr;
-bool m_is_valid = true;
-  };
   void DoExecute(Args , CommandReturnObject ) override {
 // No need to check "process" for validity as eCommandRequiresProcess
 // ensures it is valid
@@ -1106,8 +1077,8 @@ class CommandObjectMemoryFind : public 
CommandObjectParsed {
 found_location = low_addr;
 bool ever_found = false;
 while (count) {
-  found_location = FastSearch(found_location, high_addr, buffer.GetBytes(),
-  buffer.GetByteSize());
+  found_location = process->FindInMemory(
+  found_location, high_addr, buffer.GetBytes(), buffer.GetByteSize());
   if (found_location == LLDB_INVALID_ADDRESS) {
 if (!ever_found) {
   result.AppendMessage("data not found within the range.\n");
@@ -1144,34 +1115,6 @@ class CommandObjectMemoryFind : public 
CommandObjectParsed {
 result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
   }
 
-  lldb::addr_t FastSearch(lldb::addr_t low, lldb::addr_t high, uint8_t *buffer,
-  size_t buffer_size) {
-const size_t region_size = high - low;
-
-if (region_size < buffer_size)
-  return LLDB_INVALID_ADDRESS;
-
-std::vector bad_char_heuristic(256, buffer_size);
-ProcessSP process_sp = m_exe_ctx.GetProcessSP();
-ProcessMemoryIterator iterator(process_sp, low);
-
-for (size_t idx = 0; idx < buffer_size - 1; idx++) {
-  decltype(bad_char_heuristic)::size_type bcu_idx = buffer[idx];
-  bad_char_heuristic[bcu_idx] = buffer_size - idx - 1;
-}
-for (size_t s = 0; s <= (region_size - buffer_size);) {
-  int64_t j = buffer_size - 1;
-  while (j >= 0 && buffer[j] == iterator[s + j])
-  

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-28 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From a436c3faf4017b0c84b45046f6eedef9229d3e1d Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |  11 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  29 ++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  66 +
 lldb/include/lldb/API/SBAddressRangeList.h|  54 
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/API/SBTarget.h  |   1 +
 lldb/include/lldb/Core/AddressRange.h |  14 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |  51 
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 103 +++
 lldb/source/API/SBAddressRangeList.cpp|  94 +++
 lldb/source/API/SBBlock.cpp   |  10 +
 lldb/source/API/SBFunction.cpp|  14 +
 lldb/source/Core/AddressRange.cpp |  43 +++
 lldb/source/Core/AddressRangeListImpl.cpp |  50 
 lldb/source/Core/CMakeLists.txt   |   1 +
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 256 ++
 .../API/python_api/address_range/main.cpp |   8 +
 31 files changed, 859 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/include/lldb/Core/AddressRangeListImpl.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/source/Core/AddressRangeListImpl.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index ffdc3c31ec883..c91504604b6ac 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..31bcfcb64590b
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1,11 @@
+%extend lldb::SBAddressRange {
+#ifdef SWIGPYTHON
+%pythoncode%{
+  def __repr__(self):
+import lldb
+stream = lldb.SBStream()
+self.GetDescription(stream, lldb.target if lldb.target else 
lldb.SBTarget())
+return stream.GetData()
+%}
+#endif
+}
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-24 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 74ddb1e1cf40a388c1d57145fed3953ee4a5eab7 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |  11 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  27 ++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  66 +
 lldb/include/lldb/API/SBAddressRangeList.h|  54 
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/API/SBTarget.h  |   1 +
 lldb/include/lldb/Core/AddressRange.h |  14 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |  51 
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 103 +++
 lldb/source/API/SBAddressRangeList.cpp|  94 +++
 lldb/source/API/SBBlock.cpp   |  10 +
 lldb/source/API/SBFunction.cpp|  14 +
 lldb/source/Core/AddressRange.cpp |  43 +++
 lldb/source/Core/AddressRangeListImpl.cpp |  50 
 lldb/source/Core/CMakeLists.txt   |   1 +
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 251 ++
 .../API/python_api/address_range/main.cpp |   8 +
 31 files changed, 852 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/include/lldb/Core/AddressRangeListImpl.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/source/Core/AddressRangeListImpl.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index ffdc3c31ec883..c91504604b6ac 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..31bcfcb64590b
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1,11 @@
+%extend lldb::SBAddressRange {
+#ifdef SWIGPYTHON
+%pythoncode%{
+  def __repr__(self):
+import lldb
+stream = lldb.SBStream()
+self.GetDescription(stream, lldb.target if lldb.target else 
lldb.SBTarget())
+return stream.GetData()
+%}
+#endif
+}
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-21 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,65 @@
+//===-- SBAddressRange.h *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_API_SBADDRESSRANGE_H
+#define LLDB_API_SBADDRESSRANGE_H
+
+#include "lldb/API/SBDefines.h"
+
+namespace lldb {
+
+class LLDB_API SBAddressRange {
+public:
+  SBAddressRange();
+
+  SBAddressRange(const lldb::SBAddressRange );
+
+  SBAddressRange(lldb::SBAddress addr, lldb::addr_t byte_size);
+
+  ~SBAddressRange();
+
+  const lldb::SBAddressRange =(const lldb::SBAddressRange );
+
+  void Clear();
+
+  /// Check the address range refers to a valid base address and has a byte
+  /// size greater than zero.
+  ///
+  /// \return
+  /// True if the address range is valid, false otherwise.
+  bool IsValid() const;
+
+  /// Get the base address of the range.
+  ///
+  /// \return
+  /// Base address object.
+  lldb::SBAddress GetBaseAddress() const;
+
+  /// Get the byte size of this range.
+  ///
+  /// \return
+  /// The size in bytes of this address range.
+  lldb::addr_t GetByteSize() const;
+
+  bool operator==(const SBAddressRange );
+
+  bool operator!=(const SBAddressRange );
+
+  bool GetDescription(lldb::SBStream , SBTarget *target);

mbucko wrote:

Target might be null though

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-21 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From bcca8420736283bf564cf86e1442f023ba63b9e9 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |  11 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  28 ++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 +
 lldb/include/lldb/API/SBAddressRangeList.h|  54 
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/API/SBTarget.h  |   1 +
 lldb/include/lldb/Core/AddressRange.h |  14 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |  51 
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 103 
 lldb/source/API/SBAddressRangeList.cpp|  93 +++
 lldb/source/API/SBBlock.cpp   |  10 +
 lldb/source/API/SBFunction.cpp|  14 +
 lldb/source/Core/AddressRange.cpp |  43 
 lldb/source/Core/AddressRangeListImpl.cpp |  50 
 lldb/source/Core/CMakeLists.txt   |   1 +
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 240 ++
 .../API/python_api/address_range/main.cpp |   8 +
 31 files changed, 840 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/include/lldb/Core/AddressRangeListImpl.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/source/Core/AddressRangeListImpl.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index ffdc3c31ec883..c91504604b6ac 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..9ff8e78080eb2
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1,11 @@
+%extend lldb::SBAddressRange {
+#ifdef SWIGPYTHON
+%pythoncode%{
+  def __repr__(self):
+import lldb
+stream = lldb.SBStream()
+self.GetDescription(stream, lldb.target)
+return stream.GetData()
+%}
+#endif
+}
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-21 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,91 @@
+//===-- SBAddressRangeList.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/API/SBAddressRangeList.h"
+#include "Utils.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBStream.h"
+#include "lldb/Core/AddressRangeListImpl.h"
+#include "lldb/Utility/Instrumentation.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+SBAddressRangeList::SBAddressRangeList()
+: m_opaque_up(new AddressRangeListImpl()) {
+  LLDB_INSTRUMENT_VA(this);
+}
+
+SBAddressRangeList::SBAddressRangeList(const SBAddressRangeList )
+: m_opaque_up(new AddressRangeListImpl(*rhs.m_opaque_up)) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+}
+
+SBAddressRangeList::~SBAddressRangeList() = default;
+
+const SBAddressRangeList &
+SBAddressRangeList::operator=(const SBAddressRangeList ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  if (this != )
+*m_opaque_up = *rhs.m_opaque_up;
+  return *this;
+}
+
+uint32_t SBAddressRangeList::GetSize() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  return m_opaque_up->GetSize();
+}
+
+SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
+  LLDB_INSTRUMENT_VA(this, idx);
+
+  SBAddressRange sb_addr_range;
+  (*sb_addr_range.m_opaque_up) = m_opaque_up->GetAddressRangeAtIndex(idx);
+  return sb_addr_range;
+}
+
+void SBAddressRangeList::Clear() {
+  LLDB_INSTRUMENT_VA(this);
+
+  m_opaque_up->Clear();
+}
+
+void SBAddressRangeList::Append(const SBAddressRange _addr_range) {
+  LLDB_INSTRUMENT_VA(this, sb_addr_range);
+
+  m_opaque_up->Append(*sb_addr_range.m_opaque_up);
+}
+
+void SBAddressRangeList::Append(const SBAddressRangeList _addr_range_list) {
+  LLDB_INSTRUMENT_VA(this, sb_addr_range_list);
+
+  m_opaque_up->Append(*sb_addr_range_list.m_opaque_up);
+}
+
+bool SBAddressRangeList::GetDescription(SBStream ,
+SBTarget *target) {
+  LLDB_INSTRUMENT_VA(this, description);
+
+  const uint32_t num_ranges = GetSize();
+  bool is_first = true;
+  Stream  = description.ref();
+  stream << "[";
+  for (uint32_t i = 0; i < num_ranges; ++i) {
+if (is_first) {
+  is_first = false;
+} else {
+  stream.Printf(", ");
+}

mbucko wrote:

This is actually correct, it prints out:
`[a.out[0x115f-0x1167), a.out[0x1134-0x1144), a.out[0x1144-0x1164)]`

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-21 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,54 @@
+//===-- SBAddressRangeList.h *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_API_SBADDRESSRANGELIST_H
+#define LLDB_API_SBADDRESSRANGELIST_H
+
+#include 
+
+#include "lldb/API/SBDefines.h"
+
+namespace lldb_private {
+class AddressRangeListImpl;
+}
+
+namespace lldb {
+
+class LLDB_API SBAddressRangeList {
+public:
+  SBAddressRangeList();
+
+  SBAddressRangeList(const lldb::SBAddressRangeList );
+
+  ~SBAddressRangeList();
+
+  const lldb::SBAddressRangeList &
+  operator=(const lldb::SBAddressRangeList );
+
+  uint32_t GetSize() const;
+
+  void Clear();
+
+  SBAddressRange GetAddressRangeAtIndex(uint64_t idx);

mbucko wrote:

https://github.com/llvm/llvm-project/pull/92014#discussion_r1599157212

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-21 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,28 @@
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
object.'''
+  return lldb_iter(self, 'GetSize', 'GetAddressRangeAtIndex')
+
+def __getitem__(self, idx):
+  '''Get the address range at a given index in an lldb.SBAddressRangeList 
object.'''
+  if type(idx) == int:
+if idx >= self.GetSize():
+  raise IndexError("list index out of range")
+return self.GetAddressRangeAtIndex(idx)
+  else:
+print("error: unsupported idx type: %s" % type(key))
+return None

mbucko wrote:

I'm following the convention from other Extensions files

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-21 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,28 @@
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
object.'''
+  return lldb_iter(self, 'GetSize', 'GetAddressRangeAtIndex')
+
+def __getitem__(self, idx):
+  '''Get the address range at a given index in an lldb.SBAddressRangeList 
object.'''
+  if type(idx) == int:
+if idx >= self.GetSize():
+  raise IndexError("list index out of range")
+return self.GetAddressRangeAtIndex(idx)
+  else:
+print("error: unsupported idx type: %s" % type(key))
+return None
+def __repr__(self):
+  import lldb

mbucko wrote:

same as above

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-21 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,11 @@
+%extend lldb::SBAddressRange {
+#ifdef SWIGPYTHON
+%pythoncode%{
+  def __repr__(self):
+import lldb

mbucko wrote:

it's not, produces the following error:
`NameError: name 'lldb' is not defined`

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-20 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From b29f3fcea87c3ce7cf65de14dc924f1862c63098 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |  11 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  28 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  54 +
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/API/SBTarget.h  |   1 +
 lldb/include/lldb/Core/AddressRange.h |  14 ++
 lldb/include/lldb/Core/AddressRangeListImpl.h |  51 +
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 103 +
 lldb/source/API/SBAddressRangeList.cpp|  91 
 lldb/source/API/SBBlock.cpp   |  10 +
 lldb/source/API/SBFunction.cpp|  14 ++
 lldb/source/Core/AddressRange.cpp |  40 
 lldb/source/Core/AddressRangeListImpl.cpp |  50 
 lldb/source/Core/CMakeLists.txt   |   1 +
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 216 ++
 .../API/python_api/address_range/main.cpp |   8 +
 31 files changed, 811 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/include/lldb/Core/AddressRangeListImpl.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/source/Core/AddressRangeListImpl.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index ffdc3c31ec883..c91504604b6ac 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..9ff8e78080eb2
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1,11 @@
+%extend lldb::SBAddressRange {
+#ifdef SWIGPYTHON
+%pythoncode%{
+  def __repr__(self):
+import lldb
+stream = lldb.SBStream()
+self.GetDescription(stream, lldb.target)
+return stream.GetData()
+%}
+#endif
+}
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-17 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,215 @@
+"""
+Test SBAddressRange APIs.
+"""
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class AddressRangeTestCase(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+def setUp(self):
+TestBase.setUp(self)
+
+self.build()
+exe = self.getBuildArtifact("a.out")
+
+self.dbg.SetAsync(True)
+
+self.target = self.dbg.CreateTarget(exe)
+self.assertTrue(self.target, VALID_TARGET)
+self.launch_info = self.target.GetLaunchInfo()
+
self.launch_info.SetWorkingDirectory(self.get_process_working_directory())
+
+self.bp1 = self.target.BreakpointCreateByName("main", "a.out")
+self.bp2 = self.target.BreakpointCreateByName("foo", "a.out")
+self.bp3 = self.target.BreakpointCreateByName("bar", "a.out")
+
+self.assertTrue(self.bp1.IsValid())
+self.assertTrue(self.bp2.IsValid())
+self.assertTrue(self.bp3.IsValid())
+
+self.addr1 = self.bp1.GetLocationAtIndex(0).GetAddress()
+self.addr2 = self.bp2.GetLocationAtIndex(0).GetAddress()
+self.addr3 = self.bp3.GetLocationAtIndex(0).GetAddress()
+
+self.assertTrue(self.addr1.IsValid())
+self.assertTrue(self.addr2.IsValid())
+self.assertTrue(self.addr3.IsValid())
+
+def test_address_range_default(self):
+"""Testing default constructor."""
+empty_range = lldb.SBAddressRange()
+self.assertEqual(empty_range.IsValid(), False)
+
+def test_address_range_construction(self):
+"""Make sure the construction and getters work."""
+range = lldb.SBAddressRange(self.addr1, 8)
+self.assertEqual(range.IsValid(), True)
+self.assertEqual(range.GetBaseAddress(), self.addr1)
+self.assertEqual(range.GetByteSize(), 8)
+
+def test_address_range_clear(self):
+"""Make sure the clear method works."""
+range = lldb.SBAddressRange(self.addr1, 8)
+self.assertEqual(range.IsValid(), True)
+self.assertEqual(range.GetBaseAddress(), self.addr1)
+self.assertEqual(range.GetByteSize(), 8)
+
+range.Clear()
+self.assertEqual(range.IsValid(), False)
+
+def test_function(self):
+"""Make sure the range works in SBFunction APIs."""
+
+# Setup breakpoints in main
+loc = self.bp1.GetLocationAtIndex(0)
+loc_addr = loc.GetAddress()
+func = loc_addr.GetFunction()
+ranges = func.GetRanges()
+self.assertEqual(ranges.GetSize(), 1)
+
+range = ranges.GetAddressRangeAtIndex(0)
+self.assertEqual(
+range.GetByteSize(),
+func.GetEndAddress().GetOffset() - 
func.GetStartAddress().GetOffset(),
+)
+self.assertEqual(
+range.GetBaseAddress().GetOffset(),
+func.GetStartAddress().GetOffset(),
+)
+
+def test_block(self):
+"""Make sure the range works in SBBlock APIs."""
+loc = self.bp1.GetLocationAtIndex(0)
+loc_addr = loc.GetAddress()
+block = loc_addr.GetBlock()
+
+ranges = block.GetRanges()
+self.assertEqual(ranges.GetSize(), 1)
+
+range = ranges.GetAddressRangeAtIndex(0)
+self.assertEqual(
+range.GetByteSize(),
+block.GetRangeEndAddress(0).GetOffset()
+- block.GetRangeStartAddress(0).GetOffset(),
+)
+self.assertEqual(
+range.GetBaseAddress().GetOffset(),
+block.GetRangeStartAddress(0).GetOffset(),
+)
+
+def test_address_range_list(self):
+"""Make sure the SBAddressRangeList works by adding and getting 
ranges."""
+range1 = lldb.SBAddressRange(self.addr1, 8)
+range2 = lldb.SBAddressRange(self.addr2, 16)
+range3 = lldb.SBAddressRange(self.addr3, 32)
+
+range_list = lldb.SBAddressRangeList()
+self.assertEqual(range_list.GetSize(), 0)
+
+range_list.Append(range1)
+range_list.Append(range2)
+range_list.Append(range3)
+self.assertEqual(range_list.GetSize(), 3)
+self.assertRaises(IndexError, lambda: range_list[3])
+
+range1_copy = range_list.GetAddressRangeAtIndex(0)
+self.assertEqual(range1.GetByteSize(), range1_copy.GetByteSize())
+self.assertEqual(
+range1.GetBaseAddress().GetOffset(),
+range1_copy.GetBaseAddress().GetOffset(),
+)
+
+range2_copy = range_list.GetAddressRangeAtIndex(1)
+self.assertEqual(range2.GetByteSize(), range2_copy.GetByteSize())
+self.assertEqual(
+range2.GetBaseAddress().GetOffset(),
+range2_copy.GetBaseAddress().GetOffset(),
+)
+
+range3_copy = range_list.GetAddressRangeAtIndex(2)
+self.assertEqual(range3.GetByteSize(), range3_copy.GetByteSize())
+self.assertEqual(
+range3.GetBaseAddress().GetOffset(),
+range3_copy.GetBaseAddress().GetOffset(),
+)

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-17 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,102 @@
+//===-- SBAddressRange.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/API/SBAddressRange.h"
+#include "Utils.h"
+#include "lldb/API/SBAddress.h"
+#include "lldb/API/SBStream.h"
+#include "lldb/API/SBTarget.h"
+#include "lldb/Core/AddressRange.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Utility/Instrumentation.h"
+#include "lldb/Utility/Stream.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+SBAddressRange::SBAddressRange()
+: m_opaque_up(std::make_unique()) {
+  LLDB_INSTRUMENT_VA(this);
+}
+
+SBAddressRange::SBAddressRange(const SBAddressRange ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  m_opaque_up = clone(rhs.m_opaque_up);
+}
+
+SBAddressRange::SBAddressRange(lldb::SBAddress addr, lldb::addr_t byte_size)
+: m_opaque_up(std::make_unique(addr.ref(), byte_size)) {
+  LLDB_INSTRUMENT_VA(this, addr, byte_size);
+}
+
+SBAddressRange::~SBAddressRange() = default;
+
+const SBAddressRange ::operator=(const SBAddressRange ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  if (this != )
+m_opaque_up = clone(rhs.m_opaque_up);
+  return *this;
+}
+
+bool SBAddressRange::operator==(const SBAddressRange ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  if (!IsValid() || !rhs.IsValid())
+return false;
+  return m_opaque_up->operator==(*(rhs.m_opaque_up));
+}
+
+bool SBAddressRange::operator!=(const SBAddressRange ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  return !(*this == rhs);
+}
+
+void SBAddressRange::Clear() {
+  LLDB_INSTRUMENT_VA(this);
+
+  m_opaque_up.reset();
+}
+
+bool SBAddressRange::IsValid() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  return m_opaque_up && m_opaque_up->IsValid();
+}
+
+lldb::SBAddress SBAddressRange::GetBaseAddress() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  if (!IsValid())
+return lldb::SBAddress();
+  return lldb::SBAddress(m_opaque_up->GetBaseAddress());
+}
+
+lldb::addr_t SBAddressRange::GetByteSize() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  if (!IsValid())
+return 0;
+  return m_opaque_up->GetByteSize();
+}
+
+bool SBAddressRange::GetDescription(SBStream ) {
+  LLDB_INSTRUMENT_VA(this, description);
+
+  Stream  = description.ref();
+  if (!IsValid()) {
+stream << "";
+return true;
+  }
+  m_opaque_up->GetDescription(, nullptr);

mbucko wrote:

Need to figure out how to get hold of the current target to pass into 
GetDescription() so that we can resolve the loaded address.

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-17 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 0d8a110b922fde8e0439391f87a117c1d82913c4 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 ++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  54 +
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/API/SBTarget.h  |   1 +
 lldb/include/lldb/Core/AddressRange.h |  14 ++
 lldb/include/lldb/Core/AddressRangeListImpl.h |  51 +
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 +
 lldb/source/API/SBAddressRangeList.cpp|  90 
 lldb/source/API/SBBlock.cpp   |  10 +
 lldb/source/API/SBFunction.cpp|  14 ++
 lldb/source/Core/AddressRange.cpp |  39 
 lldb/source/Core/AddressRangeListImpl.cpp |  50 
 lldb/source/Core/CMakeLists.txt   |   1 +
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 215 ++
 .../API/python_api/address_range/main.cpp |   8 +
 31 files changed, 794 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/include/lldb/Core/AddressRangeListImpl.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/source/Core/AddressRangeListImpl.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-17 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 939d42eba9f88d90ac72782415640bbab360645c Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  54 +
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Core/AddressRangeListImpl.h |  51 +
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp|  81 
 lldb/source/API/SBBlock.cpp   |  10 +
 lldb/source/API/SBFunction.cpp|  14 ++
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Core/AddressRangeListImpl.cpp |  50 +
 lldb/source/Core/CMakeLists.txt   |   1 +
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 191 ++
 .../API/python_api/address_range/main.cpp |   8 +
 30 files changed, 734 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/include/lldb/Core/AddressRangeListImpl.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/source/Core/AddressRangeListImpl.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 1be2c95ae31621c6f5df72159f35b938318f9ed7 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 681 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 750414bde848902d3fe471e84912020a1f67d193 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 681 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits


@@ -44,6 +45,8 @@ class LLDB_API SBFunction {
 
   lldb::SBAddress GetEndAddress();
 
+  lldb::SBAddressRange GetRange();
+

mbucko wrote:

Or did you want me to return SBAddressRangeList which will always contain only 
one SBAddressRange unless SBFunction ever changes?

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 18c711d13a82a1c2559700c6b23d9300b0e5275b Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 681 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,139 @@
+//===-- SBAddressRangeList.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/API/SBAddressRangeList.h"
+#include "Utils.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBStream.h"
+#include "lldb/Core/AddressRange.h"
+#include "lldb/Utility/Instrumentation.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+class AddressRangeListImpl {
+public:
+  AddressRangeListImpl() : m_ranges() {}
+
+  AddressRangeListImpl(const AddressRangeListImpl ) = default;
+
+  AddressRangeListImpl =(const AddressRangeListImpl ) {
+if (this == )
+  return *this;
+m_ranges = rhs.m_ranges;
+return *this;
+  }
+
+  size_t GetSize() const { return m_ranges.size(); }
+
+  void Reserve(size_t capacity) { m_ranges.reserve(capacity); }
+
+  void Append(const AddressRange _region) {
+m_ranges.emplace_back(sb_region);
+  }
+
+  void Append(const AddressRangeListImpl ) {
+Reserve(GetSize() + list.GetSize());
+
+for (const auto  : list.m_ranges)
+  Append(range);
+  }
+
+  void Clear() { m_ranges.clear(); }
+
+  lldb_private::AddressRange GetAddressRangeAtIndex(size_t index) {
+if (index >= GetSize())
+  return AddressRange();
+return m_ranges[index];
+  }
+
+  AddressRanges () { return m_ranges; }
+
+private:
+  AddressRanges m_ranges;
+};
+
+SBAddressRangeList::SBAddressRangeList()
+: m_opaque_up(new AddressRangeListImpl()) {
+  LLDB_INSTRUMENT_VA(this);
+}
+
+SBAddressRangeList::SBAddressRangeList(const SBAddressRangeList )
+: m_opaque_up(new AddressRangeListImpl(*rhs.m_opaque_up)) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+}
+
+SBAddressRangeList::~SBAddressRangeList() = default;
+
+const SBAddressRangeList &
+SBAddressRangeList::operator=(const SBAddressRangeList ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  if (this != )
+*m_opaque_up = *rhs.m_opaque_up;
+  return *this;
+}
+
+uint32_t SBAddressRangeList::GetSize() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  return m_opaque_up->GetSize();
+}
+
+SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
+  LLDB_INSTRUMENT_VA(this, idx);
+
+  SBAddressRange sb_addr_range;
+  (*sb_addr_range.m_opaque_up) = m_opaque_up->GetAddressRangeAtIndex(idx);
+  return sb_addr_range;
+}
+
+void SBAddressRangeList::Clear() {
+  LLDB_INSTRUMENT_VA(this);
+
+  m_opaque_up->Clear();
+}
+
+void SBAddressRangeList::Append(const SBAddressRange _addr_range) {
+  LLDB_INSTRUMENT_VA(this, sb_addr_range);
+
+  m_opaque_up->Append(*sb_addr_range.m_opaque_up);
+}
+
+void SBAddressRangeList::Append(const SBAddressRangeList _addr_range_list) {
+  LLDB_INSTRUMENT_VA(this, sb_addr_range_list);
+
+  m_opaque_up->Append(*sb_addr_range_list);
+}
+
+const AddressRangeListImpl *SBAddressRangeList::operator->() const {
+  return m_opaque_up.get();
+}
+
+const AddressRangeListImpl ::operator*() const {
+  assert(m_opaque_up.get());
+  return *m_opaque_up;
+}
+
+AddressRanges ::ref() { return m_opaque_up->Ref(); }
+
+bool SBAddressRangeList::GetDescription(SBStream ) {
+  LLDB_INSTRUMENT_VA(this, description);
+
+  Stream  = description.ref();
+
+  const auto num_ranges = GetSize();
+  stream.Printf("%d address ranges:\n", num_ranges);
+  for (uint32_t i = 0; i < num_ranges; ++i) {
+stream << "";
+GetAddressRangeAtIndex(i).GetDescription(description);
+  }

mbucko wrote:

Which address would we print? There's the load address, file address and bunch 
of offsets

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From a169c0fd5bd599c8f4dc77555616a2bd5b967647 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  17 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 682 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From dc84f8b94c2500b3c1caf2b0c053069989cfc082 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  66 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  59 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  17 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 189 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 685 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,102 @@
+//===-- SBAddressRange.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/API/SBAddressRange.h"
+#include "Utils.h"
+#include "lldb/API/SBAddress.h"
+#include "lldb/API/SBStream.h"
+#include "lldb/Core/AddressRange.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Utility/Instrumentation.h"
+#include "lldb/Utility/Stream.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+SBAddressRange::SBAddressRange()
+: m_opaque_up(std::make_unique()) {
+  LLDB_INSTRUMENT_VA(this);
+}
+
+SBAddressRange::SBAddressRange(const SBAddressRange ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  m_opaque_up = clone(rhs.m_opaque_up);
+}
+
+SBAddressRange::SBAddressRange(lldb::SBAddress addr, lldb::addr_t byte_size)
+: m_opaque_up(std::make_unique(addr.ref(), byte_size)) {
+  LLDB_INSTRUMENT_VA(this, addr, byte_size);
+}
+
+SBAddressRange::~SBAddressRange() = default;
+
+const SBAddressRange ::operator=(const SBAddressRange ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  if (this != )
+m_opaque_up = clone(rhs.m_opaque_up);
+  return *this;
+}
+
+bool SBAddressRange::operator==(const SBAddressRange ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  if (!IsValid() || !rhs.IsValid())
+return false;
+  return m_opaque_up->operator==(*(rhs.m_opaque_up));
+}
+
+bool SBAddressRange::operator!=(const SBAddressRange ) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  return !(*this == rhs);
+}
+
+void SBAddressRange::Clear() {
+  LLDB_INSTRUMENT_VA(this);
+
+  m_opaque_up.reset();
+}
+
+bool SBAddressRange::IsValid() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  return m_opaque_up && m_opaque_up->IsValid();
+}
+
+lldb::SBAddress SBAddressRange::GetBaseAddress() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  if (!IsValid())
+return lldb::SBAddress();
+  return lldb::SBAddress(m_opaque_up->GetBaseAddress());
+}
+
+lldb::addr_t SBAddressRange::GetByteSize() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  if (!IsValid())
+return 0;
+  return m_opaque_up->GetByteSize();
+}
+
+bool SBAddressRange::GetDescription(SBStream ) {
+  LLDB_INSTRUMENT_VA(this, description);
+
+  Stream  = description.ref();
+
+  if (!IsValid()) {
+stream << "Invalid address range";
+return true;
+  }
+  m_opaque_up->DumpDebug();

mbucko wrote:

>>> print(range)
0x562434ae16b0: AddressRange section = 0x56243482eb90, offset = 
0x0130, byte_size = 0x0039

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-15 Thread Miro Bucko via lldb-commits

https://github.com/mbucko edited https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-15 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 44871da2279dc2fe001584f0cd41dc9b76b43fbd Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  23 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  66 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  59 ++
 lldb/include/lldb/API/SBBlock.h   |   6 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 139 +
 lldb/source/API/SBBlock.cpp   |  18 ++
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  29 ++-
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 702 insertions(+), 8 deletions(-)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..23ff5a4f7c41b
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,23 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-15 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From c28e0952a8c422a6dcadae0b2dce8f31a45c8d06 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  23 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  66 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  59 ++
 lldb/include/lldb/API/SBBlock.h   |   6 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 139 +
 lldb/source/API/SBBlock.cpp   |  18 ++
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  29 ++-
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 702 insertions(+), 8 deletions(-)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..23ff5a4f7c41b
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,23 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
object.'''
+  return lldb_iter(self, 'GetSize', 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-15 Thread Miro Bucko via lldb-commits


@@ -44,6 +45,8 @@ class LLDB_API SBFunction {
 
   lldb::SBAddress GetEndAddress();
 
+  lldb::SBAddressRange GetRange();
+

mbucko wrote:

GetRange() is just a forwarded function from lldb_private::Function::GetRange()

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-15 Thread Miro Bucko via lldb-commits


@@ -52,6 +53,8 @@ class LLDB_API SBBlock {
 
   lldb::SBAddress GetRangeEndAddress(uint32_t idx);
 
+  lldb::SBAddressRange GetRangeAtIndex(uint32_t idx);
+

mbucko wrote:

Currently Block doesn't have GetRanges() function but it does have 
GetRangeAtIndex().
Would you like me to add GetRanges() to Block and then expose both, GetRanges() 
and GetRangeAtIndex(), to SBBlock

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-15 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From f857042f377e107310b5cddfb4fcaed57706b5cc Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  23 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  66 +++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   3 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 139 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  11 ++
 lldb/source/Core/AddressRange.cpp |  15 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 184 ++
 .../API/python_api/address_range/main.cpp |   8 +
 25 files changed, 663 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..23ff5a4f7c41b
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,23 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
object.'''
+  return lldb_iter(self, 'GetSize', 'GetAddressRangeAtIndex')
+
+def __getitem__(self, idx):
+  '''Get the address range at a given index in an lldb.SBAddressRangeList 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-15 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 4255281194148b59dab6928b59f8bc7df93ca10e Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  23 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  66 +++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   3 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 103 ++
 lldb/source/API/SBAddressRangeList.cpp| 139 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  11 ++
 lldb/source/Core/AddressRange.cpp |  15 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 184 ++
 .../API/python_api/address_range/main.cpp |   8 +
 25 files changed, 664 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..23ff5a4f7c41b
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,23 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
object.'''
+  return lldb_iter(self, 'GetSize', 'GetAddressRangeAtIndex')
+
+def __getitem__(self, idx):
+  '''Get the address range at a given index in an lldb.SBAddressRangeList 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-14 Thread Miro Bucko via lldb-commits

mbucko wrote:

> I forgot to ask, what is the motivation behind this change? Is there 
> something you can't do with the SBAPI right now or that is better expressed 
> with SBAddressRange and SBAddressRangeList?

Yes, I want to add the following API:

lldb::SBError SBProcess::FindInMemory(const SBAddressRangeList , const 
void *buf, uint64_t size, SBAddressRangeList , size_t alignment);

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-14 Thread Miro Bucko via lldb-commits


@@ -242,6 +244,12 @@ class AddressRange {
   lldb::addr_t m_byte_size = 0; ///< The size in bytes of this address range.
 };
 
+// Forward-declarable wrapper.
+class AddressRanges : public std::vector {
+public:
+  using std::vector::vector;
+};

mbucko wrote:

I followed the same convention as here:
https://github.com/llvm/llvm-project/blob/main/lldb/include/lldb/Target/MemoryRegionInfo.h#L172

Do you have a preference?

https://github.com/llvm/llvm-project/pull/92014
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From ec177a0cf8c4816f86ab47e77f29e3fdf37323fd Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  13 ++
 lldb/bindings/interfaces.swig |   2 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  63 +
 lldb/include/lldb/API/SBAddressRangeList.h|  58 
 lldb/include/lldb/API/SBBlock.h   |   3 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/Core/AddressRange.h |   8 ++
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp|  78 +++
 lldb/source/API/SBAddressRangeList.cpp| 130 ++
 lldb/source/API/SBBlock.cpp   |  10 ++
 lldb/source/API/SBFunction.cpp|  11 ++
 lldb/source/Core/AddressRange.cpp |   4 +
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 124 +
 .../API/python_api/address_range/main.cpp |   3 +
 23 files changed, 531 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..781780b15e877
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,13 @@
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
object.'''
+  return lldb_iter(self, 'GetSize', 'GetAddressRangeAtIndex')
+%}
+#endif
+}
diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index a31a0b4af1eb6..b9aae318d0684 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -86,6 +86,8 @@
 
 /* API headers */
 %include "lldb/API/SBAddress.h"
+%include "lldb/API/SBAddressRange.h"
+%include "lldb/API/SBAddressRangeList.h"
 %include "lldb/API/SBAttachInfo.h"
 %include "lldb/API/SBBlock.h"
 %include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/include/lldb/API/LLDB.h b/lldb/include/lldb/API/LLDB.h
index b256544326a22..d8cc9f5067fe9 100644
--- a/lldb/include/lldb/API/LLDB.h
+++ 

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/92014

Summary:
This adds new SB API calls and classes to allow a user of the SB API to obtain 
an address range from SBFunction and SBBlock.

Test Plan:

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:

>From 309050cf7cecab87b851e5d70f5f7437577a828f Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  13 ++
 lldb/bindings/interfaces.swig |   2 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  63 +
 lldb/include/lldb/API/SBAddressRangeList.h|  57 
 lldb/include/lldb/API/SBBlock.h   |   3 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/Core/AddressRange.h |   8 ++
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp|  78 +++
 lldb/source/API/SBAddressRangeList.cpp| 131 ++
 lldb/source/API/SBBlock.cpp   |  10 ++
 lldb/source/API/SBFunction.cpp|  11 ++
 lldb/source/Core/AddressRange.cpp |   4 +
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 124 +
 .../API/python_api/address_range/main.cpp |   5 +
 23 files changed, 533 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..781780b15e877
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,13 @@
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
object.'''
+  return lldb_iter(self, 'GetSize', 'GetAddressRangeAtIndex')
+%}
+#endif
+}
diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index a31a0b4af1eb6..b9aae318d0684 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -86,6 +86,8 @@
 
 /* API headers */
 %include "lldb/API/SBAddress.h"
+%include "lldb/API/SBAddressRange.h"
+%include "lldb/API/SBAddressRangeList.h"
 %include "lldb/API/SBAttachInfo.h"
 %include "lldb/API/SBBlock.h"
 

[Lldb-commits] [lldb] [lldb-dap] Fix test_exit_status_message_sigterm test. (PR #90223)

2024-05-03 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/90223

>From c699eff1500a431225d4b292a51a467bd2c74e5d Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 26 Apr 2024 08:17:26 -0700
Subject: [PATCH] [lldb-dap] Fix test_exit_status_message_sigterm test.

Summary:
'test_exit_status_message_sigterm' is failing due to 'psutil' dependency 
introduced in PR #89405. This fix removes 'deque' dependency and checks if 
'psutil' can be imported before running the test. If 'psutil' cannot be 
imported, it emits a warning and skips the test.

Test Plan:
./bin/llvm-lit -sv 
/path-to-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
--filter=tools/lldb-dap/console/TestDAP_console.py

Reviewers:
@jeffreytan81,@clayborg,@kusmour, @JDevlieghere,@walter-erquinigo

Subscribers:

Tasks:
lldb-dap

Tags:
---
 .../tools/lldb-dap/console/TestDAP_console.py | 20 +--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index 8f456aaf890c7f..8769f39633e62f 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,17 +4,15 @@
 
 import dap_server
 import lldbdap_testcase
-import psutil
-from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
 
-def get_subprocess(process_name):
-queue = deque([psutil.Process(os.getpid())])
+def get_subprocess(root_process, process_name):
+queue = [root_process]
 while queue:
-process = queue.popleft()
+process = queue.pop()
 if process.name() == process_name:
 return process
 queue.extend(process.children())
@@ -131,7 +129,17 @@ def test_exit_status_message_sigterm(self):
 process_name = (
 "debugserver" if platform.system() in ["Darwin"] else "lldb-server"
 )
-process = get_subprocess(process_name)
+
+try:
+import psutil
+except ImportError:
+print(
+"psutil not installed, please install using 'pip install 
psutil'. "
+"Skipping test_exit_status_message_sigterm test.",
+file=sys.stderr,
+)
+return
+process = get_subprocess(psutil.Process(os.getpid()), process_name)
 process.terminate()
 process.wait()
 

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Fix test_exit_status_message_sigterm test. (PR #90223)

2024-04-30 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/90223

>From bb166a95bafc74860d78da0dedb5760c579cae48 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 26 Apr 2024 08:17:26 -0700
Subject: [PATCH] [lldb-dap] Fix test_exit_status_message_sigterm test.

Summary:
'test_exit_status_message_sigterm' is failing due to 'psutil' dependency 
introduced in PR #89405. This fix removes 'deque' dependency and checks if 
'psutil' can be imported before running the test. If 'psutil' cannot be 
imported, it emits a warning and skips the test.

Test Plan:
./bin/llvm-lit -sv 
/path-to-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
--filter=tools/lldb-dap/console/TestDAP_console.py

Reviewers:
@jeffreytan81,@clayborg,@kusmour, @JDevlieghere,@walter-erquinigo

Subscribers:

Tasks:
lldb-dap

Tags:
---
 .../tools/lldb-dap/console/TestDAP_console.py | 20 +--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index 8f456aaf890c7f..8769f39633e62f 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,17 +4,15 @@
 
 import dap_server
 import lldbdap_testcase
-import psutil
-from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
 
-def get_subprocess(process_name):
-queue = deque([psutil.Process(os.getpid())])
+def get_subprocess(root_process, process_name):
+queue = [root_process]
 while queue:
-process = queue.popleft()
+process = queue.pop()
 if process.name() == process_name:
 return process
 queue.extend(process.children())
@@ -131,7 +129,17 @@ def test_exit_status_message_sigterm(self):
 process_name = (
 "debugserver" if platform.system() in ["Darwin"] else "lldb-server"
 )
-process = get_subprocess(process_name)
+
+try:
+import psutil
+except ImportError:
+print(
+"psutil not installed, please install using 'pip install 
psutil'. "
+"Skipping test_exit_status_message_sigterm test.",
+file=sys.stderr,
+)
+return
+process = get_subprocess(psutil.Process(os.getpid()), process_name)
 process.terminate()
 process.wait()
 

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Fix test_exit_status_message_sigterm test. (PR #90223)

2024-04-26 Thread Miro Bucko via lldb-commits

mbucko wrote:

> What about trying to use a python builtin like 
> https://docs.python.org/3/library/multiprocessing.html#multiprocessing.active_children?

It seems that multiprocessing doesn't provide a way to iteratively list the 
subprocesses and there is no other built in python library afaik.
Do you know if it's possible to add 'psutil' as a dependency so that it's 
installed before the tests are run?

https://github.com/llvm/llvm-project/pull/90223
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Fix test_exit_status_message_sigterm test. (PR #90223)

2024-04-26 Thread Miro Bucko via lldb-commits

mbucko wrote:

> What about trying to use a python builtin like 
> https://docs.python.org/3/library/multiprocessing.html#multiprocessing.active_children?

Nice, I will look into it

https://github.com/llvm/llvm-project/pull/90223
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Fix test_exit_status_message_sigterm test. (PR #90223)

2024-04-26 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/90223

>From 6e1ef0f3fd733e75a3453e8e83994e0c921c09a0 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 26 Apr 2024 08:17:26 -0700
Subject: [PATCH] [lldb-dap] Fix test_exit_status_message_sigterm test.

Summary:
'test_exit_status_message_sigterm' is failing due to 'psutil' dependency 
introduced in PR #89405. This fix removes 'deque' dependency and checks if 
'psutil' can be imported before running the test. If 'psutil' cannot be 
imported, it emits a warning and skips the test.

Test Plan:
./bin/llvm-lit -sv 
/path-to-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
--filter=tools/lldb-dap/console/TestDAP_console.py

Reviewers:
@jeffreytan81,@clayborg,@kusmour, @JDevlieghere,@walter-erquinigo

Subscribers:

Tasks:
lldb-dap

Tags:
---
 .../tools/lldb-dap/console/TestDAP_console.py | 20 +--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index 8f456aaf890c7f..8769f39633e62f 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,17 +4,15 @@
 
 import dap_server
 import lldbdap_testcase
-import psutil
-from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
 
-def get_subprocess(process_name):
-queue = deque([psutil.Process(os.getpid())])
+def get_subprocess(root_process, process_name):
+queue = [root_process]
 while queue:
-process = queue.popleft()
+process = queue.pop()
 if process.name() == process_name:
 return process
 queue.extend(process.children())
@@ -131,7 +129,17 @@ def test_exit_status_message_sigterm(self):
 process_name = (
 "debugserver" if platform.system() in ["Darwin"] else "lldb-server"
 )
-process = get_subprocess(process_name)
+
+try:
+import psutil
+except ImportError:
+print(
+"psutil not installed, please install using 'pip install 
psutil'. "
+"Skipping test_exit_status_message_sigterm test.",
+file=sys.stderr,
+)
+return
+process = get_subprocess(psutil.Process(os.getpid()), process_name)
 process.terminate()
 process.wait()
 

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Fix test_exit_status_message_sigterm test. (PR #90223)

2024-04-26 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/90223

Summary:
'test_exit_status_message_sigterm' is failing due to 'psutil' dependency 
introduced in PR #89405. This fix removes 'deque' dependency and checks if 
'psutil' can be imported before running the test. If 'psutil' cannot be 
imported, it emits a warning and skips the test.

Test Plan:
./bin/llvm-lit -sv 
/path-to-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
--filter=tools/lldb-dap/console/TestDAP_console.py

Reviewers:
@jeffreytan81,@clayborg,@kusmour, @JDevlieghere,@walter-erquinigo

Subscribers:

Tasks:
lldb-dap

Tags:

>From 0860d377eaa0fefafcbc22072e6801fe57c53789 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 26 Apr 2024 08:17:26 -0700
Subject: [PATCH] [lldb-dap] Fix test_exit_status_message_sigterm test.

Summary:
'test_exit_status_message_sigterm' is failing due to 'psutil' dependency 
introduced in PR #89405. This fix removes 'deque' dependency and checks if 
'psutil' can be imported before running the test. If psutil cannot be imported, 
it emits a warning and skips the test.

Test Plan:
./bin/llvm-lit -sv 
/path-to-llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
--filter=tools/lldb-dap/console/TestDAP_console.py

Reviewers:

Subscribers:

Tasks:

Tags:
---
 .../tools/lldb-dap/console/TestDAP_console.py | 20 +--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index 8f456aaf890c7f..6fc044c02244b0 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,17 +4,15 @@
 
 import dap_server
 import lldbdap_testcase
-import psutil
-from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
 
-def get_subprocess(process_name):
-queue = deque([psutil.Process(os.getpid())])
+def get_subprocess(root_process, process_name):
+queue = [root_process]
 while queue:
-process = queue.popleft()
+process = queue.pop()
 if process.name() == process_name:
 return process
 queue.extend(process.children())
@@ -131,7 +129,17 @@ def test_exit_status_message_sigterm(self):
 process_name = (
 "debugserver" if platform.system() in ["Darwin"] else "lldb-server"
 )
-process = get_subprocess(process_name)
+
+try:
+import psutil
+except ImportError:
+print(
+"psutil not installed, please install using 'pip install 
psutil'. "
+"Skipping test_exit_status_message_sigterm test.",
+file=sys.stderr
+)
+return
+process = get_subprocess(psutil.Process(os.getpid()), process_name)
 process.terminate()
 process.wait()
 

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-25 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From edefccebc44296d9be29ddde2c48174feb5d2911 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 lldb/include/lldb/API/SBProcess.h |  2 +
 lldb/source/API/SBProcess.cpp |  8 +++
 .../tools/lldb-dap/console/TestDAP_console.py | 58 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  5 ++
 4 files changed, 73 insertions(+)

diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 7da3335a7234b7..f1b5d1fb92ce29 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -562,6 +562,8 @@ class LLDB_API SBProcess {
 
   lldb::SBScriptObject GetScriptedImplementation();
 
+  void GetStatus(SBStream );
+
 protected:
   friend class SBAddress;
   friend class SBBreakpoint;
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index c73348fde3f74d..c37c111c5a58e0 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -928,6 +928,14 @@ size_t SBProcess::WriteMemory(addr_t addr, const void 
*src, size_t src_len,
   return bytes_written;
 }
 
+void SBProcess::GetStatus(SBStream ) {
+  LLDB_INSTRUMENT_VA(this, status);
+
+  ProcessSP process_sp(GetSP());
+  if (process_sp)
+process_sp->GetStatus(status.ref());
+}
+
 bool SBProcess::GetDescription(SBStream ) {
   LLDB_INSTRUMENT_VA(this, description);
 
diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..8f456aaf890c7f 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,11 +4,23 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
 
+def get_subprocess(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process
+queue.extend(process.children())
+
+self.assertTrue(False, "No subprocess with name %s found" % process_name)
+
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
 self, lldb_command, contains_string, assert_msg, 
command_escape_prefix="`"
@@ -104,3 +116,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.system() in ["Darwin"] else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()
+process.wait()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_ok(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+self.continue_to_exit()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = 0 (0x)",
+console_output,
+"Exit status does not contain message 'exited with status'",
+   

[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From d0ed0c618aeaf81dd471fc31c9f14d4b207effaa Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 lldb/include/lldb/API/SBProcess.h |  2 +
 lldb/source/API/SBProcess.cpp |  8 +++
 .../tools/lldb-dap/console/TestDAP_console.py | 58 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  5 ++
 4 files changed, 73 insertions(+)

diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 7da3335a7234b7..f1b5d1fb92ce29 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -562,6 +562,8 @@ class LLDB_API SBProcess {
 
   lldb::SBScriptObject GetScriptedImplementation();
 
+  void GetStatus(SBStream );
+
 protected:
   friend class SBAddress;
   friend class SBBreakpoint;
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index b80664882ebcac..cf1ac1ae6b3377 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -928,6 +928,14 @@ size_t SBProcess::WriteMemory(addr_t addr, const void 
*src, size_t src_len,
   return bytes_written;
 }
 
+void SBProcess::GetStatus(SBStream ) {
+  LLDB_INSTRUMENT_VA(this, status);
+
+  ProcessSP process_sp(GetSP());
+  if (process_sp)
+process_sp->GetStatus(status.ref());
+}
+
 bool SBProcess::GetDescription(SBStream ) {
   LLDB_INSTRUMENT_VA(this, description);
 
diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..8f456aaf890c7f 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,11 +4,23 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
 
+def get_subprocess(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process
+queue.extend(process.children())
+
+self.assertTrue(False, "No subprocess with name %s found" % process_name)
+
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
 self, lldb_command, contains_string, assert_msg, 
command_escape_prefix="`"
@@ -104,3 +116,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.system() in ["Darwin"] else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()
+process.wait()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_ok(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+self.continue_to_exit()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = 0 (0x)",
+console_output,
+"Exit status does not contain message 'exited with status'",
+   

[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From 4c22c237dae73f3fbac22c0d725ae4fa449170df Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 lldb/include/lldb/API/SBProcess.h |  2 +
 lldb/source/API/SBProcess.cpp |  8 +++
 .../tools/lldb-dap/console/TestDAP_console.py | 57 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  5 ++
 4 files changed, 72 insertions(+)

diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 7da3335a7234b7..f1b5d1fb92ce29 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -562,6 +562,8 @@ class LLDB_API SBProcess {
 
   lldb::SBScriptObject GetScriptedImplementation();
 
+  void GetStatus(SBStream );
+
 protected:
   friend class SBAddress;
   friend class SBBreakpoint;
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index b80664882ebcac..cf1ac1ae6b3377 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -928,6 +928,14 @@ size_t SBProcess::WriteMemory(addr_t addr, const void 
*src, size_t src_len,
   return bytes_written;
 }
 
+void SBProcess::GetStatus(SBStream ) {
+  LLDB_INSTRUMENT_VA(this, status);
+
+  ProcessSP process_sp(GetSP());
+  if (process_sp)
+process_sp->GetStatus(status.ref());
+}
+
 bool SBProcess::GetDescription(SBStream ) {
   LLDB_INSTRUMENT_VA(this, description);
 
diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..8c71ca1777b9dd 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,10 +4,21 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+def get_subprocess(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process
+queue.extend(process.children())
+
+self.assertTrue(False, "No subprocess with name %s found" % process_name)
 
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
@@ -104,3 +115,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.system() in ["Darwin"] else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()
+process.wait()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_ok(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+self.continue_to_exit()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = 0 (0x)",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp 

[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits


@@ -4,10 +4,30 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+def get_subprocess_pid(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process.pid
+queue.extend(process.children())

mbucko wrote:

The lldb-server is not a direct subprocess of these tests. It's actually 
llvm-lit -> lldb-dap -> lldb-server. And also, lldb-dap has already been 
renamed once.

https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From b20ef7c68e23835ebf2c31f836407a0fb9f875a0 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 .../tools/lldb-dap/console/TestDAP_console.py | 57 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  8 +++
 2 files changed, 65 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..2ffb67ac84c86c 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,10 +4,21 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+def get_subprocess(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process
+queue.extend(process.children())
+
+self.assertTrue(False, "No subprocess with name %s found" % process_name)
 
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
@@ -104,3 +115,49 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = (
+"debugserver" if platform.platform() == "MacOS" else "lldb-server"
+)
+process = get_subprocess(process_name)
+process.terminate()
+process.wait(timeout=5)
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_ok(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+self.continue_to_exit()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = 0 (0x)",
+console_output,
+"Exit status does not contain message 'exited with status'",
+)
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 25c5ad56e3d6fe..124e5a087618a7 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -503,6 +503,14 @@ void EventThreadFunction() {
 SendContinuedEvent();
 break;
   case lldb::eStateExited:
+const int exit_status = process.GetExitStatus();
+const char *const exit_description = process.GetExitDescription();
+g_dap.SendFormattedOutput(
+OutputType::Console,
+"Process %" PRIu64 " exited with status = %i (0x%8.8x) %s\n",
+process.GetProcessID(), exit_status, exit_status,
+exit_description ? exit_description : "");
+
 // When restarting, we can get an "exited" event for the process we
 // just killed with the old PID, or even with no PID. In that case
 // we don't have to terminate the session.

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From 5e270c26adbb1e8febb72fc74d348d4f9619c7bf Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 .../tools/lldb-dap/console/TestDAP_console.py | 55 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  8 +++
 2 files changed, 63 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..5312cceb205830 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,10 +4,21 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+def get_subprocess(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process
+queue.extend(process.children())
+
+self.assertTrue(False, "No subprocess with name %s found" % process_name)
 
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
@@ -104,3 +115,47 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_sigterm(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = "debugserver" if platform.platform() == "MacOS" else 
"lldb-server"
+process = get_subprocess(process_name)
+process.terminate()
+process.wait(timeout=5)
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'"
+)
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message_ok(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+self.continue_to_exit()
+
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = 0 (0x)",
+console_output,
+"Exit status does not contain message 'exited with status'"
+)
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 25c5ad56e3d6fe..124e5a087618a7 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -503,6 +503,14 @@ void EventThreadFunction() {
 SendContinuedEvent();
 break;
   case lldb::eStateExited:
+const int exit_status = process.GetExitStatus();
+const char *const exit_description = process.GetExitDescription();
+g_dap.SendFormattedOutput(
+OutputType::Console,
+"Process %" PRIu64 " exited with status = %i (0x%8.8x) %s\n",
+process.GetProcessID(), exit_status, exit_status,
+exit_description ? exit_description : "");
+
 // When restarting, we can get an "exited" event for the process we
 // just killed with the old PID, or even with no PID. In that case
 // we don't have to terminate the session.

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-22 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From 91a4fa40c9fdaee1794fedb3c49707130c22a06b Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 .../tools/lldb-dap/console/TestDAP_console.py | 44 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  8 
 2 files changed, 52 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..481e6c9eaa5bfc 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,10 +4,30 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
+from collections import deque
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+def get_subprocess_pid(process_name):
+queue = deque([psutil.Process(os.getpid())])
+while queue:
+process = queue.popleft()
+if process.name() == process_name:
+return process.pid
+queue.extend(process.children())
+
+print(f"No subprocess with name {process_name} found", flush=True, 
file=sys.stderr)
+return None
+
+def killProcess(pid, process_name):
+process = psutil.Process(pid)
+process.terminate()
+try:
+process.wait(timeout=5)
+except psutil.TimeoutExpired:
+self.assertTrue(False, process_name + " process should have exited by 
now")
 
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
@@ -104,3 +124,27 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = "lldb-server"
+pid = get_subprocess_pid(process_name)
+killProcess(pid, process_name)
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'"
+)
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 25c5ad56e3d6fe..124e5a087618a7 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -503,6 +503,14 @@ void EventThreadFunction() {
 SendContinuedEvent();
 break;
   case lldb::eStateExited:
+const int exit_status = process.GetExitStatus();
+const char *const exit_description = process.GetExitDescription();
+g_dap.SendFormattedOutput(
+OutputType::Console,
+"Process %" PRIu64 " exited with status = %i (0x%8.8x) %s\n",
+process.GetProcessID(), exit_status, exit_status,
+exit_description ? exit_description : "");
+
 // When restarting, we can get an "exited" event for the process we
 // just killed with the old PID, or even with no PID. In that case
 // we don't have to terminate the session.

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam (PR #88564)

2024-04-19 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/88564

>From 3a69226e9ca90bb7ae220b9c3a71a0c2371e52fc Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 12 Apr 2024 09:55:46 -0700
Subject: [PATCH] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam

Summary:
AddMemoryList() was returning the last error status returned by ReadMemory(). 
So if an invalid memory region was read last, the function would return an 
error. Also, one of the reasons why the invalid memory region was read was 
because the check for reading permission in AddRegion() was incorrect.

Test Plan:
./bin/llvm-lit -sv 
~/src/llvm-project/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py

Reviewers:

Subscribers:

Tasks:

Tags:
---
 .../ObjectFile/Minidump/MinidumpFileBuilder.cpp   | 11 +--
 lldb/source/Target/Process.cpp|  7 +--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index cefd4cb22b6bae..601f11d51d4282 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -21,6 +21,7 @@
 #include "lldb/Target/ThreadList.h"
 #include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
 #include "lldb/Utility/RegisterValue.h"
 
 #include "llvm/ADT/StringRef.h"
@@ -663,14 +664,20 @@ MinidumpFileBuilder::AddMemoryList(const lldb::ProcessSP 
_sp,
   DataBufferHeap helper_data;
   std::vector mem_descriptors;
   for (const auto _range : core_ranges) {
-// Skip empty memory regions or any regions with no permissions.
-if (core_range.range.empty() || core_range.lldb_permissions == 0)
+// Skip empty memory regions.
+if (core_range.range.empty())
   continue;
 const addr_t addr = core_range.range.start();
 const addr_t size = core_range.range.size();
 auto data_up = std::make_unique(size, 0);
 const size_t bytes_read =
 process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
+if (error.Fail()) {
+  Log *log = GetLog(LLDBLog::Object);
+  LLDB_LOGF(log, "Failed to read memory region. Bytes read: %zu, error: 
%s",
+bytes_read, error.AsCString());
+  error.Clear();
+}
 if (bytes_read == 0)
   continue;
 // We have a good memory region with valid bytes to store.
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index f02ec37cb0f08f..606518ca541267 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -6325,8 +6325,11 @@ static bool AddDirtyPages(const MemoryRegionInfo ,
 // ranges.
 static void AddRegion(const MemoryRegionInfo , bool try_dirty_pages,
   Process::CoreFileMemoryRanges ) {
-  // Don't add empty ranges or ranges with no permissions.
-  if (region.GetRange().GetByteSize() == 0 || region.GetLLDBPermissions() == 0)
+  // Don't add empty ranges.
+  if (region.GetRange().GetByteSize() == 0)
+return;
+  // Don't add ranges with no read permissions.
+  if ((region.GetLLDBPermissions() & lldb::ePermissionsReadable) == 0)
 return;
   if (try_dirty_pages && AddDirtyPages(region, ranges))
 return;

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-19 Thread Miro Bucko via lldb-commits

https://github.com/mbucko edited https://github.com/llvm/llvm-project/pull/89405
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-19 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/89405

>From 31d688e70beec442cf731986ff8e4c8e9b5a9f0c Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 .../tools/lldb-dap/console/TestDAP_console.py | 47 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  8 
 2 files changed, 55 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py 
b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
index ffa0dc943e0693..4be05b8607c3bf 100644
--- a/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
+++ b/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
@@ -4,10 +4,33 @@
 
 import dap_server
 import lldbdap_testcase
+import psutil
 from lldbsuite.test import lldbutil
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+def get_latest_pid(process_name):
+processes = []
+for proc in psutil.process_iter():
+try:
+if proc.name() == process_name:
+processes += [proc]
+except (psutil.NoSuchProcess, psutil.AccessDenied, 
psutil.ZombieProcess):
+pass
+if len(processes) == 0:
+print("No lldb-server process found", flush=True, file=sys.stderr)
+return None
+
+processes = sorted(processes, key=lambda x:x.create_time())
+return processes[-1].pid
+
+def killProcess(pid, process_name):
+process = psutil.Process(pid)
+process.terminate()
+try:
+process.wait(timeout=5)
+except psutil.TimeoutExpired:
+self.assertTrue(False, process_name + " process should have exited by 
now")
 
 class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
 def check_lldb_command(
@@ -104,3 +127,27 @@ def test_empty_escape_prefix(self):
 "Help can be invoked",
 command_escape_prefix="",
 )
+
+@skipIfWindows
+@skipIfRemote
+def test_exit_status_message(self):
+source = "main.cpp"
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, commandEscapePrefix="")
+breakpoint1_line = line_number(source, "// breakpoint 1")
+breakpoint_ids = self.set_source_breakpoints(source, 
[breakpoint1_line])
+self.continue_to_breakpoints(breakpoint_ids)
+
+# Kill lldb-server process.
+process_name = "lldb-server"
+pid = get_latest_pid(process_name)
+killProcess(pid, process_name)
+# Get the console output
+console_output = self.collect_console(1.0)
+
+# Verify the exit status message is printed.
+self.assertIn(
+"exited with status = -1 (0x) debugserver died with signal 
SIGTERM",
+console_output,
+"Exit status does not contain message 'exited with status'"
+)
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 25c5ad56e3d6fe..124e5a087618a7 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -503,6 +503,14 @@ void EventThreadFunction() {
 SendContinuedEvent();
 break;
   case lldb::eStateExited:
+const int exit_status = process.GetExitStatus();
+const char *const exit_description = process.GetExitDescription();
+g_dap.SendFormattedOutput(
+OutputType::Console,
+"Process %" PRIu64 " exited with status = %i (0x%8.8x) %s\n",
+process.GetProcessID(), exit_status, exit_status,
+exit_description ? exit_description : "");
+
 // When restarting, we can get an "exited" event for the process we
 // just killed with the old PID, or even with no PID. In that case
 // we don't have to terminate the session.

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Report exit status message in lldb-dap, same as lldb cli (PR #89405)

2024-04-19 Thread Miro Bucko via lldb-commits

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/89405

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
`Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM`
lldb-dap on the other hand does not emit a similar message. This PR adds the 
same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following: Process 2167677 exited with 
status = -1 (0x) debugserver died with signal SIGTERM

Reviewers:
jeffreytan81,clayborg,kusmour,

Subscribers:

Tasks:
lldb-dap

Tags:

>From 93ed3f24ce581f94820900cfa3aaa082cba6f37f Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 19 Apr 2024 08:08:02 -0700
Subject: [PATCH] Report exit status message in lldb-dap, same as lldb cli

Summary:
When the target inferior process that is being debugged exits in lldb command 
line, it emits following message:
Process 4049526 exited with status = -1 (0x) debugserver died with 
signal SIGTERM
lldb-dap on the other hand does not emit a similar message.
This PR adds the same status message to lldb-dap.

Test Plan:
In VSCode debug any target and hit stop mode, kill lldb-server and observe an 
exit status message similar to the following:
Process 2167677 exited with status = -1 (0x) debugserver died with 
signal SIGTERM

Reviewers:

Subscribers:

Tasks:
lldb-dap

Tags:
---
 lldb/tools/lldb-dap/lldb-dap.cpp | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 25c5ad56e3d6fe..76c7fb17a793cb 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -503,6 +503,13 @@ void EventThreadFunction() {
 SendContinuedEvent();
 break;
   case lldb::eStateExited:
+const int exit_status = process.GetExitStatus();
+const char * const exit_description = process.GetExitDescription();
+g_dap.SendFormattedOutput(OutputType::Console,
+  "Process %" PRIu64 " exited with status = %i (0x%8.8x) %s\n",
+  process.GetProcessID(), exit_status, exit_status,
+  exit_description ? exit_description : "");
+
 // When restarting, we can get an "exited" event for the process we
 // just killed with the old PID, or even with no PID. In that case
 // we don't have to terminate the session.

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam (PR #88564)

2024-04-17 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/88564

>From 8877be23ad4d342e7f9b61896581707005f76d4e Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 12 Apr 2024 09:55:46 -0700
Subject: [PATCH] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam

Summary:
AddMemoryList() was returning the last error status returned by ReadMemory(). 
So if an invalid memory region was read last, the function would return an 
error. Also, one of the reasons why the invalid memory region was read was 
because the check for reading permission in AddRegion() was incorrect.

Test Plan:
./bin/llvm-lit -sv 
~/src/llvm-project/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py

Reviewers:

Subscribers:

Tasks:

Tags:
---
 .../ObjectFile/Minidump/MinidumpFileBuilder.cpp  | 16 +---
 lldb/source/Target/Process.cpp   |  7 +--
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index 50d1b563f469cf..25a57c6a81b091 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -20,6 +20,8 @@
 #include "lldb/Target/StopInfo.h"
 #include "lldb/Target/ThreadList.h"
 #include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
 #include "lldb/Utility/RegisterValue.h"
 
 #include "llvm/ADT/StringRef.h"
@@ -649,16 +651,24 @@ MinidumpFileBuilder::AddMemoryList(const lldb::ProcessSP 
_sp,
   DataBufferHeap helper_data;
   std::vector mem_descriptors;
   for (const auto _range : core_ranges) {
-// Skip empty memory regions or any regions with no permissions.
-if (core_range.range.empty() || core_range.lldb_permissions == 0)
+// Skip empty memory regions.
+if (core_range.range.empty())
   continue;
 const addr_t addr = core_range.range.start();
 const addr_t size = core_range.range.size();
 auto data_up = std::make_unique(size, 0);
 const size_t bytes_read =
 process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
-if (bytes_read == 0)
+if (error.Fail()) {
+  Log *log = GetLog(LLDBLog::Object);
+  LLDB_LOGF(log, "Failed to read memory region. Bytes read: %zu, error: 
%s",
+bytes_read, error.AsCString());
+  error.Clear();
+}
+if (bytes_read == 0) {
   continue;
+}
+
 // We have a good memory region with valid bytes to store.
 LocationDescriptor memory_dump;
 memory_dump.DataSize = static_cast(bytes_read);
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index f02ec37cb0f08f..606518ca541267 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -6325,8 +6325,11 @@ static bool AddDirtyPages(const MemoryRegionInfo ,
 // ranges.
 static void AddRegion(const MemoryRegionInfo , bool try_dirty_pages,
   Process::CoreFileMemoryRanges ) {
-  // Don't add empty ranges or ranges with no permissions.
-  if (region.GetRange().GetByteSize() == 0 || region.GetLLDBPermissions() == 0)
+  // Don't add empty ranges.
+  if (region.GetRange().GetByteSize() == 0)
+return;
+  // Don't add ranges with no read permissions.
+  if ((region.GetLLDBPermissions() & lldb::ePermissionsReadable) == 0)
 return;
   if (try_dirty_pages && AddDirtyPages(region, ranges))
 return;

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam (PR #88564)

2024-04-15 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/88564

>From 27f7d03cfda9c6eea67973b9d8c3089abde8b732 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 12 Apr 2024 09:55:46 -0700
Subject: [PATCH] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam

Summary:
AddMemoryList() was returning the last error status returned by ReadMemory(). 
So if an invalid memory region was read last, the function would return an 
error. Also, one of the reasons why the invalid memory region was read was 
because the check for reading permission in AddRegion() was incorrect.

Test Plan:
./bin/llvm-lit -sv 
~/src/llvm-project/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py

Reviewers:

Subscribers:

Tasks:

Tags:
---
 .../ObjectFile/Minidump/MinidumpFileBuilder.cpp | 17 ++---
 lldb/source/Target/Process.cpp  | 11 +++
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index 50d1b563f469cf..9499d441ebe7ac 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -20,6 +20,8 @@
 #include "lldb/Target/StopInfo.h"
 #include "lldb/Target/ThreadList.h"
 #include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
 #include "lldb/Utility/RegisterValue.h"
 
 #include "llvm/ADT/StringRef.h"
@@ -649,16 +651,25 @@ MinidumpFileBuilder::AddMemoryList(const lldb::ProcessSP 
_sp,
   DataBufferHeap helper_data;
   std::vector mem_descriptors;
   for (const auto _range : core_ranges) {
-// Skip empty memory regions or any regions with no permissions.
-if (core_range.range.empty() || core_range.lldb_permissions == 0)
+// Skip empty memory regions.
+if (core_range.range.empty())
   continue;
 const addr_t addr = core_range.range.start();
 const addr_t size = core_range.range.size();
 auto data_up = std::make_unique(size, 0);
 const size_t bytes_read =
 process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
-if (bytes_read == 0)
+if (error.Fail()) {
+  Log *log = GetLog(LLDBLog::SystemRuntime);
+  LLDB_LOGF(log, "Failed to read memory region. Bytes read: %zu, error: 
%s",
+bytes_read, error.AsCString());
+  error.Clear();
+}
+
+if (bytes_read == 0) {
   continue;
+}
+
 // We have a good memory region with valid bytes to store.
 LocationDescriptor memory_dump;
 memory_dump.DataSize = static_cast(bytes_read);
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index f02ec37cb0f08f..84a0a65b0e4ebf 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -3857,8 +3857,8 @@ thread_result_t Process::RunPrivateStateThread(bool 
is_secondary_thread) {
 // case we should tell it to stop doing that.  Normally, we don't NEED
 // to do that because we will next close the communication to the stub
 // and that will get it to shut down.  But there are remote debugging
-// cases where relying on that side-effect causes the shutdown to be 
-// flakey, so we should send a positive signal to interrupt the wait. 
+// cases where relying on that side-effect causes the shutdown to be
+// flakey, so we should send a positive signal to interrupt the wait.
 Status error = HaltPrivate();
 BroadcastEvent(eBroadcastBitInterrupt, nullptr);
   } else if (StateIsRunningState(m_last_broadcast_state)) {
@@ -6325,8 +6325,11 @@ static bool AddDirtyPages(const MemoryRegionInfo ,
 // ranges.
 static void AddRegion(const MemoryRegionInfo , bool try_dirty_pages,
   Process::CoreFileMemoryRanges ) {
-  // Don't add empty ranges or ranges with no permissions.
-  if (region.GetRange().GetByteSize() == 0 || region.GetLLDBPermissions() == 0)
+  // Don't add empty ranges.
+  if (region.GetRange().GetByteSize() == 0)
+return;
+  // Don't add ranges with no read permissions.
+  if ((region.GetLLDBPermissions() & lldb::ePermissionsReadable) == 0)
 return;
   if (try_dirty_pages && AddDirtyPages(region, ranges))
 return;

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam (PR #88564)

2024-04-15 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/88564

>From cfb233c0fb13c269e6431ceef4910d8c3cabb014 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 12 Apr 2024 09:55:46 -0700
Subject: [PATCH] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam

Summary:
AddMemoryList() was returning the last error status returned by ReadMemory(). 
So if an invalid memory region was read last, the function would return an 
error. Also, the permission check for the memory reagion was incorrect.

Test Plan:
./bin/llvm-lit -sv 
~/src/llvm-project/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py

Reviewers:

Subscribers:

Tasks:

Tags:
---
 .../ObjectFile/Minidump/MinidumpFileBuilder.cpp| 14 +++---
 lldb/source/Target/Process.cpp | 11 +++
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index 50d1b563f469cf..bc42c629decd48 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -20,6 +20,8 @@
 #include "lldb/Target/StopInfo.h"
 #include "lldb/Target/ThreadList.h"
 #include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
 #include "lldb/Utility/RegisterValue.h"
 
 #include "llvm/ADT/StringRef.h"
@@ -649,16 +651,22 @@ MinidumpFileBuilder::AddMemoryList(const lldb::ProcessSP 
_sp,
   DataBufferHeap helper_data;
   std::vector mem_descriptors;
   for (const auto _range : core_ranges) {
-// Skip empty memory regions or any regions with no permissions.
-if (core_range.range.empty() || core_range.lldb_permissions == 0)
+// Skip empty memory regions.
+if (core_range.range.empty())
   continue;
 const addr_t addr = core_range.range.start();
 const addr_t size = core_range.range.size();
 auto data_up = std::make_unique(size, 0);
 const size_t bytes_read =
 process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
-if (bytes_read == 0)
+if (error.Fail() || bytes_read == 0) {
+  Log *log = GetLog(LLDBLog::SystemRuntime);
+  LLDB_LOGF(log, "Failed to read memory region. Bytes read: %zu, error: 
%s",
+bytes_read, error.AsCString());
+  error.Clear();
   continue;
+}
+
 // We have a good memory region with valid bytes to store.
 LocationDescriptor memory_dump;
 memory_dump.DataSize = static_cast(bytes_read);
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index f02ec37cb0f08f..84a0a65b0e4ebf 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -3857,8 +3857,8 @@ thread_result_t Process::RunPrivateStateThread(bool 
is_secondary_thread) {
 // case we should tell it to stop doing that.  Normally, we don't NEED
 // to do that because we will next close the communication to the stub
 // and that will get it to shut down.  But there are remote debugging
-// cases where relying on that side-effect causes the shutdown to be 
-// flakey, so we should send a positive signal to interrupt the wait. 
+// cases where relying on that side-effect causes the shutdown to be
+// flakey, so we should send a positive signal to interrupt the wait.
 Status error = HaltPrivate();
 BroadcastEvent(eBroadcastBitInterrupt, nullptr);
   } else if (StateIsRunningState(m_last_broadcast_state)) {
@@ -6325,8 +6325,11 @@ static bool AddDirtyPages(const MemoryRegionInfo ,
 // ranges.
 static void AddRegion(const MemoryRegionInfo , bool try_dirty_pages,
   Process::CoreFileMemoryRanges ) {
-  // Don't add empty ranges or ranges with no permissions.
-  if (region.GetRange().GetByteSize() == 0 || region.GetLLDBPermissions() == 0)
+  // Don't add empty ranges.
+  if (region.GetRange().GetByteSize() == 0)
+return;
+  // Don't add ranges with no read permissions.
+  if ((region.GetLLDBPermissions() & lldb::ePermissionsReadable) == 0)
 return;
   if (try_dirty_pages && AddDirtyPages(region, ranges))
 return;

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam (PR #88564)

2024-04-15 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/88564

>From c588870cc8ff14806165f454d242f862ef19e89c Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 12 Apr 2024 09:55:46 -0700
Subject: [PATCH] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam

Summary:
AddMemoryList() was returning the last error status returned by ReadMemory(). 
So if an invalid memory region was read last, the function would return an 
error.

Test Plan:
./bin/llvm-lit -sv 
~/src/llvm-project/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py

Reviewers:

Subscribers:

Tasks:

Tags:
---
 .../Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp  | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index 50d1b563f469cf..5bf0cf1ad79d16 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -657,8 +657,11 @@ MinidumpFileBuilder::AddMemoryList(const lldb::ProcessSP 
_sp,
 auto data_up = std::make_unique(size, 0);
 const size_t bytes_read =
 process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
-if (bytes_read == 0)
+if (error.Fail() || bytes_read == 0) {
+  error.Clear();
   continue;
+}
+
 // We have a good memory region with valid bytes to store.
 LocationDescriptor memory_dump;
 memory_dump.DataSize = static_cast(bytes_read);

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam (PR #88564)

2024-04-12 Thread Miro Bucko via lldb-commits


@@ -655,9 +655,10 @@ MinidumpFileBuilder::AddMemoryList(const lldb::ProcessSP 
_sp,
 const addr_t addr = core_range.range.start();
 const addr_t size = core_range.range.size();
 auto data_up = std::make_unique(size, 0);
+Status read_error;

mbucko wrote:

Yes, this also works. Let me know if you'd like me to change it

https://github.com/llvm/llvm-project/pull/88564
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


  1   2   >