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

2024-06-28 Thread Pavel Labath via lldb-commits

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

This should be fine, although looking at the test case again, I think that even 
simply replacing `process.GetThreadAtIndex(0)` with `self.thread()` should be 
enough. `self.thread()` returns the "selected" thread and lldb should always be 
selecting the thread which has stopped "for a reason" (e.g. a breakpoint) and 
not a random (or first) thread in the process.

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] Add test-cases for packed/aligned structures (PR #96932)

2024-06-28 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] Add test-cases for packed/aligned structures (PR #96932)

2024-06-28 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,36 @@
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "b main" \

labath wrote:

same here

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


[Lldb-commits] [lldb] [lldb][test] Add test-cases for packed/aligned structures (PR #96932)

2024-06-28 Thread Pavel Labath via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb][test] Add test-cases for packed/aligned structures (PR #96932)

2024-06-28 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,25 @@
+// XFAIL: *
+
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "b main" \

labath wrote:

It looks like you're not actually running the binary. Do you need the 
breakpoint?

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


[Lldb-commits] [lldb] 918057c - [lldb/DWARF] Don't start class definitions in ParseStructureLikeDIE (#96755)

2024-06-28 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-06-28T09:41:48+02:00
New Revision: 918057c43aed90583eed5fe14450b2d75366b662

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

LOG: [lldb/DWARF] Don't start class definitions in ParseStructureLikeDIE 
(#96755)

Right now, ParseStructureLikeDIE begins the class definition (which
amounts to parsing the opening "{" of a class and promising to be able
to fill it in later) if it finds a definition DIE.

This makes sense in the current setup, where we eagerly search for the
definition die (so that we will either find it in the beginning or don't
find it at all), but with delayed definition searching (#92328), this
created an (in my view, undesirable) inconsistency, where the final
state of the type (whether it has begun its definition) depended on
whether we happened to start out with a definition DIE or not.

This patch attempts to pre-emptively rectify that by establishing a new
invariant: the definition is never started eagerly. It can only be
started in one of two ways:
- we're completing the type, in which case we will start the definition,
parse everything and immediately finish it
- we need to parse a member (typedef, nested class, method) of the class
without needing the definition itself. In this case, we just start the
definition to insert the member we need.

Besides the delayed definition search, I believe this setup has a couple
of other benefits:
- It treats ObjC and C++ classes the same way (we were never starting
the definition of those)
- unifies the handling of types that types that have a definition and
those that do. When adding (e.g.) a nested class we would previously be
going down a different code path depending on whether we've found a
definition DIE for that type. Now, we're always taking the
definition-not-found path (*)
- it reduces the amount of time a class spends in the funny "definition
started". Aside from the addition of stray addition of nested classes,
we always finish the definition right after we start it.

(*) Herein lies a danger, where if we're missing some calls to
PrepareContextToReceiveMembers, we could trigger a crash when
trying to add a member to the not-yet-started-to-be-defined classes.
However, this is something that could happen before as well (if we
did not have a definition for the class), and is something that
would be exacerbated by #92328 (because it could happen even if we
the definition exists, but we haven't found it yet). This way, it
will at least happen consistently, and the fix should consist of
adding a PrepareContextToReceiveMembers in the appropriate place.

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index c4a3b432ba949..8e297141f4e13 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -237,20 +237,10 @@ TypeSP 
DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc,
   return type_sp;
 }
 
-static void ForcefullyCompleteType(CompilerType type) {
-  bool started = TypeSystemClang::StartTagDeclarationDefinition(type);
-  lldbassert(started && "Unable to start a class type definition.");
-  TypeSystemClang::CompleteTagDeclarationDefinition(type);
-  const clang::TagDecl *td = ClangUtil::GetAsTagDecl(type);
-  auto ts_sp = type.GetTypeSystem();
-  auto ts = ts_sp.dyn_cast_or_null();
-  if (ts)
-ts->SetDeclIsForcefullyCompleted(td);
-}
-
-/// This function serves a similar purpose as RequireCompleteType above, but it
-/// avoids completing the type if it is not immediately necessary. It only
-/// ensures we _can_ complete the type later.
+/// This function ensures we are able to add members (nested types, functions,
+/// etc.) to this type. It does so by starting its definition even if one 
cannot
+/// be found in the debug info. This means the type may need to be "forcibly
+/// completed" later -- see CompleteTypeFromDWARF).
 static void PrepareContextToReceiveMembers(TypeSystemClang &ast,
ClangASTImporter &ast_importer,
clang::DeclContext *decl_ctx,
@@ -260,14 +250,12 @@ static void 
PrepareContextToReceiveMembers(TypeSystemClang &ast,
   if (!tag_decl_ctx)
 return; // Non-tag context are always ready.
 
-  // We have already completed the type, or we have found its definition and 
are
-  // ready to complete it later (cf. ParseStructureLikeDIE).
+  // We have already completed the type or it is already prepared.
   if (tag_decl_ctx->isCompleteDefinition() || tag_decl_ctx

[Lldb-commits] [lldb] [lldb/DWARF] Don't start class definitions in ParseStructureLikeDIE (PR #96755)

2024-06-28 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] Add test-cases for packed/aligned structures (PR #96932)

2024-06-28 Thread Michael Buch via lldb-commits

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

>From d2c28706769f89bf9f0b53071726bb59c6205ce8 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 27 Jun 2024 17:16:50 +0100
Subject: [PATCH 1/2] [lldb][test] Add test-cases for packed structures

Adds test that checks whether LLDB correctly infers the
alignment of packed structures. Specifically, the
`InferAlignment` code-path of the `ItaniumRecordLayoutBuilder`
where it assumes that overlapping field offsets imply a
packed structure and thus sets alignment to `1`. See discussion
in https://github.com/llvm/llvm-project/pull/93809.

While here, also added a test-case where we check alignment of
a class whose base has an explicit `DW_AT_alignment
(those don't get transitively propagated in DWARF, but don't seem
like a problem for LLDB).

Lastly, also added an XFAIL-ed tests where the aforementioned
`InferAlignment` kicks in for overlapping fields (but in this
case incorrectly since the structure isn't actually packed).
---
 .../TestAlignAsBaseClass.py   |  1 +
 .../API/lang/cpp/alignas_base_class/main.cpp  |  7 
 .../DWARF/no_unique_address-alignment.cpp | 25 +
 lldb/test/Shell/SymbolFile/DWARF/packed.cpp   | 36 +++
 4 files changed, 69 insertions(+)
 create mode 100644 
lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp
 create mode 100644 lldb/test/Shell/SymbolFile/DWARF/packed.cpp

diff --git a/lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py 
b/lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
index 7d97b0c42b7e1..362fc2740bf52 100644
--- a/lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
+++ b/lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
@@ -16,3 +16,4 @@ def test(self):
 # Verify specified class alignments.
 self.expect_expr("alignof(B2)", result_value="8")
 self.expect_expr("alignof(EmptyClassAlign8)", result_value="8")
+self.expect_expr("alignof(Derived)", result_value="8")
diff --git a/lldb/test/API/lang/cpp/alignas_base_class/main.cpp 
b/lldb/test/API/lang/cpp/alignas_base_class/main.cpp
index 9d37554957ba3..a37919deaebdc 100644
--- a/lldb/test/API/lang/cpp/alignas_base_class/main.cpp
+++ b/lldb/test/API/lang/cpp/alignas_base_class/main.cpp
@@ -13,4 +13,11 @@ D d3g;
 struct alignas(8) EmptyClassAlign8 {
 } t;
 
+struct alignas(8) __attribute__((packed)) AlignedAndPackedBase {
+} foo;
+
+struct Derived : AlignedAndPackedBase {
+} bar;
+static_assert(alignof(Derived) == 8);
+
 int main() {}
diff --git a/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp
new file mode 100644
index 0..6e544f40625df
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp
@@ -0,0 +1,25 @@
+// XFAIL: *
+
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "b main" \
+// RUN:   -o "expr alignof(OverlappingFields)" \
+// RUN:   -o "expr sizeof(OverlappingFields)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(OverlappingFields)
+// CHECK-NEXT: ${{.*}} = 4
+// CHECK:  (lldb) expr sizeof(OverlappingFields)
+// CHECK-NEXT: ${{.*}} = 8
+
+struct Empty {};
+
+struct OverlappingFields {
+  char y;
+  [[no_unique_address]] Empty e;
+  int z;
+} g_packed_struct;
+static_assert(alignof(OverlappingFields) == 4);
+static_assert(sizeof(OverlappingFields) == 8);
+
+int main() {}
diff --git a/lldb/test/Shell/SymbolFile/DWARF/packed.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
new file mode 100644
index 0..fb94a834d48a6
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
@@ -0,0 +1,36 @@
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "b main" \
+// RUN:   -o "expr alignof(packed)" \
+// RUN:   -o "expr sizeof(packed)" \
+// RUN:   -o "expr alignof(packed_and_aligned)" \
+// RUN:   -o "expr sizeof(packed_and_aligned)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(packed)
+// CHECK-NEXT: ${{.*}} = 1
+// CHECK:  (lldb) expr sizeof(packed)
+// CHECK-NEXT: ${{.*}} = 9
+
+// CHECK:  (lldb) expr alignof(packed_and_aligned)
+// CHECK-NEXT: ${{.*}} = 16
+// CHECK:  (lldb) expr sizeof(packed_and_aligned)
+// CHECK-NEXT: ${{.*}} = 16
+
+struct __attribute__((packed)) packed {
+  int x;
+  char y;
+  int z;
+} g_packed_struct;
+static_assert(alignof(packed) == 1);
+static_assert(sizeof(packed) == 9);
+
+struct __attribute__((packed, aligned(16))) packed_and_aligned {
+  int x;
+  char y;
+  int z;
+} g_packed_and_aligned_struct;
+static_assert(alignof(packed_and_aligned) == 16);
+static_assert(sizeof(packed_and_aligned) == 16);
+
+int main() {}

>From a7b91858c8f9e09b455a581469155152f2dea11e Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 28 Jun 2024 09:08:20 +0100
Subject: [PATCH 2/2] fixup! don't set redundant bre

[Lldb-commits] [lldb] [lldb][test] Add test-cases for packed/aligned structures (PR #96932)

2024-06-28 Thread Michael Buch via lldb-commits


@@ -0,0 +1,25 @@
+// XFAIL: *
+
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "b main" \

Michael137 wrote:

good catch, removed

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


[Lldb-commits] [lldb] [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (PR #96985)

2024-06-28 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/96985

>From 5636039087cccad8cddcb2ea48d048a669c80ed7 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Thu, 27 Jun 2024 16:30:58 -0700
Subject: [PATCH 1/2] [lldb/Interpreter] Discard
 ScriptedThreadPlan::GetStopDescription return value

This patch changes `ScriptedThreadPlan::GetStopDescription` behaviour by
discarding its return value since it is optional in the first place
(i.e. the user doesn't need to provide a return value in their implementation).

This patch also re-enables the tests that were XFAIL'd previously.

Signed-off-by: Med Ismail Bennani 
---
 .../Interpreter/Interfaces/ScriptedThreadPlanInterface.h| 4 ++--
 .../Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp | 4 ++--
 .../Python/Interfaces/ScriptedThreadPlanPythonInterface.h   | 2 +-
 lldb/source/Target/ThreadPlanPython.cpp | 6 +++---
 .../API/functionalities/step_scripted/TestStepScripted.py   | 5 +
 5 files changed, 9 insertions(+), 12 deletions(-)

diff --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
index 9130f9412cb0b..0f832b3b2029f 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
@@ -29,8 +29,8 @@ class ScriptedThreadPlanInterface : public ScriptedInterface {
 
   virtual lldb::StateType GetRunState() { return lldb::eStateStepping; }
 
-  virtual llvm::Expected GetStopDescription(lldb_private::Stream *s) {
-return true;
+  virtual llvm::Error GetStopDescription(lldb_private::Stream *s) {
+return llvm::Error::success();
   }
 };
 } // namespace lldb_private
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp
index b7e475812f22b..8148e138ae564 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp
@@ -91,7 +91,7 @@ lldb::StateType 
ScriptedThreadPlanPythonInterface::GetRunState() {
   static_cast(lldb::eStateStepping)));
 }
 
-llvm::Expected
+llvm::Error
 ScriptedThreadPlanPythonInterface::GetStopDescription(lldb_private::Stream *s) 
{
   Status error;
   Dispatch("stop_description", error, s);
@@ -99,7 +99,7 @@ 
ScriptedThreadPlanPythonInterface::GetStopDescription(lldb_private::Stream *s) {
   if (error.Fail())
 return error.ToError();
 
-  return true;
+  return llvm::Error::success();
 }
 
 #endif
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h
index 33f086786c47b..563874a590794 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h
@@ -40,7 +40,7 @@ class ScriptedThreadPlanPythonInterface : public 
ScriptedThreadPlanInterface,
 
   lldb::StateType GetRunState() override;
 
-  llvm::Expected GetStopDescription(lldb_private::Stream *s) override;
+  llvm::Error GetStopDescription(lldb_private::Stream *s) override;
 };
 } // namespace lldb_private
 
diff --git a/lldb/source/Target/ThreadPlanPython.cpp 
b/lldb/source/Target/ThreadPlanPython.cpp
index 373555324ba6e..5c0beb6409b90 100644
--- a/lldb/source/Target/ThreadPlanPython.cpp
+++ b/lldb/source/Target/ThreadPlanPython.cpp
@@ -182,9 +182,9 @@ void ThreadPlanPython::GetDescription(Stream *s, 
lldb::DescriptionLevel level) {
   if (m_implementation_sp) {
 ScriptInterpreter *script_interp = GetScriptInterpreter();
 if (script_interp) {
-  auto desc_or_err = m_interface->GetStopDescription(s);
-  if (!desc_or_err || !*desc_or_err) {
-LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), desc_or_err.takeError(),
+  llvm::Error err = m_interface->GetStopDescription(s);
+  if (err) {
+LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), std::move(err),
"Can't call ScriptedThreadPlan::GetStopDescription.");
 s->Printf("Python thread plan implemented by class %s.",
 m_class_name.c_str());
diff --git a/lldb/test/API/functionalities/step_scripted/TestStepScripted.py 
b/lldb/test/API/functionalities/step_scripted/TestStepScripted.py
index bb7479414dbbb..53901718019f9 100644
--- a/lldb/test/API/functionalities/step_scripted/TestStepScripted.py
+++ b/lldb/test/API/functionalities/step_scripted/TestStepScripted.py
@@ -7,6 +7,7 @@
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 
+
 class StepScriptedTestCase(TestBase):
 NO_DEBUG_INFO_TESTCASE = True

[Lldb-commits] [lldb] [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (PR #96985)

2024-06-28 Thread Med Ismail Bennani via lldb-commits

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


[Lldb-commits] [lldb] 1130e92 - [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (#96985)

2024-06-28 Thread via lldb-commits

Author: Med Ismail Bennani
Date: 2024-06-28T01:40:03-07:00
New Revision: 1130e923e2d7fe046101bf639bc5ebcde194c005

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

LOG: [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return 
value (#96985)

This patch changes `ScriptedThreadPlan::GetStopDescription` behavior by
discarding its return value since it is optional in the first place (the
user doesn't need to provide a return value in their implementation).

This patch also addresses the test failures in TestStepScripted
following 9a9ec22 and re-enables the tests that were XFAIL'd previously.

The issue here was that the `Stream*` that's passed to
`ThreadPlanPython::GetDescription` wasn't being passed by reference to
the python method so it was never updated to reflect how the python
method interacted with it.

This patch solves this issue by making a temporary `StreamSP` that will
be passed to the python method by reference, after what we will copy its
content to the caller `Stream` pointer argument.

-

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
lldb/include/lldb/Interpreter/ScriptInterpreter.h
lldb/source/Interpreter/ScriptInterpreter.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h
lldb/source/Target/ThreadPlanPython.cpp
lldb/test/API/functionalities/step_scripted/TestStepScripted.py

Removed: 




diff  --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
index 9130f9412cb0b..ee634d15f2a9e 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
@@ -29,8 +29,8 @@ class ScriptedThreadPlanInterface : public ScriptedInterface {
 
   virtual lldb::StateType GetRunState() { return lldb::eStateStepping; }
 
-  virtual llvm::Expected GetStopDescription(lldb_private::Stream *s) {
-return true;
+  virtual llvm::Error GetStopDescription(lldb::StreamSP &stream) {
+return llvm::Error::success();
   }
 };
 } // namespace lldb_private

diff  --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index e821a7db2c674..14a52709c1e61 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -575,7 +575,7 @@ class ScriptInterpreter : public PluginInterface {
 
   Event *GetOpaqueTypeFromSBEvent(const lldb::SBEvent &event) const;
 
-  Stream *GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
+  lldb::StreamSP GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
 
   lldb::BreakpointSP
   GetOpaqueTypeFromSBBreakpoint(const lldb::SBBreakpoint &breakpoint) const;

diff  --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 75b2a39a8d11b..65e4cbddc39a5 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << const_cast(stream).GetData();
+return s;
+  }
 
   return nullptr;
 }

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
index 7d072212676e1..699412e437a1a 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
@@ -26,15 +26,6 @@ ScriptedPythonInterface::ScriptedPythonInterface(
 ScriptInterpreterPythonImpl &interpreter)
 : ScriptedInterface(), m_interpreter(interpreter) {}
 
-template <>
-void ScriptedPythonInterface::ReverseTransform(
-lldb_private::Stream *&original_arg, python::PythonObject transformed_arg,
-Status &error) {
-  Stream *s = ExtractValueFromP

[Lldb-commits] [lldb] [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (PR #96985)

2024-06-28 Thread Med Ismail Bennani via lldb-commits

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


[Lldb-commits] [lldb] b22ea2d - [lldb] Use SmallVector::erase correctly

2024-06-28 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2024-06-28T10:40:13+02:00
New Revision: b22ea2dc1e065f14a88df44e22a62427965a9b05

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

LOG: [lldb] Use SmallVector::erase correctly

erase() invalidates the iterator, we must use the returned iterator to
continue iterating.

This does not actually make a difference with the current implementation
of SmallVector (erase will effectively return the same pointer), but it
avoids future confusion.

Added: 


Modified: 
lldb/source/Utility/Broadcaster.cpp

Removed: 




diff  --git a/lldb/source/Utility/Broadcaster.cpp 
b/lldb/source/Utility/Broadcaster.cpp
index bd65ffd86a1d0..b6d8ae39325d3 100644
--- a/lldb/source/Utility/Broadcaster.cpp
+++ b/lldb/source/Utility/Broadcaster.cpp
@@ -202,7 +202,7 @@ bool Broadcaster::BroadcasterImpl::RemoveListener(
 if (!curr_listener_sp) {
   // The weak pointer for this listener didn't resolve, lets' prune it
   // as we go.
-  m_listeners.erase(it);
+  it = m_listeners.erase(it);
   continue;
 }
 
@@ -213,8 +213,8 @@ bool Broadcaster::BroadcasterImpl::RemoveListener(
   if (!it->second)
 m_listeners.erase(it);
   return true;
-} else
-  it++;
+}
+it++;
   }
   return false;
 }



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


[Lldb-commits] [lldb] [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (PR #96985)

2024-06-28 Thread Nico Weber via lldb-commits


@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << const_cast(stream).GetData();

nico wrote:

This adds a dependency cycle: lldb::SBStream is in source/API, so this makes 
Interpreter depend on API. But API already depends on Interpreter.

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


[Lldb-commits] [lldb] [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (PR #96985)

2024-06-28 Thread Nico Weber via lldb-commits


@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << const_cast(stream).GetData();

nico wrote:

This isn't an idle complaint: It has the effect that `lldb-test` no longer 
links after this PR if you don't pass `-Wl,-dead_strip` to the linker.

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


[Lldb-commits] [lldb] [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (PR #96985)

2024-06-28 Thread Nico Weber via lldb-commits


@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << const_cast(stream).GetData();

nico wrote:

Chances are it also breaks building on Windows, where /OPT:REF might not be 
strong enough to remove this.

Also, we do have a `LLVM_NO_DEAD_STRIP` option, which presumably no longer 
builds after this change either.

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


[Lldb-commits] [lldb] a2e3af5 - Revert "[lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (#96985)"

2024-06-28 Thread Nico Weber via lldb-commits

Author: Nico Weber
Date: 2024-06-28T13:25:11+02:00
New Revision: a2e3af5d581547d3ea53e5383d6f7f1cab45120a

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

LOG: Revert "[lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription 
return value (#96985)"

This reverts commit 1130e923e2d7fe046101bf639bc5ebcde194c005.
Very likely causes build problems on Windows and with LLVM_NO_DEAD_STRIP=ON,
see https://github.com/llvm/llvm-project/pull/96985#pullrequestreview-2147599208

Added: 


Modified: 
lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
lldb/include/lldb/Interpreter/ScriptInterpreter.h
lldb/source/Interpreter/ScriptInterpreter.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h
lldb/source/Target/ThreadPlanPython.cpp
lldb/test/API/functionalities/step_scripted/TestStepScripted.py

Removed: 




diff  --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
index ee634d15f2a9e..9130f9412cb0b 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
@@ -29,8 +29,8 @@ class ScriptedThreadPlanInterface : public ScriptedInterface {
 
   virtual lldb::StateType GetRunState() { return lldb::eStateStepping; }
 
-  virtual llvm::Error GetStopDescription(lldb::StreamSP &stream) {
-return llvm::Error::success();
+  virtual llvm::Expected GetStopDescription(lldb_private::Stream *s) {
+return true;
   }
 };
 } // namespace lldb_private

diff  --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 14a52709c1e61..e821a7db2c674 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -575,7 +575,7 @@ class ScriptInterpreter : public PluginInterface {
 
   Event *GetOpaqueTypeFromSBEvent(const lldb::SBEvent &event) const;
 
-  lldb::StreamSP GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
+  Stream *GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
 
   lldb::BreakpointSP
   GetOpaqueTypeFromSBBreakpoint(const lldb::SBBreakpoint &breakpoint) const;

diff  --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 65e4cbddc39a5..75b2a39a8d11b 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -106,13 +106,10 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
+Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up) {
-lldb::StreamSP s = std::make_shared();
-*s << const_cast(stream).GetData();
-return s;
-  }
+  if (stream.m_opaque_up)
+return const_cast(stream).m_opaque_up.get();
 
   return nullptr;
 }

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
index 699412e437a1a..7d072212676e1 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
@@ -26,6 +26,15 @@ ScriptedPythonInterface::ScriptedPythonInterface(
 ScriptInterpreterPythonImpl &interpreter)
 : ScriptedInterface(), m_interpreter(interpreter) {}
 
+template <>
+void ScriptedPythonInterface::ReverseTransform(
+lldb_private::Stream *&original_arg, python::PythonObject transformed_arg,
+Status &error) {
+  Stream *s = ExtractValueFromPythonObject(transformed_arg, error);
+  *original_arg = *s;
+  original_arg->PutCString(static_cast(s)->GetData());
+}
+
 template <>
 StructuredData::ArraySP
 ScriptedPythonInterface::ExtractValueFromPythonObject(
@@ -65,8 +74,7 @@ Event 
*ScriptedPythonInterface::ExtractValueFromPythonObject(
 }
 
 template <>
-lldb::StreamSP
-ScriptedPythonInterface::ExtractValueFromPythonObject(
+Stream *ScriptedPythonInterface::ExtractValueFromPythonObject(
 python::PythonObject &p, Status &error) {
   if (lldb::SBStream *sb_stream = reinterpret_cast(
   python::LLDBSWIGPython_CastPyObject

[Lldb-commits] [lldb] [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (PR #96985)

2024-06-28 Thread Nico Weber via lldb-commits


@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << const_cast(stream).GetData();

nico wrote:

Reverted in a2e3af5d581547d3ea53e5383d6f7f1cab45120a for now.

https://github.com/llvm/llvm-project/pull/96985
___
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-06-28 Thread Michael Buch via lldb-commits

https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/97043

In one of my recent PRs I mistakenly had two test-cases with the same name, 
preventing one of them to run. Since it's an easy mistake to make (e.g., copy 
pasting existing test-cases), I ran following sanity-check script over 
`lldb/test/API`, which found couple of tests which were losing coverage because 
of this (or in some cases simply had duplicate tests):
```
import ast
import sys

filename = sys.argv[1]
print(f'Checking {filename}...')
tree = ast.parse(open(filename, 'r').read())

for node in ast.walk(tree):
if not isinstance(node, ast.ClassDef):
continue

func_names = []
for child in ast.iter_child_nodes(node):
if isinstance(child, ast.FunctionDef):
func_names.append(child.name)

seen_func_names = set()
duplicate_func_names = []
for name in func_names:
if name in seen_func_names:
duplicate_func_names.append(name)
else:
seen_func_names.add(name)

if len(duplicate_func_names) != 0:
print(f'Multiple func names found:\n\t{duplicate_func_names}\n\tclass 
{node.name}\n\tfile: {filename}')
```

This patch fixes these cases.

>From 0c1f5c2240c64cfd69afcf819c69cca1270e5d8a Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 28 Jun 2024 12:49:55 +0100
Subject: [PATCH] [lldb][test] Remove duplicate testcase names in API
 test-suite

In one of my recent PRs I mistakenly had two test-cases with
the same name, preventing one of them to run. Since it's an
easy mistake to make (e.g., copy pasting existing test-cases),
I ran following sanity-check script over `lldb/test/API`, which
found couple of tests which were losing coverage because of
this (or in some cases simply had duplicate tests):
```
import ast
import sys

filename = sys.argv[1]
print(f'Checking {filename}...')
tree = ast.parse(open(filename, 'r').read())

for node in ast.walk(tree):
if not isinstance(node, ast.ClassDef):
continue

func_names = []
for child in ast.iter_child_nodes(node):
if isinstance(child, ast.FunctionDef):
func_names.append(child.name)

seen_func_names = set()
duplicate_func_names = []
for name in func_names:
if name in seen_func_names:
duplicate_func_names.append(name)
else:
seen_func_names.add(name)

if len(duplicate_func_names) != 0:
print(f'Multiple func names found:\n\t{duplicate_func_names}\n\tclass 
{node.name}\n\tfile: {filename}')
```

This patch fixes these cases.
---
 .../log/invalid-args/TestInvalidArgsLog.py|  2 +-
 .../backtrace/TestThreadBacktraceRepeat.py|  2 -
 .../TestTraceStartStopMultipleThreads.py  | 37 ---
 .../completion/TestCompletion.py  |  6 ---
 .../gdb_remote_client/TestIOSSimulator.py |  2 +-
 .../python_os_plugin/TestPythonOSPlugin.py|  2 +-
 .../API/lang/cpp/diamond/TestCppDiamond.py|  2 +-
 .../TestMembersAndLocalsWithSameName.py   |  1 -
 .../cxx-bridged-po/TestObjCXXBridgedPO.py |  2 +-
 .../rust/enum-structs/TestRustEnumStructs.py  |  2 +-
 lldb/test/API/test_utils/TestDecorators.py|  4 +-
 11 files changed, 8 insertions(+), 54 deletions(-)

diff --git a/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py 
b/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
index 583c68d7bfacc..dbcd2d60d021a 100644
--- a/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
+++ b/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
@@ -25,7 +25,7 @@ def test_disable_empty(self):
 )
 
 @no_debug_info_test
-def test_enable_empty(self):
+def test_enable_invalid_path(self):
 invalid_path = os.path.join("this", "is", "not", "a", "valid", "path")
 self.expect(
 "log enable lldb all -f " + invalid_path,
diff --git 
a/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py 
b/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
index 9678bd42999b3..571024417560f 100644
--- a/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
+++ b/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
@@ -16,8 +16,6 @@ def test_thread_backtrace_one_thread(self):
 """Run a simplified version of the test that just hits one breakpoint 
and
 doesn't care about synchronizing the two threads - hopefully this will
 run on more systems."""
-
-def test_thread_backtrace_one_thread(self):
 self.build()
 (
 self.inferior_target,
diff --git 
a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
 
b/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
index c41e85fd670ba..12f99f07c78a8 100644
--- 
a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
+++ 
b/lldb/test/API/commands/trace/multiple-threads/Tes

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

2024-06-28 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

In one of my recent PRs I mistakenly had two test-cases with the same name, 
preventing one of them to run. Since it's an easy mistake to make (e.g., copy 
pasting existing test-cases), I ran following sanity-check script over 
`lldb/test/API`, which found couple of tests which were losing coverage because 
of this (or in some cases simply had duplicate tests):
```
import ast
import sys

filename = sys.argv[1]
print(f'Checking {filename}...')
tree = ast.parse(open(filename, 'r').read())

for node in ast.walk(tree):
if not isinstance(node, ast.ClassDef):
continue

func_names = []
for child in ast.iter_child_nodes(node):
if isinstance(child, ast.FunctionDef):
func_names.append(child.name)

seen_func_names = set()
duplicate_func_names = []
for name in func_names:
if name in seen_func_names:
duplicate_func_names.append(name)
else:
seen_func_names.add(name)

if len(duplicate_func_names) != 0:
print(f'Multiple func names found:\n\t{duplicate_func_names}\n\tclass 
{node.name}\n\tfile: {filename}')
```

This patch fixes these cases.

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


11 Files Affected:

- (modified) lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py 
(+1-1) 
- (modified) 
lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py (-2) 
- (modified) 
lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
 (-37) 
- (modified) lldb/test/API/functionalities/completion/TestCompletion.py (-6) 
- (modified) 
lldb/test/API/functionalities/gdb_remote_client/TestIOSSimulator.py (+1-1) 
- (modified) 
lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py 
(+1-1) 
- (modified) lldb/test/API/lang/cpp/diamond/TestCppDiamond.py (+1-1) 
- (modified) 
lldb/test/API/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py
 (-1) 
- (modified) lldb/test/API/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py 
(+1-1) 
- (modified) lldb/test/API/lang/rust/enum-structs/TestRustEnumStructs.py (+1-1) 
- (modified) lldb/test/API/test_utils/TestDecorators.py (+2-2) 


``diff
diff --git a/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py 
b/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
index 583c68d7bfacc..dbcd2d60d021a 100644
--- a/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
+++ b/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
@@ -25,7 +25,7 @@ def test_disable_empty(self):
 )
 
 @no_debug_info_test
-def test_enable_empty(self):
+def test_enable_invalid_path(self):
 invalid_path = os.path.join("this", "is", "not", "a", "valid", "path")
 self.expect(
 "log enable lldb all -f " + invalid_path,
diff --git 
a/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py 
b/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
index 9678bd42999b3..571024417560f 100644
--- a/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
+++ b/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
@@ -16,8 +16,6 @@ def test_thread_backtrace_one_thread(self):
 """Run a simplified version of the test that just hits one breakpoint 
and
 doesn't care about synchronizing the two threads - hopefully this will
 run on more systems."""
-
-def test_thread_backtrace_one_thread(self):
 self.build()
 (
 self.inferior_target,
diff --git 
a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
 
b/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
index c41e85fd670ba..12f99f07c78a8 100644
--- 
a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
+++ 
b/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
@@ -31,43 +31,6 @@ def testStartMultipleLiveThreads(self):
 
 self.traceStopProcess()
 
-@skipIf(oslist=no_match(["linux"]), archs=no_match(["i386", "x86_64"]))
-@testSBAPIAndCommands
-def testStartMultipleLiveThreadsWithStops(self):
-self.build()
-exe = self.getBuildArtifact("a.out")
-
-self.dbg.CreateTarget(exe)
-
-self.expect("b main")
-self.expect("b 6")
-self.expect("b 11")
-
-self.expect("r")
-self.traceStartProcess()
-
-# We'll see here the first thread
-self.expect("continue")
-
-# We are in thread 2
-self.expect("thread trace dump instructions", substrs=["main.cpp:9"])
-self.expect("thread trace dump instructions 2", substrs=["main.cpp:9"])
-
-# We stop tracing it
-self.expect("thread trace stop 2")
-
-# The trace is still in memory
-self.expect("t

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

2024-06-28 Thread Michael Buch via lldb-commits

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

>From 0c1f5c2240c64cfd69afcf819c69cca1270e5d8a Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 28 Jun 2024 12:49:55 +0100
Subject: [PATCH 1/2] [lldb][test] Remove duplicate testcase names in API
 test-suite

In one of my recent PRs I mistakenly had two test-cases with
the same name, preventing one of them to run. Since it's an
easy mistake to make (e.g., copy pasting existing test-cases),
I ran following sanity-check script over `lldb/test/API`, which
found couple of tests which were losing coverage because of
this (or in some cases simply had duplicate tests):
```
import ast
import sys

filename = sys.argv[1]
print(f'Checking {filename}...')
tree = ast.parse(open(filename, 'r').read())

for node in ast.walk(tree):
if not isinstance(node, ast.ClassDef):
continue

func_names = []
for child in ast.iter_child_nodes(node):
if isinstance(child, ast.FunctionDef):
func_names.append(child.name)

seen_func_names = set()
duplicate_func_names = []
for name in func_names:
if name in seen_func_names:
duplicate_func_names.append(name)
else:
seen_func_names.add(name)

if len(duplicate_func_names) != 0:
print(f'Multiple func names found:\n\t{duplicate_func_names}\n\tclass 
{node.name}\n\tfile: {filename}')
```

This patch fixes these cases.
---
 .../log/invalid-args/TestInvalidArgsLog.py|  2 +-
 .../backtrace/TestThreadBacktraceRepeat.py|  2 -
 .../TestTraceStartStopMultipleThreads.py  | 37 ---
 .../completion/TestCompletion.py  |  6 ---
 .../gdb_remote_client/TestIOSSimulator.py |  2 +-
 .../python_os_plugin/TestPythonOSPlugin.py|  2 +-
 .../API/lang/cpp/diamond/TestCppDiamond.py|  2 +-
 .../TestMembersAndLocalsWithSameName.py   |  1 -
 .../cxx-bridged-po/TestObjCXXBridgedPO.py |  2 +-
 .../rust/enum-structs/TestRustEnumStructs.py  |  2 +-
 lldb/test/API/test_utils/TestDecorators.py|  4 +-
 11 files changed, 8 insertions(+), 54 deletions(-)

diff --git a/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py 
b/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
index 583c68d7bfacc..dbcd2d60d021a 100644
--- a/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
+++ b/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
@@ -25,7 +25,7 @@ def test_disable_empty(self):
 )
 
 @no_debug_info_test
-def test_enable_empty(self):
+def test_enable_invalid_path(self):
 invalid_path = os.path.join("this", "is", "not", "a", "valid", "path")
 self.expect(
 "log enable lldb all -f " + invalid_path,
diff --git 
a/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py 
b/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
index 9678bd42999b3..571024417560f 100644
--- a/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
+++ b/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
@@ -16,8 +16,6 @@ def test_thread_backtrace_one_thread(self):
 """Run a simplified version of the test that just hits one breakpoint 
and
 doesn't care about synchronizing the two threads - hopefully this will
 run on more systems."""
-
-def test_thread_backtrace_one_thread(self):
 self.build()
 (
 self.inferior_target,
diff --git 
a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
 
b/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
index c41e85fd670ba..12f99f07c78a8 100644
--- 
a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
+++ 
b/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
@@ -31,43 +31,6 @@ def testStartMultipleLiveThreads(self):
 
 self.traceStopProcess()
 
-@skipIf(oslist=no_match(["linux"]), archs=no_match(["i386", "x86_64"]))
-@testSBAPIAndCommands
-def testStartMultipleLiveThreadsWithStops(self):
-self.build()
-exe = self.getBuildArtifact("a.out")
-
-self.dbg.CreateTarget(exe)
-
-self.expect("b main")
-self.expect("b 6")
-self.expect("b 11")
-
-self.expect("r")
-self.traceStartProcess()
-
-# We'll see here the first thread
-self.expect("continue")
-
-# We are in thread 2
-self.expect("thread trace dump instructions", substrs=["main.cpp:9"])
-self.expect("thread trace dump instructions 2", substrs=["main.cpp:9"])
-
-# We stop tracing it
-self.expect("thread trace stop 2")
-
-# The trace is still in memory
-self.expect("thread trace dump instructions 2", substrs=["main.cpp:9"])
-
-# We'll stop at the next breakpoint, thread 2 will be still alive, but 
not traced. Thread 3 will be traced
-   

[Lldb-commits] [lldb] [lldb][test][NFC] Remove BOM characters from tests (PR #97045)

2024-06-28 Thread Michael Buch via lldb-commits

https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/97045

These handful of tests had a BOM (Byte order mark) at the beginning of the 
file. This marker is unnecessary in our test files. The main motivation for 
this is that the `ast` python module breaks when passing a file to it with a 
BOM marker (and might break other tooling which doesn't expect it). E.g.,:
```
"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
^
SyntaxError: invalid non-printable character U+FEFF
```

If anyone is aware of a good reason to keep it, happy to drop this.

>From 51f45aca3cdd36c2183fc3ebd2da3e199e048cdd Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 28 Jun 2024 13:09:32 +0100
Subject: [PATCH] [lldb][test][NFC] Remove BOM characters from tests

These handful of tests had a BOM (Byte order mark)
at the beginning of the file. This marker is unnecessary
in our test files. The main motivation for this is that
the `ast` python module breaks when passing a file to it
with a BOM marker (and might break other tooling which
doesn't expect it). E.g.,:
```
"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
^
SyntaxError: invalid non-printable character U+FEFF
```

If anyone is aware of a good reason to keep it, happy
to drop this.
---
 .../commands/expression/call-restarts/TestCallThatRestarts.py   | 2 +-
 .../test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py | 2 +-
 lldb/test/API/functionalities/load_unload/TestLoadUnload.py | 2 +-
 .../API/functionalities/load_using_paths/TestLoadUsingPaths.py  | 2 +-
 .../location-list-lookup/TestLocationListLookup.py  | 2 +-
 lldb/test/API/functionalities/signal/TestSendSignal.py  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git 
a/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py 
b/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
index ca08591aedb39..a108ffe485efc 100644
--- a/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
+++ b/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test calling a function that hits a signal set to auto-restart, make sure the 
call completes.
 """
 
diff --git a/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py 
b/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
index 2783aaff1a0ed..0fa7bc7edf995 100644
--- a/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
+++ b/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test that SBProcess.LoadImageUsingPaths uses RTLD_LAZY
 """
 
diff --git a/lldb/test/API/functionalities/load_unload/TestLoadUnload.py 
b/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
index 2208e520f1d56..e52fb8c87377f 100644
--- a/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
+++ b/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test that breakpoint by symbol name works correctly with dynamic libs.
 """
 
diff --git 
a/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py 
b/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
index 6ee99f84adda8..c423236b219f4 100644
--- a/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
+++ b/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test that SBProcess.LoadImageUsingPaths works correctly.
 """
 
diff --git 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
index c5f4a7c6dedc1..84033daff7730 100644
--- 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
+++ 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
@@ -1,4 +1,4 @@
-"""Test that lldb picks the correct DWARF location list entry with a 
return-pc out of bounds."""
+"""Test that lldb picks the correct DWARF location list entry with a return-pc 
out of bounds."""
 
 import lldb
 from lldbsuite.test.decorators import *
diff --git a/lldb/test/API/functionalities/signal/TestSendSignal.py 
b/lldb/test/API/functionalities/signal/TestSendSignal.py
index 50435572c4d83..5b6a50a461cdf 100644
--- a/lldb/test/API/functionalities/signal/TestSendSignal.py
+++ b/lldb/test/API/functionalities/signal/TestSendSignal.py
@@ -1,4 +1,4 @@
-"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
+"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
 
 
 import lldb

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


[Lldb-commits] [lldb] [lldb][test][NFC] Remove BOM characters from tests (PR #97045)

2024-06-28 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

These handful of tests had a BOM (Byte order mark) at the beginning of the 
file. This marker is unnecessary in our test files. The main motivation for 
this is that the `ast` python module breaks when passing a file to it with a 
BOM marker (and might break other tooling which doesn't expect it). E.g.,:
```
"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
^
SyntaxError: invalid non-printable character U+FEFF
```

If anyone is aware of a good reason to keep it, happy to drop this.

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


6 Files Affected:

- (modified) 
lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py (+1-1) 
- (modified) lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py 
(+1-1) 
- (modified) lldb/test/API/functionalities/load_unload/TestLoadUnload.py (+1-1) 
- (modified) 
lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py (+1-1) 
- (modified) 
lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py 
(+1-1) 
- (modified) lldb/test/API/functionalities/signal/TestSendSignal.py (+1-1) 


``diff
diff --git 
a/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py 
b/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
index ca08591aedb39..a108ffe485efc 100644
--- a/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
+++ b/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test calling a function that hits a signal set to auto-restart, make sure the 
call completes.
 """
 
diff --git a/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py 
b/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
index 2783aaff1a0ed..0fa7bc7edf995 100644
--- a/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
+++ b/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test that SBProcess.LoadImageUsingPaths uses RTLD_LAZY
 """
 
diff --git a/lldb/test/API/functionalities/load_unload/TestLoadUnload.py 
b/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
index 2208e520f1d56..e52fb8c87377f 100644
--- a/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
+++ b/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test that breakpoint by symbol name works correctly with dynamic libs.
 """
 
diff --git 
a/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py 
b/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
index 6ee99f84adda8..c423236b219f4 100644
--- a/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
+++ b/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test that SBProcess.LoadImageUsingPaths works correctly.
 """
 
diff --git 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
index c5f4a7c6dedc1..84033daff7730 100644
--- 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
+++ 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
@@ -1,4 +1,4 @@
-"""Test that lldb picks the correct DWARF location list entry with a 
return-pc out of bounds."""
+"""Test that lldb picks the correct DWARF location list entry with a return-pc 
out of bounds."""
 
 import lldb
 from lldbsuite.test.decorators import *
diff --git a/lldb/test/API/functionalities/signal/TestSendSignal.py 
b/lldb/test/API/functionalities/signal/TestSendSignal.py
index 50435572c4d83..5b6a50a461cdf 100644
--- a/lldb/test/API/functionalities/signal/TestSendSignal.py
+++ b/lldb/test/API/functionalities/signal/TestSendSignal.py
@@ -1,4 +1,4 @@
-"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
+"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
 
 
 import lldb

``




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


[Lldb-commits] [lldb] [lldb][test][NFC] Remove BOM characters from tests (PR #97045)

2024-06-28 Thread David Spickett via lldb-commits

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

These tests are not testing anything do do with character encoding, so this 
LGTM.

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


[Lldb-commits] [lldb] 9c95617 - [lldb][test][NFC] Remove BOM characters from tests (#97045)

2024-06-28 Thread via lldb-commits

Author: Michael Buch
Date: 2024-06-28T14:06:39+01:00
New Revision: 9c95617c796f1cd178eaf3001bce543b8acee32f

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

LOG: [lldb][test][NFC] Remove BOM characters from tests (#97045)

These handful of tests had a BOM (Byte order mark) at the beginning of
the file. This marker is unnecessary in our test files. The main
motivation for this is that the `ast` python module breaks when passing
a file to it with a BOM marker (and might break other tooling which
doesn't expect it). E.g.,:
```
"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
^
SyntaxError: invalid non-printable character U+FEFF
```

If anyone is aware of a good reason to keep it, happy to drop this.

Added: 


Modified: 
lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
lldb/test/API/functionalities/load_unload/TestLoadUnload.py
lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
lldb/test/API/functionalities/signal/TestSendSignal.py

Removed: 




diff  --git 
a/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py 
b/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
index ca08591aedb39..a108ffe485efc 100644
--- a/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
+++ b/lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test calling a function that hits a signal set to auto-restart, make sure the 
call completes.
 """
 

diff  --git a/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py 
b/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
index 2783aaff1a0ed..0fa7bc7edf995 100644
--- a/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
+++ b/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test that SBProcess.LoadImageUsingPaths uses RTLD_LAZY
 """
 

diff  --git a/lldb/test/API/functionalities/load_unload/TestLoadUnload.py 
b/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
index 2208e520f1d56..e52fb8c87377f 100644
--- a/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
+++ b/lldb/test/API/functionalities/load_unload/TestLoadUnload.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test that breakpoint by symbol name works correctly with dynamic libs.
 """
 

diff  --git 
a/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py 
b/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
index 6ee99f84adda8..c423236b219f4 100644
--- a/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
+++ b/lldb/test/API/functionalities/load_using_paths/TestLoadUsingPaths.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test that SBProcess.LoadImageUsingPaths works correctly.
 """
 

diff  --git 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
index c5f4a7c6dedc1..84033daff7730 100644
--- 
a/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
+++ 
b/lldb/test/API/functionalities/location-list-lookup/TestLocationListLookup.py
@@ -1,4 +1,4 @@
-"""Test that lldb picks the correct DWARF location list entry with a 
return-pc out of bounds."""
+"""Test that lldb picks the correct DWARF location list entry with a return-pc 
out of bounds."""
 
 import lldb
 from lldbsuite.test.decorators import *

diff  --git a/lldb/test/API/functionalities/signal/TestSendSignal.py 
b/lldb/test/API/functionalities/signal/TestSendSignal.py
index 50435572c4d83..5b6a50a461cdf 100644
--- a/lldb/test/API/functionalities/signal/TestSendSignal.py
+++ b/lldb/test/API/functionalities/signal/TestSendSignal.py
@@ -1,4 +1,4 @@
-"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
+"""Test that lldb command 'process signal SIGUSR1' to send a signal to the 
inferior works."""
 
 
 import lldb



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


[Lldb-commits] [lldb] [lldb][test][NFC] Remove BOM characters from tests (PR #97045)

2024-06-28 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (PR #96985)

2024-06-28 Thread Vlad Serebrennikov via lldb-commits


@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << const_cast(stream).GetData();

Endilll wrote:

I think this is what broke my linux build with the following linker error:
```
mold: error: undefined symbol: lldb::SBStream::GetData()
>>> referenced by ScriptInterpreter.cpp
>>>   
>>> lib/liblldbInterpreter.a(ScriptInterpreter.cpp.o):(lldb_private::ScriptInterpreter::GetOpaqueTypeFromSBStream(lldb::SBStream
>>>  const&) const)
```
lld complains in the same way.

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


[Lldb-commits] [lldb] 1e01e0c - [lldb][test][NFC] TestWatchpointConditionCmd.py: remove BOM character

2024-06-28 Thread Michael Buch via lldb-commits

Author: Michael Buch
Date: 2024-06-28T14:10:08+01:00
New Revision: 1e01e0c19ace6c9b165ee0cbbcd24ab55d27d8e0

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

LOG: [lldb][test][NFC] TestWatchpointConditionCmd.py: remove BOM character

Missed this file in https://github.com/llvm/llvm-project/pull/97045

Added: 


Modified: 

lldb/test/API/commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py

Removed: 




diff  --git 
a/lldb/test/API/commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py
 
b/lldb/test/API/commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py
index 9e8db7025219d..3a60859b9ce7d 100644
--- 
a/lldb/test/API/commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py
+++ 
b/lldb/test/API/commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py
@@ -1,4 +1,4 @@
-"""
+"""
 Test watchpoint modify command to set condition on a watchpoint.
 """
 



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


[Lldb-commits] [lldb] 46e848a - [lldb][test] Add test-cases for packed/aligned structures (#96932)

2024-06-28 Thread via lldb-commits

Author: Michael Buch
Date: 2024-06-28T14:15:09+01:00
New Revision: 46e848a23b212204b01abdc898a53b553d9a57c0

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

LOG: [lldb][test] Add test-cases for packed/aligned structures (#96932)

Adds test that checks whether LLDB correctly infers the
alignment of packed structures. Specifically, the
`InferAlignment` code-path of the `ItaniumRecordLayoutBuilder`
where it assumes that overlapping field offsets imply a
packed structure and thus sets alignment to `1`. See discussion
in https://github.com/llvm/llvm-project/pull/93809.

While here, also added a test-case where we check alignment of
a class whose base has an explicit `DW_AT_alignment
(those don't get transitively propagated in DWARF, but don't seem
like a problem for LLDB).

Lastly, also added an XFAIL-ed tests where the aforementioned
`InferAlignment` kicks in for overlapping fields (but in this
case incorrectly since the structure isn't actually packed).

Added: 
lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp
lldb/test/Shell/SymbolFile/DWARF/packed.cpp

Modified: 
lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
lldb/test/API/lang/cpp/alignas_base_class/main.cpp

Removed: 




diff  --git a/lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py 
b/lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
index 7d97b0c42b7e1..362fc2740bf52 100644
--- a/lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
+++ b/lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
@@ -16,3 +16,4 @@ def test(self):
 # Verify specified class alignments.
 self.expect_expr("alignof(B2)", result_value="8")
 self.expect_expr("alignof(EmptyClassAlign8)", result_value="8")
+self.expect_expr("alignof(Derived)", result_value="8")

diff  --git a/lldb/test/API/lang/cpp/alignas_base_class/main.cpp 
b/lldb/test/API/lang/cpp/alignas_base_class/main.cpp
index 9d37554957ba3..a37919deaebdc 100644
--- a/lldb/test/API/lang/cpp/alignas_base_class/main.cpp
+++ b/lldb/test/API/lang/cpp/alignas_base_class/main.cpp
@@ -13,4 +13,11 @@ D d3g;
 struct alignas(8) EmptyClassAlign8 {
 } t;
 
+struct alignas(8) __attribute__((packed)) AlignedAndPackedBase {
+} foo;
+
+struct Derived : AlignedAndPackedBase {
+} bar;
+static_assert(alignof(Derived) == 8);
+
 int main() {}

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp
new file mode 100644
index 0..1488199a3ad2d
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp
@@ -0,0 +1,24 @@
+// XFAIL: *
+
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(OverlappingFields)" \
+// RUN:   -o "expr sizeof(OverlappingFields)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(OverlappingFields)
+// CHECK-NEXT: ${{.*}} = 4
+// CHECK:  (lldb) expr sizeof(OverlappingFields)
+// CHECK-NEXT: ${{.*}} = 8
+
+struct Empty {};
+
+struct OverlappingFields {
+  char y;
+  [[no_unique_address]] Empty e;
+  int z;
+} g_overlapping_struct;
+static_assert(alignof(OverlappingFields) == 4);
+static_assert(sizeof(OverlappingFields) == 8);
+
+int main() {}

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/packed.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
new file mode 100644
index 0..640a2e0454c92
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
@@ -0,0 +1,35 @@
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(packed)" \
+// RUN:   -o "expr sizeof(packed)" \
+// RUN:   -o "expr alignof(packed_and_aligned)" \
+// RUN:   -o "expr sizeof(packed_and_aligned)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(packed)
+// CHECK-NEXT: ${{.*}} = 1
+// CHECK:  (lldb) expr sizeof(packed)
+// CHECK-NEXT: ${{.*}} = 9
+
+// CHECK:  (lldb) expr alignof(packed_and_aligned)
+// CHECK-NEXT: ${{.*}} = 16
+// CHECK:  (lldb) expr sizeof(packed_and_aligned)
+// CHECK-NEXT: ${{.*}} = 16
+
+struct __attribute__((packed)) packed {
+  int x;
+  char y;
+  int z;
+} g_packed_struct;
+static_assert(alignof(packed) == 1);
+static_assert(sizeof(packed) == 9);
+
+struct __attribute__((packed, aligned(16))) packed_and_aligned {
+  int x;
+  char y;
+  int z;
+} g_packed_and_aligned_struct;
+static_assert(alignof(packed_and_aligned) == 16);
+static_assert(sizeof(packed_and_aligned) == 16);
+
+int main() {}



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


[Lldb-commits] [lldb] [lldb][test] Add test-cases for packed/aligned structures (PR #96932)

2024-06-28 Thread Michael Buch via lldb-commits

https://github.com/Michael137 closed 
https://github.com/llvm/llvm-project/pull/96932
___
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-06-28 Thread Jonas Devlieghere via lldb-commits

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


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] [lldb][test] Remove duplicate testcase names in API test-suite (PR #97043)

2024-06-28 Thread Jonas Devlieghere via lldb-commits

JDevlieghere 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. 

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] [lldb] Use `Address` to setup breakpoint (PR #94794)

2024-06-28 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Use `Address` to setup breakpoint (PR #94794)

2024-06-28 Thread Jonas Devlieghere via lldb-commits


@@ -90,17 +90,9 @@ void InstrumentationRuntimeASanLibsanitizers::Activate() {
   if (!process_sp)
 return;
 
-  lldb::ModuleSP module_sp = GetRuntimeModuleSP();
-
   Breakpoint *breakpoint = ReportRetriever::SetupBreakpoint(
-  module_sp, process_sp, ConstString("sanitizers_address_on_report"));
-
-  if (!breakpoint) {
-breakpoint = ReportRetriever::SetupBreakpoint(
-module_sp, process_sp,
-ConstString("_Z22raise_sanitizers_error23sanitizer_error_context"));
-  }
-
+  GetRuntimeModuleSP(), process_sp,
+  ConstString("sanitizers_address_on_report"));

JDevlieghere wrote:

@clayborg The old code had a fallback to 
`_Z22raise_sanitizers_error23sanitizer_error_context` but this breakpoint is 
still the right one. 

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


[Lldb-commits] [lldb] [lldb] Use `Address` to setup breakpoint (PR #94794)

2024-06-28 Thread Jonas Devlieghere via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [lldb][test] Add tests for alignof on class with overlapping bases (PR #97068)

2024-06-28 Thread Michael Buch via lldb-commits

https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/97068

Follow-up to https://github.com/llvm/llvm-project/pull/96932

Adds XFAILed test where LLDB incorrectly infers the alignment of a derived 
class whose bases are overlapping due to [[no_unique_address]]. Specifically, 
the `InferAlignment` code-path of the `ItaniumRecordLayoutBuilder` assumes that 
overlapping base offsets imply a packed structure and thus sets alignment to 1. 
See discussion in https://github.com/llvm/llvm-project/pull/93809.

Also adds test where LLDB correctly infers an alignment of `1` when a packed 
base class is overlapping with other bases.

Lastly, there were a couple of `alignof` inconsistencies which I encapsulated 
in an XFAIL-ed `packed-alignof.cpp`.

>From 1c924c866cc2de5e9e1d84ce0b185e9dacefd4ec Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 28 Jun 2024 15:29:54 +0100
Subject: [PATCH] [lldb][test] Add tests for alignof on class with overlapping
 bases

Follow-up to https://github.com/llvm/llvm-project/pull/96932

Adds XFAILed test where LLDB incorrectly infers the
alignment of a derived class whose bases are overlapping
due to [[no_unique_address]]. Specifically, the `InferAlignment`
code-path of the `ItaniumRecordLayoutBuilder` assumes that overlapping
base offsets imply a packed structure and thus sets alignment
to 1. See discussion in https://github.com/llvm/llvm-project/pull/93809.

Also adds test where LLDB correctly infers an alignment
of `1` when a packed base class is overlapping with other bases.

Lastly, there were a couple of `alignof` inconsistencies which
I encapsulated in an XFAIL-ed `packed-alignof.cpp`.
---
 .../no_unique_address-base-alignment.cpp  | 30 ++
 .../Shell/SymbolFile/DWARF/packed-alignof.cpp | 41 +++
 lldb/test/Shell/SymbolFile/DWARF/packed.cpp   | 14 +++
 3 files changed, 85 insertions(+)
 create mode 100644 
lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp
 create mode 100644 lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp

diff --git 
a/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp
new file mode 100644
index 0..634d461e6ff19
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp
@@ -0,0 +1,30 @@
+// XFAIL: *
+
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(OverlappingDerived)" \
+// RUN:   -o "expr sizeof(OverlappingDerived)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(OverlappingDerived)
+// CHECK-NEXT: ${{.*}} = 4
+// CHECK:  (lldb) expr sizeof(OverlappingDerived)
+// CHECK-NEXT: ${{.*}} = 4
+
+struct Empty {};
+
+struct OverlappingBase {
+  [[no_unique_address]] Empty e;
+};
+static_assert(sizeof(OverlappingBase) == 1);
+static_assert(alignof(OverlappingBase) == 1);
+
+struct Base {
+  int mem;
+};
+
+struct OverlappingDerived : Base, OverlappingBase {};
+static_assert(alignof(OverlappingDerived) == 4);
+static_assert(sizeof(OverlappingDerived) == 4);
+
+int main() { OverlappingDerived d; }
diff --git a/lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp
new file mode 100644
index 0..a15e88f0b65df
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp
@@ -0,0 +1,41 @@
+// XFAIL: *
+//
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(base)" \
+// RUN:   -o "expr alignof(packed_base)" \
+// RUN:   -o "expr alignof(derived)" \
+// RUN:   -o "expr sizeof(derived)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(base)
+// CHECK-NEXT: ${{.*}} = 4
+// CHECK:  (lldb) expr alignof(packed_base)
+// CHECK-NEXT: ${{.*}} = 1
+// CHECK:  (lldb) expr alignof(derived)
+// CHECK-NEXT: ${{.*}} = 2
+// CHECK:  (lldb) expr sizeof(derived)
+// CHECK-NEXT: ${{.*}} = 16
+
+struct __attribute__((packed)) packed {
+  int x;
+  char y;
+  int z;
+} g_packed_struct;
+
+// LLDB incorrectly calculates alignof(base)
+struct foo {};
+struct base : foo { int x; };
+static_assert(alignof(base) == 4);
+
+// LLDB incorrectly calculates alignof(packed_base)
+struct __attribute__((packed)) packed_base { int x; };
+static_assert(alignof(packed_base) == 1);
+
+struct derived : packed, packed_base {
+  short s;
+} g_derived;
+static_assert(alignof(derived) == 2);
+static_assert(sizeof(derived) == 16);
+
+int main() {}
diff --git a/lldb/test/Shell/SymbolFile/DWARF/packed.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
index 640a2e0454c92..135808f46d7ea 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
@@ -4,6 +4,8 @@
 // RUN:   -o "expr sizeof(packed)" \
 // RUN:   -o "expr alignof(packed_and_aligned)" \
 // RUN:   -o "expr sizeof(packed_and_aligned)" \
+// RUN:   -o "expr alignof(derived)" \
+// 

[Lldb-commits] [lldb] [lldb][test] Add tests for alignof on class with overlapping bases (PR #97068)

2024-06-28 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

Follow-up to https://github.com/llvm/llvm-project/pull/96932

Adds XFAILed test where LLDB incorrectly infers the alignment of a derived 
class whose bases are overlapping due to [[no_unique_address]]. Specifically, 
the `InferAlignment` code-path of the `ItaniumRecordLayoutBuilder` assumes that 
overlapping base offsets imply a packed structure and thus sets alignment to 1. 
See discussion in https://github.com/llvm/llvm-project/pull/93809.

Also adds test where LLDB correctly infers an alignment of `1` when a packed 
base class is overlapping with other bases.

Lastly, there were a couple of `alignof` inconsistencies which I encapsulated 
in an XFAIL-ed `packed-alignof.cpp`.

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


3 Files Affected:

- (added) lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp 
(+30) 
- (added) lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp (+41) 
- (modified) lldb/test/Shell/SymbolFile/DWARF/packed.cpp (+14) 


``diff
diff --git 
a/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp
new file mode 100644
index 0..634d461e6ff19
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp
@@ -0,0 +1,30 @@
+// XFAIL: *
+
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(OverlappingDerived)" \
+// RUN:   -o "expr sizeof(OverlappingDerived)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(OverlappingDerived)
+// CHECK-NEXT: ${{.*}} = 4
+// CHECK:  (lldb) expr sizeof(OverlappingDerived)
+// CHECK-NEXT: ${{.*}} = 4
+
+struct Empty {};
+
+struct OverlappingBase {
+  [[no_unique_address]] Empty e;
+};
+static_assert(sizeof(OverlappingBase) == 1);
+static_assert(alignof(OverlappingBase) == 1);
+
+struct Base {
+  int mem;
+};
+
+struct OverlappingDerived : Base, OverlappingBase {};
+static_assert(alignof(OverlappingDerived) == 4);
+static_assert(sizeof(OverlappingDerived) == 4);
+
+int main() { OverlappingDerived d; }
diff --git a/lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp
new file mode 100644
index 0..a15e88f0b65df
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp
@@ -0,0 +1,41 @@
+// XFAIL: *
+//
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(base)" \
+// RUN:   -o "expr alignof(packed_base)" \
+// RUN:   -o "expr alignof(derived)" \
+// RUN:   -o "expr sizeof(derived)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(base)
+// CHECK-NEXT: ${{.*}} = 4
+// CHECK:  (lldb) expr alignof(packed_base)
+// CHECK-NEXT: ${{.*}} = 1
+// CHECK:  (lldb) expr alignof(derived)
+// CHECK-NEXT: ${{.*}} = 2
+// CHECK:  (lldb) expr sizeof(derived)
+// CHECK-NEXT: ${{.*}} = 16
+
+struct __attribute__((packed)) packed {
+  int x;
+  char y;
+  int z;
+} g_packed_struct;
+
+// LLDB incorrectly calculates alignof(base)
+struct foo {};
+struct base : foo { int x; };
+static_assert(alignof(base) == 4);
+
+// LLDB incorrectly calculates alignof(packed_base)
+struct __attribute__((packed)) packed_base { int x; };
+static_assert(alignof(packed_base) == 1);
+
+struct derived : packed, packed_base {
+  short s;
+} g_derived;
+static_assert(alignof(derived) == 2);
+static_assert(sizeof(derived) == 16);
+
+int main() {}
diff --git a/lldb/test/Shell/SymbolFile/DWARF/packed.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
index 640a2e0454c92..135808f46d7ea 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
@@ -4,6 +4,8 @@
 // RUN:   -o "expr sizeof(packed)" \
 // RUN:   -o "expr alignof(packed_and_aligned)" \
 // RUN:   -o "expr sizeof(packed_and_aligned)" \
+// RUN:   -o "expr alignof(derived)" \
+// RUN:   -o "expr sizeof(derived)" \
 // RUN:   -o exit | FileCheck %s
 
 // CHECK:  (lldb) expr alignof(packed)
@@ -16,6 +18,11 @@
 // CHECK:  (lldb) expr sizeof(packed_and_aligned)
 // CHECK-NEXT: ${{.*}} = 16
 
+// CHECK:  (lldb) expr alignof(derived)
+// CHECK-NEXT: ${{.*}} = 1
+// CHECK:  (lldb) expr sizeof(derived)
+// CHECK-NEXT: ${{.*}} = 13
+
 struct __attribute__((packed)) packed {
   int x;
   char y;
@@ -32,4 +39,11 @@ struct __attribute__((packed, aligned(16))) 
packed_and_aligned {
 static_assert(alignof(packed_and_aligned) == 16);
 static_assert(sizeof(packed_and_aligned) == 16);
 
+struct __attribute__((packed)) packed_base { int x; };
+static_assert(alignof(packed_base) == 1);
+
+struct derived : packed, packed_base {} g_derived;
+static_assert(alignof(derived) == 1);
+static_assert(sizeof(derived) == 13);
+
 int main() {}

``




https://github.com/llvm/llvm-project/pull/97068
__

[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)

2024-06-28 Thread Santhosh Kumar Ellendula via lldb-commits

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


[Lldb-commits] [lldb] a52be0c - [lldb-dap] Added "port" property to vscode "attach" command. (#91570)

2024-06-28 Thread via lldb-commits

Author: Santhosh Kumar Ellendula
Date: 2024-06-28T10:20:50-05:00
New Revision: a52be0cc114cc58a35bee65c517adaeb66ee6d89

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

LOG: [lldb-dap] Added "port" property to vscode "attach" command. (#91570)

Adding a "port" property to the VsCode "attach" command likely extends
the functionality of the debugger configuration to allow attaching to a
process using PID or PORT number.
Currently, the "Attach" configuration lets the user specify a pid. We
tell the user to use the attachCommands property to run "gdb-remote ".
Followed the below conditions for "attach" command with "port" and "pid"
We should add a "port" property. If port is specified and pid is not,
use that port to attach. If both port and pid are specified, return an
error saying that the user can't specify both pid and port.

Ex - launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "lldb-dap Debug",
"type": "lldb-dap",
"request": "attach",
"gdb-remote-port":1234,
"program": "${workspaceFolder}/a.out",
"args": [],
"stopOnEntry": false,
"cwd": "${workspaceFolder}",
"env": [],

}
]
}

-

Co-authored-by: Santhosh Kumar Ellendula 
Co-authored-by: Santhosh Kumar Ellendula 

Added: 
lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py

Modified: 
lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
lldb/test/API/tools/lldb-server/commandline/TestGdbRemoteConnection.py
lldb/tools/lldb-dap/lldb-dap.cpp
lldb/tools/lldb-dap/package.json

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index a9eeec1840990..a324af57b61df 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -574,6 +574,8 @@ def request_attach(
 coreFile=None,
 postRunCommands=None,
 sourceMap=None,
+gdbRemotePort=None,
+gdbRemoteHostname=None,
 ):
 args_dict = {}
 if pid is not None:
@@ -603,6 +605,10 @@ def request_attach(
 args_dict["postRunCommands"] = postRunCommands
 if sourceMap:
 args_dict["sourceMap"] = sourceMap
+if gdbRemotePort is not None:
+args_dict["gdb-remote-port"] = gdbRemotePort
+if gdbRemoteHostname is not None:
+args_dict["gdb-remote-hostname"] = gdbRemoteHostname
 command_dict = {"command": "attach", "type": "request", "arguments": 
args_dict}
 return self.send_recv(command_dict)
 

diff  --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index 600dc2b5fe9bb..a312a88ebd7e5 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -3,6 +3,8 @@
 
 import dap_server
 from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbplatformutil
+import lldbgdbserverutils
 
 
 class DAPTestCaseBase(TestBase):
@@ -299,6 +301,8 @@ def attach(
 sourceMap=None,
 sourceInitFile=False,
 expectFailure=False,
+gdbRemotePort=None,
+gdbRemoteHostname=None,
 ):
 """Build the default Makefile target, create the DAP debug adaptor,
 and attach to the process.
@@ -329,6 +333,8 @@ def cleanup():
 coreFile=coreFile,
 postRunCommands=postRunCommands,
 sourceMap=sourceMap,
+gdbRemotePort=gdbRemotePort,
+gdbRemoteHostname=gdbRemoteHostname,
 )
 if expectFailure:
 return response
@@ -485,3 +491,18 @@ def build_and_launch(
 launchCommands=launchCommands,
 expectFailure=expectFailure,
 )
+
+def getBuiltinDebugServerTool(self):
+# Tries to find simulation/lldb-server/gdbserver tool path.
+server_tool = None
+if lldbplatformutil.getPlatform() == "linux":
+server_tool = lldbgdbserverutils.get_lldb_server_exe()
+if server_tool is None:
+self.dap_server.request_disconnect(terminateDebuggee=True)
+self.assertIsNotNone(server_tool, "lldb-server not found.")
+elif lldbplatformutil.getPlatform() == "macosx":
+server_tool = lldbgdbserverutils.get_debugserver_exe()
+if server_tool is None:
+self.dap_server.request_disconnect(terminateDebuggee=True)
+  

[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)

2024-06-28 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] Add tests for alignof on class with overlapping bases (PR #97068)

2024-06-28 Thread David Blaikie via lldb-commits


@@ -0,0 +1,30 @@
+// XFAIL: *
+
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(OverlappingDerived)" \
+// RUN:   -o "expr sizeof(OverlappingDerived)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(OverlappingDerived)
+// CHECK-NEXT: ${{.*}} = 4

dwblaikie wrote:

Might be nice to put the checks next to the static_asserts?

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


[Lldb-commits] [lldb] In `statistics dump --summary`, add back the `targets` section (PR #97004)

2024-06-28 Thread via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] f65a52a - In `statistics dump --summary`, add back the `targets` section (#97004)

2024-06-28 Thread via lldb-commits

Author: royitaqi
Date: 2024-06-28T12:13:13-04:00
New Revision: f65a52ab0ec22cf5c25ccf3c9d86b7635964b864

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

LOG: In `statistics dump --summary`, add back the `targets` section (#97004)

# Change

https://github.com/llvm/llvm-project/pull/95075 accidentally removed the
`targets` section from `statistics dump --summary`. Adding it back, by
setting the default value to `true` in
`StatisticsOptions::GetIncludeTargets()`.

Updated the description for the options.
Updated tests.


# Verification

Manually verified the fix by running `statist dump --summary` and
comparing three versions of LLDB (in commit order):
1. Before https://github.com/llvm/llvm-project/pull/95075
2. After https://github.com/llvm/llvm-project/pull/95075
3. After this fix

The expected result is that 1 and 3 give the same sections, while 2 is
missing the `targets` section when in summary mode. The output (see
Appendix) matches the expectation.


# Appendix: Manual Test Output

## `statistics dump --summary` of 1

```
(lldb) statistics dump --summary
{
  "memory": {
"strings": {
  "bytesTotal": 724992,
  "bytesUnused": 714547,
  "bytesUsed": 10445
}
  },
  "targets": [
{
  "sourceMapDeduceCount": 0,
  "totalSharedLibraryEventHitCount": 0
}
  ],
  "totalDebugInfoByteSize": 597,
  "totalDebugInfoEnabled": 1,
  "totalDebugInfoIndexLoadedFromCache": 0,
  "totalDebugInfoIndexSavedToCache": 0,
  "totalDebugInfoIndexTime": 0.00070695,
  "totalDebugInfoParseTime": 2.5998e-05,
  "totalModuleCount": 1,
  "totalModuleCountHasDebugInfo": 1,
  "totalModuleCountWithIncompleteTypes": 0,
  "totalModuleCountWithVariableErrors": 0,
  "totalSymbolTableIndexTime": 0.000223,
  "totalSymbolTableParseTime": 0.00025798,
  "totalSymbolTableStripped": 0,
  "totalSymbolTablesLoadedFromCache": 0,
  "totalSymbolTablesSavedToCache": 0
}
(lldb)
```

## `statistics dump --summary` of 3

Should be the same as above.

```
(lldb) statistics dump --summary
{
  "memory": {
"strings": {
  "bytesTotal": 516096,
  "bytesUnused": 510353,
  "bytesUsed": 5743
}
  },
  "targets": [
{
  "sourceMapDeduceCount": 0,
  "totalSharedLibraryEventHitCount": 0
}
  ],
  "totalDebugInfoByteSize": 597,
  "totalDebugInfoEnabled": 1,
  "totalDebugInfoIndexLoadedFromCache": 0,
  "totalDebugInfoIndexSavedToCache": 0,
  "totalDebugInfoIndexTime": 0.0022138,
  "totalDebugInfoParseTime": 0.00031701,
  "totalModuleCount": 1,
  "totalModuleCountHasDebugInfo": 1,
  "totalModuleCountWithIncompleteTypes": 0,
  "totalModuleCountWithVariableErrors": 0,
  "totalSymbolTableIndexTime": 0.0014499,
  "totalSymbolTableParseTime": 0.001848,
  "totalSymbolTableStripped": 0,
  "totalSymbolTablesLoadedFromCache": 0,
  "totalSymbolTablesSavedToCache": 0
}
(lldb)
```

## `statistics dump --summary` of 2

Should be missing the `targets` section.

```
(lldb) statistics dump --summary
{
  "memory": {
"strings": {
  "bytesTotal": 716800,
  "bytesUnused": 705887,
  "bytesUsed": 10913
}
  },
  "totalDebugInfoByteSize": 597,
  "totalDebugInfoEnabled": 1,
  "totalDebugInfoIndexLoadedFromCache": 0,
  "totalDebugInfoIndexSavedToCache": 0,
  "totalDebugInfoIndexTime": 0.001374,
  "totalDebugInfoParseTime": 0.000174,
  "totalModuleCount": 1,
  "totalModuleCountHasDebugInfo": 1,
  "totalModuleCountWithIncompleteTypes": 0,
  "totalModuleCountWithVariableErrors": 0,
  "totalSymbolTableIndexTime": 0.00068301,
  "totalSymbolTableParseTime": 0.0010139,
  "totalSymbolTableStripped": 0,
  "totalSymbolTablesLoadedFromCache": 0,
  "totalSymbolTablesSavedToCache": 0
}
(lldb)
```

Co-authored-by: royshi 

Added: 


Modified: 
lldb/include/lldb/Target/Statistics.h
lldb/source/Commands/Options.td
lldb/test/API/commands/statistics/basic/TestStats.py

Removed: 




diff  --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index 122eb3ddd711f..35bd7f8a66e05 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -144,9 +144,8 @@ struct StatisticsOptions {
   bool GetIncludeTargets() const {
 if (m_include_targets.has_value())
   return m_include_targets.value();
-// `m_include_targets` has no value set, so return a value based on
-// `m_summary_only`.
-return !GetSummaryOnly();
+// Default to true in both default mode and summary mode.
+return true;
   }
 
   void SetIncludeModules(bool value) { m_include_modules = value; }

diff  --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index ba256e5ab917a..fa8af7cb3d762 100644
--- a/lldb/source/Commands/Options.td
+

[Lldb-commits] [lldb] In `statistics dump --summary`, add back the `targets` section (PR #97004)

2024-06-28 Thread via lldb-commits

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


[Lldb-commits] [lldb] f0bffb1 - Fix the test to deal with non-deterministic output. (#96800)

2024-06-28 Thread via lldb-commits

Author: Greg Clayton
Date: 2024-06-28T09:44:11-07:00
New Revision: f0bffb15b26e65436fa6cf4de12aa85ad0566efa

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

LOG: Fix the test to deal with non-deterministic output. (#96800)

When we check for the "struct CustomType" in the NODWP, we can just make
sure that we have both types showing up, the next tests will validate
the types are correct. Also added a "-DAG" to the integer and float
types. This should fix the flakiness in this test.

Added: 


Modified: 
lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp

Removed: 




diff  --git a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
index 8dd5a5472ed4c..4df1b33dd7d91 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
@@ -30,24 +30,14 @@
 // RUN:   -o "type lookup CustomType" \
 // RUN:   -b %t | FileCheck %s --check-prefix=NODWP
 // NODWP: (lldb) type lookup IntegerType
-// NODWP-NEXT: int
-// NODWP-NEXT: unsigned int
+// NODWP-DAG: int
+// NODWP-DAG: unsigned int
 // NODWP: (lldb) type lookup FloatType
-// NODWP-NEXT: double
-// NODWP-NEXT: float
+// NODWP-DAG: double
+// NODWP-DAG: float
 // NODWP: (lldb) type lookup CustomType
-// NODWP-NEXT: struct CustomType {
-// NODWP-NEXT: typedef int IntegerType;
-// NODWP-NEXT: typedef double FloatType;
-// NODWP-NEXT: CustomType::IntegerType x;
-// NODWP-NEXT: CustomType::FloatType y;
-// NODWP-NEXT: }
-// NODWP-NEXT: struct CustomType {
-// NODWP-NEXT: typedef unsigned int IntegerType;
-// NODWP-NEXT: typedef float FloatType;
-// NODWP-NEXT: CustomType::IntegerType x;
-// NODWP-NEXT: CustomType::FloatType y;
-// NODWP-NEXT: }
+// NODWP: struct CustomType {
+// NODWP: struct CustomType {
 
 // Check when we make the .dwp file with %t.main.dwo first so it will
 // pick the type unit from %t.main.dwo. Verify we find only the types from



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


[Lldb-commits] [lldb] Fix the test to deal with non-deterministic output. (PR #96800)

2024-06-28 Thread Greg Clayton via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Parse and display register field enums (PR #95768)

2024-06-28 Thread Alex Langford via lldb-commits


@@ -4179,21 +4179,124 @@ struct GdbServerTargetInfo {
   RegisterSetMap reg_set_map;
 };
 
-static std::vector ParseFlagsFields(XMLNode flags_node,
-  unsigned size) {
+static FieldEnum::Enumerators ParseEnumEvalues(const XMLNode &enum_node) {
+  Log *log(GetLog(GDBRLog::Process));
+  // We will use the last instance of each value. Also we preserve the order
+  // of declaration in the XML, as it may not be numerical.
+  std::map enumerators;

bulbazord wrote:

That's fair, was mostly asking to get an idea of what one can expect the data 
to look like. std::map is a fine choice here :)

https://github.com/llvm/llvm-project/pull/95768
___
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-06-28 Thread Michael Buch via lldb-commits

Michael137 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

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] [LLDB] DebugInfoD tests: attempt to fix Fuchsia build (PR #96802)

2024-06-28 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei updated 
https://github.com/llvm/llvm-project/pull/96802

>From 95832768ffb3b115e95df19ae5ef14231cad32cc Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Mon, 25 Mar 2024 08:23:47 -0700
Subject: [PATCH 01/13] Trying to deal with Linux AArch64 test failures :/

---
 .../SymbolVendor/ELF/SymbolVendorELF.cpp  |  18 ++
 .../API/debuginfod/Normal/TestDebuginfod.py   | 187 +
 .../SplitDWARF/TestDebuginfodDWP.py   | 196 ++
 3 files changed, 401 insertions(+)
 create mode 100644 lldb/test/API/debuginfod/Normal/TestDebuginfod.py
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py

diff --git a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp 
b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
index b5fe35d71032a..a881218a56cef 100644
--- a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
+++ b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
@@ -44,6 +44,24 @@ llvm::StringRef 
SymbolVendorELF::GetPluginDescriptionStatic() {
  "executables.";
 }
 
+// If this is needed elsewhere, it can be exported/moved.
+static bool IsDwpSymbolFile(const lldb::ModuleSP &module_sp,
+const FileSpec &file_spec) {
+  DataBufferSP dwp_file_data_sp;
+  lldb::offset_t dwp_file_data_offset = 0;
+  // Try to create an ObjectFile from the file_spec.
+  ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
+  module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
+  dwp_file_data_sp, dwp_file_data_offset);
+  // The presence of a debug_cu_index section is the key identifying feature of
+  // a DWP file. Make sure we don't fill in the section list on dwp_obj_file
+  // (by calling GetSectionList(false)) as this is invoked before we may have
+  // all the symbol files collected and available.
+  return dwp_obj_file && ObjectFileELF::classof(dwp_obj_file.get()) &&
+ dwp_obj_file->GetSectionList(false)->FindSectionByType(
+ eSectionTypeDWARFDebugCuIndex, false);
+}
+
 // CreateInstance
 //
 // Platforms can register a callback to use when creating symbol vendors to
diff --git a/lldb/test/API/debuginfod/Normal/TestDebuginfod.py 
b/lldb/test/API/debuginfod/Normal/TestDebuginfod.py
new file mode 100644
index 0..a662fb9fc6e68
--- /dev/null
+++ b/lldb/test/API/debuginfod/Normal/TestDebuginfod.py
@@ -0,0 +1,187 @@
+import os
+import shutil
+import tempfile
+import struct
+
+import lldb
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+def getUUID(aoutuuid):
+"""
+Pull the 20 byte UUID out of the .note.gnu.build-id section that was dumped
+to a file already, as part of the build.
+"""
+with open(aoutuuid, "rb") as f:
+data = f.read(36)
+if len(data) != 36:
+return None
+header = struct.unpack_from("<4I", data)
+if len(header) != 4:
+return None
+# 4 element 'prefix', 20 bytes of uuid, 3 byte long string: 'GNU':
+if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 
0x554E47:
+return None
+return data[16:].hex()
+
+
+"""
+Test support for the DebugInfoD network symbol acquisition protocol.
+This one is for simple / no split-dwarf scenarios.
+
+For no-split-dwarf scenarios, there are 2 variations:
+1 - A stripped binary with it's corresponding unstripped binary:
+2 - A stripped binary with a corresponding --only-keep-debug symbols file
+"""
+
+
+@skipUnlessPlatform(["linux", "freebsd"])
+class DebugInfodTests(TestBase):
+# No need to try every flavor of debug inf.
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_normal_no_symbols(self):
+"""
+Validate behavior with no symbols or symbol locator.
+('baseline negative' behavior)
+"""
+test_root = self.config_test(["a.out"])
+self.try_breakpoint(False)
+
+def test_normal_default(self):
+"""
+Validate behavior with symbols, but no symbol locator.
+('baseline positive' behavior)
+"""
+test_root = self.config_test(["a.out", "a.out.debug"])
+self.try_breakpoint(True)
+
+def test_debuginfod_symbols(self):
+"""
+Test behavior with the full binary available from Debuginfod as
+'debuginfo' from the plug-in.
+"""
+test_root = self.config_test(["a.out"], "a.out.full")
+self.try_breakpoint(True)
+
+def test_debuginfod_executable(self):
+"""
+Test behavior with the full binary available from Debuginfod as
+'executable' from the plug-in.
+"""
+test_root = self.config_test(["a.out"], None, "a.out.full")
+self.try_breakpoint(True)
+
+def test_debuginfod_okd_symbols(self):
+"""
+Test behavior with the 'only-keep-debug' symbols available from 
Debuginfod.
+"""
+  

[Lldb-commits] [lldb] [lldb][test] Add tests for alignof on class with overlapping bases (PR #97068)

2024-06-28 Thread Michael Buch via lldb-commits

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

>From 1c924c866cc2de5e9e1d84ce0b185e9dacefd4ec Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 28 Jun 2024 15:29:54 +0100
Subject: [PATCH 1/2] [lldb][test] Add tests for alignof on class with
 overlapping bases

Follow-up to https://github.com/llvm/llvm-project/pull/96932

Adds XFAILed test where LLDB incorrectly infers the
alignment of a derived class whose bases are overlapping
due to [[no_unique_address]]. Specifically, the `InferAlignment`
code-path of the `ItaniumRecordLayoutBuilder` assumes that overlapping
base offsets imply a packed structure and thus sets alignment
to 1. See discussion in https://github.com/llvm/llvm-project/pull/93809.

Also adds test where LLDB correctly infers an alignment
of `1` when a packed base class is overlapping with other bases.

Lastly, there were a couple of `alignof` inconsistencies which
I encapsulated in an XFAIL-ed `packed-alignof.cpp`.
---
 .../no_unique_address-base-alignment.cpp  | 30 ++
 .../Shell/SymbolFile/DWARF/packed-alignof.cpp | 41 +++
 lldb/test/Shell/SymbolFile/DWARF/packed.cpp   | 14 +++
 3 files changed, 85 insertions(+)
 create mode 100644 
lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp
 create mode 100644 lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp

diff --git 
a/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp
new file mode 100644
index 0..634d461e6ff19
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp
@@ -0,0 +1,30 @@
+// XFAIL: *
+
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(OverlappingDerived)" \
+// RUN:   -o "expr sizeof(OverlappingDerived)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(OverlappingDerived)
+// CHECK-NEXT: ${{.*}} = 4
+// CHECK:  (lldb) expr sizeof(OverlappingDerived)
+// CHECK-NEXT: ${{.*}} = 4
+
+struct Empty {};
+
+struct OverlappingBase {
+  [[no_unique_address]] Empty e;
+};
+static_assert(sizeof(OverlappingBase) == 1);
+static_assert(alignof(OverlappingBase) == 1);
+
+struct Base {
+  int mem;
+};
+
+struct OverlappingDerived : Base, OverlappingBase {};
+static_assert(alignof(OverlappingDerived) == 4);
+static_assert(sizeof(OverlappingDerived) == 4);
+
+int main() { OverlappingDerived d; }
diff --git a/lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp
new file mode 100644
index 0..a15e88f0b65df
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/packed-alignof.cpp
@@ -0,0 +1,41 @@
+// XFAIL: *
+//
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(base)" \
+// RUN:   -o "expr alignof(packed_base)" \
+// RUN:   -o "expr alignof(derived)" \
+// RUN:   -o "expr sizeof(derived)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(base)
+// CHECK-NEXT: ${{.*}} = 4
+// CHECK:  (lldb) expr alignof(packed_base)
+// CHECK-NEXT: ${{.*}} = 1
+// CHECK:  (lldb) expr alignof(derived)
+// CHECK-NEXT: ${{.*}} = 2
+// CHECK:  (lldb) expr sizeof(derived)
+// CHECK-NEXT: ${{.*}} = 16
+
+struct __attribute__((packed)) packed {
+  int x;
+  char y;
+  int z;
+} g_packed_struct;
+
+// LLDB incorrectly calculates alignof(base)
+struct foo {};
+struct base : foo { int x; };
+static_assert(alignof(base) == 4);
+
+// LLDB incorrectly calculates alignof(packed_base)
+struct __attribute__((packed)) packed_base { int x; };
+static_assert(alignof(packed_base) == 1);
+
+struct derived : packed, packed_base {
+  short s;
+} g_derived;
+static_assert(alignof(derived) == 2);
+static_assert(sizeof(derived) == 16);
+
+int main() {}
diff --git a/lldb/test/Shell/SymbolFile/DWARF/packed.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
index 640a2e0454c92..135808f46d7ea 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/packed.cpp
@@ -4,6 +4,8 @@
 // RUN:   -o "expr sizeof(packed)" \
 // RUN:   -o "expr alignof(packed_and_aligned)" \
 // RUN:   -o "expr sizeof(packed_and_aligned)" \
+// RUN:   -o "expr alignof(derived)" \
+// RUN:   -o "expr sizeof(derived)" \
 // RUN:   -o exit | FileCheck %s
 
 // CHECK:  (lldb) expr alignof(packed)
@@ -16,6 +18,11 @@
 // CHECK:  (lldb) expr sizeof(packed_and_aligned)
 // CHECK-NEXT: ${{.*}} = 16
 
+// CHECK:  (lldb) expr alignof(derived)
+// CHECK-NEXT: ${{.*}} = 1
+// CHECK:  (lldb) expr sizeof(derived)
+// CHECK-NEXT: ${{.*}} = 13
+
 struct __attribute__((packed)) packed {
   int x;
   char y;
@@ -32,4 +39,11 @@ struct __attribute__((packed, aligned(16))) 
packed_and_aligned {
 static_assert(alignof(packed_and_aligned) == 16);
 static_assert(sizeof(packed_and_aligned) == 16);
 
+struct __attribute__((packed)) packed_base { int x; };
+static_a

[Lldb-commits] [lldb] [lldb][test] Add tests for alignof on class with overlapping bases (PR #97068)

2024-06-28 Thread Michael Buch via lldb-commits


@@ -0,0 +1,30 @@
+// XFAIL: *
+
+// RUN: %clangxx_host -gdwarf -o %t %s
+// RUN: %lldb %t \
+// RUN:   -o "expr alignof(OverlappingDerived)" \
+// RUN:   -o "expr sizeof(OverlappingDerived)" \
+// RUN:   -o exit | FileCheck %s
+
+// CHECK:  (lldb) expr alignof(OverlappingDerived)
+// CHECK-NEXT: ${{.*}} = 4

Michael137 wrote:

good point, done

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


[Lldb-commits] [lldb] [lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (PR #96985)

2024-06-28 Thread Med Ismail Bennani via lldb-commits


@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << const_cast(stream).GetData();

medismailben wrote:

Looks like it broke the windows bot: 
https://lab.llvm.org/buildbot/#/builders/141/builds/369

@nico Thanks to the revert, I think I have a fix for this.

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


[Lldb-commits] [lldb] [lldb] Parse and display register field enums (PR #95768)

2024-06-28 Thread Chelsea Cassanova via lldb-commits

chelcassanova wrote:

Hey David! It looks like this commit broke the `TestXMLRegisterFlags.py` test 
on macOS sanitized buildbots: 
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake-sanitized/425/console

https://github.com/llvm/llvm-project/pull/95768
___
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-06-28 Thread Med Ismail Bennani via lldb-commits

medismailben 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

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] Reland "[lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (#96985)" (PR #97092)

2024-06-28 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben created 
https://github.com/llvm/llvm-project/pull/97092

This reverts commit a2e3af5d581547d3ea53e5383d6f7f1cab45120a and solves the 
build error in https://lab.llvm.org/buildbot/#/builders/141/builds/369.

>From dfb2b17c32a22b970f8d4fbadc3ddb07a219e992 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Fri, 28 Jun 2024 11:15:50 -0700
Subject: [PATCH] Revert "Revert "[lldb/Interpreter] Discard
 ScriptedThreadPlan::GetStopDescription return value (#96985)""

This reverts commit a2e3af5d581547d3ea53e5383d6f7f1cab45120a and solves
the build error in https://lab.llvm.org/buildbot/#/builders/141/builds/369.

Signed-off-by: Med Ismail Bennani 
---
 .../Interfaces/ScriptedThreadPlanInterface.h |  4 ++--
 lldb/include/lldb/Interpreter/ScriptInterpreter.h|  2 +-
 lldb/include/lldb/Utility/StreamString.h |  4 
 lldb/source/Interpreter/ScriptInterpreter.cpp|  9 ++---
 .../Python/Interfaces/ScriptedPythonInterface.cpp| 12 ++--
 .../Python/Interfaces/ScriptedPythonInterface.h  |  7 ---
 .../Interfaces/ScriptedThreadPlanPythonInterface.cpp |  8 
 .../Interfaces/ScriptedThreadPlanPythonInterface.h   |  2 +-
 lldb/source/Target/ThreadPlanPython.cpp  | 11 +++
 .../step_scripted/TestStepScripted.py|  5 +
 10 files changed, 32 insertions(+), 32 deletions(-)

diff --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
index 9130f9412cb0b..ee634d15f2a9e 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
@@ -29,8 +29,8 @@ class ScriptedThreadPlanInterface : public ScriptedInterface {
 
   virtual lldb::StateType GetRunState() { return lldb::eStateStepping; }
 
-  virtual llvm::Expected GetStopDescription(lldb_private::Stream *s) {
-return true;
+  virtual llvm::Error GetStopDescription(lldb::StreamSP &stream) {
+return llvm::Error::success();
   }
 };
 } // namespace lldb_private
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index e821a7db2c674..14a52709c1e61 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -575,7 +575,7 @@ class ScriptInterpreter : public PluginInterface {
 
   Event *GetOpaqueTypeFromSBEvent(const lldb::SBEvent &event) const;
 
-  Stream *GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
+  lldb::StreamSP GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
 
   lldb::BreakpointSP
   GetOpaqueTypeFromSBBreakpoint(const lldb::SBBreakpoint &breakpoint) const;
diff --git a/lldb/include/lldb/Utility/StreamString.h 
b/lldb/include/lldb/Utility/StreamString.h
index 3d675caf8f3f4..3287f328a1be3 100644
--- a/lldb/include/lldb/Utility/StreamString.h
+++ b/lldb/include/lldb/Utility/StreamString.h
@@ -20,6 +20,8 @@
 
 namespace lldb_private {
 
+class ScriptInterpreter;
+
 class StreamString : public Stream {
 public:
   StreamString(bool colors = false);
@@ -45,6 +47,8 @@ class StreamString : public Stream {
   void FillLastLineToColumn(uint32_t column, char fill_char);
 
 protected:
+  friend class ScriptInterpreter;
+
   std::string m_packet;
   size_t WriteImpl(const void *s, size_t length) override;
 };
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 75b2a39a8d11b..fa23964a52ffe 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << reinterpret_cast(stream.m_opaque_up.get())->m_packet;
+return s;
+  }
 
   return nullptr;
 }
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
index 7d072212676e1..699412e437a1a 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
@@ -26,15 +26,6 @@ ScriptedPythonInterface::ScriptedPythonInterface(
 ScriptInterpreterPythonImpl &interpreter)
 : ScriptedInterface(), m_interpreter(interpreter) {}
 
-template <>
-void ScriptedPythonInterface::ReverseTransform(
-lldb_private::Stream *&original_arg, python::PythonObjec

[Lldb-commits] [lldb] Reland "[lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (#96985)" (PR #97092)

2024-06-28 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Med Ismail Bennani (medismailben)


Changes

This reverts commit a2e3af5d581547d3ea53e5383d6f7f1cab45120a and solves the 
build error in https://lab.llvm.org/buildbot/#/builders/141/builds/369.

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


10 Files Affected:

- (modified) 
lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h (+2-2) 
- (modified) lldb/include/lldb/Interpreter/ScriptInterpreter.h (+1-1) 
- (modified) lldb/include/lldb/Utility/StreamString.h (+4) 
- (modified) lldb/source/Interpreter/ScriptInterpreter.cpp (+6-3) 
- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
 (+2-10) 
- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
 (+4-3) 
- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp
 (+4-4) 
- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h
 (+1-1) 
- (modified) lldb/source/Target/ThreadPlanPython.cpp (+7-4) 
- (modified) lldb/test/API/functionalities/step_scripted/TestStepScripted.py 
(+1-4) 


``diff
diff --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
index 9130f9412cb0b..ee634d15f2a9e 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
@@ -29,8 +29,8 @@ class ScriptedThreadPlanInterface : public ScriptedInterface {
 
   virtual lldb::StateType GetRunState() { return lldb::eStateStepping; }
 
-  virtual llvm::Expected GetStopDescription(lldb_private::Stream *s) {
-return true;
+  virtual llvm::Error GetStopDescription(lldb::StreamSP &stream) {
+return llvm::Error::success();
   }
 };
 } // namespace lldb_private
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index e821a7db2c674..14a52709c1e61 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -575,7 +575,7 @@ class ScriptInterpreter : public PluginInterface {
 
   Event *GetOpaqueTypeFromSBEvent(const lldb::SBEvent &event) const;
 
-  Stream *GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
+  lldb::StreamSP GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
 
   lldb::BreakpointSP
   GetOpaqueTypeFromSBBreakpoint(const lldb::SBBreakpoint &breakpoint) const;
diff --git a/lldb/include/lldb/Utility/StreamString.h 
b/lldb/include/lldb/Utility/StreamString.h
index 3d675caf8f3f4..3287f328a1be3 100644
--- a/lldb/include/lldb/Utility/StreamString.h
+++ b/lldb/include/lldb/Utility/StreamString.h
@@ -20,6 +20,8 @@
 
 namespace lldb_private {
 
+class ScriptInterpreter;
+
 class StreamString : public Stream {
 public:
   StreamString(bool colors = false);
@@ -45,6 +47,8 @@ class StreamString : public Stream {
   void FillLastLineToColumn(uint32_t column, char fill_char);
 
 protected:
+  friend class ScriptInterpreter;
+
   std::string m_packet;
   size_t WriteImpl(const void *s, size_t length) override;
 };
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 75b2a39a8d11b..fa23964a52ffe 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << reinterpret_cast(stream.m_opaque_up.get())->m_packet;
+return s;
+  }
 
   return nullptr;
 }
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
index 7d072212676e1..699412e437a1a 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
@@ -26,15 +26,6 @@ ScriptedPythonInterface::ScriptedPythonInterface(
 ScriptInterpreterPythonImpl &interpreter)
 : ScriptedInterface(), m_interpreter(interpreter) {}
 
-template <>
-void ScriptedPythonInterface::ReverseTransform(
-lldb_private::Stream *&original_arg, python::PythonObject transformed_arg,
-Status &error) {
-  Stream *s = ExtractValueFromPythonObject(transformed_arg, error);
-  *original_arg = *s;
-  original_arg->PutCString(static_

[Lldb-commits] [lldb] [lldb] [ObjectFileMachO] BSS segments are loadable segments (PR #96983)

2024-06-28 Thread Jason Molenda via lldb-commits

jasonmolenda wrote:

I was about to add a macosx/ API test to compile a program with only BSS data 
in the DATA segment, and I noticed I'd written 
`TestBSSOnlyDataSectionSliding.py` last year when I opted sections named "DATA" 
out of this "don't set a load address for BSS-only segments" behavior in 
ObjectFileMachO.  This existing test is already covering the change I'm making 
in this PR.

https://github.com/llvm/llvm-project/pull/96983
___
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-06-28 Thread Jonas Devlieghere via lldb-commits

JDevlieghere 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. 

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] Reland "[lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (#96985)" (PR #97092)

2024-06-28 Thread via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] 6cb45ae - Reland "[lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (#96985)" (#97092)

2024-06-28 Thread via lldb-commits

Author: Med Ismail Bennani
Date: 2024-06-28T11:53:19-07:00
New Revision: 6cb45aea92dc87974a0064c182600228c6e94329

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

LOG: Reland "[lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription 
return value (#96985)" (#97092)

This reverts commit a2e3af5d581547d3ea53e5383d6f7f1cab45120a and solves
the build error in
https://lab.llvm.org/buildbot/#/builders/141/builds/369.

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
lldb/include/lldb/Interpreter/ScriptInterpreter.h
lldb/include/lldb/Utility/StreamString.h
lldb/source/Interpreter/ScriptInterpreter.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h
lldb/source/Target/ThreadPlanPython.cpp
lldb/test/API/functionalities/step_scripted/TestStepScripted.py

Removed: 




diff  --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
index 9130f9412cb0b..ee634d15f2a9e 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h
@@ -29,8 +29,8 @@ class ScriptedThreadPlanInterface : public ScriptedInterface {
 
   virtual lldb::StateType GetRunState() { return lldb::eStateStepping; }
 
-  virtual llvm::Expected GetStopDescription(lldb_private::Stream *s) {
-return true;
+  virtual llvm::Error GetStopDescription(lldb::StreamSP &stream) {
+return llvm::Error::success();
   }
 };
 } // namespace lldb_private

diff  --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index e821a7db2c674..14a52709c1e61 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -575,7 +575,7 @@ class ScriptInterpreter : public PluginInterface {
 
   Event *GetOpaqueTypeFromSBEvent(const lldb::SBEvent &event) const;
 
-  Stream *GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
+  lldb::StreamSP GetOpaqueTypeFromSBStream(const lldb::SBStream &stream) const;
 
   lldb::BreakpointSP
   GetOpaqueTypeFromSBBreakpoint(const lldb::SBBreakpoint &breakpoint) const;

diff  --git a/lldb/include/lldb/Utility/StreamString.h 
b/lldb/include/lldb/Utility/StreamString.h
index 3d675caf8f3f4..3287f328a1be3 100644
--- a/lldb/include/lldb/Utility/StreamString.h
+++ b/lldb/include/lldb/Utility/StreamString.h
@@ -20,6 +20,8 @@
 
 namespace lldb_private {
 
+class ScriptInterpreter;
+
 class StreamString : public Stream {
 public:
   StreamString(bool colors = false);
@@ -45,6 +47,8 @@ class StreamString : public Stream {
   void FillLastLineToColumn(uint32_t column, char fill_char);
 
 protected:
+  friend class ScriptInterpreter;
+
   std::string m_packet;
   size_t WriteImpl(const void *s, size_t length) override;
 };

diff  --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 75b2a39a8d11b..fa23964a52ffe 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -106,10 +106,13 @@ ScriptInterpreter::GetOpaqueTypeFromSBEvent(const 
lldb::SBEvent &event) const {
   return event.m_opaque_ptr;
 }
 
-Stream *ScriptInterpreter::GetOpaqueTypeFromSBStream(
+lldb::StreamSP ScriptInterpreter::GetOpaqueTypeFromSBStream(
 const lldb::SBStream &stream) const {
-  if (stream.m_opaque_up)
-return const_cast(stream).m_opaque_up.get();
+  if (stream.m_opaque_up) {
+lldb::StreamSP s = std::make_shared();
+*s << reinterpret_cast(stream.m_opaque_up.get())->m_packet;
+return s;
+  }
 
   return nullptr;
 }

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
index 7d072212676e1..699412e437a1a 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp
@@ -26,15 +26,6 @@ ScriptedPythonInterface::ScriptedPythonInterface(
 ScriptInterpreterPythonImpl &interpreter)
 : ScriptedInterface(), m_interpreter(interpreter) {}
 
-template <>
-void ScriptedPythonInterface::ReverseTransform(
-lldb_private::Stream

[Lldb-commits] [lldb] Reland "[lldb/Interpreter] Discard ScriptedThreadPlan::GetStopDescription return value (#96985)" (PR #97092)

2024-06-28 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben closed 
https://github.com/llvm/llvm-project/pull/97092
___
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-06-28 Thread Med Ismail Bennani via lldb-commits

medismailben 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.

I don't mind running as part of the test suite but I think it would be harder 
to integrate with it rather than running the script standalone as part of the 
CI. Also I think these categories of errors are more related to linting than 
actually test failures.

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] a4c1813 - [lldb][test] Remove duplicate testcase names in API test-suite (#97043)

2024-06-28 Thread via lldb-commits

Author: Michael Buch
Date: 2024-06-28T20:08:53+01:00
New Revision: a4c18137d84bc48df49ee0101bef465a955e62ac

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

LOG: [lldb][test] Remove duplicate testcase names in API test-suite (#97043)

In one of my recent PRs I mistakenly had two test-cases with the same
name, preventing one of them to run. Since it's an easy mistake to make
(e.g., copy pasting existing test-cases), I ran following sanity-check
script over `lldb/test/API`, which found couple of tests which were
losing coverage because of this (or in some cases simply had duplicate
tests):
```
import ast
import sys

filename = sys.argv[1]
print(f'Checking {filename}...')
tree = ast.parse(open(filename, 'r').read())

for node in ast.walk(tree):
if not isinstance(node, ast.ClassDef):
continue

func_names = []
for child in ast.iter_child_nodes(node):
if isinstance(child, ast.FunctionDef):
func_names.append(child.name)

seen_func_names = set()
duplicate_func_names = []
for name in func_names:
if name in seen_func_names:
duplicate_func_names.append(name)
else:
seen_func_names.add(name)

if len(duplicate_func_names) != 0:
print(f'Multiple func names found:\n\t{duplicate_func_names}\n\tclass 
{node.name}\n\tfile: {filename}')
```

This patch fixes these cases.

Added: 


Modified: 
lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py

lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
lldb/test/API/functionalities/completion/TestCompletion.py
lldb/test/API/functionalities/gdb_remote_client/TestIOSSimulator.py
lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py
lldb/test/API/lang/cpp/diamond/TestCppDiamond.py
lldb/test/API/lang/objcxx/cxx-bridged-po/TestObjCXXBridgedPO.py
lldb/test/API/lang/rust/enum-structs/TestRustEnumStructs.py
lldb/test/API/test_utils/TestDecorators.py

Removed: 




diff  --git a/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py 
b/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
index 583c68d7bfacc..dbcd2d60d021a 100644
--- a/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
+++ b/lldb/test/API/commands/log/invalid-args/TestInvalidArgsLog.py
@@ -25,7 +25,7 @@ def test_disable_empty(self):
 )
 
 @no_debug_info_test
-def test_enable_empty(self):
+def test_enable_invalid_path(self):
 invalid_path = os.path.join("this", "is", "not", "a", "valid", "path")
 self.expect(
 "log enable lldb all -f " + invalid_path,

diff  --git 
a/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py 
b/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
index 9678bd42999b3..571024417560f 100644
--- a/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
+++ b/lldb/test/API/commands/thread/backtrace/TestThreadBacktraceRepeat.py
@@ -16,8 +16,6 @@ def test_thread_backtrace_one_thread(self):
 """Run a simplified version of the test that just hits one breakpoint 
and
 doesn't care about synchronizing the two threads - hopefully this will
 run on more systems."""
-
-def test_thread_backtrace_one_thread(self):
 self.build()
 (
 self.inferior_target,

diff  --git 
a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
 
b/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
index c41e85fd670ba..12f99f07c78a8 100644
--- 
a/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
+++ 
b/lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py
@@ -31,43 +31,6 @@ def testStartMultipleLiveThreads(self):
 
 self.traceStopProcess()
 
-@skipIf(oslist=no_match(["linux"]), archs=no_match(["i386", "x86_64"]))
-@testSBAPIAndCommands
-def testStartMultipleLiveThreadsWithStops(self):
-self.build()
-exe = self.getBuildArtifact("a.out")
-
-self.dbg.CreateTarget(exe)
-
-self.expect("b main")
-self.expect("b 6")
-self.expect("b 11")
-
-self.expect("r")
-self.traceStartProcess()
-
-# We'll see here the first thread
-self.expect("continue")
-
-# We are in thread 2
-self.expect("thread trace dump instructions", substrs=["main.cpp:9"])
-self.expect("thread trace dump instructions 2", substrs=["main.cpp:9"])
-
-# We stop tracing it
-self.expect("thread trace stop 2")
-
-# The trace is still in memory
-

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

2024-06-28 Thread Michael Buch via lldb-commits

https://github.com/Michael137 closed 
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 flake in TestZerothFrame.py (PR #96685)

2024-06-28 Thread Kendal Harland via lldb-commits

https://github.com/kendalharland updated 
https://github.com/llvm/llvm-project/pull/96685

>From 1d2c11e18e833104279fa6a005e4a64bb7be6216 Mon Sep 17 00:00:00 2001
From: kendal 
Date: Mon, 24 Jun 2024 13:42:20 -0700
Subject: [PATCH] Fix flake in TestZerothFrame.py

This test is relying on the order of `process.threads` which is
nondeterministic. By selecting the thread based on whether it is
stopped at our breakpoint we can reliably select the correct one.
---
 .../unwind/zeroth_frame/TestZerothFrame.py| 23 ---
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git 
a/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py 
b/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py
index f4e883d314644..deb30669cc40e 100644
--- a/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py
+++ b/lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py
@@ -40,28 +40,24 @@ 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
-)
-lldbutil.run_break_set_by_file_and_line(
-self, "main.c", bp2_line, num_expected_locations=1
-)
+main_dot_c = lldb.SBFileSpec("main.c")
+bp1 = target.BreakpointCreateBySourceRegex("// Set breakpoint 1 here", 
main_dot_c)
+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 breakpoint.
 self.assertEqual(
-process.GetThreadAtIndex(0).frame[0].GetLineEntry().GetLine(),
-bp1_line,
+thread.frame[0].GetLineEntry().GetLine(),
+bp1.GetLocationAtIndex(0).GetAddress().GetLineEntry().GetLine(),
 "LLDB reported incorrect line number.",
 )
 
@@ -70,7 +66,6 @@ def test(self):
 # 'continue' command.
 process.Continue()
 
-thread = process.GetThreadAtIndex(0)
 if self.TraceOn():
 print("Backtrace at the second breakpoint:")
 for f in thread.frames:
@@ -78,7 +73,7 @@ def test(self):
 # Check that we have stopped at the breakpoint
 self.assertEqual(
 thread.frame[0].GetLineEntry().GetLine(),
-bp2_line,
+bp2.GetLocationAtIndex(0).GetAddress().GetLineEntry().GetLine(),
 "LLDB reported incorrect line number.",
 )
 # Double-check with GetPCAddress()

___
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-06-28 Thread Kendal Harland via lldb-commits

kendalharland wrote:

> This should be fine, although looking at the test case again, I think that 
> even simply replacing process.GetThreadAtIndex(0) with self.thread() should 
> be enough. self.thread() returns the "selected" thread and lldb should always 
> be selecting the thread which has stopped "for a reason" (e.g. a breakpoint) 
> and not a random (or first) thread in the process.

This also works. Agreed it's much better. Ty for the suggestion! Updated.

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-06-28 Thread Kendal Harland via lldb-commits

https://github.com/kendalharland edited 
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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,102 @@
+//===-- ThreadPlanSingleThreadTimeout.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+#define LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Utility/Event.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/State.h"
+
+#include 
+
+namespace lldb_private {
+
+//
+// Thread plan used by single thread execution to issue timeout. This is useful
+// to detect potential deadlock in single thread execution. The timeout 
measures
+// the elapsed time from the last internal stop and gets reset by each internal
+// stop to ensure we are accurately detecting execution not moving forward.
+// This means this thread plan may be created/destroyed multiple times by the
+// parent execution plan.
+//
+// When timeout happens, the thread plan resolves the potential deadlock by

jimingham wrote:

"When a timeout happens"

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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,102 @@
+//===-- ThreadPlanSingleThreadTimeout.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+#define LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Utility/Event.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/State.h"
+
+#include 
+
+namespace lldb_private {
+
+//
+// Thread plan used by single thread execution to issue timeout. This is useful
+// to detect potential deadlock in single thread execution. The timeout 
measures
+// the elapsed time from the last internal stop and gets reset by each internal
+// stop to ensure we are accurately detecting execution not moving forward.
+// This means this thread plan may be created/destroyed multiple times by the
+// parent execution plan.
+//
+// When timeout happens, the thread plan resolves the potential deadlock by
+// issuing a thread specific async interrupt to enter stop state, then all
+// threads execution are resumed to resolve the potential deadlock.

jimingham wrote:

"then execution is resumed with all threads running to resolve the potential 
deadlock"

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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,102 @@
+//===-- ThreadPlanSingleThreadTimeout.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+#define LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Utility/Event.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/State.h"
+
+#include 
+
+namespace lldb_private {
+
+//
+// Thread plan used by single thread execution to issue timeout. This is useful
+// to detect potential deadlock in single thread execution. The timeout 
measures
+// the elapsed time from the last internal stop and gets reset by each internal
+// stop to ensure we are accurately detecting execution not moving forward.
+// This means this thread plan may be created/destroyed multiple times by the
+// parent execution plan.
+//
+// When timeout happens, the thread plan resolves the potential deadlock by
+// issuing a thread specific async interrupt to enter stop state, then all
+// threads execution are resumed to resolve the potential deadlock.
+//
+class ThreadPlanSingleThreadTimeout : public ThreadPlan {
+  enum class State {
+WaitTimeout,// Waiting for timeout.
+AsyncInterrupt, // Async interrupt has been issued.
+Done,   // Finished resume all threads.
+  };
+
+public:
+  struct TimeoutInfo {

jimingham wrote:

This isn't something you need to do in this patch, but it would be good to 
allow different thread plan invocations to use different timeouts, and not just 
depend on the thread timeout.  For instance, we should be able to reimplement 
RunThreadPlan with this infrastructure.  But the timeouts you want for 
expression evaluation and stepping are likely to be very different (and 
different executions also use different timeouts).  So being able to pass in 
the timeout, rather than relying on one thread specific one will be necessary.  
We could for instance add the timeout to the TimeoutInfo and plumb that so that 
the ThreadPlan that mixes in TimeoutResumeAll can pass in a timeout.

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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,102 @@
+//===-- ThreadPlanSingleThreadTimeout.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+#define LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Utility/Event.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/State.h"
+
+#include 
+
+namespace lldb_private {
+
+//
+// Thread plan used by single thread execution to issue timeout. This is useful
+// to detect potential deadlock in single thread execution. The timeout 
measures
+// the elapsed time from the last internal stop and gets reset by each internal
+// stop to ensure we are accurately detecting execution not moving forward.
+// This means this thread plan may be created/destroyed multiple times by the
+// parent execution plan.
+//
+// When timeout happens, the thread plan resolves the potential deadlock by
+// issuing a thread specific async interrupt to enter stop state, then all
+// threads execution are resumed to resolve the potential deadlock.
+//
+class ThreadPlanSingleThreadTimeout : public ThreadPlan {
+  enum class State {
+WaitTimeout,// Waiting for timeout.
+AsyncInterrupt, // Async interrupt has been issued.
+Done,   // Finished resume all threads.
+  };
+
+public:
+  struct TimeoutInfo {
+ThreadPlanSingleThreadTimeout *m_instance = nullptr;
+ThreadPlanSingleThreadTimeout::State m_last_state = State::WaitTimeout;
+  };
+
+  ~ThreadPlanSingleThreadTimeout() override;
+
+  // If input \param thread is running in single thread mode, push a
+  // new ThreadPlanSingleThreadTimeout based on timeout setting from fresh new
+  // state. The reference of \param info is passed in so that when
+  // ThreadPlanSingleThreadTimeout got popped out its last state can be stored

jimingham wrote:

"popped out" is confusing.  We just say "popped" for the most part.


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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===-- ThreadPlanStepOverRange.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
+#include "lldb/Target/ThreadPlanStepThrough.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(Thread &thread,
+ TimeoutInfo &info)
+: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
+ thread, eVoteNo, eVoteNoOpinion),
+  m_info(info), m_state(State::WaitTimeout), m_exit_flag(false) {
+  m_timer_thread = std::thread(TimeoutThreadFunc, this);
+  m_info.m_instance = this;
+  m_state = m_info.m_last_state;
+}
+
+ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {
+  m_info.m_instance = nullptr;
+  if (m_state == State::Done)

jimingham wrote:

This seems like an odd thing to do in the destructor.  Why is this necessary?

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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===-- ThreadPlanStepOverRange.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
+#include "lldb/Target/ThreadPlanStepThrough.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(Thread &thread,
+ TimeoutInfo &info)
+: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
+ thread, eVoteNo, eVoteNoOpinion),
+  m_info(info), m_state(State::WaitTimeout), m_exit_flag(false) {
+  m_timer_thread = std::thread(TimeoutThreadFunc, this);
+  m_info.m_instance = this;
+  m_state = m_info.m_last_state;
+}
+
+ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {
+  m_info.m_instance = nullptr;
+  if (m_state == State::Done)
+m_state = State::WaitTimeout;
+}
+
+void ThreadPlanSingleThreadTimeout::GetDescription(
+Stream *s, lldb::DescriptionLevel level) {
+  s->Printf("Single thread timeout, state(%s)", 
StateToString(m_state).c_str());

jimingham wrote:

I think it would be super handy to print the time remaining here.

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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===-- ThreadPlanStepOverRange.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
+#include "lldb/Target/ThreadPlanStepThrough.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(Thread &thread,
+ TimeoutInfo &info)
+: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
+ thread, eVoteNo, eVoteNoOpinion),
+  m_info(info), m_state(State::WaitTimeout), m_exit_flag(false) {
+  m_timer_thread = std::thread(TimeoutThreadFunc, this);
+  m_info.m_instance = this;
+  m_state = m_info.m_last_state;
+}
+
+ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {
+  m_info.m_instance = nullptr;
+  if (m_state == State::Done)
+m_state = State::WaitTimeout;
+}
+
+void ThreadPlanSingleThreadTimeout::GetDescription(
+Stream *s, lldb::DescriptionLevel level) {
+  s->Printf("Single thread timeout, state(%s)", 
StateToString(m_state).c_str());
+}
+
+std::string ThreadPlanSingleThreadTimeout::StateToString(State state) {
+  switch (state) {
+  case State::WaitTimeout:
+return "WaitTimeout";
+  case State::AsyncInterrupt:
+return "AsyncInterrupt";
+  case State::Done:
+return "Done";
+  }
+}
+
+void ThreadPlanSingleThreadTimeout::PushNewWithTimeout(Thread &thread,
+   TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout pushing a brand new one");

jimingham wrote:

definitely want the timeout in this log message.

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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===-- ThreadPlanStepOverRange.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
+#include "lldb/Target/ThreadPlanStepThrough.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(Thread &thread,
+ TimeoutInfo &info)
+: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
+ thread, eVoteNo, eVoteNoOpinion),
+  m_info(info), m_state(State::WaitTimeout), m_exit_flag(false) {
+  m_timer_thread = std::thread(TimeoutThreadFunc, this);
+  m_info.m_instance = this;
+  m_state = m_info.m_last_state;
+}
+
+ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {
+  m_info.m_instance = nullptr;
+  if (m_state == State::Done)
+m_state = State::WaitTimeout;
+}
+
+void ThreadPlanSingleThreadTimeout::GetDescription(
+Stream *s, lldb::DescriptionLevel level) {
+  s->Printf("Single thread timeout, state(%s)", 
StateToString(m_state).c_str());
+}
+
+std::string ThreadPlanSingleThreadTimeout::StateToString(State state) {
+  switch (state) {
+  case State::WaitTimeout:
+return "WaitTimeout";
+  case State::AsyncInterrupt:
+return "AsyncInterrupt";
+  case State::Done:
+return "Done";
+  }
+}
+
+void ThreadPlanSingleThreadTimeout::PushNewWithTimeout(Thread &thread,
+   TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout pushing a brand new one");
+}
+
+void ThreadPlanSingleThreadTimeout::ResumeFromPrevState(Thread &thread,
+TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  if (info.m_instance != nullptr)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout reset from previous state");

jimingham wrote:

Also here, for debugging purposes it will be really handy to have the timeout 
value here.

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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===-- ThreadPlanStepOverRange.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
+#include "lldb/Target/ThreadPlanStepThrough.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(Thread &thread,
+ TimeoutInfo &info)
+: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
+ thread, eVoteNo, eVoteNoOpinion),
+  m_info(info), m_state(State::WaitTimeout), m_exit_flag(false) {
+  m_timer_thread = std::thread(TimeoutThreadFunc, this);
+  m_info.m_instance = this;
+  m_state = m_info.m_last_state;
+}
+
+ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {
+  m_info.m_instance = nullptr;
+  if (m_state == State::Done)
+m_state = State::WaitTimeout;
+}
+
+void ThreadPlanSingleThreadTimeout::GetDescription(
+Stream *s, lldb::DescriptionLevel level) {
+  s->Printf("Single thread timeout, state(%s)", 
StateToString(m_state).c_str());
+}
+
+std::string ThreadPlanSingleThreadTimeout::StateToString(State state) {
+  switch (state) {
+  case State::WaitTimeout:
+return "WaitTimeout";
+  case State::AsyncInterrupt:
+return "AsyncInterrupt";
+  case State::Done:
+return "Done";
+  }
+}
+
+void ThreadPlanSingleThreadTimeout::PushNewWithTimeout(Thread &thread,
+   TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout pushing a brand new one");
+}
+
+void ThreadPlanSingleThreadTimeout::ResumeFromPrevState(Thread &thread,
+TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  if (info.m_instance != nullptr)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout reset from previous state");
+}
+
+bool ThreadPlanSingleThreadTimeout::WillStop() {
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout::WillStop().");
+
+  // Reset the state during stop.
+  m_info.m_last_state = State::WaitTimeout;
+  m_info.m_instance = this;

jimingham wrote:

I'm not clear what this m_instance variable is for?  You don't use it as a 
pointer, so I don't think it needs to hold `this`.  It seems to be a 
`should_resume_from_prev_state` flag.  Is that right?  Anyway, this is 
confusing.  If this needs to be the `this` pointer you should say why 
somewhere.  If it's a state variable, use a bool instead.

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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===-- ThreadPlanStepOverRange.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
+#include "lldb/Target/ThreadPlanStepThrough.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(Thread &thread,
+ TimeoutInfo &info)
+: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
+ thread, eVoteNo, eVoteNoOpinion),
+  m_info(info), m_state(State::WaitTimeout), m_exit_flag(false) {
+  m_timer_thread = std::thread(TimeoutThreadFunc, this);
+  m_info.m_instance = this;
+  m_state = m_info.m_last_state;
+}
+
+ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {
+  m_info.m_instance = nullptr;
+  if (m_state == State::Done)
+m_state = State::WaitTimeout;
+}
+
+void ThreadPlanSingleThreadTimeout::GetDescription(
+Stream *s, lldb::DescriptionLevel level) {
+  s->Printf("Single thread timeout, state(%s)", 
StateToString(m_state).c_str());
+}
+
+std::string ThreadPlanSingleThreadTimeout::StateToString(State state) {
+  switch (state) {
+  case State::WaitTimeout:
+return "WaitTimeout";
+  case State::AsyncInterrupt:
+return "AsyncInterrupt";
+  case State::Done:
+return "Done";
+  }
+}
+
+void ThreadPlanSingleThreadTimeout::PushNewWithTimeout(Thread &thread,
+   TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout pushing a brand new one");
+}
+
+void ThreadPlanSingleThreadTimeout::ResumeFromPrevState(Thread &thread,
+TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  if (info.m_instance != nullptr)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout reset from previous state");
+}
+
+bool ThreadPlanSingleThreadTimeout::WillStop() {
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout::WillStop().");
+
+  // Reset the state during stop.
+  m_info.m_last_state = State::WaitTimeout;
+  m_info.m_instance = this;
+  return true;
+}
+
+void ThreadPlanSingleThreadTimeout::DidPop() {
+  Log *log = GetLog(LLDBLog::Step);
+  {
+std::lock_guard lock(m_mutex);
+LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout::DidPop().");
+// Tell timer thread to exit.
+m_exit_flag = true;
+  }
+  m_wakeup_cv.notify_one();
+  // Wait for timer thread to exit.
+  m_timer_thread.join();
+}
+
+bool ThreadPlanSingleThreadTimeout::DoPlanExplainsStop(Event *event_ptr) {
+  lldb::StateType stop_state =
+  Process::ProcessEventData::GetStateFromEvent(event_ptr);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(

jimingham wrote:

This is another place where it will probably be useful to see the timeout value 
if we're logging.

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] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===-- ThreadPlanStepOverRange.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
+#include "lldb/Target/ThreadPlanStepThrough.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(Thread &thread,
+ TimeoutInfo &info)
+: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
+ thread, eVoteNo, eVoteNoOpinion),
+  m_info(info), m_state(State::WaitTimeout), m_exit_flag(false) {
+  m_timer_thread = std::thread(TimeoutThreadFunc, this);
+  m_info.m_instance = this;
+  m_state = m_info.m_last_state;
+}
+
+ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {
+  m_info.m_instance = nullptr;
+  if (m_state == State::Done)
+m_state = State::WaitTimeout;
+}
+
+void ThreadPlanSingleThreadTimeout::GetDescription(
+Stream *s, lldb::DescriptionLevel level) {
+  s->Printf("Single thread timeout, state(%s)", 
StateToString(m_state).c_str());
+}
+
+std::string ThreadPlanSingleThreadTimeout::StateToString(State state) {
+  switch (state) {
+  case State::WaitTimeout:
+return "WaitTimeout";
+  case State::AsyncInterrupt:
+return "AsyncInterrupt";
+  case State::Done:
+return "Done";
+  }
+}
+
+void ThreadPlanSingleThreadTimeout::PushNewWithTimeout(Thread &thread,
+   TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout pushing a brand new one");
+}
+
+void ThreadPlanSingleThreadTimeout::ResumeFromPrevState(Thread &thread,
+TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  if (info.m_instance != nullptr)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout reset from previous state");
+}
+
+bool ThreadPlanSingleThreadTimeout::WillStop() {
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout::WillStop().");
+
+  // Reset the state during stop.
+  m_info.m_last_state = State::WaitTimeout;
+  m_info.m_instance = this;
+  return true;
+}
+
+void ThreadPlanSingleThreadTimeout::DidPop() {
+  Log *log = GetLog(LLDBLog::Step);
+  {
+std::lock_guard lock(m_mutex);
+LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout::DidPop().");
+// Tell timer thread to exit.
+m_exit_flag = true;
+  }
+  m_wakeup_cv.notify_one();
+  // Wait for timer thread to exit.
+  m_timer_thread.join();
+}
+
+bool ThreadPlanSingleThreadTimeout::DoPlanExplainsStop(Event *event_ptr) {
+  lldb::StateType stop_state =
+  Process::ProcessEventData::GetStateFromEvent(event_ptr);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(
+  log,
+  "ThreadPlanSingleThreadTimeout::DoPlanExplainsStop(): got event: %s.",
+  StateAsCString(stop_state));
+  return true;
+}
+
+lldb::StateType ThreadPlanSingleThreadTimeout::GetPlanRunState() {
+  return GetPreviousPlan()->GetPlanRunState();
+}
+
+void ThreadPlanSingleThreadTimeout::TimeoutThreadFunc(
+ThreadPlanSingleThreadTimeout *self) {

jimingham wrote:

Depending on how much this gets used, we might not want to spin up this threa

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

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===-- ThreadPlanStepOverRange.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
+#include "lldb/Target/ThreadPlanStepThrough.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(Thread &thread,
+ TimeoutInfo &info)
+: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
+ thread, eVoteNo, eVoteNoOpinion),
+  m_info(info), m_state(State::WaitTimeout), m_exit_flag(false) {
+  m_timer_thread = std::thread(TimeoutThreadFunc, this);
+  m_info.m_instance = this;
+  m_state = m_info.m_last_state;
+}
+
+ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {
+  m_info.m_instance = nullptr;
+  if (m_state == State::Done)
+m_state = State::WaitTimeout;
+}
+
+void ThreadPlanSingleThreadTimeout::GetDescription(
+Stream *s, lldb::DescriptionLevel level) {
+  s->Printf("Single thread timeout, state(%s)", 
StateToString(m_state).c_str());
+}
+
+std::string ThreadPlanSingleThreadTimeout::StateToString(State state) {
+  switch (state) {
+  case State::WaitTimeout:
+return "WaitTimeout";
+  case State::AsyncInterrupt:
+return "AsyncInterrupt";
+  case State::Done:
+return "Done";
+  }
+}
+
+void ThreadPlanSingleThreadTimeout::PushNewWithTimeout(Thread &thread,
+   TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout pushing a brand new one");
+}
+
+void ThreadPlanSingleThreadTimeout::ResumeFromPrevState(Thread &thread,
+TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  if (info.m_instance != nullptr)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout reset from previous state");
+}
+
+bool ThreadPlanSingleThreadTimeout::WillStop() {
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout::WillStop().");
+
+  // Reset the state during stop.
+  m_info.m_last_state = State::WaitTimeout;
+  m_info.m_instance = this;
+  return true;
+}
+
+void ThreadPlanSingleThreadTimeout::DidPop() {
+  Log *log = GetLog(LLDBLog::Step);
+  {
+std::lock_guard lock(m_mutex);
+LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout::DidPop().");
+// Tell timer thread to exit.
+m_exit_flag = true;
+  }
+  m_wakeup_cv.notify_one();
+  // Wait for timer thread to exit.
+  m_timer_thread.join();
+}
+
+bool ThreadPlanSingleThreadTimeout::DoPlanExplainsStop(Event *event_ptr) {
+  lldb::StateType stop_state =
+  Process::ProcessEventData::GetStateFromEvent(event_ptr);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(
+  log,
+  "ThreadPlanSingleThreadTimeout::DoPlanExplainsStop(): got event: %s.",
+  StateAsCString(stop_state));
+  return true;
+}
+
+lldb::StateType ThreadPlanSingleThreadTimeout::GetPlanRunState() {
+  return GetPreviousPlan()->GetPlanRunState();
+}
+
+void ThreadPlanSingleThreadTimeout::TimeoutThreadFunc(
+ThreadPlanSingleThreadTimeout *self) {
+  std::unique_lock lock(self->m_mutex);
+  uint64_t timeout_in_ms = self->GetThread().GetSingleThreadPlanTimeou

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

2024-06-28 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===-- ThreadPlanStepOverRange.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Target/ThreadPlanSingleThreadTimeout.h"
+#include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanStepOut.h"
+#include "lldb/Target/ThreadPlanStepThrough.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+ThreadPlanSingleThreadTimeout::ThreadPlanSingleThreadTimeout(Thread &thread,
+ TimeoutInfo &info)
+: ThreadPlan(ThreadPlan::eKindSingleThreadTimeout, "Single thread timeout",
+ thread, eVoteNo, eVoteNoOpinion),
+  m_info(info), m_state(State::WaitTimeout), m_exit_flag(false) {
+  m_timer_thread = std::thread(TimeoutThreadFunc, this);
+  m_info.m_instance = this;
+  m_state = m_info.m_last_state;
+}
+
+ThreadPlanSingleThreadTimeout::~ThreadPlanSingleThreadTimeout() {
+  m_info.m_instance = nullptr;
+  if (m_state == State::Done)
+m_state = State::WaitTimeout;
+}
+
+void ThreadPlanSingleThreadTimeout::GetDescription(
+Stream *s, lldb::DescriptionLevel level) {
+  s->Printf("Single thread timeout, state(%s)", 
StateToString(m_state).c_str());
+}
+
+std::string ThreadPlanSingleThreadTimeout::StateToString(State state) {
+  switch (state) {
+  case State::WaitTimeout:
+return "WaitTimeout";
+  case State::AsyncInterrupt:
+return "AsyncInterrupt";
+  case State::Done:
+return "Done";
+  }
+}
+
+void ThreadPlanSingleThreadTimeout::PushNewWithTimeout(Thread &thread,
+   TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout pushing a brand new one");
+}
+
+void ThreadPlanSingleThreadTimeout::ResumeFromPrevState(Thread &thread,
+TimeoutInfo &info) {
+  uint64_t timeout_in_ms = thread.GetSingleThreadPlanTimeout();
+  if (timeout_in_ms == 0)
+return;
+
+  if (info.m_instance != nullptr)
+return;
+
+  // Do not create timeout if we are not stopping other threads.
+  if (!thread.GetCurrentPlan()->StopOthers())
+return;
+
+  auto timeout_plan = new ThreadPlanSingleThreadTimeout(thread, info);
+  ThreadPlanSP thread_plan_sp(timeout_plan);
+  auto status = thread.QueueThreadPlan(thread_plan_sp,
+   /*abort_other_plans*/ false);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout reset from previous state");
+}
+
+bool ThreadPlanSingleThreadTimeout::WillStop() {
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout::WillStop().");
+
+  // Reset the state during stop.
+  m_info.m_last_state = State::WaitTimeout;
+  m_info.m_instance = this;
+  return true;
+}
+
+void ThreadPlanSingleThreadTimeout::DidPop() {
+  Log *log = GetLog(LLDBLog::Step);
+  {
+std::lock_guard lock(m_mutex);
+LLDB_LOGF(log, "ThreadPlanSingleThreadTimeout::DidPop().");
+// Tell timer thread to exit.
+m_exit_flag = true;
+  }
+  m_wakeup_cv.notify_one();
+  // Wait for timer thread to exit.
+  m_timer_thread.join();
+}
+
+bool ThreadPlanSingleThreadTimeout::DoPlanExplainsStop(Event *event_ptr) {
+  lldb::StateType stop_state =
+  Process::ProcessEventData::GetStateFromEvent(event_ptr);
+  Log *log = GetLog(LLDBLog::Step);
+  LLDB_LOGF(
+  log,
+  "ThreadPlanSingleThreadTimeout::DoPlanExplainsStop(): got event: %s.",
+  StateAsCString(stop_state));
+  return true;
+}
+
+lldb::StateType ThreadPlanSingleThreadTimeout::GetPlanRunState() {
+  return GetPreviousPlan()->GetPlanRunState();
+}
+
+void ThreadPlanSingleThreadTimeout::TimeoutThreadFunc(
+ThreadPlanSingleThreadTimeout *self) {
+  std::unique_lock lock(self->m_mutex);
+  uint64_t timeout_in_ms = self->GetThread().GetSingleThreadPlanTimeou

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

2024-06-28 Thread via lldb-commits


@@ -58,8 +58,13 @@ class ThreadPlanStepRange : public ThreadPlan {
   // run' plan, then just single step.
   bool SetNextBranchBreakpoint();
 
+  // Whether the input stop info is caused by the next branch breakpoint.

jimingham wrote:

This routine does NOT distinguish between the cases where the next branch 
breakpoint is the ONLY breakpoint at this site, and where it's one of many 
breakpoints that share this site.  Later, you distinguish between the two cases 
where this is used (e.g. in 
ThreadPlanStepRange::NextRangeBreakpointExplainsStop.
It might be interesting to see if it makes sense to incorporate the logic that 
does that into IsNextBranchBreakpointStop.  If it does that would allow some 
code reuse.  If it does not, you should note in the comment here that it does 
not distinguish between the two cases, so someone doesn't make a mistake later 
on.

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][FreeBSD][AArch64] Enable register field detection (PR #85058)

2024-06-28 Thread Alex Langford via lldb-commits

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

Can't say I know a ton about FreeBSD but this looks fine to me. I left one 
suggestion but I would recommend getting a sign-off from one of the FreeBSD 
folks.

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


[Lldb-commits] [lldb] [llvm] [lldb][FreeBSD][AArch64] Enable register field detection (PR #85058)

2024-06-28 Thread Alex Langford via lldb-commits

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


[Lldb-commits] [lldb] [llvm] [lldb][FreeBSD][AArch64] Enable register field detection (PR #85058)

2024-06-28 Thread Alex Langford via lldb-commits


@@ -18,9 +18,9 @@ namespace lldb_private {
 struct RegisterInfo;
 
 /// This class manages the storage and detection of register field information
-/// for Arm64 Linux registers. The same register may have different fields on
-/// different CPUs. This class abstracts out the field detection process so we
-/// can use it on live processes and core files.
+/// for Arm64 Linux and FreeBSD registers. The same register may have different

bulbazord wrote:

Suggestion: Remove the mention of Linux and FreeBSD. If this class is used for 
more platforms without updating this comment, the comment will be wrong.

https://github.com/llvm/llvm-project/pull/85058
___
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-06-28 Thread via lldb-commits

jimingham wrote:

I left some more comments, most of them either nits or future work - unless you 
want to do them here...

This makes sense to me, so it's likely right.  But the tests you've written so 
far are just about making sure that deadlocks are resolved in a simple stepping 
situation where nothing user-visible happens while you are stepping.

We need to make sure that if the "next" is interrupted - for instance by 
hitting a breakpoint in the code being stepped over, that once stopped, lldb 
can do other step operations having stopped and they work as expected.  

Also, in lldb, if you do a `next` and that steps over a function that hits a 
breakpoint, the next stays on the stack and then "continue" will resume 
execution of the "next" ThreadPlan, completing the step.  We should make sure 
that works and keeps tracking the single thread in a case where there's no 
deadlock to resolve, or goes on to resolve the deadlock.

We also really want to make sure that the async interrupt that you use here and 
the one that the user uses (through SBProcess.SendAsyncInterrupt) don't 
interfere with one another.  So step over something with a really long user 
step timeout, then send an asynchronous interrupt and make sure we stop with 
the right stop reason.  And then make sure the next continues successfully 
after that.

Also, if we can it would be nice to test that this succeeds in NOT allowing the 
other threads to run before the timeout elapses.  You could have your worker 
thread stop right before code that's going to crash, and then switch to the 
main thread and do a bunch of steps over code that calls some function that 
will do a pthread yield.  If the process doesn't crash after those steps, 
you're good.

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] [lldb] Make semantics of SupportFile equivalence explicit (PR #97126)

2024-06-28 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/97126

This is an improved attempt to improve the semantics of SupportFile 
equivalence, taking into account the feedback from #95606.

Pavel's comment about the lack of a concise name because the concept isn't 
trivial made me realize that I don't want to abstract this concept away behind 
a helper function. Instead, I opted for a rather verbose enum that forces the 
caller to consider exactly what kind of comparison is appropriate for every 
call.

>From 0c39366879c56ceb0ef6b021d8098bc73e26445b Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Fri, 28 Jun 2024 16:50:05 -0700
Subject: [PATCH] [lldb] Make semantics of SupportFile equivalence explicit

This is an improved attempt to improve the semantics of SupportFile
equivalence, taking into account the feedback from #95606.

Pavel's comment about the lack of a concise name because the concept
isn't trivial made me realize that I don't want to abstract this concept
away behind a helper function. Instead, I opted for a rather verbose
enum that forces the caller to consider exactly what kind of comparison
is appropriate for every call.
---
 lldb/include/lldb/Utility/SupportFile.h   | 39 +++
 lldb/source/Breakpoint/BreakpointResolver.cpp |  5 ++-
 lldb/source/Commands/CommandObjectSource.cpp  |  8 +++-
 lldb/source/Symbol/LineEntry.cpp  |  3 +-
 lldb/source/Symbol/LineTable.cpp  |  2 +-
 .../source/Target/ThreadPlanStepOverRange.cpp | 15 ---
 lldb/source/Target/ThreadPlanStepRange.cpp|  5 ++-
 7 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/lldb/include/lldb/Utility/SupportFile.h 
b/lldb/include/lldb/Utility/SupportFile.h
index 21b986dcaba28..4b672684e4b4e 100644
--- a/lldb/include/lldb/Utility/SupportFile.h
+++ b/lldb/include/lldb/Utility/SupportFile.h
@@ -11,6 +11,7 @@
 
 #include "lldb/Utility/Checksum.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Flags.h"
 
 namespace lldb_private {
 
@@ -30,15 +31,37 @@ class SupportFile {
 
   virtual ~SupportFile() = default;
 
-  /// Return true if both SupportFiles have the same FileSpec and, if both have
-  /// a valid Checksum, the Checksum is the same.
-  bool operator==(const SupportFile &other) const {
-if (m_checksum && other.m_checksum)
-  return m_file_spec == other.m_file_spec && m_checksum == 
other.m_checksum;
-return m_file_spec == other.m_file_spec;
-  }
+  enum SupportFileEquality : uint8_t {
+eEqualFileSpec = (1u << 1),
+eEqualChecksum = (1u << 2),
+eEqualChecksumIfSet = (1u << 3),
+eEqualFileSpecAndChecksum = eEqualFileSpec | eEqualChecksum,
+eEqualFileSpecAndChecksumIfSet = eEqualFileSpec | eEqualChecksumIfSet,
+  };
+
+  bool Equal(const SupportFile &other,
+ SupportFileEquality equality = eEqualFileSpecAndChecksum) const {
+assert(!(equality & eEqualChecksum & eEqualChecksumIfSet) &&
+   "eEqualChecksum and eEqualChecksumIfSet are mutually exclusive");
+
+if (equality & eEqualFileSpec) {
+  if (m_file_spec != other.m_file_spec)
+return false;
+}
 
-  bool operator!=(const SupportFile &other) const { return !(*this == other); }
+if (equality & eEqualChecksum) {
+  if (m_checksum != other.m_checksum)
+return false;
+}
+
+if (equality & eEqualChecksumIfSet) {
+  if (m_checksum && other.m_checksum)
+if (m_checksum != other.m_checksum)
+  return false;
+}
+
+return true;
+  }
 
   /// Return the file name only. Useful for resolving breakpoints by file name.
   const FileSpec &GetSpecOnly() const { return m_file_spec; };
diff --git a/lldb/source/Breakpoint/BreakpointResolver.cpp 
b/lldb/source/Breakpoint/BreakpointResolver.cpp
index ff4e2a9985197..2d52cbf827ef9 100644
--- a/lldb/source/Breakpoint/BreakpointResolver.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolver.cpp
@@ -222,8 +222,9 @@ void BreakpointResolver::SetSCMatchesByLine(
 auto worklist_begin = std::partition(
 all_scs.begin(), all_scs.end(), [&](const SymbolContext &sc) {
   if (sc.line_entry.GetFile() == match.line_entry.GetFile() ||
-  *sc.line_entry.original_file_sp ==
-  *match.line_entry.original_file_sp) {
+  sc.line_entry.original_file_sp->Equal(
+  *match.line_entry.original_file_sp,
+  SupportFile::eEqualFileSpecAndChecksumIfSet)) {
 // When a match is found, keep track of the smallest line number.
 closest_line = std::min(closest_line, sc.line_entry.line);
 return false;
diff --git a/lldb/source/Commands/CommandObjectSource.cpp 
b/lldb/source/Commands/CommandObjectSource.cpp
index 0c1267456a184..f54b712adfc46 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -747,13 +747,17 @@ class CommandObjectSourceList : public 
CommandObjectParsed {
 
 b

[Lldb-commits] [lldb] [lldb] Make semantics of SupportFile equivalence explicit (PR #97126)

2024-06-28 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

This is an improved attempt to improve the semantics of SupportFile 
equivalence, taking into account the feedback from #95606.

Pavel's comment about the lack of a concise name because the concept isn't 
trivial made me realize that I don't want to abstract this concept away behind 
a helper function. Instead, I opted for a rather verbose enum that forces the 
caller to consider exactly what kind of comparison is appropriate for every 
call.

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


7 Files Affected:

- (modified) lldb/include/lldb/Utility/SupportFile.h (+31-8) 
- (modified) lldb/source/Breakpoint/BreakpointResolver.cpp (+3-2) 
- (modified) lldb/source/Commands/CommandObjectSource.cpp (+6-2) 
- (modified) lldb/source/Symbol/LineEntry.cpp (+2-1) 
- (modified) lldb/source/Symbol/LineTable.cpp (+1-1) 
- (modified) lldb/source/Target/ThreadPlanStepOverRange.cpp (+9-6) 
- (modified) lldb/source/Target/ThreadPlanStepRange.cpp (+3-2) 


``diff
diff --git a/lldb/include/lldb/Utility/SupportFile.h 
b/lldb/include/lldb/Utility/SupportFile.h
index 21b986dcaba28..4b672684e4b4e 100644
--- a/lldb/include/lldb/Utility/SupportFile.h
+++ b/lldb/include/lldb/Utility/SupportFile.h
@@ -11,6 +11,7 @@
 
 #include "lldb/Utility/Checksum.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Flags.h"
 
 namespace lldb_private {
 
@@ -30,15 +31,37 @@ class SupportFile {
 
   virtual ~SupportFile() = default;
 
-  /// Return true if both SupportFiles have the same FileSpec and, if both have
-  /// a valid Checksum, the Checksum is the same.
-  bool operator==(const SupportFile &other) const {
-if (m_checksum && other.m_checksum)
-  return m_file_spec == other.m_file_spec && m_checksum == 
other.m_checksum;
-return m_file_spec == other.m_file_spec;
-  }
+  enum SupportFileEquality : uint8_t {
+eEqualFileSpec = (1u << 1),
+eEqualChecksum = (1u << 2),
+eEqualChecksumIfSet = (1u << 3),
+eEqualFileSpecAndChecksum = eEqualFileSpec | eEqualChecksum,
+eEqualFileSpecAndChecksumIfSet = eEqualFileSpec | eEqualChecksumIfSet,
+  };
+
+  bool Equal(const SupportFile &other,
+ SupportFileEquality equality = eEqualFileSpecAndChecksum) const {
+assert(!(equality & eEqualChecksum & eEqualChecksumIfSet) &&
+   "eEqualChecksum and eEqualChecksumIfSet are mutually exclusive");
+
+if (equality & eEqualFileSpec) {
+  if (m_file_spec != other.m_file_spec)
+return false;
+}
 
-  bool operator!=(const SupportFile &other) const { return !(*this == other); }
+if (equality & eEqualChecksum) {
+  if (m_checksum != other.m_checksum)
+return false;
+}
+
+if (equality & eEqualChecksumIfSet) {
+  if (m_checksum && other.m_checksum)
+if (m_checksum != other.m_checksum)
+  return false;
+}
+
+return true;
+  }
 
   /// Return the file name only. Useful for resolving breakpoints by file name.
   const FileSpec &GetSpecOnly() const { return m_file_spec; };
diff --git a/lldb/source/Breakpoint/BreakpointResolver.cpp 
b/lldb/source/Breakpoint/BreakpointResolver.cpp
index ff4e2a9985197..2d52cbf827ef9 100644
--- a/lldb/source/Breakpoint/BreakpointResolver.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolver.cpp
@@ -222,8 +222,9 @@ void BreakpointResolver::SetSCMatchesByLine(
 auto worklist_begin = std::partition(
 all_scs.begin(), all_scs.end(), [&](const SymbolContext &sc) {
   if (sc.line_entry.GetFile() == match.line_entry.GetFile() ||
-  *sc.line_entry.original_file_sp ==
-  *match.line_entry.original_file_sp) {
+  sc.line_entry.original_file_sp->Equal(
+  *match.line_entry.original_file_sp,
+  SupportFile::eEqualFileSpecAndChecksumIfSet)) {
 // When a match is found, keep track of the smallest line number.
 closest_line = std::min(closest_line, sc.line_entry.line);
 return false;
diff --git a/lldb/source/Commands/CommandObjectSource.cpp 
b/lldb/source/Commands/CommandObjectSource.cpp
index 0c1267456a184..f54b712adfc46 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -747,13 +747,17 @@ class CommandObjectSourceList : public 
CommandObjectParsed {
 
 bool operator==(const SourceInfo &rhs) const {
   return function == rhs.function &&
- *line_entry.original_file_sp == *rhs.line_entry.original_file_sp 
&&
+ line_entry.original_file_sp->Equal(
+ *rhs.line_entry.original_file_sp,
+ SupportFile::eEqualFileSpecAndChecksumIfSet) &&
  line_entry.line == rhs.line_entry.line;
 }
 
 bool operator!=(const SourceInfo &rhs) const {
   return function != rhs.function ||
- *line_entry.original_file_sp != *rhs.line_entry.original_file_