[Lldb-commits] [lldb] 5e136b7 - [lldb] Make Listener::m_broadcasters_mutex non-recursive (#97552)

2024-07-08 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-07-08T09:21:38+02:00
New Revision: 5e136b7e0d310b368ce5025d55bfd7a376391199

URL: 
https://github.com/llvm/llvm-project/commit/5e136b7e0d310b368ce5025d55bfd7a376391199
DIFF: 
https://github.com/llvm/llvm-project/commit/5e136b7e0d310b368ce5025d55bfd7a376391199.diff

LOG: [lldb] Make Listener::m_broadcasters_mutex non-recursive (#97552)

Follow-up to #97400. No changes apart from changing the type were
necessary. The mutex was already not used recursively.

Added: 


Modified: 
lldb/include/lldb/Utility/Listener.h
lldb/source/Utility/Listener.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/Listener.h 
b/lldb/include/lldb/Utility/Listener.h
index daa7deb345f30..eec8af023f263 100644
--- a/lldb/include/lldb/Utility/Listener.h
+++ b/lldb/include/lldb/Utility/Listener.h
@@ -127,7 +127,7 @@ class Listener : public 
std::enable_shared_from_this {
 
   std::string m_name;
   broadcaster_collection m_broadcasters;
-  std::recursive_mutex m_broadcasters_mutex; // Protects m_broadcasters
+  std::mutex m_broadcasters_mutex; // Protects m_broadcasters
   event_collection m_events;
   std::mutex m_events_mutex; // Protects m_broadcasters and m_events
   std::condition_variable m_events_condition;

diff  --git a/lldb/source/Utility/Listener.cpp 
b/lldb/source/Utility/Listener.cpp
index 0b28cb5cdc642..6265c30af0d18 100644
--- a/lldb/source/Utility/Listener.cpp
+++ b/lldb/source/Utility/Listener.cpp
@@ -38,8 +38,7 @@ Listener::~Listener() {
 
 void Listener::Clear() {
   Log *log = GetLog(LLDBLog::Object);
-  std::lock_guard broadcasters_guard(
-  m_broadcasters_mutex);
+  std::lock_guard broadcasters_guard(m_broadcasters_mutex);
   broadcaster_collection::iterator pos, end = m_broadcasters.end();
   for (pos = m_broadcasters.begin(); pos != end; ++pos) {
 Broadcaster::BroadcasterImplSP broadcaster_sp(pos->first.lock());
@@ -68,8 +67,7 @@ uint32_t Listener::StartListeningForEvents(Broadcaster 
*broadcaster,
 // Scope for "locker"
 // Tell the broadcaster to add this object as a listener
 {
-  std::lock_guard broadcasters_guard(
-  m_broadcasters_mutex);
+  std::lock_guard broadcasters_guard(m_broadcasters_mutex);
   Broadcaster::BroadcasterImplWP 
impl_wp(broadcaster->GetBroadcasterImpl());
   m_broadcasters.insert(
   std::make_pair(impl_wp, BroadcasterInfo(event_mask)));
@@ -99,8 +97,7 @@ uint32_t Listener::StartListeningForEvents(Broadcaster 
*broadcaster,
 // Scope for "locker"
 // Tell the broadcaster to add this object as a listener
 {
-  std::lock_guard broadcasters_guard(
-  m_broadcasters_mutex);
+  std::lock_guard broadcasters_guard(m_broadcasters_mutex);
   Broadcaster::BroadcasterImplWP 
impl_wp(broadcaster->GetBroadcasterImpl());
   m_broadcasters.insert(std::make_pair(
   impl_wp, BroadcasterInfo(event_mask, callback, callback_user_data)));
@@ -131,8 +128,7 @@ bool Listener::StopListeningForEvents(Broadcaster 
*broadcaster,
   if (broadcaster) {
 // Scope for "locker"
 {
-  std::lock_guard broadcasters_guard(
-  m_broadcasters_mutex);
+  std::lock_guard broadcasters_guard(m_broadcasters_mutex);
   m_broadcasters.erase(broadcaster->GetBroadcasterImpl());
 }
 // Remove the broadcaster from our set of broadcasters
@@ -147,8 +143,7 @@ bool Listener::StopListeningForEvents(Broadcaster 
*broadcaster,
 void Listener::BroadcasterWillDestruct(Broadcaster *broadcaster) {
   // Scope for "broadcasters_locker"
   {
-std::lock_guard broadcasters_guard(
-m_broadcasters_mutex);
+std::lock_guard broadcasters_guard(m_broadcasters_mutex);
 m_broadcasters.erase(broadcaster->GetBroadcasterImpl());
   }
 
@@ -322,7 +317,7 @@ bool Listener::GetEvent(EventSP &event_sp, const 
Timeout &timeout) {
 
 size_t Listener::HandleBroadcastEvent(EventSP &event_sp) {
   size_t num_handled = 0;
-  std::lock_guard guard(m_broadcasters_mutex);
+  std::lock_guard guard(m_broadcasters_mutex);
   Broadcaster *broadcaster = event_sp->GetBroadcaster();
   if (!broadcaster)
 return 0;
@@ -357,7 +352,7 @@ Listener::StartListeningForEventSpec(const 
BroadcasterManagerSP &manager_sp,
   // The BroadcasterManager mutex must be locked before m_broadcasters_mutex to
   // avoid violating the lock hierarchy (manager before broadcasters).
   std::lock_guard manager_guard(manager_sp->m_manager_mutex);
-  std::lock_guard guard(m_broadcasters_mutex);
+  std::lock_guard guard(m_broadcasters_mutex);
 
   uint32_t bits_acquired = manager_sp->RegisterListenerForEventsNoLock(
   this->shared_from_this(), event_spec);
@@ -379,7 +374,7 @@ bool Listener::StopListeningForEventSpec(const 
BroadcasterManagerSP &manager_sp,
   // The BroadcasterManager mutex must be locked before m_broadcasters_mutex to
   // avoid violating the lock hierarchy (manager before broadcasters).
   std:

[Lldb-commits] [lldb] [lldb] Make Listener::m_broadcasters_mutex non-recursive (PR #97552)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] Remove duplicate testcase names in API test-suite (PR #97043)

2024-07-08 Thread Pavel Labath via lldb-commits

labath wrote:

> > > > LGTM. This has definitely come up in the past. If you feel motivated, 
> > > > I'm sure there must be a way to detect this issue in Python and we 
> > > > could have assert/warning/error that captures this at the dotest level.
> > > 
> > > 
> > > Agreed, making it part of `dotest` would be amazing. Maybe someone with 
> > > better python knowledge has some ideas (@medismailben @kastiglione ?). In 
> > > the meantime I'll have a think of how one might do that
> > 
> > 
> > I think instead of having this be part of our test-suite, I'd run it as 
> > part of PR testing in a GitHub action
> 
> The test suite would/will run as part of PR testing. Are you saying you would 
> **only** run it at PR time? Why wait and not find out at your test? We 
> already collect all the test names to run them as separate lit tests (similar 
> but different problem) and I bet we also already iterate over the tests 
> inside a file too to build the variants.

Yes, but we do that on a fully parsed representation of the class, where the 
name conflicts would not be visible. Michael's script constructs the ast of the 
python file, and walks that manually. In that sense this check does seem more 
of like a thing that a linter would do, but I don't know if there are existing 
linters that would flag this sort of thing..

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


[Lldb-commits] [lldb] fix issue with debug-types-dwo-cross-reference.cpp.tmp test (PR #97381)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] fix issue with debug-types-dwo-cross-reference.cpp.tmp test (PR #97381)

2024-07-08 Thread Pavel Labath via lldb-commits

labath wrote:

The test doesn't fail at HEAD per 
https://github.com/llvm/llvm-project/issues/97380#issuecomment-2205201579

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


[Lldb-commits] [lldb] [lldb] Improve error message for unrecognized executables (PR #97490)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


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


[Lldb-commits] [lldb] [lldb] Remove Listener::SetShadow (PR #97555)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/97555

>From 9f81f804c4c451a5ff2266405740d208dffae60f Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Wed, 3 Jul 2024 10:37:52 +
Subject: [PATCH 1/2] [lldb] Remove Listener::SetShadow

It's not used since https://reviews.llvm.org/D157556.
---
 lldb/include/lldb/Utility/Listener.h | 3 ---
 lldb/source/API/SBAttachInfo.cpp | 8 +---
 lldb/source/API/SBLaunchInfo.cpp | 8 +---
 lldb/source/Utility/Listener.cpp | 9 +++--
 4 files changed, 5 insertions(+), 23 deletions(-)

diff --git a/lldb/include/lldb/Utility/Listener.h 
b/lldb/include/lldb/Utility/Listener.h
index daa7deb345f301..f687852d558bdb 100644
--- a/lldb/include/lldb/Utility/Listener.h
+++ b/lldb/include/lldb/Utility/Listener.h
@@ -94,8 +94,6 @@ class Listener : public 
std::enable_shared_from_this {
 
   size_t HandleBroadcastEvent(lldb::EventSP &event_sp);
 
-  void SetShadow(bool is_shadow) { m_is_shadow = is_shadow; }
-
 private:
   // Classes that inherit from Listener can see and modify these
   struct BroadcasterInfo {
@@ -132,7 +130,6 @@ class Listener : public 
std::enable_shared_from_this {
   std::mutex m_events_mutex; // Protects m_broadcasters and m_events
   std::condition_variable m_events_condition;
   broadcaster_manager_collection m_broadcaster_managers;
-  bool m_is_shadow = false;
 
   void BroadcasterWillDestruct(Broadcaster *);
 
diff --git a/lldb/source/API/SBAttachInfo.cpp b/lldb/source/API/SBAttachInfo.cpp
index 8ce1f1d65c4964..a9f712c79c7fe0 100644
--- a/lldb/source/API/SBAttachInfo.cpp
+++ b/lldb/source/API/SBAttachInfo.cpp
@@ -266,13 +266,7 @@ SBListener SBAttachInfo::GetShadowListener() {
 void SBAttachInfo::SetShadowListener(SBListener &listener) {
   LLDB_INSTRUMENT_VA(this, listener);
 
-  ListenerSP listener_sp = listener.GetSP();
-  if (listener_sp && listener.IsValid())
-listener_sp->SetShadow(true);
-  else
-listener_sp = nullptr;
-
-  m_opaque_sp->SetShadowListener(listener_sp);
+  m_opaque_sp->SetShadowListener(listener.GetSP());
 }
 
 const char *SBAttachInfo::GetScriptedProcessClassName() const {
diff --git a/lldb/source/API/SBLaunchInfo.cpp b/lldb/source/API/SBLaunchInfo.cpp
index d5f935083e6c1e..d6b52e8a67a49e 100644
--- a/lldb/source/API/SBLaunchInfo.cpp
+++ b/lldb/source/API/SBLaunchInfo.cpp
@@ -402,11 +402,5 @@ SBListener SBLaunchInfo::GetShadowListener() {
 void SBLaunchInfo::SetShadowListener(SBListener &listener) {
   LLDB_INSTRUMENT_VA(this, listener);
 
-  ListenerSP listener_sp = listener.GetSP();
-  if (listener_sp && listener.IsValid())
-listener_sp->SetShadow(true);
-  else
-listener_sp = nullptr;
-
-  m_opaque_sp->SetShadowListener(listener_sp);
+  m_opaque_sp->SetShadowListener(listener.GetSP());
 }
diff --git a/lldb/source/Utility/Listener.cpp b/lldb/source/Utility/Listener.cpp
index 0b28cb5cdc6424..317525335f0f6f 100644
--- a/lldb/source/Utility/Listener.cpp
+++ b/lldb/source/Utility/Listener.cpp
@@ -18,13 +18,10 @@
 using namespace lldb;
 using namespace lldb_private;
 
-Listener::Listener(const char *name)
-: m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(),
-  m_events_mutex(), m_is_shadow() {
+Listener::Listener(const char *name) : m_name(name) {
   Log *log = GetLog(LLDBLog::Object);
-  if (log != nullptr)
-LLDB_LOGF(log, "%p Listener::Listener('%s')", static_cast(this),
-  m_name.c_str());
+  LLDB_LOGF(log, "%p Listener::Listener('%s')", static_cast(this),
+m_name.c_str());
 }
 
 Listener::~Listener() {

>From 7259eab8b5660df7c57d18392e9d14cb5c877f7a Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 8 Jul 2024 10:32:48 +0200
Subject: [PATCH 2/2] rid of log

---
 lldb/source/Utility/Listener.cpp | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/lldb/source/Utility/Listener.cpp b/lldb/source/Utility/Listener.cpp
index 317525335f0f6f..5bbe6908afd2a6 100644
--- a/lldb/source/Utility/Listener.cpp
+++ b/lldb/source/Utility/Listener.cpp
@@ -19,18 +19,15 @@ using namespace lldb;
 using namespace lldb_private;
 
 Listener::Listener(const char *name) : m_name(name) {
-  Log *log = GetLog(LLDBLog::Object);
-  LLDB_LOGF(log, "%p Listener::Listener('%s')", static_cast(this),
-m_name.c_str());
+  LLDB_LOGF(GetLog(LLDBLog::Object), "%p Listener::Listener('%s')",
+static_cast(this), m_name.c_str());
 }
 
 Listener::~Listener() {
-  Log *log = GetLog(LLDBLog::Object);
-
   // Don't call Clear() from here as that can cause races. See #96750.
 
-  LLDB_LOGF(log, "%p Listener::%s('%s')", static_cast(this),
-__FUNCTION__, m_name.c_str());
+  LLDB_LOGF(GetLog(LLDBLog::Object), "%p Listener::%s('%s')",
+static_cast(this), __FUNCTION__, m_name.c_str());
 }
 
 void Listener::Clear() {

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


[Lldb-commits] [lldb] [lldb] Remove Listener::SetShadow (PR #97555)

2024-07-08 Thread Pavel Labath via lldb-commits


@@ -18,13 +18,10 @@
 using namespace lldb;
 using namespace lldb_private;
 
-Listener::Listener(const char *name)
-: m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(),
-  m_events_mutex(), m_is_shadow() {
+Listener::Listener(const char *name) : m_name(name) {
   Log *log = GetLog(LLDBLog::Object);
-  if (log != nullptr)
-LLDB_LOGF(log, "%p Listener::Listener('%s')", static_cast(this),
-  m_name.c_str());
+  LLDB_LOGF(log, "%p Listener::Listener('%s')", static_cast(this),
+m_name.c_str());

labath wrote:

Done. I though about it myself, but I had to stop with the drive-by changes 
somewhere.

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


[Lldb-commits] [lldb] [lldb] Make variant formatter work with libstdc++-14 (PR #97568)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/97568

>From 53b9fda6f7bf0ec4df32869c9d4ba2203aa1870a Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Wed, 3 Jul 2024 12:20:12 +
Subject: [PATCH 1/2] [lldb] Make variant formatter work with libstdc++-14

In this version the internal data member has grown an additional
template parameter (bool), which was throwing the summary provider off.

This patch uses the type of the entire variant object. This is part of
the API/ABI, so it should be more stable, but it means we have to
explicitly strip typedefs and references to get to the interesting bits,
which is why I've extended the test case with examples of those.
---
 lldb/examples/synthetic/gnu_libstdcpp.py  |  7 +--
 .../TestDataFormatterLibStdcxxVariant.py  | 20 ++-
 .../libstdcpp/variant/main.cpp|  5 +
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/lldb/examples/synthetic/gnu_libstdcpp.py 
b/lldb/examples/synthetic/gnu_libstdcpp.py
index f778065aaca377..59970574a36040 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -914,12 +914,15 @@ def get_variant_npos_value(index_byte_size):
 if index == npos_value:
 return " No Value"
 
+# Strip references and typedefs.
+variant_type = raw_obj.GetType().GetCanonicalType().GetDereferencedType();
+template_arg_count = variant_type.GetNumberOfTemplateArguments()
+
 # Invalid index can happen when the variant is not initialized yet.
-template_arg_count = data_obj.GetType().GetNumberOfTemplateArguments()
 if index >= template_arg_count:
 return " "
 
-active_type = data_obj.GetType().GetTemplateArgumentType(index)
+active_type = variant_type.GetTemplateArgumentType(index)
 return f" Active Type = {active_type.GetDisplayTypeName()} "
 
 
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
index ba1641888b6f30..05f31087a566e8 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
@@ -21,15 +21,17 @@ def test_with_run_command(self):
 
 lldbutil.continue_to_breakpoint(self.process, bkpt)
 
-self.expect(
-"frame variable v1",
-substrs=["v1 =  Active Type = int  {", "Value = 12", "}"],
-)
-
-self.expect(
-"frame variable v1_ref",
-substrs=["v1_ref =  Active Type = int : {", "Value = 12", "}"],
-)
+for name in ["v1", "v1_typedef"]:
+  self.expect(
+  "frame variable " + name,
+  substrs=[name + " =  Active Type = int  {", "Value = 12", "}"],
+  )
+
+for name in ["v1_ref", "v1_typedef_ref"]:
+  self.expect(
+  "frame variable " + name,
+  substrs=[name + " =  Active Type = int : {", "Value = 12", "}"],
+  )
 
 self.expect(
 "frame variable v_v1",
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
index 545318f9358b67..36e0f74f831f8a 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
@@ -14,6 +14,10 @@ int main() {
 
   std::variant v1;
   std::variant &v1_ref = v1;
+  using V1_typedef = std::variant;
+  V1_typedef v1_typedef;
+  V1_typedef &v1_typedef_ref = v1_typedef;
+
   std::variant v2;
   std::variant v3;
   std::variant> v_v1;
@@ -43,6 +47,7 @@ int main() {
   v_many_types_no_value;
 
   v1 = 12; // v contains int
+  v1_typedef = v1;
   v_v1 = v1;
   int i = std::get(v1);
   printf("%d\n", i); // break here

>From 3c40961b34f641ea6c509feebad0719f9f87e970 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 8 Jul 2024 10:41:43 +0200
Subject: [PATCH 2/2] fix formatting

---
 lldb/examples/synthetic/gnu_libstdcpp.py |  2 +-
 .../variant/TestDataFormatterLibStdcxxVariant.py | 16 
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lldb/examples/synthetic/gnu_libstdcpp.py 
b/lldb/examples/synthetic/gnu_libstdcpp.py
index 59970574a36040..d98495b8a9df38 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -915,7 +915,7 @@ def get_variant_npos_value(index_byte_size):
 return " No Value"
 
 # Strip references and typedefs.
-variant_type = raw_obj.GetType().GetCanonicalType

[Lldb-commits] [lldb] [lldb] Make variant formatter work with libstdc++-14 (PR #97568)

2024-07-08 Thread Pavel Labath via lldb-commits

labath wrote:

> LGTM
> 
> Been wondering if we should follow the same principle as we did with 
> `std::string` and simulate the layouts for all the STL types, keeping a 
> record of them as they change. So we know we don't break the old layouts. Of 
> course it has a separate maintenance cost

Yeah, I think the biggest hurdle is the initial work in getting a stripped down 
version of the class in place. The problem is that the container types use a 
lot of template metaprogramming to implement various optimizations like empty 
base class and whatnot. Copying that verbatim would make the test huge (and in 
the case of libstdc++ its probably not even possible), and recreating it from 
scratch is not trivial. I believe that after I wrote the std::string test this 
way I tried to also do the same for some of the container types (it may have 
actually been variant), and just gave up after I saw hold long it would take.

Nonetheless, I think there's definitely value in tests like this (for one, 
going through the implementation in this way makes it obvious how many corner 
cases need testing), and it's nice to see there's interest for these tests. 
I'll keep that in mind when working on future changes.

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Remove support for old std::map layout (PR #97549)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.

I'd say eight years is a sufficient compatibility window. :)

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Clean up LibcxxStdMapSyntheticFrontEnd::GetKeyValuePair (PR #97551)

2024-07-08 Thread Pavel Labath via lldb-commits

labath wrote:

Why do we even have the `GetValueOffset` function? Wouldn't it be possible to 
dredge the actual type describing the node layout from somewhere (a template 
argument of something, or a return value of some method?)

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Clean up LibcxxStdMapSyntheticFrontEnd::GetKeyValuePair (PR #97551)

2024-07-08 Thread Michael Buch via lldb-commits

Michael137 wrote:

> Why do we even have the `GetValueOffset` function? Wouldn't it be possible to 
> dredge the actual type describing the node layout from somewhere (a template 
> argument of something, or a return value of some method?)

Agreed? that’s actually what I’m planning to do in 
https://github.com/llvm/llvm-project/pull/97579 (by getting the type via a 
typedef). This patch was kind of an intermediate step to make the followup more 
straightforward to review, but now looking at it, I’m not sure there’s value in 
that. I guess we could just skip this and do the refactor in one go

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


[Lldb-commits] [lldb] [API] add GetSyntheticValue (PR #95959)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


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


[Lldb-commits] [lldb] [lldb] Make variant formatter work with libstdc++-14 (PR #97568)

2024-07-08 Thread Michael Buch via lldb-commits

Michael137 wrote:

> > LGTM
> > Been wondering if we should follow the same principle as we did with 
> > `std::string` and simulate the layouts for all the STL types, keeping a 
> > record of them as they change. So we know we don't break the old layouts. 
> > Of course it has a separate maintenance cost
> 
> Yeah, I think the biggest hurdle is the initial work in getting a stripped 
> down version of the class in place. The problem is that the container types 
> use a lot of template metaprogramming to implement various optimizations like 
> empty base class and whatnot. Copying that verbatim would make the test huge 
> (and in the case of libstdc++ its probably not even possible), and recreating 
> it from scratch is not trivial. I believe that after I wrote the std::string 
> test this way I tried to also do the same for some of the container types (it 
> may have actually been variant), and just gave up after I saw hold long it 
> would take.
> 
> Nonetheless, I think there's definitely value in tests like this (for one, 
> going through the implementation in this way makes it obvious how many corner 
> cases need testing), and it's nice to see there's interest for these tests. 
> I'll keep that in mind when working on future changes.

Agreed, they can get pretty unwieldy. I'll see what the `std::(unordered_)map` 
simulator could look like since we're making changes there at the moment

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Remove support for old std::map layout (PR #97549)

2024-07-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/97549

>From 5dc61f0721746359cbaa70e5f50dd15de4a1f082 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 3 Jul 2024 12:06:49 +0200
Subject: [PATCH 1/2] [lldb][DataFormatter] Remove support for old std::map
 layout

We currently supported the layout from pre-2016 (before the layout
change in 14caaddd3f08e798dcd9ac0ddfc).
We have another upcoming layout change in `__tree` and `map` (as part of
require rewriting parts of this formatter. Removing the support will
make those changes more straightforward to review/maintain.

Being backward compatible would be great but we have no tests that
actually verify that the old layout still works (and our oldest
matrix bot tests clang-15). If anyone feels strongly about keeping
this layout, we could possibly factor out that logic and keep it around.
---
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  | 76 ---
 1 file changed, 30 insertions(+), 46 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index 6c2bc1a34137a..141b525da063b 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -248,11 +248,6 @@ bool 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType() {
   deref = m_root_node->Dereference(error);
   if (!deref || error.Fail())
 return false;
-  deref = deref->GetChildMemberWithName("__value_");
-  if (deref) {
-m_element_type = deref->GetCompilerType();
-return true;
-  }
   deref = m_backend.GetChildAtNamePath({"__tree_", "__pair3_"});
   if (!deref)
 return false;
@@ -280,40 +275,35 @@ void 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset(
 return;
   if (!node)
 return;
+
   CompilerType node_type(node->GetCompilerType());
-  uint64_t bit_offset;
-  if (node_type.GetIndexOfFieldWithName("__value_", nullptr, &bit_offset) !=
-  UINT32_MAX) {
-// Old layout (pre d05b10ab4fc65)
-m_skip_size = bit_offset / 8u;
-  } else {
-auto ast_ctx = 
node_type.GetTypeSystem().dyn_cast_or_null();
-if (!ast_ctx)
-  return;
-CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
-llvm::StringRef(),
-{{"ptr0", 
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
- {"ptr1", 
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
- {"ptr2", 
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
- {"cw", ast_ctx->GetBasicType(lldb::eBasicTypeBool)},
- {"payload", (m_element_type.GetCompleteType(), m_element_type)}});
-std::string child_name;
-uint32_t child_byte_size;
-int32_t child_byte_offset = 0;
-uint32_t child_bitfield_bit_size;
-uint32_t child_bitfield_bit_offset;
-bool child_is_base_class;
-bool child_is_deref_of_parent;
-uint64_t language_flags;
-auto child_type =
-llvm::expectedToStdOptional(tree_node_type.GetChildCompilerTypeAtIndex(
-nullptr, 4, true, true, true, child_name, child_byte_size,
-child_byte_offset, child_bitfield_bit_size,
-child_bitfield_bit_offset, child_is_base_class,
-child_is_deref_of_parent, nullptr, language_flags));
-if (child_type && child_type->IsValid())
-  m_skip_size = (uint32_t)child_byte_offset;
-  }
+  auto ast_ctx = node_type.GetTypeSystem().dyn_cast_or_null();
+  if (!ast_ctx)
+return;
+
+  CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
+  llvm::StringRef(),
+  {{"ptr0", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
+   {"ptr1", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
+   {"ptr2", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
+   {"cw", ast_ctx->GetBasicType(lldb::eBasicTypeBool)},
+   {"payload", (m_element_type.GetCompleteType(), m_element_type)}});
+  std::string child_name;
+  uint32_t child_byte_size;
+  int32_t child_byte_offset = 0;
+  uint32_t child_bitfield_bit_size;
+  uint32_t child_bitfield_bit_offset;
+  bool child_is_base_class;
+  bool child_is_deref_of_parent;
+  uint64_t language_flags;
+  auto child_type =
+  llvm::expectedToStdOptional(tree_node_type.GetChildCompilerTypeAtIndex(
+  nullptr, 4, true, true, true, child_name, child_byte_size,
+  child_byte_offset, child_bitfield_bit_size, 
child_bitfield_bit_offset,
+  child_is_base_class, child_is_deref_of_parent, nullptr,
+  language_flags));
+  if (child_type && child_type->IsValid())
+m_skip_size = (uint32_t)child_byte_offset;
 }
 
 ValueObjectSP
@@ -348,14 +338,8 @@ 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetKeyValuePair(
   return nullptr;
 
 GetValueOffset(iterated_sp);
-auto child_sp = iterated_sp->GetChildMemberWithName("__value_");
-if (child_sp) {
-  // Ol

[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::map formatter (PR #97579)

2024-07-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/97579

>From 9dabd3a399f37789b6a9bc7578b76e738c344f1d Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 3 Jul 2024 10:55:40 +0200
Subject: [PATCH 1/2] [lldb][DataFormatter][NFC] Factor out MapIterator logic
 into separate helper

This patch factors all the logic for advancing the `MapIterator`
out of `GetChildAtIndex`. This, in my opinion, helps readability,
and will be useful for upcoming cleanups in this area.

While here, some drive-by changes:
* added a couple of clarification comments
* fixed a variable name typo
* turned the `return lldb::ValueObjectSP()` into `return nullptr`
* added an assertion to make sure we keep the iterator cache in a valid
  state
---
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  | 115 +++---
 1 file changed, 72 insertions(+), 43 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index 44fe294ced722..370dfa35e7703 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -17,6 +17,7 @@
 #include "lldb/Utility/Endian.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/Stream.h"
+#include "lldb/lldb-forward.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -184,6 +185,22 @@ class LibcxxStdMapSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
 
   void GetValueOffset(const lldb::ValueObjectSP &node);
 
+  /// Returns the ValueObject for the __tree_node type that
+  /// holds the key/value pair of the node at index \ref idx.
+  ///
+  /// \param[in] idx The child index that we're looking to get
+  ///the key/value pair for.
+  ///
+  /// \param[in] max_depth The maximum search depth after which
+  ///  we stop trying to find the key/value
+  ///  pair for.
+  ///
+  /// \returns On success, returns the ValueObjectSP corresponding
+  ///  to the __tree_node's __value_ member (which holds
+  ///  the key/value pair the formatter wants to display).
+  ///  On failure, will return nullptr.
+  ValueObjectSP GetKeyValuePair(size_t idx, size_t max_depth);
+
   ValueObject *m_tree = nullptr;
   ValueObject *m_root_node = nullptr;
   CompilerType m_element_type;
@@ -299,75 +316,88 @@ void 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset(
   }
 }
 
-lldb::ValueObjectSP
-lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex(
-uint32_t idx) {
-  static ConstString g_cc_("__cc_"), g_cc("__cc");
-  static ConstString g_nc("__nc");
-  uint32_t num_children = CalculateNumChildrenIgnoringErrors();
-  if (idx >= num_children)
-return lldb::ValueObjectSP();
-  if (m_tree == nullptr || m_root_node == nullptr)
-return lldb::ValueObjectSP();
-
-  MapIterator iterator(m_root_node, num_children);
+ValueObjectSP
+lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetKeyValuePair(
+size_t idx, size_t max_depth) {
+  MapIterator iterator(m_root_node, max_depth);
 
   const bool need_to_skip = (idx > 0);
-  size_t actual_advancde = idx;
+  size_t actual_advance = idx;
   if (need_to_skip) {
+// If we have already created the iterator for the previous
+// index, we can start from there and advance by 1.
 auto cached_iterator = m_iterators.find(idx - 1);
 if (cached_iterator != m_iterators.end()) {
   iterator = cached_iterator->second;
-  actual_advancde = 1;
+  actual_advance = 1;
 }
   }
 
-  ValueObjectSP iterated_sp(iterator.advance(actual_advancde));
-  if (!iterated_sp) {
+  ValueObjectSP iterated_sp(iterator.advance(actual_advance));
+  if (!iterated_sp)
 // this tree is garbage - stop
-m_tree =
-nullptr; // this will stop all future searches until an Update() 
happens
-return iterated_sp;
-  }
+return nullptr;
 
-  if (!GetDataType()) {
-m_tree = nullptr;
-return lldb::ValueObjectSP();
-  }
+  if (!GetDataType())
+return nullptr;
 
   if (!need_to_skip) {
 Status error;
 iterated_sp = iterated_sp->Dereference(error);
-if (!iterated_sp || error.Fail()) {
-  m_tree = nullptr;
-  return lldb::ValueObjectSP();
-}
+if (!iterated_sp || error.Fail())
+  return nullptr;
+
 GetValueOffset(iterated_sp);
 auto child_sp = iterated_sp->GetChildMemberWithName("__value_");
-if (child_sp)
+if (child_sp) {
+  // Old layout (pre 089a7cc5dea)
   iterated_sp = child_sp;
-else
+} else {
   iterated_sp = iterated_sp->GetSyntheticChildAtOffset(
   m_skip_size, m_element_type, true);
-if (!iterated_sp) {
-  m_tree = nullptr;
-  return lldb::ValueObjectSP();
 }
+
+if (!iterated_sp)
+  return nullptr;
   } else {
 // because of the way our debug info is made, we need to read item 0
 // first so that we can cache information used to ge

[Lldb-commits] [lldb] [lldb][DataFormatter] Clean up LibcxxStdMapSyntheticFrontEnd::GetKeyValuePair (PR #97551)

2024-07-08 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] Fix test assertions in TestDAP_stepInTargets.py (PR #96687)

2024-07-08 Thread Pavel Labath via lldb-commits


@@ -55,14 +55,23 @@ def test_basic(self):
 self.assertEqual(len(step_in_targets), 3, "expect 3 step in targets")
 
 # Verify the target names are correct.
-self.assertEqual(step_in_targets[0]["label"], "bar()", "expect bar()")
-self.assertEqual(step_in_targets[1]["label"], "bar2()", "expect 
bar2()")
-self.assertEqual(
-step_in_targets[2]["label"], "foo(int, int)", "expect foo(int, 
int)"
-)
+# The order of funcA and funcB may change depending on the compiler 
ABI.
+funcA_target = None
+funcB_target = None
+for target in step_in_targets[0:2]:
+if "funcB" in target["label"]:
+funcB_target = target
+elif "funcA" in target["label"]:
+funcA_target = target
+else:
+self.fail(f"Unexpected step in target: {target}")
+
+self.assertIsNotNone(funcA_target, "expect funcA")
+self.assertIsNotNone(funcB_target, "expect funcB")
+self.assertIn("foo", step_in_targets[2]["label"], "expect foo")
 
-# Choose to step into second target and verify that we are in bar2()
-self.stepIn(threadId=tid, targetId=step_in_targets[1]["id"], 
waitForStop=True)
+# Choose to step into second target and verify that we are in funcB()

labath wrote:

funcB is not necessarily going to be the second target, so this comment is 
incorrect. However, instead of changing the comment, I think it'd be actually 
better to change the code so that it steps into the second function, regardless 
of what that function might be. This is because we would end up in the first 
function even if we did a "normal" step in operation rather than the fancy 
targetted one. Stepping into the second function verifies that we can correctly 
ignore the first function that gets called. (I wasn't the person who wrote the 
test, but I suspect this is roughly the motivation for it being written the way 
it is).

So basically, you could keep the `targetId=step_in_targets[1]["id"]` thing in 
the line below, but then change the expectation on line 77 to expect the 
function that we tried stepping into.

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


[Lldb-commits] [lldb] 5ce9a86 - [lldb] Make variant formatter work with libstdc++-14 (#97568)

2024-07-08 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-07-08T12:06:10+02:00
New Revision: 5ce9a86110df0592d036688dc5b3ae2fbdbf99db

URL: 
https://github.com/llvm/llvm-project/commit/5ce9a86110df0592d036688dc5b3ae2fbdbf99db
DIFF: 
https://github.com/llvm/llvm-project/commit/5ce9a86110df0592d036688dc5b3ae2fbdbf99db.diff

LOG: [lldb] Make variant formatter work with libstdc++-14 (#97568)

In this version the internal data member has grown an additional
template parameter (bool), which was throwing the summary provider off.

This patch uses the type of the entire variant object. This is part of
the API/ABI, so it should be more stable, but it means we have to
explicitly strip typedefs and references to get to the interesting bits,
which is why I've extended the test case with examples of those.

Added: 


Modified: 
lldb/examples/synthetic/gnu_libstdcpp.py

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp

Removed: 




diff  --git a/lldb/examples/synthetic/gnu_libstdcpp.py 
b/lldb/examples/synthetic/gnu_libstdcpp.py
index f778065aaca37..d98495b8a9df3 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -914,12 +914,15 @@ def get_variant_npos_value(index_byte_size):
 if index == npos_value:
 return " No Value"
 
+# Strip references and typedefs.
+variant_type = raw_obj.GetType().GetCanonicalType().GetDereferencedType()
+template_arg_count = variant_type.GetNumberOfTemplateArguments()
+
 # Invalid index can happen when the variant is not initialized yet.
-template_arg_count = data_obj.GetType().GetNumberOfTemplateArguments()
 if index >= template_arg_count:
 return " "
 
-active_type = data_obj.GetType().GetTemplateArgumentType(index)
+active_type = variant_type.GetTemplateArgumentType(index)
 return f" Active Type = {active_type.GetDisplayTypeName()} "
 
 

diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
index ba1641888b6f3..ea4a53fcb4097 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/TestDataFormatterLibStdcxxVariant.py
@@ -21,15 +21,17 @@ def test_with_run_command(self):
 
 lldbutil.continue_to_breakpoint(self.process, bkpt)
 
-self.expect(
-"frame variable v1",
-substrs=["v1 =  Active Type = int  {", "Value = 12", "}"],
-)
-
-self.expect(
-"frame variable v1_ref",
-substrs=["v1_ref =  Active Type = int : {", "Value = 12", "}"],
-)
+for name in ["v1", "v1_typedef"]:
+self.expect(
+"frame variable " + name,
+substrs=[name + " =  Active Type = int  {", "Value = 12", "}"],
+)
+
+for name in ["v1_ref", "v1_typedef_ref"]:
+self.expect(
+"frame variable " + name,
+substrs=[name + " =  Active Type = int : {", "Value = 12", 
"}"],
+)
 
 self.expect(
 "frame variable v_v1",

diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
index 545318f9358b6..36e0f74f831f8 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp
@@ -14,6 +14,10 @@ int main() {
 
   std::variant v1;
   std::variant &v1_ref = v1;
+  using V1_typedef = std::variant;
+  V1_typedef v1_typedef;
+  V1_typedef &v1_typedef_ref = v1_typedef;
+
   std::variant v2;
   std::variant v3;
   std::variant> v_v1;
@@ -43,6 +47,7 @@ int main() {
   v_many_types_no_value;
 
   v1 = 12; // v contains int
+  v1_typedef = v1;
   v_v1 = v1;
   int i = std::get(v1);
   printf("%d\n", i); // break here



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


[Lldb-commits] [lldb] [lldb] Make variant formatter work with libstdc++-14 (PR #97568)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] b590e9a - [lldb] Remove Listener::SetShadow (#97555)

2024-07-08 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-07-08T12:06:32+02:00
New Revision: b590e9a5aedabeceb00d81d49897abbf02ab3b87

URL: 
https://github.com/llvm/llvm-project/commit/b590e9a5aedabeceb00d81d49897abbf02ab3b87
DIFF: 
https://github.com/llvm/llvm-project/commit/b590e9a5aedabeceb00d81d49897abbf02ab3b87.diff

LOG: [lldb] Remove Listener::SetShadow (#97555)

It's not used since https://reviews.llvm.org/D157556.

Added: 


Modified: 
lldb/include/lldb/Utility/Listener.h
lldb/source/API/SBAttachInfo.cpp
lldb/source/API/SBLaunchInfo.cpp
lldb/source/Utility/Listener.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/Listener.h 
b/lldb/include/lldb/Utility/Listener.h
index eec8af023f263..d48816ec0ea4d 100644
--- a/lldb/include/lldb/Utility/Listener.h
+++ b/lldb/include/lldb/Utility/Listener.h
@@ -94,8 +94,6 @@ class Listener : public 
std::enable_shared_from_this {
 
   size_t HandleBroadcastEvent(lldb::EventSP &event_sp);
 
-  void SetShadow(bool is_shadow) { m_is_shadow = is_shadow; }
-
 private:
   // Classes that inherit from Listener can see and modify these
   struct BroadcasterInfo {
@@ -132,7 +130,6 @@ class Listener : public 
std::enable_shared_from_this {
   std::mutex m_events_mutex; // Protects m_broadcasters and m_events
   std::condition_variable m_events_condition;
   broadcaster_manager_collection m_broadcaster_managers;
-  bool m_is_shadow = false;
 
   void BroadcasterWillDestruct(Broadcaster *);
 

diff  --git a/lldb/source/API/SBAttachInfo.cpp 
b/lldb/source/API/SBAttachInfo.cpp
index 8ce1f1d65c496..a9f712c79c7fe 100644
--- a/lldb/source/API/SBAttachInfo.cpp
+++ b/lldb/source/API/SBAttachInfo.cpp
@@ -266,13 +266,7 @@ SBListener SBAttachInfo::GetShadowListener() {
 void SBAttachInfo::SetShadowListener(SBListener &listener) {
   LLDB_INSTRUMENT_VA(this, listener);
 
-  ListenerSP listener_sp = listener.GetSP();
-  if (listener_sp && listener.IsValid())
-listener_sp->SetShadow(true);
-  else
-listener_sp = nullptr;
-
-  m_opaque_sp->SetShadowListener(listener_sp);
+  m_opaque_sp->SetShadowListener(listener.GetSP());
 }
 
 const char *SBAttachInfo::GetScriptedProcessClassName() const {

diff  --git a/lldb/source/API/SBLaunchInfo.cpp 
b/lldb/source/API/SBLaunchInfo.cpp
index d5f935083e6c1..d6b52e8a67a49 100644
--- a/lldb/source/API/SBLaunchInfo.cpp
+++ b/lldb/source/API/SBLaunchInfo.cpp
@@ -402,11 +402,5 @@ SBListener SBLaunchInfo::GetShadowListener() {
 void SBLaunchInfo::SetShadowListener(SBListener &listener) {
   LLDB_INSTRUMENT_VA(this, listener);
 
-  ListenerSP listener_sp = listener.GetSP();
-  if (listener_sp && listener.IsValid())
-listener_sp->SetShadow(true);
-  else
-listener_sp = nullptr;
-
-  m_opaque_sp->SetShadowListener(listener_sp);
+  m_opaque_sp->SetShadowListener(listener.GetSP());
 }

diff  --git a/lldb/source/Utility/Listener.cpp 
b/lldb/source/Utility/Listener.cpp
index 6265c30af0d18..1efaad392502c 100644
--- a/lldb/source/Utility/Listener.cpp
+++ b/lldb/source/Utility/Listener.cpp
@@ -18,22 +18,16 @@
 using namespace lldb;
 using namespace lldb_private;
 
-Listener::Listener(const char *name)
-: m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(),
-  m_events_mutex(), m_is_shadow() {
-  Log *log = GetLog(LLDBLog::Object);
-  if (log != nullptr)
-LLDB_LOGF(log, "%p Listener::Listener('%s')", static_cast(this),
-  m_name.c_str());
+Listener::Listener(const char *name) : m_name(name) {
+  LLDB_LOGF(GetLog(LLDBLog::Object), "%p Listener::Listener('%s')",
+static_cast(this), m_name.c_str());
 }
 
 Listener::~Listener() {
-  Log *log = GetLog(LLDBLog::Object);
-
   // Don't call Clear() from here as that can cause races. See #96750.
 
-  LLDB_LOGF(log, "%p Listener::%s('%s')", static_cast(this),
-__FUNCTION__, m_name.c_str());
+  LLDB_LOGF(GetLog(LLDBLog::Object), "%p Listener::%s('%s')",
+static_cast(this), __FUNCTION__, m_name.c_str());
 }
 
 void Listener::Clear() {



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


[Lldb-commits] [lldb] [lldb] Remove Listener::SetShadow (PR #97555)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::map formatter (PR #97579)

2024-07-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/97579

>From 223606fa569d4d9ced91461ec10e63ef414ad15e Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 3 Jul 2024 11:43:47 +0200
Subject: [PATCH] [lldb][DataFormatter] Simplify std::map formatter

Depends on:
* https://github.com/llvm/llvm-project/pull/97544
* https://github.com/llvm/llvm-project/pull/97549
* https://github.com/llvm/llvm-project/pull/97551

This patch tries to simplify the way in which the
`std::map` formatter goes from the root `__tree`
pointer to a specific key/value pair.

Previously we would synthesize a structure that
mimicked what `__iter_pointer` looked like
in memory, then called `GetChildCompilerTypeAtIndex`
on it to find the byte offset into that structure
at which the pair was located at, and finally
use that offset through a call to `GetSyntheticChildAtOffset`
to retrieve that pair. Not only was this logic hard to follow,
and encoded the libc++ layout in non-obvious ways, it was also
fragile to alignment miscalculations
(https://github.com/llvm/llvm-project/pull/97443); this would
break after the new layout of std::map landed as part of
inhttps://github.com/llvm/llvm-project/issues/93069.

Instead, this patch simply casts the `__iter_pointer` to
the `__node_pointer` and uses a straightforward
`GetChildMemberWithName("__value_")` to get to the key/value
we care about. This allows us to get rid of some support
infrastructure/class state.

Ideally we would fix the underlying alignment issue, but
this unblocks the libc++ refactor in the interim,
while also benefitting the formatter in terms of readability (in my opinion).
---
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  | 172 +-
 1 file changed, 48 insertions(+), 124 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index c2bb3555908be..093e182df1188 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -18,11 +18,31 @@
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/lldb-forward.h"
+#include 
+#include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
 
+// The flattened layout of the std::__tree_iterator::__ptr_ looks
+// as follows:
+//
+// The following shows the contiguous block of memory:
+//
+//+-+ class __tree_end_node
+// __ptr_ | pointer __left_;|
+//+-+ class __tree_node_base
+//| pointer __right_;   |
+//| __parent_pointer __parent_; |
+//| bool __is_black_;   |
+//+-+ class __tree_node
+//| __node_value_type __value_; | <<< our key/value pair
+//+-+
+//
+// where __ptr_ has type __iter_pointer.
+
 class MapEntry {
 public:
   MapEntry() = default;
@@ -181,10 +201,6 @@ class LibcxxStdMapSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
   size_t GetIndexOfChildWithName(ConstString name) override;
 
 private:
-  bool GetDataType();
-
-  void GetValueOffset(const lldb::ValueObjectSP &node);
-
   /// Returns the ValueObject for the __tree_node type that
   /// holds the key/value pair of the node at index \ref idx.
   ///
@@ -203,8 +219,7 @@ class LibcxxStdMapSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
 
   ValueObject *m_tree = nullptr;
   ValueObject *m_root_node = nullptr;
-  CompilerType m_element_type;
-  uint32_t m_skip_size = UINT32_MAX;
+  CompilerType m_node_ptr_type;
   size_t m_count = UINT32_MAX;
   std::map m_iterators;
 };
@@ -234,7 +249,7 @@ class LibCxxMapIteratorSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
 
 lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
 LibcxxStdMapSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp), m_element_type(), m_iterators() {
+: SyntheticChildrenFrontEnd(*valobj_sp) {
   if (valobj_sp)
 Update();
 }
@@ -260,146 +275,52 @@ llvm::Expected lldb_private::formatters::
   return m_count;
 }
 
-bool lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType() {
-  if (m_element_type.IsValid())
-return true;
-  m_element_type.Clear();
-  ValueObjectSP deref;
-  Status error;
-  deref = m_root_node->Dereference(error);
-  if (!deref || error.Fail())
-return false;
-  deref = deref->GetChildMemberWithName("__value_");
-  if (deref) {
-m_element_type = deref->GetCompilerType();
-return true;
-  }
-  deref = m_backend.GetChildAtNamePath({"__tree_", "__pair3_"});
-  if (!deref)
-return false;
-  m_element_type = deref->GetCompilerType()
-   .GetTypeTemplateArgument(1)
-   .GetTypeTemplateArgument(1);
-  if (m_element_type) {
-std::string name;
-uint64_t bit_offset_p

[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (PR #97713)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (PR #97713)

2024-07-08 Thread Pavel Labath via lldb-commits


@@ -456,3 +477,97 @@ 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator(
 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
   return (valobj_sp ? new LibcxxStdMapSyntheticFrontEnd(valobj_sp) : nullptr);
 }
+
+lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
+LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
+: SyntheticChildrenFrontEnd(*valobj_sp) {
+  if (valobj_sp)
+Update();
+}
+
+lldb::ChildCacheState
+lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
+  m_pair_sp.reset();
+
+  ValueObjectSP valobj_sp = m_backend.GetSP();
+  if (!valobj_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  TargetSP target_sp(valobj_sp->GetTargetSP());
+  if (!target_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  auto tree_iter_sp = valobj_sp->GetChildMemberWithName("__i_");
+  if (!tree_iter_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  auto node_pointer_type =
+  tree_iter_sp->GetCompilerType().GetDirectNestedTypeWithName(
+  "__node_pointer");
+  if (!node_pointer_type.IsValid())
+return lldb::ChildCacheState::eRefetch;
+
+  auto iter_pointer_sp = tree_iter_sp->GetChildMemberWithName("__ptr_");
+  if (!iter_pointer_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  auto node_pointer_sp = iter_pointer_sp->Cast(node_pointer_type);
+  if (!node_pointer_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  Status err;
+  node_pointer_sp = node_pointer_sp->Dereference(err);
+  if (!node_pointer_sp || err.Fail())
+return lldb::ChildCacheState::eRefetch;
+
+  auto key_value_sp = node_pointer_sp->GetChildMemberWithName("__value_");
+  if (!key_value_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  key_value_sp = key_value_sp->Clone(ConstString("name"));
+  if (key_value_sp->GetNumChildrenIgnoringErrors() == 1) {
+auto child0_sp = key_value_sp->GetChildAtIndex(0);
+if (child0_sp &&
+(child0_sp->GetName() == "__cc_" || child0_sp->GetName() == "__cc"))
+  key_value_sp = child0_sp->Clone(ConstString("pair"));
+  }
+
+  m_pair_sp = key_value_sp;
+
+  return lldb::ChildCacheState::eRefetch;
+}
+
+llvm::Expected lldb_private::formatters::
+LibCxxMapIteratorSyntheticFrontEnd::CalculateNumChildren() {
+  return 2;
+}
+
+lldb::ValueObjectSP
+lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::GetChildAtIndex(
+uint32_t idx) {
+  if (!m_pair_sp)
+return nullptr;
+
+  return m_pair_sp->GetChildAtIndex(idx);
+}
+
+bool lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
+MightHaveChildren() {
+  return true;
+}
+
+size_t lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
+GetIndexOfChildWithName(ConstString name) {
+  if (name == "first")

labath wrote:

Since `GetChildAtIndex` is forwarding to m_pair_sp, could this do the same as 
well?

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (PR #97713)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


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


[Lldb-commits] [lldb] [lldb][DataFormatter] Move std::unordered_map::iterator formatter into LibCxxUnorderedMap.cpp (PR #97752)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (PR #97713)

2024-07-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/97713

>From f6b3e6055a9e2263f61e3f70d7a97ddbb7db5ab0 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 4 Jul 2024 09:30:19 +0200
Subject: [PATCH 1/2] [lldb][DataFormatter][NFC] Move std::map iterator
 formatter into LibCxxMap.cpp

The two formatters follow very similar techniques to retrieve data out of the 
map. We're changing this for `std::map` in 
https://github.com/llvm/llvm-project/pull/97579 and plan to change it in the 
same way for the iterator formatter. Having them in the same place will allow 
us to re-use some of the logic (and we won't have to repeat some of the 
clarification comments).
---
 .../Plugins/Language/CPlusPlus/LibCxx.cpp | 188 --
 .../Plugins/Language/CPlusPlus/LibCxx.h   |  29 +--
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  | 187 +
 3 files changed, 191 insertions(+), 213 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index ad467c3966e60..05cfa0568c25d 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -202,194 +202,6 @@ bool 
lldb_private::formatters::LibcxxUniquePointerSummaryProvider(
   return true;
 }
 
-/*
- (lldb) fr var ibeg --raw --ptr-depth 1
- (std::__1::__map_iterator,
- std::__1::allocator > >, std::__1::__tree_node,
- std::__1::allocator > >, void *> *, long> >) ibeg = {
- __i_ = {
- __ptr_ = 0x000100103870 {
- std::__1::__tree_node_base = {
- std::__1::__tree_end_node *> = {
- __left_ = 0x
- }
- __right_ = 0x
- __parent_ = 0x0001001038b0
- __is_black_ = true
- }
- __value_ = {
- first = 0
- second = { std::string }
- */
-
-lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
-LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp), m_pair_ptr(), m_pair_sp() {
-  if (valobj_sp)
-Update();
-}
-
-lldb::ChildCacheState
-lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
-  m_pair_sp.reset();
-  m_pair_ptr = nullptr;
-
-  ValueObjectSP valobj_sp = m_backend.GetSP();
-  if (!valobj_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  TargetSP target_sp(valobj_sp->GetTargetSP());
-
-  if (!target_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  // this must be a ValueObject* because it is a child of the ValueObject we
-  // are producing children for it if were a ValueObjectSP, we would end up
-  // with a loop (iterator -> synthetic -> child -> parent == iterator) and
-  // that would in turn leak memory by never allowing the ValueObjects to die
-  // and free their memory
-  m_pair_ptr = valobj_sp
-   ->GetValueForExpressionPath(
-   ".__i_.__ptr_->__value_", nullptr, nullptr,
-   ValueObject::GetValueForExpressionPathOptions()
-   .DontCheckDotVsArrowSyntax()
-   .SetSyntheticChildrenTraversal(
-   ValueObject::GetValueForExpressionPathOptions::
-   SyntheticChildrenTraversal::None),
-   nullptr)
-   .get();
-
-  if (!m_pair_ptr) {
-m_pair_ptr = valobj_sp
- ->GetValueForExpressionPath(
- ".__i_.__ptr_", nullptr, nullptr,
- ValueObject::GetValueForExpressionPathOptions()
- .DontCheckDotVsArrowSyntax()
- .SetSyntheticChildrenTraversal(
- 
ValueObject::GetValueForExpressionPathOptions::
- SyntheticChildrenTraversal::None),
- nullptr)
- .get();
-if (m_pair_ptr) {
-  auto __i_(valobj_sp->GetChildMemberWithName("__i_"));
-  if (!__i_) {
-m_pair_ptr = nullptr;
-return lldb::ChildCacheState::eRefetch;
-  }
-  CompilerType pair_type(
-  __i_->GetCompilerType().GetTypeTemplateArgument(0));
-  std::string name;
-  uint64_t bit_offset_ptr;
-  uint32_t bitfield_bit_size_ptr;
-  bool is_bitfield_ptr;
-  pair_type = pair_type.GetFieldAtIndex(
-  0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
-  if (!pair_type) {
-m_pair_ptr = nullptr;
-return lldb::ChildCacheState::eRefetch;
-  }
-
-  auto addr(m_pair_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS));
-  m_pair_ptr = nullptr;
-  if (addr && addr != LLDB_INVALID_ADDRESS) {
-auto ts = pair_type.GetTypeSystem();
-auto ast_ctx = ts.dyn_cast_or_null();
-if (!ast_ctx)
-  return lldb::ChildCacheState::eRefetch;
-
-// Mimick layout of std::__tree_iterator::__ptr_ and read it in
-// from process memory.
-//
-   

[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)

2024-07-08 Thread Pavel Labath via lldb-commits


@@ -246,3 +270,119 @@ 
lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEndCreator(
   return (valobj_sp ? new LibcxxStdUnorderedMapSyntheticFrontEnd(valobj_sp)
 : nullptr);
 }
+
+lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd::
+LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
+: SyntheticChildrenFrontEnd(*valobj_sp) {
+  if (valobj_sp)
+Update();
+}
+
+lldb::ChildCacheState lldb_private::formatters::
+LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() {
+  m_pair_sp.reset();
+
+  ValueObjectSP valobj_sp = m_backend.GetSP();
+  if (!valobj_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  TargetSP target_sp(valobj_sp->GetTargetSP());
+
+  if (!target_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  // Get the unordered_map::iterator
+  // m_backend is an 'unordered_map::iterator', aka a
+  // '__hash_map_iterator<__hash_table::iterator>'
+  //
+  // __hash_map_iterator::__i_ is a __hash_table::iterator (aka
+  // __hash_iterator<__node_pointer>)
+  auto hash_iter_sp = valobj_sp->GetChildMemberWithName("__i_");
+  if (!hash_iter_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  // Type is '__hash_iterator<__node_pointer>'
+  auto hash_iter_type = hash_iter_sp->GetCompilerType();
+  if (!hash_iter_type.IsValid())
+return lldb::ChildCacheState::eRefetch;
+
+  // Type is '__node_pointer'
+  auto node_pointer_type = hash_iter_type.GetTypeTemplateArgument(0);
+  if (!node_pointer_type.IsValid())
+return lldb::ChildCacheState::eRefetch;
+
+  // Cast the __hash_iterator to a __node_pointer (which stores our key/value
+  // pair)
+  auto hash_node_sp = hash_iter_sp->Cast(node_pointer_type);
+  if (!hash_node_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  auto key_value_sp = hash_node_sp->GetChildMemberWithName("__value_");
+  if (!key_value_sp) {
+// clang-format off
+// Since D101206 (ba79fb2e1f), libc++ wraps the `__value_` in an
+// anonymous union.
+// Child 0: __hash_node_base base class
+// Child 1: __hash_
+// Child 2: anonymous union
+// clang-format on
+auto anon_union_sp = hash_node_sp->GetChildAtIndex(2);
+if (!anon_union_sp)
+  return lldb::ChildCacheState::eRefetch;
+
+key_value_sp = anon_union_sp->GetChildMemberWithName("__value_");
+if (!key_value_sp)
+  return lldb::ChildCacheState::eRefetch;
+  }
+
+  // Create the synthetic child, which is a pair where the key and value can be
+  // retrieved // by querying the synthetic frontend for

labath wrote:

remove extra `//`

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


[Lldb-commits] [lldb] Fix flake in TestZerothFrame.py (PR #96685)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


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


[Lldb-commits] [lldb] 4c23625 - Fix flake in TestZerothFrame.py (#96685)

2024-07-08 Thread via lldb-commits

Author: Kendal Harland
Date: 2024-07-08T12:20:45+02:00
New Revision: 4c23625357b0b6091bc97478a79d522a832c2b21

URL: 
https://github.com/llvm/llvm-project/commit/4c23625357b0b6091bc97478a79d522a832c2b21
DIFF: 
https://github.com/llvm/llvm-project/commit/4c23625357b0b6091bc97478a79d522a832c2b21.diff

LOG: Fix flake in TestZerothFrame.py (#96685)

This test is currently flaky on a local Windows amd64 build. The reason
is that it relies on the order of `process.threads` but this order is
nondeterministic:

If we print lldb's inputs and outputs while running, we can see that the
breakpoints are always being set correctly, and always being hit:

```sh
runCmd: breakpoint set -f "main.c" -l 2
output: Breakpoint 1: where = a.out`func_inner + 1 at main.c:2:9, address = 
0x000140001001

runCmd: breakpoint set -f "main.c" -l 7
output: Breakpoint 2: where = a.out`main + 17 at main.c:7:5, address = 
0x000140001021

runCmd: run
output: Process 52328 launched: 
'C:\workspace\llvm-project\llvm\build\lldb-test-build.noindex\functionalities\unwind\zeroth_frame\TestZerothFrame.test_dwarf\a.out'
 (x86_64)
Process 52328 stopped
* thread #1, stop reason = breakpoint 1.1
frame #0: 0x7ff68f6b1001 a.out`func_inner at main.c:2:9
   1void func_inner() {
-> 2int a = 1;  // Set breakpoint 1 here
^
   3}
   4
   5int main() {
   6func_inner();
   7return 0; // Set breakpoint 2 here
```

However, sometimes the backtrace printed in this test shows that the
process is stopped inside NtWaitForWorkViaWorkerFactory from
`ntdll.dll`:

```sh
Backtrace at the first breakpoint:
frame #0: 0x7ffecc7b3bf4 ntdll.dll`NtWaitForWorkViaWorkerFactory + 20
frame #1: 0x7ffecc74585e ntdll.dll`RtlClearThreadWorkOnBehalfTicket + 862
frame #2: 0x7ffecc3e257d kernel32.dll`BaseThreadInitThunk + 29
frame #3: 0x7ffecc76af28 ntdll.dll`RtlUserThreadStart + 40
```

When this happens, the test fails with an assertion error that the
stopped thread's zeroth frame's current line number does not match the
expected line number. This is because the test is looking at the wrong
thread: `process.threads[0]`.

If we print the list of threads each time the test is run, we notice
that threads are sometimes in a different order, within
`process.threads`:

```sh
Thread 0: thread #4: tid = 0x9c38, 0x7ffecc7b3bf4 
ntdll.dll`NtWaitForWorkViaWorkerFactory + 20
Thread 1: thread #2: tid = 0xa950, 0x7ffecc7b3bf4 
ntdll.dll`NtWaitForWorkViaWorkerFactory + 20
Thread 2: thread #1: tid = 0xab18, 0x7ff64bc81001 a.out`func_inner at 
main.c:2:9, stop reason = breakpoint 1.1
Thread 3: thread #3: tid = 0xc514, 0x7ffecc7b3bf4 
ntdll.dll`NtWaitForWorkViaWorkerFactory + 20

Thread 0: thread #3: tid = 0x018c, 0x7ffecc7b3bf4 
ntdll.dll`NtWaitForWorkViaWorkerFactory + 20
Thread 1: thread #1: tid = 0x85c8, 0x7ff7130c1001 a.out`func_inner at 
main.c:2:9, stop reason = breakpoint 1.1
Thread 2: thread #2: tid = 0xf344, 0x7ffecc7b3bf4 
ntdll.dll`NtWaitForWorkViaWorkerFactory + 20
Thread 3: thread #4: tid = 0x6a50, 0x7ffecc7b3bf4 
ntdll.dll`NtWaitForWorkViaWorkerFactory + 20
```

Use `self.thread()` to consistently select the correct thread, instead.

Co-authored-by: kendal 

Added: 


Modified: 
lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py 
b/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py
index f4e883d314644..d660844405e13 100644
--- a/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py
+++ b/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py
@@ -40,28 +40,28 @@ def test(self):
 target = self.dbg.CreateTarget(exe)
 self.assertTrue(target, VALID_TARGET)
 
-bp1_line = line_number("main.c", "// Set breakpoint 1 here")
-bp2_line = line_number("main.c", "// Set breakpoint 2 here")
-
-lldbutil.run_break_set_by_file_and_line(
-self, "main.c", bp1_line, num_expected_locations=1
+main_dot_c = lldb.SBFileSpec("main.c")
+bp1 = target.BreakpointCreateBySourceRegex(
+"// Set breakpoint 1 here", main_dot_c
 )
-lldbutil.run_break_set_by_file_and_line(
-self, "main.c", bp2_line, num_expected_locations=1
+bp2 = target.BreakpointCreateBySourceRegex(
+"// Set breakpoint 2 here", main_dot_c
 )
 
 process = target.LaunchSimple(None, None, 
self.get_process_working_directory())
 self.assertTrue(process, VALID_PROCESS)
 
-thread = process.GetThreadAtIndex(0)
+thread = self.thread()
+
 if self.TraceOn():
 print("Backtrace at the first breakpoint:")
 for f in thread.frames:
 print(f)
+
 # Check that we have stopped at correct break

[Lldb-commits] [lldb] Fix flake in TestZerothFrame.py (PR #96685)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] Fix flake in TestZerothFrame.py (PR #96685)

2024-07-08 Thread via lldb-commits

github-actions[bot] wrote:



@kendalharland Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/96685
___
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 type error when calling random.randrange with 'float' arg (PR #97328)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


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


[Lldb-commits] [lldb] 857700f - [lldb][test] Fix type error when calling random.randrange with 'float' arg (#97328)

2024-07-08 Thread via lldb-commits

Author: Kendal Harland
Date: 2024-07-08T12:22:03+02:00
New Revision: 857700ff6fb9f9f653c3788445df06db07e7bb59

URL: 
https://github.com/llvm/llvm-project/commit/857700ff6fb9f9f653c3788445df06db07e7bb59
DIFF: 
https://github.com/llvm/llvm-project/commit/857700ff6fb9f9f653c3788445df06db07e7bb59.diff

LOG: [lldb][test] Fix type error when calling random.randrange with 'float' arg 
(#97328)

This test only runs on Windows and fails because we're passing a literal
of the wrong type to random.randrange.

Co-authored-by: kendal 

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py

Removed: 




diff  --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
index 5bd352d3ac549..94376a16d39f6 100644
--- 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
+++ 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
@@ -1042,7 +1042,7 @@ def __init__(self):
 class Pipe(object):
 def __init__(self, prefix):
 while True:
-self.name = "lldb-" + str(random.randrange(1e10))
+self.name = "lldb-" + str(random.randrange(10**10))
 full_name = ".\\pipe\\" + self.name
 self._handle = CreateNamedPipe(
 full_name,



___
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 type error when calling random.randrange with 'float' arg (PR #97328)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath closed https://github.com/llvm/llvm-project/pull/97328
___
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 type error when calling random.randrange with 'float' arg (PR #97328)

2024-07-08 Thread via lldb-commits

github-actions[bot] wrote:



@kendalharland Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[Lldb-commits] [lldb] [lldb][test] Support remote run of Shell tests (PR #95986)

2024-07-08 Thread Vladislav Dzhidzhoev via lldb-commits

dzhidzhoev wrote:

Could you please give your opinion @JDevlieghere ?

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-08 Thread Vladislav Dzhidzhoev via lldb-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/96654

>From c107d5d43ed4f696bb2095b2a7d32ca59696f220 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Wed, 19 Jun 2024 23:50:18 +
Subject: [PATCH] [lldb][test] Set target and host OS for API tests in case of
 remote testing

Makefile.rules uses HOST_OS and OS variables for determining host and target
OSes for API tests compilation.

This commit starts moving the platform detection logic from Makefile to Python 
lldb
test suite.

When lldb's target is set to remote-linux, Makefile.rules script should be
executed with the target OS variable set to Linux.

This is useful for the case of Windows-to-Linux cross-testing.
---
 .../Python/lldbsuite/test/lldbplatformutil.py | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 21f2095db90f8..0c7a6807974b4 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -56,6 +56,10 @@ def target_is_android():
 return configuration.lldb_platform_name == "remote-android"
 
 
+def target_is_remote_linux():
+return configuration.lldb_platform_name == "remote-linux"
+
+
 def android_device_api():
 if not hasattr(android_device_api, "result"):
 assert configuration.lldb_platform_url is not None
@@ -92,11 +96,22 @@ def match_android_device(device_arch, valid_archs=None, 
valid_api_levels=None):
 
 
 def finalize_build_dictionary(dictionary):
+if dictionary is None:
+dictionary = {}
 if target_is_android():
-if dictionary is None:
-dictionary = {}
 dictionary["OS"] = "Android"
 dictionary["PIE"] = 1
+elif platformIsDarwin():
+dictionary["OS"] = "Darwin"
+else:
+# Provide uname-like platform name
+platform_name_to_uname = { "linux": "Linux",
+"netbsd": "NetBSD",
+"freebsd": "FreeBSD",
+"windows": "Windows_NT",
+}
+dictionary["OS"] = platform_name_to_uname[getPlatform()]
+dictionary["HOST_OS"] = platform_name_to_uname[getHostPlatform()]
 return dictionary
 
 

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-08 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
857700ff6fb9f9f653c3788445df06db07e7bb59...c107d5d43ed4f696bb2095b2a7d32ca59696f220
 lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
``





View the diff from darker here.


``diff
--- lldbplatformutil.py 2024-07-08 11:24:08.00 +
+++ lldbplatformutil.py 2024-07-08 12:14:00.945465 +
@@ -103,15 +103,16 @@
 dictionary["PIE"] = 1
 elif platformIsDarwin():
 dictionary["OS"] = "Darwin"
 else:
 # Provide uname-like platform name
-platform_name_to_uname = { "linux": "Linux",
-"netbsd": "NetBSD",
-"freebsd": "FreeBSD",
-"windows": "Windows_NT",
-}
+platform_name_to_uname = {
+"linux": "Linux",
+"netbsd": "NetBSD",
+"freebsd": "FreeBSD",
+"windows": "Windows_NT",
+}
 dictionary["OS"] = platform_name_to_uname[getPlatform()]
 dictionary["HOST_OS"] = platform_name_to_uname[getHostPlatform()]
 return dictionary
 
 

``




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


[Lldb-commits] [lldb] 1e6dfc6 - [lldb][DataFormatter] Remove support for old std::map layout (#97549)

2024-07-08 Thread via lldb-commits

Author: Michael Buch
Date: 2024-07-08T13:47:44+01:00
New Revision: 1e6dfc624867fbfc6cd6e5dd534bd11f0616e7fc

URL: 
https://github.com/llvm/llvm-project/commit/1e6dfc624867fbfc6cd6e5dd534bd11f0616e7fc
DIFF: 
https://github.com/llvm/llvm-project/commit/1e6dfc624867fbfc6cd6e5dd534bd11f0616e7fc.diff

LOG: [lldb][DataFormatter] Remove support for old std::map layout (#97549)

We currently supported the layout from pre-2016 (before the layout
change in
[14caaddd3f08e798dcd9ac0ddfc](https://github.com/llvm/llvm-project/commit/14caaddd3f08e798dcd9ac0ddfc)).
We have another upcoming layout change in `__tree` and `map` (as part of
https://github.com/llvm/llvm-project/issues/93069) which will likely
require rewriting parts of this formatter. Removing the support for the
pre-2016 layout will make those changes more straightforward to
review/maintain.

Being backward compatible would be great but we have no tests that
actually verify that the old layout still works (and our oldest matrix
bot tests clang-15). If anyone feels strongly about keeping this layout,
we could possibly factor out that logic and keep it around.

Added: 


Modified: 
lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index c2bb3555908be..9fcb9e22bfc38 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -269,11 +269,6 @@ bool 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType() {
   deref = m_root_node->Dereference(error);
   if (!deref || error.Fail())
 return false;
-  deref = deref->GetChildMemberWithName("__value_");
-  if (deref) {
-m_element_type = deref->GetCompilerType();
-return true;
-  }
   deref = m_backend.GetChildAtNamePath({"__tree_", "__pair3_"});
   if (!deref)
 return false;
@@ -301,40 +296,35 @@ void 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset(
 return;
   if (!node)
 return;
+
   CompilerType node_type(node->GetCompilerType());
-  uint64_t bit_offset;
-  if (node_type.GetIndexOfFieldWithName("__value_", nullptr, &bit_offset) !=
-  UINT32_MAX) {
-// Old layout (pre d05b10ab4fc65)
-m_skip_size = bit_offset / 8u;
-  } else {
-auto ast_ctx = 
node_type.GetTypeSystem().dyn_cast_or_null();
-if (!ast_ctx)
-  return;
-CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
-llvm::StringRef(),
-{{"ptr0", 
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
- {"ptr1", 
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
- {"ptr2", 
ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
- {"cw", ast_ctx->GetBasicType(lldb::eBasicTypeBool)},
- {"payload", (m_element_type.GetCompleteType(), m_element_type)}});
-std::string child_name;
-uint32_t child_byte_size;
-int32_t child_byte_offset = 0;
-uint32_t child_bitfield_bit_size;
-uint32_t child_bitfield_bit_offset;
-bool child_is_base_class;
-bool child_is_deref_of_parent;
-uint64_t language_flags;
-auto child_type =
-llvm::expectedToStdOptional(tree_node_type.GetChildCompilerTypeAtIndex(
-nullptr, 4, true, true, true, child_name, child_byte_size,
-child_byte_offset, child_bitfield_bit_size,
-child_bitfield_bit_offset, child_is_base_class,
-child_is_deref_of_parent, nullptr, language_flags));
-if (child_type && child_type->IsValid())
-  m_skip_size = (uint32_t)child_byte_offset;
-  }
+  auto ast_ctx = node_type.GetTypeSystem().dyn_cast_or_null();
+  if (!ast_ctx)
+return;
+
+  CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
+  llvm::StringRef(),
+  {{"ptr0", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
+   {"ptr1", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
+   {"ptr2", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
+   {"cw", ast_ctx->GetBasicType(lldb::eBasicTypeBool)},
+   {"payload", (m_element_type.GetCompleteType(), m_element_type)}});
+  std::string child_name;
+  uint32_t child_byte_size;
+  int32_t child_byte_offset = 0;
+  uint32_t child_bitfield_bit_size;
+  uint32_t child_bitfield_bit_offset;
+  bool child_is_base_class;
+  bool child_is_deref_of_parent;
+  uint64_t language_flags;
+  auto child_type =
+  llvm::expectedToStdOptional(tree_node_type.GetChildCompilerTypeAtIndex(
+  nullptr, 4, true, true, true, child_name, child_byte_size,
+  child_byte_offset, child_bitfield_bit_size, 
child_bitfield_bit_offset,
+  child_is_base_class, child_is_deref_of_parent, nullptr,
+  language_flags));
+  if (child_type && child_type->IsValid())
+m_skip_size = (uint32_t)c

[Lldb-commits] [lldb] [lldb][DataFormatter] Remove support for old std::map layout (PR #97549)

2024-07-08 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] cb72aec - [lldb][DataFormatter] Move std::unordered_map::iterator formatter into LibCxxUnorderedMap.cpp (#97752)

2024-07-08 Thread via lldb-commits

Author: Michael Buch
Date: 2024-07-08T13:48:06+01:00
New Revision: cb72aecea6e7da49c7a7fbeb1bde4e401324b9ba

URL: 
https://github.com/llvm/llvm-project/commit/cb72aecea6e7da49c7a7fbeb1bde4e401324b9ba
DIFF: 
https://github.com/llvm/llvm-project/commit/cb72aecea6e7da49c7a7fbeb1bde4e401324b9ba.diff

LOG: [lldb][DataFormatter] Move std::unordered_map::iterator formatter into 
LibCxxUnorderedMap.cpp (#97752)

Similar to how we moved the `std::map::iterator` formatter in
https://github.com/llvm/llvm-project/pull/97687, do the same for
`std::unordered_map::iterator`.

Again the `unordered_map` and `unordered_map::iterator` formatters try
to do very similar things: retrieve data out of the map. The iterator
formatter does this in a fragile way (similar to how `std::map` does it,
see https://github.com/llvm/llvm-project/pull/97579). Thus we will be
refactoring the `std::unordered_map::iterator` in upcoming patches.
Having it in `LibCxxUnorderedMap` will allow us to re-use some of the
logic (and we won't have to repeat some of the clarification comments).

Added: 


Modified: 
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index 05cfa0568c25d..feaa51a96843a 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -202,155 +202,6 @@ bool 
lldb_private::formatters::LibcxxUniquePointerSummaryProvider(
   return true;
 }
 
-lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd::
-LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp) {
-  if (valobj_sp)
-Update();
-}
-
-lldb::ChildCacheState lldb_private::formatters::
-LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() {
-  m_pair_sp.reset();
-  m_iter_ptr = nullptr;
-
-  ValueObjectSP valobj_sp = m_backend.GetSP();
-  if (!valobj_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  TargetSP target_sp(valobj_sp->GetTargetSP());
-
-  if (!target_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  if (!valobj_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions()
- .DontCheckDotVsArrowSyntax()
- .SetSyntheticChildrenTraversal(
- 
ValueObject::GetValueForExpressionPathOptions::
- SyntheticChildrenTraversal::None);
-
-  // This must be a ValueObject* because it is a child of the ValueObject we
-  // are producing children for it if were a ValueObjectSP, we would end up
-  // with a loop (iterator -> synthetic -> child -> parent == iterator) and
-  // that would in turn leak memory by never allowing the ValueObjects to die
-  // and free their memory.
-  m_iter_ptr =
-  valobj_sp
-  ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr,
-  exprPathOptions, nullptr)
-  .get();
-
-  if (m_iter_ptr) {
-auto iter_child(valobj_sp->GetChildMemberWithName("__i_"));
-if (!iter_child) {
-  m_iter_ptr = nullptr;
-  return lldb::ChildCacheState::eRefetch;
-}
-
-CompilerType node_type(iter_child->GetCompilerType()
-   .GetTypeTemplateArgument(0)
-   .GetPointeeType());
-
-CompilerType pair_type(node_type.GetTypeTemplateArgument(0));
-
-std::string name;
-uint64_t bit_offset_ptr;
-uint32_t bitfield_bit_size_ptr;
-bool is_bitfield_ptr;
-
-pair_type = pair_type.GetFieldAtIndex(
-0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
-if (!pair_type) {
-  m_iter_ptr = nullptr;
-  return lldb::ChildCacheState::eRefetch;
-}
-
-uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
-m_iter_ptr = nullptr;
-
-if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
-  return lldb::ChildCacheState::eRefetch;
-
-auto ts = pair_type.GetTypeSystem();
-auto ast_ctx = ts.dyn_cast_or_null();
-if (!ast_ctx)
-  return lldb::ChildCacheState::eRefetch;
-
-// Mimick layout of std::__hash_iterator::__node_ and read it in
-// from process memory.
-//
-// The following shows the contiguous block of memory:
-//
-// +-+ class __hash_node_base
-// __node_ | __next_pointer __next_; |
-// +-+ class __hash_node
-// | size_t __hash_; |
-// | __node_value_type __value_; | <<< our key/value pair
-// +-+
-/

[Lldb-commits] [lldb] [lldb][DataFormatter] Move std::unordered_map::iterator formatter into LibCxxUnorderedMap.cpp (PR #97752)

2024-07-08 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)

2024-07-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/97754

>From b10f76bd6d02106e80315a70a7b72461cb6f2a99 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 4 Jul 2024 13:35:21 +0200
Subject: [PATCH 1/2] [lldb][DataFormatter] Move std::unordered_map::iterator
 formatter into LibCxxUnorderedMap.cpp

---
 .../Plugins/Language/CPlusPlus/LibCxx.cpp | 149 -
 .../Plugins/Language/CPlusPlus/LibCxx.h   |  54 +
 .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 196 ++
 3 files changed, 200 insertions(+), 199 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index 05cfa0568c25d4..feaa51a96843ab 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -202,155 +202,6 @@ bool 
lldb_private::formatters::LibcxxUniquePointerSummaryProvider(
   return true;
 }
 
-lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd::
-LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp) {
-  if (valobj_sp)
-Update();
-}
-
-lldb::ChildCacheState lldb_private::formatters::
-LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() {
-  m_pair_sp.reset();
-  m_iter_ptr = nullptr;
-
-  ValueObjectSP valobj_sp = m_backend.GetSP();
-  if (!valobj_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  TargetSP target_sp(valobj_sp->GetTargetSP());
-
-  if (!target_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  if (!valobj_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions()
- .DontCheckDotVsArrowSyntax()
- .SetSyntheticChildrenTraversal(
- 
ValueObject::GetValueForExpressionPathOptions::
- SyntheticChildrenTraversal::None);
-
-  // This must be a ValueObject* because it is a child of the ValueObject we
-  // are producing children for it if were a ValueObjectSP, we would end up
-  // with a loop (iterator -> synthetic -> child -> parent == iterator) and
-  // that would in turn leak memory by never allowing the ValueObjects to die
-  // and free their memory.
-  m_iter_ptr =
-  valobj_sp
-  ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr,
-  exprPathOptions, nullptr)
-  .get();
-
-  if (m_iter_ptr) {
-auto iter_child(valobj_sp->GetChildMemberWithName("__i_"));
-if (!iter_child) {
-  m_iter_ptr = nullptr;
-  return lldb::ChildCacheState::eRefetch;
-}
-
-CompilerType node_type(iter_child->GetCompilerType()
-   .GetTypeTemplateArgument(0)
-   .GetPointeeType());
-
-CompilerType pair_type(node_type.GetTypeTemplateArgument(0));
-
-std::string name;
-uint64_t bit_offset_ptr;
-uint32_t bitfield_bit_size_ptr;
-bool is_bitfield_ptr;
-
-pair_type = pair_type.GetFieldAtIndex(
-0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
-if (!pair_type) {
-  m_iter_ptr = nullptr;
-  return lldb::ChildCacheState::eRefetch;
-}
-
-uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
-m_iter_ptr = nullptr;
-
-if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
-  return lldb::ChildCacheState::eRefetch;
-
-auto ts = pair_type.GetTypeSystem();
-auto ast_ctx = ts.dyn_cast_or_null();
-if (!ast_ctx)
-  return lldb::ChildCacheState::eRefetch;
-
-// Mimick layout of std::__hash_iterator::__node_ and read it in
-// from process memory.
-//
-// The following shows the contiguous block of memory:
-//
-// +-+ class __hash_node_base
-// __node_ | __next_pointer __next_; |
-// +-+ class __hash_node
-// | size_t __hash_; |
-// | __node_value_type __value_; | <<< our key/value pair
-// +-+
-//
-CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
-llvm::StringRef(),
-{{"__next_",
-  ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
- {"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)},
- {"__value_", pair_type}});
-std::optional size = tree_node_type.GetByteSize(nullptr);
-if (!size)
-  return lldb::ChildCacheState::eRefetch;
-WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0));
-ProcessSP process_sp(target_sp->GetProcessSP());
-Status error;
-process_sp->ReadMemory(addr, buffer_sp->GetBytes(),
-   buffer_sp->GetByteSize(), error);
-if (error.Fail())
-  return lldb::ChildCacheState::eRefetch

[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::map formatter (PR #97579)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-08 Thread Pavel Labath via lldb-commits


@@ -92,11 +96,22 @@ def match_android_device(device_arch, valid_archs=None, 
valid_api_levels=None):
 
 
 def finalize_build_dictionary(dictionary):
+if dictionary is None:
+dictionary = {}
 if target_is_android():
-if dictionary is None:
-dictionary = {}
 dictionary["OS"] = "Android"
 dictionary["PIE"] = 1
+elif platformIsDarwin():
+dictionary["OS"] = "Darwin"
+else:
+# Provide uname-like platform name
+platform_name_to_uname = { "linux": "Linux",
+"netbsd": "NetBSD",
+"freebsd": "FreeBSD",
+"windows": "Windows_NT",
+}
+dictionary["OS"] = platform_name_to_uname[getPlatform()]
+dictionary["HOST_OS"] = platform_name_to_uname[getHostPlatform()]

labath wrote:

Why is this under the `else:` branch? I would expect we need to set `HOST_OS` 
even if we're targetting android or darwin...

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-08 Thread Pavel Labath via lldb-commits


@@ -56,6 +56,10 @@ def target_is_android():
 return configuration.lldb_platform_name == "remote-android"
 
 
+def target_is_remote_linux():
+return configuration.lldb_platform_name == "remote-linux"
+
+

labath wrote:

I guess this isn't used anymore.

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (PR #97713)

2024-07-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/97713

>From f6b3e6055a9e2263f61e3f70d7a97ddbb7db5ab0 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 4 Jul 2024 09:30:19 +0200
Subject: [PATCH 1/6] [lldb][DataFormatter][NFC] Move std::map iterator
 formatter into LibCxxMap.cpp

The two formatters follow very similar techniques to retrieve data out of the 
map. We're changing this for `std::map` in 
https://github.com/llvm/llvm-project/pull/97579 and plan to change it in the 
same way for the iterator formatter. Having them in the same place will allow 
us to re-use some of the logic (and we won't have to repeat some of the 
clarification comments).
---
 .../Plugins/Language/CPlusPlus/LibCxx.cpp | 188 --
 .../Plugins/Language/CPlusPlus/LibCxx.h   |  29 +--
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  | 187 +
 3 files changed, 191 insertions(+), 213 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index ad467c3966e60..05cfa0568c25d 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -202,194 +202,6 @@ bool 
lldb_private::formatters::LibcxxUniquePointerSummaryProvider(
   return true;
 }
 
-/*
- (lldb) fr var ibeg --raw --ptr-depth 1
- (std::__1::__map_iterator,
- std::__1::allocator > >, std::__1::__tree_node,
- std::__1::allocator > >, void *> *, long> >) ibeg = {
- __i_ = {
- __ptr_ = 0x000100103870 {
- std::__1::__tree_node_base = {
- std::__1::__tree_end_node *> = {
- __left_ = 0x
- }
- __right_ = 0x
- __parent_ = 0x0001001038b0
- __is_black_ = true
- }
- __value_ = {
- first = 0
- second = { std::string }
- */
-
-lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
-LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp), m_pair_ptr(), m_pair_sp() {
-  if (valobj_sp)
-Update();
-}
-
-lldb::ChildCacheState
-lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
-  m_pair_sp.reset();
-  m_pair_ptr = nullptr;
-
-  ValueObjectSP valobj_sp = m_backend.GetSP();
-  if (!valobj_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  TargetSP target_sp(valobj_sp->GetTargetSP());
-
-  if (!target_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  // this must be a ValueObject* because it is a child of the ValueObject we
-  // are producing children for it if were a ValueObjectSP, we would end up
-  // with a loop (iterator -> synthetic -> child -> parent == iterator) and
-  // that would in turn leak memory by never allowing the ValueObjects to die
-  // and free their memory
-  m_pair_ptr = valobj_sp
-   ->GetValueForExpressionPath(
-   ".__i_.__ptr_->__value_", nullptr, nullptr,
-   ValueObject::GetValueForExpressionPathOptions()
-   .DontCheckDotVsArrowSyntax()
-   .SetSyntheticChildrenTraversal(
-   ValueObject::GetValueForExpressionPathOptions::
-   SyntheticChildrenTraversal::None),
-   nullptr)
-   .get();
-
-  if (!m_pair_ptr) {
-m_pair_ptr = valobj_sp
- ->GetValueForExpressionPath(
- ".__i_.__ptr_", nullptr, nullptr,
- ValueObject::GetValueForExpressionPathOptions()
- .DontCheckDotVsArrowSyntax()
- .SetSyntheticChildrenTraversal(
- 
ValueObject::GetValueForExpressionPathOptions::
- SyntheticChildrenTraversal::None),
- nullptr)
- .get();
-if (m_pair_ptr) {
-  auto __i_(valobj_sp->GetChildMemberWithName("__i_"));
-  if (!__i_) {
-m_pair_ptr = nullptr;
-return lldb::ChildCacheState::eRefetch;
-  }
-  CompilerType pair_type(
-  __i_->GetCompilerType().GetTypeTemplateArgument(0));
-  std::string name;
-  uint64_t bit_offset_ptr;
-  uint32_t bitfield_bit_size_ptr;
-  bool is_bitfield_ptr;
-  pair_type = pair_type.GetFieldAtIndex(
-  0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
-  if (!pair_type) {
-m_pair_ptr = nullptr;
-return lldb::ChildCacheState::eRefetch;
-  }
-
-  auto addr(m_pair_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS));
-  m_pair_ptr = nullptr;
-  if (addr && addr != LLDB_INVALID_ADDRESS) {
-auto ts = pair_type.GetTypeSystem();
-auto ast_ctx = ts.dyn_cast_or_null();
-if (!ast_ctx)
-  return lldb::ChildCacheState::eRefetch;
-
-// Mimick layout of std::__tree_iterator::__ptr_ and read it in
-// from process memory.
-//
-   

[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (PR #97713)

2024-07-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/97713

>From f6b3e6055a9e2263f61e3f70d7a97ddbb7db5ab0 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 4 Jul 2024 09:30:19 +0200
Subject: [PATCH 1/7] [lldb][DataFormatter][NFC] Move std::map iterator
 formatter into LibCxxMap.cpp

The two formatters follow very similar techniques to retrieve data out of the 
map. We're changing this for `std::map` in 
https://github.com/llvm/llvm-project/pull/97579 and plan to change it in the 
same way for the iterator formatter. Having them in the same place will allow 
us to re-use some of the logic (and we won't have to repeat some of the 
clarification comments).
---
 .../Plugins/Language/CPlusPlus/LibCxx.cpp | 188 --
 .../Plugins/Language/CPlusPlus/LibCxx.h   |  29 +--
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  | 187 +
 3 files changed, 191 insertions(+), 213 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index ad467c3966e609..05cfa0568c25d4 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -202,194 +202,6 @@ bool 
lldb_private::formatters::LibcxxUniquePointerSummaryProvider(
   return true;
 }
 
-/*
- (lldb) fr var ibeg --raw --ptr-depth 1
- (std::__1::__map_iterator,
- std::__1::allocator > >, std::__1::__tree_node,
- std::__1::allocator > >, void *> *, long> >) ibeg = {
- __i_ = {
- __ptr_ = 0x000100103870 {
- std::__1::__tree_node_base = {
- std::__1::__tree_end_node *> = {
- __left_ = 0x
- }
- __right_ = 0x
- __parent_ = 0x0001001038b0
- __is_black_ = true
- }
- __value_ = {
- first = 0
- second = { std::string }
- */
-
-lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
-LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp), m_pair_ptr(), m_pair_sp() {
-  if (valobj_sp)
-Update();
-}
-
-lldb::ChildCacheState
-lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
-  m_pair_sp.reset();
-  m_pair_ptr = nullptr;
-
-  ValueObjectSP valobj_sp = m_backend.GetSP();
-  if (!valobj_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  TargetSP target_sp(valobj_sp->GetTargetSP());
-
-  if (!target_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  // this must be a ValueObject* because it is a child of the ValueObject we
-  // are producing children for it if were a ValueObjectSP, we would end up
-  // with a loop (iterator -> synthetic -> child -> parent == iterator) and
-  // that would in turn leak memory by never allowing the ValueObjects to die
-  // and free their memory
-  m_pair_ptr = valobj_sp
-   ->GetValueForExpressionPath(
-   ".__i_.__ptr_->__value_", nullptr, nullptr,
-   ValueObject::GetValueForExpressionPathOptions()
-   .DontCheckDotVsArrowSyntax()
-   .SetSyntheticChildrenTraversal(
-   ValueObject::GetValueForExpressionPathOptions::
-   SyntheticChildrenTraversal::None),
-   nullptr)
-   .get();
-
-  if (!m_pair_ptr) {
-m_pair_ptr = valobj_sp
- ->GetValueForExpressionPath(
- ".__i_.__ptr_", nullptr, nullptr,
- ValueObject::GetValueForExpressionPathOptions()
- .DontCheckDotVsArrowSyntax()
- .SetSyntheticChildrenTraversal(
- 
ValueObject::GetValueForExpressionPathOptions::
- SyntheticChildrenTraversal::None),
- nullptr)
- .get();
-if (m_pair_ptr) {
-  auto __i_(valobj_sp->GetChildMemberWithName("__i_"));
-  if (!__i_) {
-m_pair_ptr = nullptr;
-return lldb::ChildCacheState::eRefetch;
-  }
-  CompilerType pair_type(
-  __i_->GetCompilerType().GetTypeTemplateArgument(0));
-  std::string name;
-  uint64_t bit_offset_ptr;
-  uint32_t bitfield_bit_size_ptr;
-  bool is_bitfield_ptr;
-  pair_type = pair_type.GetFieldAtIndex(
-  0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
-  if (!pair_type) {
-m_pair_ptr = nullptr;
-return lldb::ChildCacheState::eRefetch;
-  }
-
-  auto addr(m_pair_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS));
-  m_pair_ptr = nullptr;
-  if (addr && addr != LLDB_INVALID_ADDRESS) {
-auto ts = pair_type.GetTypeSystem();
-auto ast_ctx = ts.dyn_cast_or_null();
-if (!ast_ctx)
-  return lldb::ChildCacheState::eRefetch;
-
-// Mimick layout of std::__tree_iterator::__ptr_ and read it in
-// from process memory.
-//
- 

[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (PR #97713)

2024-07-08 Thread Michael Buch via lldb-commits


@@ -456,3 +477,97 @@ 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator(
 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
   return (valobj_sp ? new LibcxxStdMapSyntheticFrontEnd(valobj_sp) : nullptr);
 }
+
+lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
+LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
+: SyntheticChildrenFrontEnd(*valobj_sp) {
+  if (valobj_sp)
+Update();
+}
+
+lldb::ChildCacheState
+lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
+  m_pair_sp.reset();
+
+  ValueObjectSP valobj_sp = m_backend.GetSP();
+  if (!valobj_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  TargetSP target_sp(valobj_sp->GetTargetSP());
+  if (!target_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  auto tree_iter_sp = valobj_sp->GetChildMemberWithName("__i_");
+  if (!tree_iter_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  auto node_pointer_type =
+  tree_iter_sp->GetCompilerType().GetDirectNestedTypeWithName(
+  "__node_pointer");
+  if (!node_pointer_type.IsValid())
+return lldb::ChildCacheState::eRefetch;
+
+  auto iter_pointer_sp = tree_iter_sp->GetChildMemberWithName("__ptr_");
+  if (!iter_pointer_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  auto node_pointer_sp = iter_pointer_sp->Cast(node_pointer_type);
+  if (!node_pointer_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  Status err;
+  node_pointer_sp = node_pointer_sp->Dereference(err);
+  if (!node_pointer_sp || err.Fail())
+return lldb::ChildCacheState::eRefetch;
+
+  auto key_value_sp = node_pointer_sp->GetChildMemberWithName("__value_");
+  if (!key_value_sp)
+return lldb::ChildCacheState::eRefetch;
+
+  key_value_sp = key_value_sp->Clone(ConstString("name"));
+  if (key_value_sp->GetNumChildrenIgnoringErrors() == 1) {
+auto child0_sp = key_value_sp->GetChildAtIndex(0);
+if (child0_sp &&
+(child0_sp->GetName() == "__cc_" || child0_sp->GetName() == "__cc"))
+  key_value_sp = child0_sp->Clone(ConstString("pair"));
+  }
+
+  m_pair_sp = key_value_sp;
+
+  return lldb::ChildCacheState::eRefetch;
+}
+
+llvm::Expected lldb_private::formatters::
+LibCxxMapIteratorSyntheticFrontEnd::CalculateNumChildren() {
+  return 2;
+}
+
+lldb::ValueObjectSP
+lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::GetChildAtIndex(
+uint32_t idx) {
+  if (!m_pair_sp)
+return nullptr;
+
+  return m_pair_sp->GetChildAtIndex(idx);
+}
+
+bool lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
+MightHaveChildren() {
+  return true;
+}
+
+size_t lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
+GetIndexOfChildWithName(ConstString name) {
+  if (name == "first")

Michael137 wrote:

yup good idea!

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)

2024-07-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/97754

>From b10f76bd6d02106e80315a70a7b72461cb6f2a99 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 4 Jul 2024 13:35:21 +0200
Subject: [PATCH 1/3] [lldb][DataFormatter] Move std::unordered_map::iterator
 formatter into LibCxxUnorderedMap.cpp

---
 .../Plugins/Language/CPlusPlus/LibCxx.cpp | 149 -
 .../Plugins/Language/CPlusPlus/LibCxx.h   |  54 +
 .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 196 ++
 3 files changed, 200 insertions(+), 199 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index 05cfa0568c25d..feaa51a96843a 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -202,155 +202,6 @@ bool 
lldb_private::formatters::LibcxxUniquePointerSummaryProvider(
   return true;
 }
 
-lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd::
-LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp) {
-  if (valobj_sp)
-Update();
-}
-
-lldb::ChildCacheState lldb_private::formatters::
-LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() {
-  m_pair_sp.reset();
-  m_iter_ptr = nullptr;
-
-  ValueObjectSP valobj_sp = m_backend.GetSP();
-  if (!valobj_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  TargetSP target_sp(valobj_sp->GetTargetSP());
-
-  if (!target_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  if (!valobj_sp)
-return lldb::ChildCacheState::eRefetch;
-
-  auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions()
- .DontCheckDotVsArrowSyntax()
- .SetSyntheticChildrenTraversal(
- 
ValueObject::GetValueForExpressionPathOptions::
- SyntheticChildrenTraversal::None);
-
-  // This must be a ValueObject* because it is a child of the ValueObject we
-  // are producing children for it if were a ValueObjectSP, we would end up
-  // with a loop (iterator -> synthetic -> child -> parent == iterator) and
-  // that would in turn leak memory by never allowing the ValueObjects to die
-  // and free their memory.
-  m_iter_ptr =
-  valobj_sp
-  ->GetValueForExpressionPath(".__i_.__node_", nullptr, nullptr,
-  exprPathOptions, nullptr)
-  .get();
-
-  if (m_iter_ptr) {
-auto iter_child(valobj_sp->GetChildMemberWithName("__i_"));
-if (!iter_child) {
-  m_iter_ptr = nullptr;
-  return lldb::ChildCacheState::eRefetch;
-}
-
-CompilerType node_type(iter_child->GetCompilerType()
-   .GetTypeTemplateArgument(0)
-   .GetPointeeType());
-
-CompilerType pair_type(node_type.GetTypeTemplateArgument(0));
-
-std::string name;
-uint64_t bit_offset_ptr;
-uint32_t bitfield_bit_size_ptr;
-bool is_bitfield_ptr;
-
-pair_type = pair_type.GetFieldAtIndex(
-0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
-if (!pair_type) {
-  m_iter_ptr = nullptr;
-  return lldb::ChildCacheState::eRefetch;
-}
-
-uint64_t addr = m_iter_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
-m_iter_ptr = nullptr;
-
-if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
-  return lldb::ChildCacheState::eRefetch;
-
-auto ts = pair_type.GetTypeSystem();
-auto ast_ctx = ts.dyn_cast_or_null();
-if (!ast_ctx)
-  return lldb::ChildCacheState::eRefetch;
-
-// Mimick layout of std::__hash_iterator::__node_ and read it in
-// from process memory.
-//
-// The following shows the contiguous block of memory:
-//
-// +-+ class __hash_node_base
-// __node_ | __next_pointer __next_; |
-// +-+ class __hash_node
-// | size_t __hash_; |
-// | __node_value_type __value_; | <<< our key/value pair
-// +-+
-//
-CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
-llvm::StringRef(),
-{{"__next_",
-  ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
- {"__hash_", ast_ctx->GetBasicType(lldb::eBasicTypeUnsignedLongLong)},
- {"__value_", pair_type}});
-std::optional size = tree_node_type.GetByteSize(nullptr);
-if (!size)
-  return lldb::ChildCacheState::eRefetch;
-WritableDataBufferSP buffer_sp(new DataBufferHeap(*size, 0));
-ProcessSP process_sp(target_sp->GetProcessSP());
-Status error;
-process_sp->ReadMemory(addr, buffer_sp->GetBytes(),
-   buffer_sp->GetByteSize(), error);
-if (error.Fail())
-  return lldb::ChildCacheState::eRefetch;

[Lldb-commits] [lldb] da827d0 - [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (#97754)

2024-07-08 Thread via lldb-commits

Author: Michael Buch
Date: 2024-07-08T14:38:58+01:00
New Revision: da827d0896e5e66fe9130f8f4479537d3bbee1da

URL: 
https://github.com/llvm/llvm-project/commit/da827d0896e5e66fe9130f8f4479537d3bbee1da
DIFF: 
https://github.com/llvm/llvm-project/commit/da827d0896e5e66fe9130f8f4479537d3bbee1da.diff

LOG: [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter 
(#97754)

Depends on https://github.com/llvm/llvm-project/pull/97752

This patch changes the way we retrieve the key/value pair in the
`std::unordered_map::iterator` formatter (similar to how we are changing
it for `std::map::iterator` in
https://github.com/llvm/llvm-project/pull/97713, the motivations being
the same).

The old logic was not very easy to follow, and encoded the libc++ layout
in non-obvious ways. But mainly it was also fragile to alignment
miscalculations (https://github.com/llvm/llvm-project/pull/97443); this
would break once the new layout of `std::unordered_map` landed as part
of https://github.com/llvm/llvm-project/issues/93069.

Instead, this patch simply casts the `__hash_iterator` to a
`__node_pointer` (which is what libc++ does too) and uses a
straightforward `GetChildMemberWithName("__value_")` to get to the
key/value we care about.

The `std::unordered_map` already does it this way, so we align the
iterator counterpart to do the same. We can eventually re-use the
core-part of the `std::unordered_map` and `std::unordered_map::iterator`
formatters. But it will be an easier to change to review once both
simplifications landed.

Added: 


Modified: 
lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/main.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index f5be2f5a5c317..93e7f4f4fd86c 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -52,26 +52,6 @@ class LibcxxStdUnorderedMapSyntheticFrontEnd
   std::vector> m_elements_cache;
 };
 
-/// Formats libcxx's std::unordered_map iterators
-///
-/// In raw form a std::unordered_map::iterator is represented as follows:
-///
-/// (lldb) var it --raw --ptr-depth 1
-/// (std::__1::__hash_map_iterator<
-///std::__1::__hash_iterator<
-///  std::__1::__hash_node<
-///std::__1::__hash_value_type<
-///std::__1::basic_string,
-///std::__1::allocator >, std::__1::basic_string, std::__1::allocator > >,
-///void *> *> >)
-///  it = {
-///   __i_ = {
-/// __node_ = 0x61700040 {
-///   __next_ = 0x61704000
-/// }
-///   }
-/// }
 class LibCxxUnorderedMapIteratorSyntheticFrontEnd
 : public SyntheticChildrenFrontEnd {
 public:
@@ -90,9 +70,6 @@ class LibCxxUnorderedMapIteratorSyntheticFrontEnd
   size_t GetIndexOfChildWithName(ConstString name) override;
 
 private:
-  ValueObject *m_iter_ptr = nullptr; ///< Held, not owned. Child of iterator
- ///< ValueObject supplied at construction.
-
   lldb::ValueObjectSP m_pair_sp; ///< ValueObject for the key/value pair
  ///< that the iterator currently points
  ///< to.
@@ -304,7 +281,6 @@ 
lldb_private::formatters::LibCxxUnorderedMapIteratorSyntheticFrontEnd::
 lldb::ChildCacheState lldb_private::formatters::
 LibCxxUnorderedMapIteratorSyntheticFrontEnd::Update() {
   m_pair_sp.reset();
-  m_iter_ptr = nullptr;
 
   ValueObjectSP valobj_sp = m_backend.GetSP();
   if (!valobj_sp)
@@ -315,98 +291,66 @@ lldb::ChildCacheState lldb_private::formatters::
   if (!target_sp)
 return lldb::ChildCacheState::eRefetch;
 
-  if (!valobj_sp)
+  // Get the unordered_map::iterator
+  // m_backend is an 'unordered_map::iterator', aka a
+  // '__hash_map_iterator<__hash_table::iterator>'
+  //
+  // __hash_map_iterator::__i_ is a __hash_table::iterator (aka
+  // __hash_iterator<__node_pointer>)
+  auto hash_iter_sp = valobj_sp->GetChildMemberWithName("__i_");
+  if (!hash_iter_sp)
 return lldb::ChildCacheState::eRefetch;
 
-  auto exprPathOptions = ValueObject::GetValueForExpressionPathOptions()
- .DontCheckDotVsArrowSyntax()
- .SetSyntheticChildrenTraversal(
- 
ValueObject::GetValueForExpressionPathOptions::
- SyntheticChildrenTraversal::None);
-
-  // This must be a ValueObject* because it is a child of the ValueObject we
-  // are producing children for it if were a ValueObjectSP, we would end up
-  // with a loop (iterator -> synthetic -> chil

[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::unordered_map::iterator formatter (PR #97754)

2024-07-08 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::map formatter (PR #97579)

2024-07-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/97579

>From 223606fa569d4d9ced91461ec10e63ef414ad15e Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 3 Jul 2024 11:43:47 +0200
Subject: [PATCH] [lldb][DataFormatter] Simplify std::map formatter

Depends on:
* https://github.com/llvm/llvm-project/pull/97544
* https://github.com/llvm/llvm-project/pull/97549
* https://github.com/llvm/llvm-project/pull/97551

This patch tries to simplify the way in which the
`std::map` formatter goes from the root `__tree`
pointer to a specific key/value pair.

Previously we would synthesize a structure that
mimicked what `__iter_pointer` looked like
in memory, then called `GetChildCompilerTypeAtIndex`
on it to find the byte offset into that structure
at which the pair was located at, and finally
use that offset through a call to `GetSyntheticChildAtOffset`
to retrieve that pair. Not only was this logic hard to follow,
and encoded the libc++ layout in non-obvious ways, it was also
fragile to alignment miscalculations
(https://github.com/llvm/llvm-project/pull/97443); this would
break after the new layout of std::map landed as part of
inhttps://github.com/llvm/llvm-project/issues/93069.

Instead, this patch simply casts the `__iter_pointer` to
the `__node_pointer` and uses a straightforward
`GetChildMemberWithName("__value_")` to get to the key/value
we care about. This allows us to get rid of some support
infrastructure/class state.

Ideally we would fix the underlying alignment issue, but
this unblocks the libc++ refactor in the interim,
while also benefitting the formatter in terms of readability (in my opinion).
---
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  | 172 +-
 1 file changed, 48 insertions(+), 124 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index c2bb3555908bee..093e182df11889 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -18,11 +18,31 @@
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/lldb-forward.h"
+#include 
+#include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
 
+// The flattened layout of the std::__tree_iterator::__ptr_ looks
+// as follows:
+//
+// The following shows the contiguous block of memory:
+//
+//+-+ class __tree_end_node
+// __ptr_ | pointer __left_;|
+//+-+ class __tree_node_base
+//| pointer __right_;   |
+//| __parent_pointer __parent_; |
+//| bool __is_black_;   |
+//+-+ class __tree_node
+//| __node_value_type __value_; | <<< our key/value pair
+//+-+
+//
+// where __ptr_ has type __iter_pointer.
+
 class MapEntry {
 public:
   MapEntry() = default;
@@ -181,10 +201,6 @@ class LibcxxStdMapSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
   size_t GetIndexOfChildWithName(ConstString name) override;
 
 private:
-  bool GetDataType();
-
-  void GetValueOffset(const lldb::ValueObjectSP &node);
-
   /// Returns the ValueObject for the __tree_node type that
   /// holds the key/value pair of the node at index \ref idx.
   ///
@@ -203,8 +219,7 @@ class LibcxxStdMapSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
 
   ValueObject *m_tree = nullptr;
   ValueObject *m_root_node = nullptr;
-  CompilerType m_element_type;
-  uint32_t m_skip_size = UINT32_MAX;
+  CompilerType m_node_ptr_type;
   size_t m_count = UINT32_MAX;
   std::map m_iterators;
 };
@@ -234,7 +249,7 @@ class LibCxxMapIteratorSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
 
 lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
 LibcxxStdMapSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp), m_element_type(), m_iterators() {
+: SyntheticChildrenFrontEnd(*valobj_sp) {
   if (valobj_sp)
 Update();
 }
@@ -260,146 +275,52 @@ llvm::Expected lldb_private::formatters::
   return m_count;
 }
 
-bool lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType() {
-  if (m_element_type.IsValid())
-return true;
-  m_element_type.Clear();
-  ValueObjectSP deref;
-  Status error;
-  deref = m_root_node->Dereference(error);
-  if (!deref || error.Fail())
-return false;
-  deref = deref->GetChildMemberWithName("__value_");
-  if (deref) {
-m_element_type = deref->GetCompilerType();
-return true;
-  }
-  deref = m_backend.GetChildAtNamePath({"__tree_", "__pair3_"});
-  if (!deref)
-return false;
-  m_element_type = deref->GetCompilerType()
-   .GetTypeTemplateArgument(1)
-   .GetTypeTemplateArgument(1);
-  if (m_element_type) {
-std::string name;
-uint64_t bit_offset

[Lldb-commits] [lldb] [llvm] [lldb] [lldb-server] Introduce Host/qnx and NativeProcessQNX (PR #97630)

2024-07-08 Thread Pavel Labath via lldb-commits


@@ -35,6 +39,10 @@
 #include 
 #endif
 
+#if !defined(EOK)

labath wrote:

Everything else just uses zero (`0`) as "no error". I don't see a reason for 
this code to be different.

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


[Lldb-commits] [lldb] [llvm] [lldb] [lldb-server] Introduce Host/qnx and NativeProcessQNX (PR #97630)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

This is only a very light review. I agree with others that an RFC thread is a 
better place to discuss this. After we sort that out, this patch should be 
further subdivided into smaller pieces.

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


[Lldb-commits] [lldb] [llvm] [lldb] [lldb-server] Introduce Host/qnx and NativeProcessQNX (PR #97630)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [llvm] [lldb] [lldb-server] Introduce Host/qnx and NativeProcessQNX (PR #97630)

2024-07-08 Thread Pavel Labath via lldb-commits


@@ -222,6 +232,148 @@ struct ForkLaunchInfo {
 
 // End of code running in the child process.
 
+#if defined(__QNX__)
+static ::pid_t PosixSpawn(const ForkLaunchInfo &info,

labath wrote:

This is basically reimplementing `LaunchProcessPosixSpawn` inside 
`ProcessLauncherPosixFork.cpp`. Instead of shoehorning the `posix_spawn` 
implementation into ProcessLauncherPosix**Fork** (I assume you're doing this 
because your os doesn't support `fork`), it would be better to create a 
separate ProcessLauncher subclass for that. If there are things that can be 
meaningfully shared between the two implementations, they can go into a 
separate base class (but I expect that there's more sharing potential with the 
aforementioned (currently, mac-specific) `LaunchProcessPosixSpawn` 
implementation.

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


[Lldb-commits] [lldb] [llvm] [lldb] [lldb-server] Introduce Host/qnx and NativeProcessQNX (PR #97630)

2024-07-08 Thread Pavel Labath via lldb-commits


@@ -36,10 +38,17 @@ using namespace lldb;
 using namespace lldb_private;
 
 static sig_atomic_t g_signal_flags[NSIG];
+#if defined(__QNX__)
+static llvm::DenseMap g_signal_info;

labath wrote:

This code is definitely not async-signal-safe. However, before you try to fix 
that, I'd like clear up a couple of things:
1. Is this absolutely necessary? I see you're using this to get the PID of the 
process that stopped, but is that the only way to determine that? Could you 
e.g. iterate through the list of processes (you will only likely have one or 
two, so it's not like it will be slow) and query each one? (that's how it's 
done on linux)
2. Is this guaranteed to work all the time? For example, what happens if you're 
debugging two processes and they both stop simultaneously. Does the OS 
guarantee to deliver two signals or can it coalesce them? (technically, I 
believe linux is allowed to do that, which is why this implementation does not 
rely on the contents/number of signals, just their presence. (plus it's also 
convenient to not have to worry about how to capture multiple instances of one 
signal safely)

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


[Lldb-commits] [lldb] [lldb][test] Set target OS for API tests in case of remote testing (PR #96654)

2024-07-08 Thread Vladislav Dzhidzhoev via lldb-commits

https://github.com/dzhidzhoev updated 
https://github.com/llvm/llvm-project/pull/96654

>From be1646f4b41c5dced296a279b448624996c592d0 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Wed, 19 Jun 2024 23:50:18 +
Subject: [PATCH] [lldb][test] Set target and host OS for API tests in case of
 remote testing

Makefile.rules uses HOST_OS and OS variables for determining host and target
OSes for API tests compilation.

This commit starts moving the platform detection logic from Makefile to Python 
lldb
test suite.

When lldb's target is set to remote-linux, Makefile.rules script should be
executed with the target OS variable set to Linux.

This is useful for the case of Windows-to-Linux cross-testing.
---
 .../Python/lldbsuite/test/lldbplatformutil.py | 25 +--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 21f2095db90f8..a9cd8772d514f 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -56,6 +56,10 @@ def target_is_android():
 return configuration.lldb_platform_name == "remote-android"
 
 
+def target_is_remote_linux():
+return configuration.lldb_platform_name == "remote-linux"
+
+
 def android_device_api():
 if not hasattr(android_device_api, "result"):
 assert configuration.lldb_platform_url is not None
@@ -92,11 +96,28 @@ def match_android_device(device_arch, valid_archs=None, 
valid_api_levels=None):
 
 
 def finalize_build_dictionary(dictionary):
+# Provide uname-like platform name
+platform_name_to_uname = { "linux": "Linux",
+"netbsd": "NetBSD",
+"freebsd": "FreeBSD",
+"windows": "Windows_NT",
+}
+
+if dictionary is None:
+dictionary = {}
 if target_is_android():
-if dictionary is None:
-dictionary = {}
 dictionary["OS"] = "Android"
 dictionary["PIE"] = 1
+elif platformIsDarwin():
+dictionary["OS"] = "Darwin"
+else:
+dictionary["OS"] = platform_name_to_uname[getPlatform()]
+
+if platformIsDarwin():
+dictionary["HOST_OS"] = "Darwin"
+else:
+dictionary["HOST_OS"] = platform_name_to_uname[getHostPlatform()]
+
 return dictionary
 
 

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


[Lldb-commits] [lldb] 9dca3ac - [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (#97713)

2024-07-08 Thread via lldb-commits

Author: Michael Buch
Date: 2024-07-08T15:56:05+01:00
New Revision: 9dca3ac2efb180398ef8e84bfa9f0ef283d0e6fd

URL: 
https://github.com/llvm/llvm-project/commit/9dca3ac2efb180398ef8e84bfa9f0ef283d0e6fd
DIFF: 
https://github.com/llvm/llvm-project/commit/9dca3ac2efb180398ef8e84bfa9f0ef283d0e6fd.diff

LOG: [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (#97713)

Depends on https://github.com/llvm/llvm-project/pull/97687

Similar to https://github.com/llvm/llvm-project/pull/97579, this patch
simplifies the way in which we retrieve the key/value pair of a
`std::map` (in this case of the `std::map::iterator`).

We do this for the same reason: not only was the old logic hard to
follow, and encoded the libc++ layout in non-obvious ways, it was also
fragile to alignment miscalculations
(https://github.com/llvm/llvm-project/pull/97443); this would break once
the new layout of std::map landed as part of
https://github.com/llvm/llvm-project/issues/93069.

Instead, this patch simply casts the `__iter_pointer` to the
`__node_pointer` and uses a straightforward
`GetChildMemberWithName("__value_")` to get to the key/value we care
about.

We can eventually re-use the core-part of the `std::map` and
`std::map::iterator` formatters. But it will be an easier to change to
review once both simplifications landed.

Added: 


Modified: 
lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py

Removed: 




diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index 9fcb9e22bfc38..0fe7fe69244ae 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -17,6 +17,7 @@
 #include "lldb/Utility/Endian.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/Stream.h"
+#include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-forward.h"
 
 using namespace lldb;
@@ -223,11 +224,10 @@ class LibCxxMapIteratorSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
 
   size_t GetIndexOfChildWithName(ConstString name) override;
 
-  ~LibCxxMapIteratorSyntheticFrontEnd() override;
+  ~LibCxxMapIteratorSyntheticFrontEnd() override = default;
 
 private:
-  ValueObject *m_pair_ptr;
-  lldb::ValueObjectSP m_pair_sp;
+  ValueObjectSP m_pair_sp = nullptr;
 };
 } // namespace formatters
 } // namespace lldb_private
@@ -464,7 +464,7 @@ 
lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator(
 
 lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
 LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp), m_pair_ptr(), m_pair_sp() {
+: SyntheticChildrenFrontEnd(*valobj_sp) {
   if (valobj_sp)
 Update();
 }
@@ -472,117 +472,63 @@ 
lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::
 lldb::ChildCacheState
 lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEnd::Update() {
   m_pair_sp.reset();
-  m_pair_ptr = nullptr;
 
   ValueObjectSP valobj_sp = m_backend.GetSP();
   if (!valobj_sp)
 return lldb::ChildCacheState::eRefetch;
 
   TargetSP target_sp(valobj_sp->GetTargetSP());
-
   if (!target_sp)
 return lldb::ChildCacheState::eRefetch;
 
-  // this must be a ValueObject* because it is a child of the ValueObject we
-  // are producing children for it if were a ValueObjectSP, we would end up
-  // with a loop (iterator -> synthetic -> child -> parent == iterator) and
-  // that would in turn leak memory by never allowing the ValueObjects to die
-  // and free their memory
-  m_pair_ptr = valobj_sp
-   ->GetValueForExpressionPath(
-   ".__i_.__ptr_->__value_", nullptr, nullptr,
-   ValueObject::GetValueForExpressionPathOptions()
-   .DontCheckDotVsArrowSyntax()
-   .SetSyntheticChildrenTraversal(
-   ValueObject::GetValueForExpressionPathOptions::
-   SyntheticChildrenTraversal::None),
-   nullptr)
-   .get();
-
-  if (!m_pair_ptr) {
-m_pair_ptr = valobj_sp
- ->GetValueForExpressionPath(
- ".__i_.__ptr_", nullptr, nullptr,
- ValueObject::GetValueForExpressionPathOptions()
- .DontCheckDotVsArrowSyntax()
- .SetSyntheticChildrenTraversal(
- 
ValueObject::GetValueForExpressionPathOptions::
- SyntheticChildrenTraversal::None),
- nullptr)
- .get();
-if (m_pair_ptr) {
-  auto __i_(valobj_sp->GetChildMemberWithName("__i_"));
-  if (!__i_) {
-

[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify libc++ std::map::iterator formatter (PR #97713)

2024-07-08 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [lldb] [ObjectFileELF] Detect QNX Neutrino RTOS targets (PR #97439)

2024-07-08 Thread Ayush Sahay via lldb-commits

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


[Lldb-commits] [lldb] [lldb] [Platform] Introduce PlatformQNX (PR #97487)

2024-07-08 Thread Ayush Sahay via lldb-commits

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


[Lldb-commits] [lldb] [lldb] [DynamicLoaderPOSIXDYLD] Enable POSIX-DYLD for QNX (PR #97536)

2024-07-08 Thread Ayush Sahay via lldb-commits

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


[Lldb-commits] [lldb] [llvm] [lldb] [lldb-server] Introduce Host/qnx and NativeProcessQNX (PR #97630)

2024-07-08 Thread Ayush Sahay via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache (PR #98041)

2024-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath created 
https://github.com/llvm/llvm-project/pull/98041

In async mode, the test terminates sooner that it should 
(`run_to_source_breakpoint` does not work in this mode), and then the test 
crashes due to #98038. Most of the time, the test does not fail because its 
already XFAILed, but the crash still registers as a failure.

>From afe79a9ccc3f08eb145ad41f5f690d3f4e1e719e Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 8 Jul 2024 18:08:45 +0200
Subject: [PATCH] [lldb] Put the new debugger in synchronous mode in
 TestGlobalModuleCache

In async mode, the test terminates sooner that it should
(`run_to_source_breakpoint` does not work in this mode), and then the
test crashes due to #98038. Most of the time, the test does not fail
because its already XFAILed, but the crash still registers as a failure.
---
 .../API/python_api/global_module_cache/TestGlobalModuleCache.py  | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 0942dcd655b750..ccefc28946e062 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -111,6 +111,7 @@ def do_test(self, one_target, one_debugger):
 else:
 if one_target:
 new_debugger = lldb.SBDebugger().Create()
+new_debugger.SetAsync(False)
 self.old_debugger = self.dbg
 self.dbg = new_debugger
 

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


[Lldb-commits] [lldb] [lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache (PR #98041)

2024-07-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

In async mode, the test terminates sooner that it should 
(`run_to_source_breakpoint` does not work in this mode), and then the test 
crashes due to #98038. Most of the time, the test does not fail because 
its already XFAILed, but the crash still registers as a failure.

---
Full diff: https://github.com/llvm/llvm-project/pull/98041.diff


1 Files Affected:

- (modified) 
lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py (+1) 


``diff
diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 0942dcd655b75..ccefc28946e06 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -111,6 +111,7 @@ def do_test(self, one_target, one_debugger):
 else:
 if one_target:
 new_debugger = lldb.SBDebugger().Create()
+new_debugger.SetAsync(False)
 self.old_debugger = self.dbg
 self.dbg = new_debugger
 

``




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


[Lldb-commits] [lldb] [lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache (PR #98041)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] fe8933b - [lldb][DataFormatter] Simplify std::map formatter (#97579)

2024-07-08 Thread via lldb-commits

Author: Michael Buch
Date: 2024-07-08T17:19:25+01:00
New Revision: fe8933ba211da094dc866b2bde64928c8121131b

URL: 
https://github.com/llvm/llvm-project/commit/fe8933ba211da094dc866b2bde64928c8121131b
DIFF: 
https://github.com/llvm/llvm-project/commit/fe8933ba211da094dc866b2bde64928c8121131b.diff

LOG: [lldb][DataFormatter] Simplify std::map formatter  (#97579)

Depends on:
* https://github.com/llvm/llvm-project/pull/97544
* https://github.com/llvm/llvm-project/pull/97549
* https://github.com/llvm/llvm-project/pull/97551

This patch tries to simplify the way in which the `std::map` formatter
goes from the root `__tree` pointer to a specific key/value pair.

Previously we would:
1. synthesize a structure that mimicked what `__iter_pointer` looked
like in memory
2. call `GetChildCompilerTypeAtIndex` on it to find the byte offset at
which the pair was located in the synthesized structure
3. finally, use that offset through a call to
`GetSyntheticChildAtOffset` to retrieve the key/value pair

Not only was this logic hard to follow, and encoded the libc++ layout in
non-obvious ways, it was also fragile to alignment miscalculations
(https://github.com/llvm/llvm-project/pull/97443); this would break once
the new layout of std::map landed as part of
https://github.com/https://github.com/llvm/llvm-project/issues/93069.

Instead, this patch simply casts the `__iter_pointer` to the
`__node_pointer` and uses a straightforward
`GetChildMemberWithName("__value_")` to get to the key/value we care
about. This allows us to get rid of some support infrastructure/class
state.

Ideally we would fix the underlying alignment issue, but this unblocks
the libc++ refactor in the interim, while also benefitting the formatter
in terms of readability (in my opinion).

Added: 


Modified: 
lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index 0fe7fe69244ae..5106a63d531f8 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -19,11 +19,31 @@
 #include "lldb/Utility/Stream.h"
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-forward.h"
+#include 
+#include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
 
+// The flattened layout of the std::__tree_iterator::__ptr_ looks
+// as follows:
+//
+// The following shows the contiguous block of memory:
+//
+//+-+ class __tree_end_node
+// __ptr_ | pointer __left_;|
+//+-+ class __tree_node_base
+//| pointer __right_;   |
+//| __parent_pointer __parent_; |
+//| bool __is_black_;   |
+//+-+ class __tree_node
+//| __node_value_type __value_; | <<< our key/value pair
+//+-+
+//
+// where __ptr_ has type __iter_pointer.
+
 class MapEntry {
 public:
   MapEntry() = default;
@@ -182,10 +202,6 @@ class LibcxxStdMapSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
   size_t GetIndexOfChildWithName(ConstString name) override;
 
 private:
-  bool GetDataType();
-
-  void GetValueOffset(const lldb::ValueObjectSP &node);
-
   /// Returns the ValueObject for the __tree_node type that
   /// holds the key/value pair of the node at index \ref idx.
   ///
@@ -204,8 +220,7 @@ class LibcxxStdMapSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
 
   ValueObject *m_tree = nullptr;
   ValueObject *m_root_node = nullptr;
-  CompilerType m_element_type;
-  uint32_t m_skip_size = UINT32_MAX;
+  CompilerType m_node_ptr_type;
   size_t m_count = UINT32_MAX;
   std::map m_iterators;
 };
@@ -234,7 +249,7 @@ class LibCxxMapIteratorSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
 
 lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
 LibcxxStdMapSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-: SyntheticChildrenFrontEnd(*valobj_sp), m_element_type(), m_iterators() {
+: SyntheticChildrenFrontEnd(*valobj_sp) {
   if (valobj_sp)
 Update();
 }
@@ -260,130 +275,44 @@ llvm::Expected lldb_private::formatters::
   return m_count;
 }
 
-bool lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType() {
-  if (m_element_type.IsValid())
-return true;
-  m_element_type.Clear();
-  ValueObjectSP deref;
-  Status error;
-  deref = m_root_node->Dereference(error);
-  if (!deref || error.Fail())
-return false;
-  deref = m_backend.GetChildAtNamePath({"__tree_", "__pair3_"});
-  if (!deref)
-return false;
-  m_element_type = deref->GetCompilerType()
-   .GetTypeTemplateArgument(1)
-   .GetTypeTemplateArgument(1);
-  if (m_element_type) {
-std::string name;
- 

[Lldb-commits] [lldb] [lldb][DataFormatter] Simplify std::map formatter (PR #97579)

2024-07-08 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache (PR #98041)

2024-07-08 Thread Pavel Labath via lldb-commits

labath wrote:

This explains why the `test_OneTargetTwoDebuggers` flavour of the test was 
crashing. It doesn't explain why would the other two versions crash. However 
I'm not sure if the other two flavours are indeed crashing (all of the crashes 
I've seen were in this flavour).

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


[Lldb-commits] [lldb] [lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache (PR #98041)

2024-07-08 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] ed7e468 - [lldb] Improve error message for unrecognized executables (#97490)

2024-07-08 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2024-07-08T09:29:01-07:00
New Revision: ed7e46877dc7f09b5d194f87c87bfc2bebfcf27a

URL: 
https://github.com/llvm/llvm-project/commit/ed7e46877dc7f09b5d194f87c87bfc2bebfcf27a
DIFF: 
https://github.com/llvm/llvm-project/commit/ed7e46877dc7f09b5d194f87c87bfc2bebfcf27a.diff

LOG: [lldb] Improve error message for unrecognized executables (#97490)

Currently, LLDB prints out a rather unhelpful error message when passed
a file that it doesn't recognize as an executable.

> error: '/path/to/file' doesn't contain any 'host' platform
> architectures: arm64, armv7, armv7f, armv7k, armv7s, armv7m, armv7em,
> armv6m, armv6, armv5, armv4, arm, thumbv7, thumbv7k, thumbv7s,
> thumbv7f, thumbv7m, thumbv7em, thumbv6m, thumbv6, thumbv5, thumbv4t,
> thumb, x86_64, x86_64, arm64, arm64e

I did a quick search internally and found at least 24 instances of users
being confused by this. This patch improves the error message when it
doesn't recognize the file as an executable, but keeps the existing
error message otherwise, i.e. when it's an object file we understand,
but the current platform doesn't support.

Added: 


Modified: 
lldb/include/lldb/Symbol/ObjectFile.h
lldb/source/Symbol/ObjectFile.cpp
lldb/source/Target/Platform.cpp
lldb/test/Shell/ObjectFile/PECOFF/invalid-export-table.yaml

Removed: 




diff  --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index 6348d8103f85d..8592323322e38 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -178,6 +178,7 @@ class ObjectFile : public 
std::enable_shared_from_this,
 lldb::offset_t file_offset,
 lldb::offset_t file_size,
 lldb_private::ModuleSpecList &specs);
+  static bool IsObjectFile(lldb_private::FileSpec file_spec);
   /// Split a path into a file path with object name.
   ///
   /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path up into

diff  --git a/lldb/source/Symbol/ObjectFile.cpp 
b/lldb/source/Symbol/ObjectFile.cpp
index d890ad92e8312..2608a9c5fb79a 100644
--- a/lldb/source/Symbol/ObjectFile.cpp
+++ b/lldb/source/Symbol/ObjectFile.cpp
@@ -184,6 +184,15 @@ ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP 
&module_sp,
   return object_file_sp;
 }
 
+bool ObjectFile::IsObjectFile(lldb_private::FileSpec file_spec) {
+  DataBufferSP data_sp;
+  offset_t data_offset = 0;
+  ModuleSP module_sp = std::make_shared(file_spec);
+  return static_cast(ObjectFile::FindPlugin(
+  module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
+  data_sp, data_offset));
+}
+
 size_t ObjectFile::GetModuleSpecifications(const FileSpec &file,
lldb::offset_t file_offset,
lldb::offset_t file_size,

diff  --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index c06abd3070f31..bb90c377d86b2 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -732,7 +732,6 @@ Status
 Platform::ResolveExecutable(const ModuleSpec &module_spec,
 lldb::ModuleSP &exe_module_sp,
 const FileSpecList *module_search_paths_ptr) {
-  Status error;
 
   // We may connect to a process and use the provided executable (Don't use
   // local $PATH).
@@ -741,55 +740,57 @@ Platform::ResolveExecutable(const ModuleSpec &module_spec,
   // Resolve any executable within a bundle on MacOSX
   Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
 
-  if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) ||
-  module_spec.GetUUID().IsValid()) {
-if (resolved_module_spec.GetArchitecture().IsValid() ||
-resolved_module_spec.GetUUID().IsValid()) {
-  error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
-  module_search_paths_ptr, nullptr,
-  nullptr);
+  if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) &&
+  !module_spec.GetUUID().IsValid())
+return Status::createWithFormat("'{0}' does not exist",
+resolved_module_spec.GetFileSpec());
+
+  if (resolved_module_spec.GetArchitecture().IsValid() ||
+  resolved_module_spec.GetUUID().IsValid()) {
+Status error =
+ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
+module_search_paths_ptr, nullptr, nullptr);
 
+if (exe_module_sp && exe_module_sp->GetObjectFile())
+  return error;
+exe_module_sp.reset();
+  }
+  // No valid architecture was specified or the exact arch wasn't found.
+  // Ask the platform for the architectures that

[Lldb-commits] [lldb] [lldb] Improve error message for unrecognized executables (PR #97490)

2024-07-08 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [LLDB] Support exception breakpoints for plugin-provided languages (PR #97675)

2024-07-08 Thread via lldb-commits

jimingham wrote:

> CommandObjectBreakpoint has a harcoded list of languages for which exception 
> breakpoints can be enabled. I'm making this a bit more generic so that my 
> Mojo plugin can get this feature. Basically, I'm adding a new overridable 
> method `Language::SupportsExceptionBreakpoints` that can be used by language 
> plugins to determine whether they support this feature or not. This method is 
> used in addition to the hardcoded list and, as an example, I'm using it for 
> the ObjC language support.
> 
> Another route is simply to avoid doing the check that it's being done right 
> now and simply try to the create the exception breakpoint for whatever 
> language that is not in the hardcoded list. I'm happy to do that if the 
> reviewers think it's a good idea.
> 
> As a note, the other possible place for adding this 
> `SupportsExceptionBreakpoints` method is in `LanguageRuntime`. However, 
> accessing it requires having a process, which is not always the case when 
> invoking the `breakpoint set -E` command. The process might not be alive yet, 
> so `Language` is a good second place for this.
> 

Exception Breakpoints are created by the static method 
LanguageRuntime::CreateExceptionBreakpoint.  So they don't require a process.  
Exception breakpoint resolvers can be "resolver discovering resolvers".  This 
used to be necessary when there were two ObjC runtimes possible on MacOS X, and 
you couldn't necessarily tell which one was going to be used till the program 
till it ran.  So they are able to adjust themselves when their Target launches 
a process.

It's a little awkward to have a static method in LanguageRuntime that makes the 
Exception breakpoint conditioned by a Language method 
'SupportsExceptionBreakpoint".

> And as a final note, I don't want to make this `SupportsExceptionBreakpoints` 
> complicated. I'm keeping it as simple as possible because it can easily 
> evolve as it's not part of the public API.



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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-08 Thread via lldb-commits

jeffreytan81 wrote:

> @jeffreytan81 I think the callout for multiple exception is a good question. 
> I made a C# testbed to see what would happen if I had multiple simultaneous 
> exceptions. [Gist 
> here](https://gist.github.com/Jlalond/467bc990f10fbb75cc9ca7db897a7beb). When 
> manually collecting a minidump on my Windows system and then viewing it, I do 
> get a warning that my application has multiple exceptions.
> 
> ![image](https://private-user-images.githubusercontent.com/25160653/346230140-d7f7f1c2-3de9-40bd-b692-f3f3ef23fd38.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA0NTk4NzIsIm5iZiI6MTcyMDQ1OTU3MiwicGF0aCI6Ii8yNTE2MDY1My8zNDYyMzAxNDAtZDdmN2YxYzItM2RlOS00MGJkLWI2OTItZjNmM2VmMjNmZDM4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA4VDE3MjYxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTViZTBkMGEzMmUyMDgzMDUyYzQyZWZiMzEzNmY2YmU1MzQ2OTU4Y2M5MWE5YWUwNzIxOGQyZTQzMzRjNjFmYmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.0hYRLR8moBxXwtvieDm-QrmHXdH_pxUUt8xLF4HriVE)
> 
> This leads me to believe multiple exceptions is acceptable, albeit rare.

That's good to know, but this is still a indirectly way to check. We would feel 
much convinced if you can copy the minidump generated by lldb to Windows and 
give windbg or Visual Studio a try. 

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


[Lldb-commits] [lldb] [lldb][NFC] Add maybe_unused to err used in asserts (PR #98055)

2024-07-08 Thread Keith Smiley via lldb-commits

https://github.com/keith created https://github.com/llvm/llvm-project/pull/98055

None

>From 6a6fc355e3623a0d0aacc465220a562e103e6dfc Mon Sep 17 00:00:00 2001
From: Keith Smiley 
Date: Mon, 8 Jul 2024 10:28:22 -0700
Subject: [PATCH] [lldb][NFC] Add maybe_unused to err used in asserts

---
 lldb/tools/debugserver/source/PThreadMutex.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lldb/tools/debugserver/source/PThreadMutex.h 
b/lldb/tools/debugserver/source/PThreadMutex.h
index a4535dd79172c..17f9fdff5f2d3 100644
--- a/lldb/tools/debugserver/source/PThreadMutex.h
+++ b/lldb/tools/debugserver/source/PThreadMutex.h
@@ -78,13 +78,13 @@ class PThreadMutex {
   };
 
   PThreadMutex() {
-int err;
+[[maybe_unused]] int err;
 err = ::pthread_mutex_init(&m_mutex, NULL);
 assert(err == 0);
   }
 
   PThreadMutex(int type) {
-int err;
+[[maybe_unused]] int err;
 ::pthread_mutexattr_t attr;
 err = ::pthread_mutexattr_init(&attr);
 assert(err == 0);
@@ -97,7 +97,7 @@ class PThreadMutex {
   }
 
   ~PThreadMutex() {
-int err;
+[[maybe_unused]] int err;
 err = ::pthread_mutex_destroy(&m_mutex);
 if (err != 0) {
   err = Unlock();

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


[Lldb-commits] [lldb] [lldb][NFC] Add maybe_unused to err used in asserts (PR #98055)

2024-07-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Keith Smiley (keith)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/98055.diff


1 Files Affected:

- (modified) lldb/tools/debugserver/source/PThreadMutex.h (+3-3) 


``diff
diff --git a/lldb/tools/debugserver/source/PThreadMutex.h 
b/lldb/tools/debugserver/source/PThreadMutex.h
index a4535dd79172c2..17f9fdff5f2d3a 100644
--- a/lldb/tools/debugserver/source/PThreadMutex.h
+++ b/lldb/tools/debugserver/source/PThreadMutex.h
@@ -78,13 +78,13 @@ class PThreadMutex {
   };
 
   PThreadMutex() {
-int err;
+[[maybe_unused]] int err;
 err = ::pthread_mutex_init(&m_mutex, NULL);
 assert(err == 0);
   }
 
   PThreadMutex(int type) {
-int err;
+[[maybe_unused]] int err;
 ::pthread_mutexattr_t attr;
 err = ::pthread_mutexattr_init(&attr);
 assert(err == 0);
@@ -97,7 +97,7 @@ class PThreadMutex {
   }
 
   ~PThreadMutex() {
-int err;
+[[maybe_unused]] int err;
 err = ::pthread_mutex_destroy(&m_mutex);
 if (err != 0) {
   err = Unlock();

``




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


[Lldb-commits] [lldb] [lldb][NFC] Add maybe_unused to err used in asserts (PR #98055)

2024-07-08 Thread Joe Loser via lldb-commits

https://github.com/JoeLoser approved this pull request.


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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-08 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond updated 
https://github.com/llvm/llvm-project/pull/97470

>From dc4730dcff31c2c9212d2ce5412ecb8a9f4d83c0 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 2 Jul 2024 12:41:02 -0700
Subject: [PATCH 1/6] Add support to read multiple exception streams in
 minidumps

---
 .../Process/minidump/MinidumpParser.cpp   |  11 +-
 .../Plugins/Process/minidump/MinidumpParser.h |   2 +-
 .../Process/minidump/ProcessMinidump.cpp  | 122 ++
 .../Process/minidump/ProcessMinidump.h|   2 +-
 .../Process/minidump/ThreadMinidump.cpp   |  14 +-
 .../Plugins/Process/minidump/ThreadMinidump.h |   3 +-
 .../Process/minidump/MinidumpParserTest.cpp   |  11 +-
 llvm/include/llvm/Object/Minidump.h   |  34 -
 llvm/lib/Object/Minidump.cpp  |  37 ++
 llvm/lib/ObjectYAML/MinidumpYAML.cpp  |   4 +-
 10 files changed, 162 insertions(+), 78 deletions(-)

diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index be9fae938e227..ac487a5ed0c0a 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -408,7 +408,7 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
 continue;
   }
   // This module has been seen. Modules are sometimes mentioned multiple
-  // times when they are mapped discontiguously, so find the module with
+  // times when they are mapped discontiguously, so find the module with 
   // the lowest "base_of_image" and use that as the filtered module.
   if (module.BaseOfImage < dup_module->BaseOfImage)
 filtered_modules[iter->second] = &module;
@@ -417,14 +417,15 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
   return filtered_modules;
 }
 
-const minidump::ExceptionStream *MinidumpParser::GetExceptionStream() {
-  auto ExpectedStream = GetMinidumpFile().getExceptionStream();
+const std::vector 
MinidumpParser::GetExceptionStreams() {
+  auto ExpectedStream = GetMinidumpFile().getExceptionStreams();
   if (ExpectedStream)
-return &*ExpectedStream;
+return ExpectedStream.get();
 
   LLDB_LOG_ERROR(GetLog(LLDBLog::Process), ExpectedStream.takeError(),
  "Failed to read minidump exception stream: {0}");
-  return nullptr;
+  // return empty on failure.
+  return std::vector();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.h 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
index 050ba086f46f5..e552c7210e330 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -82,7 +82,7 @@ class MinidumpParser {
   // have the same name, it keeps the copy with the lowest load address.
   std::vector GetFilteredModuleList();
 
-  const llvm::minidump::ExceptionStream *GetExceptionStream();
+  const std::vector GetExceptionStreams();
 
   std::optional FindMemoryRange(lldb::addr_t addr);
 
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp 
b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 13599f4a1553f..9f707c0d8a7a7 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
@@ -157,7 +158,7 @@ ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp,
  const FileSpec &core_file,
  DataBufferSP core_data)
 : PostMortemProcess(target_sp, listener_sp, core_file),
-  m_core_data(std::move(core_data)), m_active_exception(nullptr),
+  m_core_data(std::move(core_data)),
   m_is_wow64(false) {}
 
 ProcessMinidump::~ProcessMinidump() {
@@ -209,7 +210,19 @@ Status ProcessMinidump::DoLoadCore() {
   GetTarget().SetArchitecture(arch, true /*set_platform*/);
 
   m_thread_list = m_minidump_parser->GetThreads();
-  m_active_exception = m_minidump_parser->GetExceptionStream();
+  std::vector exception_streams = 
m_minidump_parser->GetExceptionStreams();
+  for (const auto &exception_stream : exception_streams) {
+if (m_exceptions_by_tid.count(exception_stream.ThreadId) > 0) {
+  // We only cast to avoid the warning around converting little endian in 
printf.
+  error.SetErrorStringWithFormat("duplicate exception stream for tid %" 
PRIu32, (uint32_t)exception_stream.ThreadId);
+  return error;
+} else 
+  m_exceptions_by_tid[exception_stream.ThreadId] = exception_stream;
+
+
+std::cout << "Adding Exception Stream # " << 
(uint32_t)exception_stream.ThreadId << std::endl;
+std::cout << "Added index " << 
(uint32_t)m_exceptions_by_tid[exception_stream.ThreadId].ExceptionRecord.ExceptionCode
 << std::endl;
+  }
 
   SetUnixSignals(UnixSignals::Create(GetArchitecture()));
 
@@ -232,60 

[Lldb-commits] [lldb] [LLDB] DebugInfoD tests: attempt to fix Fuchsia build (PR #96802)

2024-07-08 Thread Kevin Frei via lldb-commits

kevinfrei wrote:

Friendly ping @JDevlieghere 

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


[Lldb-commits] [lldb] [llvm] [lldb] [lldb-server] Introduce Host/qnx and NativeProcessQNX (PR #97630)

2024-07-08 Thread Ayush Sahay via lldb-commits

ayushsahay1837 wrote:

> This is only a very light review. I agree with others that an RFC thread is a 
> better place to discuss this. After we sort that out, this patch should be 
> further subdivided into smaller pieces.

Thanks, @labath! I'll look into these and get back to you at the earliest.

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


[Lldb-commits] [clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-08 Thread Justin Bogner via lldb-commits


@@ -115,6 +116,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
 
 } // namespace
 
+llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
+  assert(T->isHLSLSpecificType() && "Not an HLSL specific type!");
+
+  // Check if the target has a specific translation for this type first.
+  if (llvm::Type *TargetTy = CGM.getTargetCodeGenInfo().getHLSLType(CGM, T))
+return TargetTy;
+
+  // TODO: What do we actually want to do generically here? OpenCL uses a
+  // pointer in a particular address space.
+  llvm_unreachable("Generic handling of HLSL types is not implemented yet");

bogner wrote:

For DirectX and SPIR-V we'll implement `getHLSLType` and this should really be 
unreachable, but we may want to do something generic in the future if/when we 
want to generate code for GPU or CPU targets directly generically. Something 
like the OpenCL approach mentioned in the comment might make sense in that case.

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


[Lldb-commits] [lldb] [lldb][NFC] Add maybe_unused to err used in asserts (PR #98055)

2024-07-08 Thread Jason Molenda via lldb-commits

https://github.com/jasonmolenda approved this pull request.

LGTM.

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


[Lldb-commits] [lldb] [LLDB] DebugInfoD tests: attempt to fix Fuchsia build (PR #96802)

2024-07-08 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere approved this pull request.


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


[Lldb-commits] [lldb] [lldb-dap] Support throw and catch exception breakpoints for dynamica… (PR #97871)

2024-07-08 Thread Alex Langford via lldb-commits


@@ -58,10 +58,17 @@ DAP::DAP()
 
 DAP::~DAP() = default;
 
+/// Return string with first character capitalized.
+static std::string capitalize(llvm::StringRef str) {
+  if (str.empty())
+return "";
+  return ((llvm::Twine)llvm::toUpper(str[0]) + str.drop_front()).str();
+}
+
 void DAP::PopulateExceptionBreakpoints() {
   llvm::call_once(init_exception_breakpoints_flag, [this]() {
 exception_breakpoints = std::vector {};
-
+

bulbazord wrote:

Unrelated whitespace change

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


[Lldb-commits] [lldb] [lldb-dap] Support throw and catch exception breakpoints for dynamica… (PR #97871)

2024-07-08 Thread Alex Langford via lldb-commits


@@ -26,3 +26,43 @@ SBLanguageRuntime::GetNameForLanguageType(lldb::LanguageType 
language) {
 
   return Language::GetNameForLanguageType(language);
 }
+
+bool SBLanguageRuntime::LanguageIsCPlusPlus(lldb::LanguageType language) {
+  return Language::LanguageIsCPlusPlus(language);
+}
+
+bool SBLanguageRuntime::LanguageIsObjC(lldb::LanguageType language) {
+  return Language::LanguageIsObjC(language);
+}
+
+bool SBLanguageRuntime::LanguageIsCFamily(lldb::LanguageType language) {
+  return Language::LanguageIsCFamily(language);
+}
+
+bool SBLanguageRuntime::SupportsExceptionBreakpointsOnThrow(
+lldb::LanguageType language) {
+  if (Language *lang_plugin = Language::FindPlugin(language))
+return lang_plugin->SupportsExceptionBreakpointsOnThrow();
+  return false;
+}
+
+bool SBLanguageRuntime::SupportsExceptionBreakpointsOnCatch(
+lldb::LanguageType language) {
+  if (Language *lang_plugin = Language::FindPlugin(language))
+return lang_plugin->SupportsExceptionBreakpointsOnCatch();
+  return false;
+}
+
+const char *
+SBLanguageRuntime::GetThrowKeywordForLanguage(lldb::LanguageType language) {
+  if (Language *lang_plugin = Language::FindPlugin(language))
+return lang_plugin->GetThrowKeyword().data();

bulbazord wrote:

You should wrap these in `ConstString`. It is not safe in general for LLDB to 
pass out `const char *` values that are derived from `llvm::StringRef`. I know 
that `GetThrowKeyword` and `GetCatchKeyword` are passing out static c-strings 
wrapped in a `llvm::StringRef`, but those are virtual and plugins may not do 
the same.

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


[Lldb-commits] [lldb] [lldb-dap] Support throw and catch exception breakpoints for dynamica… (PR #97871)

2024-07-08 Thread Alex Langford via lldb-commits


@@ -80,6 +87,46 @@ void DAP::PopulateExceptionBreakpoints() {
   exception_breakpoints->emplace_back("swift_throw", "Swift Throw",
   lldb::eLanguageTypeSwift);
 }
+// Besides handling the hardcoded list of languages from above, we try to
+// find any other languages that support exception breakpoints using the
+// SB API.
+for (int raw_lang = lldb::eLanguageTypeUnknown;
+ raw_lang < lldb::eNumLanguageTypes; ++raw_lang) {
+  lldb::LanguageType lang = static_cast(raw_lang);
+
+  // We first discard any languages already handled above.
+  if (lldb::SBLanguageRuntime::LanguageIsCFamily(lang) ||
+  lang == lldb::eLanguageTypeSwift)
+continue;
+
+  if (!lldb::SBDebugger::SupportsLanguage(lang))
+continue;
+
+  const char *name = lldb::SBLanguageRuntime::GetNameForLanguageType(lang);
+  if (!name)
+continue;
+  std::string raw_lang_name = name;
+  std::string capitalized_lang_name = capitalize(name);
+  const char *raw_throw_keyword =
+  lldb::SBLanguageRuntime::GetThrowKeywordForLanguage(lang);
+  const char *raw_catch_keyword =
+  lldb::SBLanguageRuntime::GetCatchKeywordForLanguage(lang);
+  std::string throw_keyword =
+  raw_throw_keyword ? raw_throw_keyword : "throw";
+  std::string catch_keyword =
+  raw_catch_keyword ? raw_catch_keyword : "catch";
+
+  if (lldb::SBLanguageRuntime::SupportsExceptionBreakpointsOnThrow(lang)) {
+exception_breakpoints->emplace_back(
+raw_lang_name + "_" + throw_keyword,
+capitalized_lang_name + " " + capitalize(throw_keyword), lang);
+  }

bulbazord wrote:

nit: [single-statement if 
](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements)

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


[Lldb-commits] [lldb] [lldb-dap] Support throw and catch exception breakpoints for dynamica… (PR #97871)

2024-07-08 Thread Alex Langford via lldb-commits


@@ -80,6 +87,46 @@ void DAP::PopulateExceptionBreakpoints() {
   exception_breakpoints->emplace_back("swift_throw", "Swift Throw",
   lldb::eLanguageTypeSwift);
 }
+// Besides handling the hardcoded list of languages from above, we try to
+// find any other languages that support exception breakpoints using the
+// SB API.
+for (int raw_lang = lldb::eLanguageTypeUnknown;
+ raw_lang < lldb::eNumLanguageTypes; ++raw_lang) {
+  lldb::LanguageType lang = static_cast(raw_lang);
+
+  // We first discard any languages already handled above.
+  if (lldb::SBLanguageRuntime::LanguageIsCFamily(lang) ||
+  lang == lldb::eLanguageTypeSwift)
+continue;
+
+  if (!lldb::SBDebugger::SupportsLanguage(lang))
+continue;
+
+  const char *name = lldb::SBLanguageRuntime::GetNameForLanguageType(lang);
+  if (!name)
+continue;
+  std::string raw_lang_name = name;
+  std::string capitalized_lang_name = capitalize(name);
+  const char *raw_throw_keyword =
+  lldb::SBLanguageRuntime::GetThrowKeywordForLanguage(lang);
+  const char *raw_catch_keyword =
+  lldb::SBLanguageRuntime::GetCatchKeywordForLanguage(lang);
+  std::string throw_keyword =
+  raw_throw_keyword ? raw_throw_keyword : "throw";
+  std::string catch_keyword =
+  raw_catch_keyword ? raw_catch_keyword : "catch";
+
+  if (lldb::SBLanguageRuntime::SupportsExceptionBreakpointsOnThrow(lang)) {
+exception_breakpoints->emplace_back(
+raw_lang_name + "_" + throw_keyword,
+capitalized_lang_name + " " + capitalize(throw_keyword), lang);
+  }
+  if (lldb::SBLanguageRuntime::SupportsExceptionBreakpointsOnCatch(lang)) {
+exception_breakpoints->emplace_back(
+raw_lang_name + "_" + catch_keyword,
+capitalized_lang_name + " " + capitalize(catch_keyword), lang);
+  }

bulbazord wrote:

same as above

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


[Lldb-commits] [lldb] [lldb] Fix string truncation method when substring is the prefix of string (NFC) (PR #94785)

2024-07-08 Thread Alex Langford via lldb-commits


@@ -287,7 +287,7 @@ Status PlatformAndroid::DownloadModuleSlice(const FileSpec 
&src_file_spec,
   static constexpr llvm::StringLiteral k_zip_separator("!/");
   size_t pos = source_file.find(k_zip_separator);
   if (pos != std::string::npos)
-source_file = source_file.substr(0, pos);
+source_file = source_file.resize(0, pos);

bulbazord wrote:

This still isn't resolved, you're still doing `source_file = 
source_file.resize(pos)`. It doesn't return a value.

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


[Lldb-commits] [lldb] [lldb] Fix string truncation method when substring is the prefix of string (NFC) (PR #94785)

2024-07-08 Thread Alex Langford via lldb-commits

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


[Lldb-commits] [lldb] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-07-08 Thread via lldb-commits

jeffreytan81 wrote:

@jimingham, thanks for the comment.

When I try to add a new testcase for stepping over a function with a user set 
breakpoint, there is a bug found -- the user set breakpoint did not stop with 
`ThreadPlanSingleThreadTimeout` present (which is `c` case in your RFC comment)

I did some investigation, when we issue normal step-over, the all thread plans 
in the stack return false for `PlanExplainsStop`, so base thread plan got a 
chance to check thread's stop info and stop the execution. 

However, while doing single thread stepping, `ThreadPlanSingleThreadTimeout` as 
leaf plan always return true for `PlanExplainsStop`, causing the logic to use 
the second while loop in `Thread::ShouldStop()`, eventually, 
`ThreadPlanStepOut::MischiefManaged()` returns false causing the loop to 
terminate early without giving base thread plan to decide should stop or not:
https://github.com/llvm/llvm-project/blob/393eff4e02e7ab3d234d246a8d6912c8e745e6f9/lldb/source/Target/Thread.cpp#L905-L907

So overall the `Thread::ShouldStop()` returns false and ignores the hit inner 
breakpoint during stepping. Any suggestion how to fix this? 



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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-08 Thread Jacob Lalonde via lldb-commits

Jlalond wrote:

> > @jeffreytan81 I think the callout for multiple exception is a good 
> > question. I made a C# testbed to see what would happen if I had multiple 
> > simultaneous exceptions. [Gist 
> > here](https://gist.github.com/Jlalond/467bc990f10fbb75cc9ca7db897a7beb). 
> > When manually collecting a minidump on my Windows system and then viewing 
> > it, I do get a warning that my application has multiple exceptions.
> > ![image](https://private-user-images.githubusercontent.com/25160653/346230140-d7f7f1c2-3de9-40bd-b692-f3f3ef23fd38.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA0NTk4NzIsIm5iZiI6MTcyMDQ1OTU3MiwicGF0aCI6Ii8yNTE2MDY1My8zNDYyMzAxNDAtZDdmN2YxYzItM2RlOS00MGJkLWI2OTItZjNmM2VmMjNmZDM4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA4VDE3MjYxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTViZTBkMGEzMmUyMDgzMDUyYzQyZWZiMzEzNmY2YmU1MzQ2OTU4Y2M5MWE5YWUwNzIxOGQyZTQzMzRjNjFmYmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.0hYRLR8moBxXwtvieDm-QrmHXdH_pxUUt8xLF4HriVE)
> > This leads me to believe multiple exceptions is acceptable, albeit rare.
> 
> That's good to know, but this is still an indirectly way to check. We would 
> feel much convinced if you can copy the minidump generated by lldb to Windows 
> and give windbg or Visual Studio a try.

Okay, I took the same program and then collected a dump with LLDB. As this was 
.net, we have an issue not collecting information about private core lib or the 
windows OS version, so Visual studio does encounter some issue. However I can 
still enter managed debug and see the exception objects on every thread.

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


[Lldb-commits] [lldb] [LLDB] Support exception breakpoints for plugin-provided languages (PR #97675)

2024-07-08 Thread Walter Erquinigo via lldb-commits

walter-erquinigo wrote:

> Exception Breakpoints are created by the static method 
> LanguageRuntime::CreateExceptionBreakpoint. So they don't require a process. 

Indeed, but let me elaborate. What I need is a method that doesn't require a 
process that could tell me if a certain language can support exception 
breakpoints, as that's what the checks in the `breakpoint set -E ` 
command try to do.

Then I had two main choices w.r.t `LanguageRuntime`:
- Add the method as non-static `LanguageRuntime`, but `LanguageRuntime` 
instances do require a process.
- Add a static method in `LanguageRuntime`, like `CreateExceptionBreakpoint`, 
but it turns out that `CreateExceptionBreakpoint` ends up relying on 
`Language::GetDefaultExceptionResolverDescription` and 
`Language::GetExceptionResolverDescription`. So this made me believe that it'd 
be better to place all the static exception feature bits in `Language` and not 
`LanguageRuntime`. `LanguageRuntime` seems to be a place more suited for 
dealing with runtime behaviors and not static pieces of information.

> It's a little awkward to have a static method in LanguageRuntime that makes 
> the Exception breakpoint conditioned by a Language method 
> 'SupportsExceptionBreakpoint".

I somewhat agree with it, but probably I'd end up writing a static method 
`LanguageRuntime::SupportsExceptionBreakpoint` that invokes a non-static 
`Language::SupportsExceptionBreakpoint`. And as I mentioned, there's already 
precedent for other exception related stuff in `Language`.

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


[Lldb-commits] [lldb] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-07-08 Thread via lldb-commits

jimingham wrote:



> On Jul 8, 2024, at 12:55 PM, jeffreytan81 ***@***.***> wrote:
> 
> 
> @jimingham , thanks for the comment.
> 
> When I try to add a new testcase for stepping over a function with a user set 
> breakpoint, there is a bug found -- the user set breakpoint did not stop with 
> ThreadPlanSingleThreadTimeout present (which is c case in your RFC comment)
> 
> I did some investigation, when we issue normal step-over, the all thread 
> plans in the stack return false for PlanExplainsStop, so base thread plan got 
> a chance to check thread's stop info and stop the execution.
> 
> However, while doing single thread stepping, ThreadPlanSingleThreadTimeout as 
> leaf plan always return true for PlanExplainsStop, causing the logic to use 
> the second while loop in Thread::ShouldStop(), eventually, 
> ThreadPlanStepOut::MischiefManaged() returns false causing the loop to 
> terminate early without giving base thread plan to decide should stop or not:
> https://github.com/llvm/llvm-project/blob/393eff4e02e7ab3d234d246a8d6912c8e745e6f9/lldb/source/Target/Thread.cpp#L905-L907
> 
> So overall the Thread::ShouldStop() returns false and ignores the hit inner 
> breakpoint during stepping. Any suggestion how to fix this?
> 

Why does the ThreadPlanSingleThreadTimeout have to claim to explain stops (like 
a random breakpoint hit) that on the face of it it's not responsible for?  What 
would happen if it just didn't explain this breakpoint, and instead uses 
marking itself as stale when a user stop like this comes in to make sure it 
will get popped.

I don't remember anymore why I had to do this as a two-pass thing, making the 
first plan that explains the stop privileged.  That's an odd asymmetry, and it 
seems like going back to the "explains stop" loop after processing a previous 
"I explain the stop" plan will fix this issue.  But it will probably require a 
bunch of fiddling to get right again (and maybe discovering why I did it this 
way in the first place)...  So that should be a later resort.

Jim


> —
> Reply to this email directly, view it on GitHub 
> , or 
> unsubscribe 
> .
> You are receiving this because you were mentioned.
> 



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


  1   2   >