[Lldb-commits] [lldb] [lldb][test][x86_64][win] Split assertion in TestBreakpointConditions (PR #100487)

2024-08-02 Thread David Spickett via lldb-commits

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


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


[Lldb-commits] [lldb] 3c3851f - [lldb][test][x86_64][win] Split assertion in TestBreakpointConditions (#100487)

2024-08-02 Thread via lldb-commits

Author: Kendal Harland
Date: 2024-08-02T10:03:39+01:00
New Revision: 3c3851f3ed837aaae7df76e9a4cbb866dbfee3ac

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

LOG: [lldb][test][x86_64][win] Split assertion in TestBreakpointConditions 
(#100487)

This PR splits the test assertion that verifies we're on the correct
line and have the correct value of `val` to make the error message more
clear. At present it just shows `Assertion error: True != False`

Co-authored-by: kendal 

Added: 


Modified: 

lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
 
b/lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
index 50ba0317fd094..4e7a8ccb9fbeb 100644
--- 
a/lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
+++ 
b/lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
@@ -176,11 +176,15 @@ def breakpoint_conditions_python(self):
 thread.IsValid(),
 "There should be a thread stopped due to breakpoint condition",
 )
+
 frame0 = thread.GetFrameAtIndex(0)
 var = frame0.FindValue("val", lldb.eValueTypeVariableArgument)
-self.assertTrue(
-frame0.GetLineEntry().GetLine() == self.line1 and var.GetValue() 
== "3"
+self.assertEqual(
+frame0.GetLineEntry().GetLine(),
+self.line1,
+"The debugger stopped on the correct line",
 )
+self.assertEqual(var.GetValue(), "3")
 
 # The hit count for the breakpoint should be 1.
 self.assertEqual(breakpoint.GetHitCount(), 1)



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


[Lldb-commits] [lldb] [lldb][test][x86_64][win] Split assertion in TestBreakpointConditions (PR #100487)

2024-08-02 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-08-02 Thread David Spickett via lldb-commits

DavidSpickett wrote:

What did you intend with `/H`? If anything it would be 
https://learn.microsoft.com/en-us/cpp/build/reference/h-restrict-length-of-external-names?view=msvc-170
 but clang-cl doesn't support this one.

(yes, the bot uses clang-cl, we really should change the name)

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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

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

We plan to eventually use the Clang driver to initialize the `CompilerInstance`.

This should make refactorings of this code more straightforward.

>From a4518719a09ef2910209663c62544dc5797f2df7 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 13:48:18 +0100
Subject: [PATCH] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic
 out of ClangExpressionParser constructor

We plan to eventually use the Clang driver to initialize the
`CompilerInstance`.

This should make refactorings of this code more straightforward.
---
 lldb/include/lldb/Expression/Expression.h |   2 +-
 lldb/include/lldb/Expression/UserExpression.h |   2 +-
 .../Clang/ClangExpressionParser.cpp   | 301 +-
 3 files changed, 157 insertions(+), 148 deletions(-)

diff --git a/lldb/include/lldb/Expression/Expression.h 
b/lldb/include/lldb/Expression/Expression.h
index 356fe4b82ae43..8de9364436ccf 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -56,7 +56,7 @@ class Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  virtual ResultType DesiredResultType() { return eResultTypeAny; }
+  virtual ResultType DesiredResultType() const { return eResultTypeAny; }
 
   /// Flags
 
diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index b04d00b72e8fa..7ce463d2cb4e7 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -206,7 +206,7 @@ class UserExpression : public Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  ResultType DesiredResultType() override { return m_desired_type; }
+  ResultType DesiredResultType() const override { return m_desired_type; }
 
   /// Return true if validation code should be inserted into the expression.
   bool NeedsValidation() override { return true; }
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..11d519e738ee5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -77,6 +77,7 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ExecutionContextScope.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -351,62 +352,20 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
-//===--===//
-// Implementation of ClangExpressionParser
-//===--===//
-
-ClangExpressionParser::ClangExpressionParser(
-ExecutionContextScope *exe_scope, Expression &expr,
-bool generate_debug_info, std::vector include_directories,
-std::string filename)
-: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
-  m_pp_callbacks(nullptr),
-  m_include_directories(std::move(include_directories)),
-  m_filename(std::move(filename)) {
+static void SetupLangOpts(CompilerInstance &compiler,
+  ExecutionContextScope &exe_scope,
+  Expression const &expr) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  // We can't compile expressions without a target.  So if the exe_scope is
-  // null or doesn't have a target, then we just need to get out of here.  I'll
-  // lldbassert and not make any of the compiler objects since
-  // I can't return errors directly from the constructor.  Further calls will
-  // check if the compiler was made and
-  // bag out if it wasn't.
-
-  if (!exe_scope) {
-lldbassert(exe_scope &&
-   "Can't make an expression parser with a null scope.");
-return;
-  }
-
-  lldb::TargetSP target_sp;
-  target_sp = exe_scope->CalculateTarget();
-  if (!target_sp) {
-lldbassert(target_sp.get() &&
-   "Can't make an expression parser with a null target.");
-return;
-  }
-
-  // 1. Create a new compiler instance.
-  m_compiler = std::make_unique();
+  // If the expression is being evaluated in the context of an existing stack
+  // frame, we introspect to see if the language runtime is available.
 
-  // Make sure clang uses the same VFS as LLDB.
-  m_compiler->createFileManager(FileSystem::Instance().GetVirtualFileSystem());
+  lldb::StackFrameSP frame_sp = exe_scope.CalculateStackFrame();
+  lldb::ProcessSP process_sp = exe_scope.CalculateProcess();
 
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLangu

[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

2024-08-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

We plan to eventually use the Clang driver to initialize the `CompilerInstance`.

This should make refactorings of this code more straightforward.

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


3 Files Affected:

- (modified) lldb/include/lldb/Expression/Expression.h (+1-1) 
- (modified) lldb/include/lldb/Expression/UserExpression.h (+1-1) 
- (modified) 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (+155-146) 


``diff
diff --git a/lldb/include/lldb/Expression/Expression.h 
b/lldb/include/lldb/Expression/Expression.h
index 356fe4b82ae43..8de9364436ccf 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -56,7 +56,7 @@ class Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  virtual ResultType DesiredResultType() { return eResultTypeAny; }
+  virtual ResultType DesiredResultType() const { return eResultTypeAny; }
 
   /// Flags
 
diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index b04d00b72e8fa..7ce463d2cb4e7 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -206,7 +206,7 @@ class UserExpression : public Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  ResultType DesiredResultType() override { return m_desired_type; }
+  ResultType DesiredResultType() const override { return m_desired_type; }
 
   /// Return true if validation code should be inserted into the expression.
   bool NeedsValidation() override { return true; }
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..11d519e738ee5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -77,6 +77,7 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ExecutionContextScope.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -351,62 +352,20 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
-//===--===//
-// Implementation of ClangExpressionParser
-//===--===//
-
-ClangExpressionParser::ClangExpressionParser(
-ExecutionContextScope *exe_scope, Expression &expr,
-bool generate_debug_info, std::vector include_directories,
-std::string filename)
-: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
-  m_pp_callbacks(nullptr),
-  m_include_directories(std::move(include_directories)),
-  m_filename(std::move(filename)) {
+static void SetupLangOpts(CompilerInstance &compiler,
+  ExecutionContextScope &exe_scope,
+  Expression const &expr) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  // We can't compile expressions without a target.  So if the exe_scope is
-  // null or doesn't have a target, then we just need to get out of here.  I'll
-  // lldbassert and not make any of the compiler objects since
-  // I can't return errors directly from the constructor.  Further calls will
-  // check if the compiler was made and
-  // bag out if it wasn't.
-
-  if (!exe_scope) {
-lldbassert(exe_scope &&
-   "Can't make an expression parser with a null scope.");
-return;
-  }
-
-  lldb::TargetSP target_sp;
-  target_sp = exe_scope->CalculateTarget();
-  if (!target_sp) {
-lldbassert(target_sp.get() &&
-   "Can't make an expression parser with a null target.");
-return;
-  }
-
-  // 1. Create a new compiler instance.
-  m_compiler = std::make_unique();
+  // If the expression is being evaluated in the context of an existing stack
+  // frame, we introspect to see if the language runtime is available.
 
-  // Make sure clang uses the same VFS as LLDB.
-  m_compiler->createFileManager(FileSystem::Instance().GetVirtualFileSystem());
+  lldb::StackFrameSP frame_sp = exe_scope.CalculateStackFrame();
+  lldb::ProcessSP process_sp = exe_scope.CalculateProcess();
 
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLanguageType();
 
-  std::string abi;
-  ArchSpec target_arch;
-  target_arch = target_sp->GetArchitecture();
-
-  const auto target_machine = target_arch.GetMachine();
-
-  // If the expression is being evaluated in the context of an existing stack
-  // frame, we introspect to see if the language runtime is

[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows bui… (PR #101672)

2024-08-02 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett created 
https://github.com/llvm/llvm-project/pull/101672

…ld issue"

This reverts commit 9effefbae8d96006a4dd29bb9ab8532fd408559d.

With the include order in ScriptedProcessPythonInterface.cpp fixed (though I 
cannot explain exactly why it works) and removes the /H flag intended for 
debugging this issue.

I think it is something to do with Process.h pulling in PosixApi.h somewhere 
along the line, and including Process.h after lldb-python.h means that NO_PID_T 
is defined to prevent a redefinition of pid_t.

>From 87807974ed13d43416121f2c8ac23caade9eb932 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Fri, 2 Aug 2024 13:19:03 +
Subject: [PATCH] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the
 windows build issue"

This reverts commit 9effefbae8d96006a4dd29bb9ab8532fd408559d.

With the include order in ScriptedProcessPythonInterface.cpp fixed
(though I cannot explain exactly why it works) and removes the
/H flag intended for debugging this issue.

I think it is something to do with Process.h pulling in PosixApi.h somewhere
along the line, and including Process.h after lldb-python.h means that
NO_PID_T is defined to prevent a redefinition of pid_t.
---
 .../Python/Interfaces/CMakeLists.txt  |  2 +-
 .../CMakeLists.txt| 16 +++
 .../ScriptedProcessPythonInterface.cpp| 43 +++
 .../ScriptedProcessPythonInterface.h  | 18 ++--
 .../Python/ScriptInterpreterPython.cpp|  2 +-
 5 files changed, 68 insertions(+), 13 deletions(-)
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
ScriptedProcessPythonInterface}/ScriptedProcessPythonInterface.cpp (84%)
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
ScriptedProcessPythonInterface}/ScriptedProcessPythonInterface.h (88%)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
index 8c7e92bead32c..eb22a960b5345 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
@@ -21,7 +21,6 @@ endif()
 
 add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
   ScriptedPythonInterface.cpp
-  ScriptedProcessPythonInterface.cpp
   ScriptedThreadPythonInterface.cpp
 
   LINK_LIBS
@@ -38,5 +37,6 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
 
 add_subdirectory(OperatingSystemPythonInterface)
 add_subdirectory(ScriptedPlatformPythonInterface)
+add_subdirectory(ScriptedProcessPythonInterface)
 add_subdirectory(ScriptedThreadPlanPythonInterface)
 
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
new file mode 100644
index 0..66ed041853f67
--- /dev/null
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
@@ -0,0 +1,16 @@
+add_lldb_library(lldbPluginScriptInterpreterPythonScriptedProcessPythonInterface
 PLUGIN
+
+  ScriptedProcessPythonInterface.cpp
+
+  LINK_LIBS
+lldbCore
+lldbHost
+lldbInterpreter
+lldbTarget
+lldbPluginScriptInterpreterPython
+${Python3_LIBRARIES}
+${LLDB_LIBEDIT_LIBS}
+
+  LINK_COMPONENTS
+Support
+  )
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
similarity index 84%
rename from 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
rename to 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
index 313c597ce48f3..c744d7028d04e 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
@@ -6,22 +6,27 @@
 //
 
//===--===//
 
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Host/Config.h"
-#if LLDB_ENABLE_PYTHON
-// LLDB Python header must be included first
-#include "../lldb-python.h"
-#endif
-#include "lldb/Target/Process.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/lldb-enumerations.h"
 
 #if LLDB_ENABLE_PYTHON
 
-#include "../SWIGPythonBridge.h"
-#include "../ScriptInterpreterPythonImpl.h"
+// clang-format off
+// LLDB Python header must be included first
+#include "../../lldb-python.h"
+
+#include "../.

[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-02 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-02 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)


Changes

This reverts commit 9effefbae8d96006a4dd29bb9ab8532fd408559d.

With the include order in ScriptedProcessPythonInterface.cpp fixed (though I 
cannot explain exactly why it works) and removes the /H flag intended for 
debugging this issue.

I think it is something to do with Process.h pulling in PosixApi.h somewhere 
along the line, and including Process.h after lldb-python.h means that NO_PID_T 
is defined to prevent a redefinition of pid_t.

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


5 Files Affected:

- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt (+1-1) 
- (added) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
 (+16) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
 (+35-8) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.h
 (+15-3) 
- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+1-1) 


``diff
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
index 8c7e92bead32c..eb22a960b5345 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
@@ -21,7 +21,6 @@ endif()
 
 add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
   ScriptedPythonInterface.cpp
-  ScriptedProcessPythonInterface.cpp
   ScriptedThreadPythonInterface.cpp
 
   LINK_LIBS
@@ -38,5 +37,6 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
 
 add_subdirectory(OperatingSystemPythonInterface)
 add_subdirectory(ScriptedPlatformPythonInterface)
+add_subdirectory(ScriptedProcessPythonInterface)
 add_subdirectory(ScriptedThreadPlanPythonInterface)
 
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
new file mode 100644
index 0..66ed041853f67
--- /dev/null
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
@@ -0,0 +1,16 @@
+add_lldb_library(lldbPluginScriptInterpreterPythonScriptedProcessPythonInterface
 PLUGIN
+
+  ScriptedProcessPythonInterface.cpp
+
+  LINK_LIBS
+lldbCore
+lldbHost
+lldbInterpreter
+lldbTarget
+lldbPluginScriptInterpreterPython
+${Python3_LIBRARIES}
+${LLDB_LIBEDIT_LIBS}
+
+  LINK_COMPONENTS
+Support
+  )
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
similarity index 84%
rename from 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
rename to 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
index 313c597ce48f3..c744d7028d04e 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
@@ -6,22 +6,27 @@
 //
 
//===--===//
 
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Host/Config.h"
-#if LLDB_ENABLE_PYTHON
-// LLDB Python header must be included first
-#include "../lldb-python.h"
-#endif
-#include "lldb/Target/Process.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/lldb-enumerations.h"
 
 #if LLDB_ENABLE_PYTHON
 
-#include "../SWIGPythonBridge.h"
-#include "../ScriptInterpreterPythonImpl.h"
+// clang-format off
+// LLDB Python header must be included first
+#include "../../lldb-python.h"
+
+#include "../../SWIGPythonBridge.h"
+#include "../../ScriptInterpreterPythonImpl.h"
+#include "../ScriptedThreadPythonInterface.h"
 #include "ScriptedProcessPythonInterface.h"
-#include "ScriptedThreadPythonInterface.h"
+
+// Included in this position to prevent redefinition of pid_t on Windows.
+#include "lldb/Target/Process.h"
+//clang-format off
+
 #include 
 
 using namespace lldb;
@@ -29,6 +34,8 @@ using namespace lldb_private;
 using namespace lldb_private::python;
 using Locker = ScriptInterpreterPythonImpl::Locker;
 
+LLDB_PLUGIN_DEFINE_ADV(ScriptedProcessPythonInterface, 
ScriptInterpreterPythonScriptedProcessPythonInterface)
+
 ScriptedProcessPythonInterface::ScriptedProcessPythonInterface(
 ScriptInterpreterPythonImpl &interpreter

[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-02 Thread David Spickett via lldb-commits

DavidSpickett wrote:

I tried making lldb-pthon.h the literal first include of the file but this 
doesn't work. When it gets to SWIGPythonBridge.h the redefinition happens 
again, no idea why, I'd think NO_PID_T would still be defined.

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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


@@ -551,42 +448,14 @@ ClangExpressionParser::ClangExpressionParser(
   if (expr.DesiredResultType() == Expression::eResultTypeId)
 lang_opts.DebuggerCastResultToId = true;
 
-  lang_opts.CharIsSigned = ArchSpec(m_compiler->getTargetOpts().Triple.c_str())
-   .CharIsSignedByDefault();
+  lang_opts.CharIsSigned =
+  
ArchSpec(compiler.getTargetOpts().Triple.c_str()).CharIsSignedByDefault();

Michael137 wrote:

due to `clang-format`

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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

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

>From a4518719a09ef2910209663c62544dc5797f2df7 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 13:48:18 +0100
Subject: [PATCH 1/2] [lldb][ClangExpressionParser][NFC] Factor LangOptions
 logic out of ClangExpressionParser constructor

We plan to eventually use the Clang driver to initialize the
`CompilerInstance`.

This should make refactorings of this code more straightforward.
---
 lldb/include/lldb/Expression/Expression.h |   2 +-
 lldb/include/lldb/Expression/UserExpression.h |   2 +-
 .../Clang/ClangExpressionParser.cpp   | 301 +-
 3 files changed, 157 insertions(+), 148 deletions(-)

diff --git a/lldb/include/lldb/Expression/Expression.h 
b/lldb/include/lldb/Expression/Expression.h
index 356fe4b82ae43..8de9364436ccf 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -56,7 +56,7 @@ class Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  virtual ResultType DesiredResultType() { return eResultTypeAny; }
+  virtual ResultType DesiredResultType() const { return eResultTypeAny; }
 
   /// Flags
 
diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index b04d00b72e8fa..7ce463d2cb4e7 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -206,7 +206,7 @@ class UserExpression : public Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  ResultType DesiredResultType() override { return m_desired_type; }
+  ResultType DesiredResultType() const override { return m_desired_type; }
 
   /// Return true if validation code should be inserted into the expression.
   bool NeedsValidation() override { return true; }
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..11d519e738ee5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -77,6 +77,7 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ExecutionContextScope.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -351,62 +352,20 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
-//===--===//
-// Implementation of ClangExpressionParser
-//===--===//
-
-ClangExpressionParser::ClangExpressionParser(
-ExecutionContextScope *exe_scope, Expression &expr,
-bool generate_debug_info, std::vector include_directories,
-std::string filename)
-: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
-  m_pp_callbacks(nullptr),
-  m_include_directories(std::move(include_directories)),
-  m_filename(std::move(filename)) {
+static void SetupLangOpts(CompilerInstance &compiler,
+  ExecutionContextScope &exe_scope,
+  Expression const &expr) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  // We can't compile expressions without a target.  So if the exe_scope is
-  // null or doesn't have a target, then we just need to get out of here.  I'll
-  // lldbassert and not make any of the compiler objects since
-  // I can't return errors directly from the constructor.  Further calls will
-  // check if the compiler was made and
-  // bag out if it wasn't.
-
-  if (!exe_scope) {
-lldbassert(exe_scope &&
-   "Can't make an expression parser with a null scope.");
-return;
-  }
-
-  lldb::TargetSP target_sp;
-  target_sp = exe_scope->CalculateTarget();
-  if (!target_sp) {
-lldbassert(target_sp.get() &&
-   "Can't make an expression parser with a null target.");
-return;
-  }
-
-  // 1. Create a new compiler instance.
-  m_compiler = std::make_unique();
+  // If the expression is being evaluated in the context of an existing stack
+  // frame, we introspect to see if the language runtime is available.
 
-  // Make sure clang uses the same VFS as LLDB.
-  m_compiler->createFileManager(FileSystem::Instance().GetVirtualFileSystem());
+  lldb::StackFrameSP frame_sp = exe_scope.CalculateStackFrame();
+  lldb::ProcessSP process_sp = exe_scope.CalculateProcess();
 
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLanguageType();
 
-  std::string abi;
-  ArchSpec target_arch;
-  target_arch = target_sp->GetArchitecture();
-
-  const auto target_machine = target

[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor out TargetOpts logic out of ClangExpressionParser (PR #101681)

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

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

Same motivation as https://github.com/llvm/llvm-project/pull/101669. We plan to 
eventually use the Clang driver to initialize the `CompilerInstance`.

This should make refactorings of this code more straightforward.

**Changes**:
* Introduced `SetupTargetOpts`
* Called them from `ClangExpressionParser::ClangExpressionParser`
* Made `GetClangTargetABI` a file-local function since it's not using any of 
the state in `ClangExpressionParser`, and isn't used anywhere outside the 
source file

>From 904f5938946bd73eb06884c139b6c75446a9ce88 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 15:27:16 +0100
Subject: [PATCH] [lldb][ClangExpressionParser][NFC] Factor out TargetOpts
 logic out of ClangExpressionParser

---
 .../Clang/ClangExpressionParser.cpp   | 142 +-
 .../Clang/ClangExpressionParser.h |   9 --
 2 files changed, 75 insertions(+), 76 deletions(-)

diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..2d34f657793c3 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -351,6 +351,80 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
+/// Returns a string representing current ABI.
+///
+/// \param[in] target_arch
+/// The target architecture.
+///
+/// \return
+/// A string representing target ABI for the current architecture.
+static std::string GetClangTargetABI(const ArchSpec &target_arch) {
+  std::string abi;
+
+  if (target_arch.IsMIPS()) {
+switch (target_arch.GetFlags() & ArchSpec::eMIPSABI_mask) {
+case ArchSpec::eMIPSABI_N64:
+  abi = "n64";
+  break;
+case ArchSpec::eMIPSABI_N32:
+  abi = "n32";
+  break;
+case ArchSpec::eMIPSABI_O32:
+  abi = "o32";
+  break;
+default:
+  break;
+}
+  }
+  return abi;
+}
+
+static void SetupTargetOpts(CompilerInstance &compiler,
+lldb_private::Target const &target) {
+  Log *log = GetLog(LLDBLog::Expressions);
+  ArchSpec target_arch = target.GetArchitecture();
+
+  const auto target_machine = target_arch.GetMachine();
+  if (target_arch.IsValid()) {
+std::string triple = target_arch.GetTriple().str();
+compiler.getTargetOpts().Triple = triple;
+LLDB_LOGF(log, "Using %s as the target triple",
+  compiler.getTargetOpts().Triple.c_str());
+  } else {
+// If we get here we don't have a valid target and just have to guess.
+// Sometimes this will be ok to just use the host target triple (when we
+// evaluate say "2+3", but other expressions like breakpoint conditions and
+// other things that _are_ target specific really shouldn't just be using
+// the host triple. In such a case the language runtime should expose an
+// overridden options set (3), below.
+compiler.getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple();
+LLDB_LOGF(log, "Using default target triple of %s",
+  compiler.getTargetOpts().Triple.c_str());
+  }
+  // Now add some special fixes for known architectures: Any arm32 iOS
+  // environment, but not on arm64
+  if (compiler.getTargetOpts().Triple.find("arm64") == std::string::npos &&
+  compiler.getTargetOpts().Triple.find("arm") != std::string::npos &&
+  compiler.getTargetOpts().Triple.find("ios") != std::string::npos) {
+compiler.getTargetOpts().ABI = "apcs-gnu";
+  }
+  // Supported subsets of x86
+  if (target_machine == llvm::Triple::x86 ||
+  target_machine == llvm::Triple::x86_64) {
+compiler.getTargetOpts().FeaturesAsWritten.push_back("+sse");
+compiler.getTargetOpts().FeaturesAsWritten.push_back("+sse2");
+  }
+
+  // Set the target CPU to generate code for. This will be empty for any CPU
+  // that doesn't really need to make a special
+  // CPU string.
+  compiler.getTargetOpts().CPU = target_arch.GetClangTargetCPU();
+
+  // Set the target ABI
+  if (std::string abi = GetClangTargetABI(target_arch); !abi.empty())
+compiler.getTargetOpts().ABI = std::move(abi);
+}
+
 
//===--===//
 // Implementation of ClangExpressionParser
 
//===--===//
@@ -395,12 +469,6 @@ ClangExpressionParser::ClangExpressionParser(
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLanguageType();
 
-  std::string abi;
-  ArchSpec target_arch;
-  target_arch = target_sp->GetArchitecture();
-
-  const auto target_machine = target_arch.GetMachine();
-
   // If the expression is being evaluated in the context of an existing stack
   // frame, we introspect to see if the language runtime is availab

[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor out TargetOpts logic out of ClangExpressionParser (PR #101681)

2024-08-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

Same motivation as https://github.com/llvm/llvm-project/pull/101669. We plan to 
eventually use the Clang driver to initialize the `CompilerInstance`.

This should make refactorings of this code more straightforward.

**Changes**:
* Introduced `SetupTargetOpts`
* Called them from `ClangExpressionParser::ClangExpressionParser`
* Made `GetClangTargetABI` a file-local function since it's not using any of 
the state in `ClangExpressionParser`, and isn't used anywhere outside the 
source file

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


2 Files Affected:

- (modified) 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (+75-67) 
- (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h 
(-9) 


``diff
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..2d34f657793c3 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -351,6 +351,80 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
+/// Returns a string representing current ABI.
+///
+/// \param[in] target_arch
+/// The target architecture.
+///
+/// \return
+/// A string representing target ABI for the current architecture.
+static std::string GetClangTargetABI(const ArchSpec &target_arch) {
+  std::string abi;
+
+  if (target_arch.IsMIPS()) {
+switch (target_arch.GetFlags() & ArchSpec::eMIPSABI_mask) {
+case ArchSpec::eMIPSABI_N64:
+  abi = "n64";
+  break;
+case ArchSpec::eMIPSABI_N32:
+  abi = "n32";
+  break;
+case ArchSpec::eMIPSABI_O32:
+  abi = "o32";
+  break;
+default:
+  break;
+}
+  }
+  return abi;
+}
+
+static void SetupTargetOpts(CompilerInstance &compiler,
+lldb_private::Target const &target) {
+  Log *log = GetLog(LLDBLog::Expressions);
+  ArchSpec target_arch = target.GetArchitecture();
+
+  const auto target_machine = target_arch.GetMachine();
+  if (target_arch.IsValid()) {
+std::string triple = target_arch.GetTriple().str();
+compiler.getTargetOpts().Triple = triple;
+LLDB_LOGF(log, "Using %s as the target triple",
+  compiler.getTargetOpts().Triple.c_str());
+  } else {
+// If we get here we don't have a valid target and just have to guess.
+// Sometimes this will be ok to just use the host target triple (when we
+// evaluate say "2+3", but other expressions like breakpoint conditions and
+// other things that _are_ target specific really shouldn't just be using
+// the host triple. In such a case the language runtime should expose an
+// overridden options set (3), below.
+compiler.getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple();
+LLDB_LOGF(log, "Using default target triple of %s",
+  compiler.getTargetOpts().Triple.c_str());
+  }
+  // Now add some special fixes for known architectures: Any arm32 iOS
+  // environment, but not on arm64
+  if (compiler.getTargetOpts().Triple.find("arm64") == std::string::npos &&
+  compiler.getTargetOpts().Triple.find("arm") != std::string::npos &&
+  compiler.getTargetOpts().Triple.find("ios") != std::string::npos) {
+compiler.getTargetOpts().ABI = "apcs-gnu";
+  }
+  // Supported subsets of x86
+  if (target_machine == llvm::Triple::x86 ||
+  target_machine == llvm::Triple::x86_64) {
+compiler.getTargetOpts().FeaturesAsWritten.push_back("+sse");
+compiler.getTargetOpts().FeaturesAsWritten.push_back("+sse2");
+  }
+
+  // Set the target CPU to generate code for. This will be empty for any CPU
+  // that doesn't really need to make a special
+  // CPU string.
+  compiler.getTargetOpts().CPU = target_arch.GetClangTargetCPU();
+
+  // Set the target ABI
+  if (std::string abi = GetClangTargetABI(target_arch); !abi.empty())
+compiler.getTargetOpts().ABI = std::move(abi);
+}
+
 
//===--===//
 // Implementation of ClangExpressionParser
 
//===--===//
@@ -395,12 +469,6 @@ ClangExpressionParser::ClangExpressionParser(
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLanguageType();
 
-  std::string abi;
-  ArchSpec target_arch;
-  target_arch = target_sp->GetArchitecture();
-
-  const auto target_machine = target_arch.GetMachine();
-
   // If the expression is being evaluated in the context of an existing stack
   // frame, we introspect to see if the language runtime is available.
 
@@ -419,45 +487,7 @@ ClangExpressionParser::ClangExpressionParser(
 
   // 2. Configure the compiler with a set of default options

[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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

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

>From a4518719a09ef2910209663c62544dc5797f2df7 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 13:48:18 +0100
Subject: [PATCH 1/3] [lldb][ClangExpressionParser][NFC] Factor LangOptions
 logic out of ClangExpressionParser constructor

We plan to eventually use the Clang driver to initialize the
`CompilerInstance`.

This should make refactorings of this code more straightforward.
---
 lldb/include/lldb/Expression/Expression.h |   2 +-
 lldb/include/lldb/Expression/UserExpression.h |   2 +-
 .../Clang/ClangExpressionParser.cpp   | 301 +-
 3 files changed, 157 insertions(+), 148 deletions(-)

diff --git a/lldb/include/lldb/Expression/Expression.h 
b/lldb/include/lldb/Expression/Expression.h
index 356fe4b82ae43..8de9364436ccf 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -56,7 +56,7 @@ class Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  virtual ResultType DesiredResultType() { return eResultTypeAny; }
+  virtual ResultType DesiredResultType() const { return eResultTypeAny; }
 
   /// Flags
 
diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index b04d00b72e8fa..7ce463d2cb4e7 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -206,7 +206,7 @@ class UserExpression : public Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  ResultType DesiredResultType() override { return m_desired_type; }
+  ResultType DesiredResultType() const override { return m_desired_type; }
 
   /// Return true if validation code should be inserted into the expression.
   bool NeedsValidation() override { return true; }
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..11d519e738ee5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -77,6 +77,7 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ExecutionContextScope.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -351,62 +352,20 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
-//===--===//
-// Implementation of ClangExpressionParser
-//===--===//
-
-ClangExpressionParser::ClangExpressionParser(
-ExecutionContextScope *exe_scope, Expression &expr,
-bool generate_debug_info, std::vector include_directories,
-std::string filename)
-: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
-  m_pp_callbacks(nullptr),
-  m_include_directories(std::move(include_directories)),
-  m_filename(std::move(filename)) {
+static void SetupLangOpts(CompilerInstance &compiler,
+  ExecutionContextScope &exe_scope,
+  Expression const &expr) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  // We can't compile expressions without a target.  So if the exe_scope is
-  // null or doesn't have a target, then we just need to get out of here.  I'll
-  // lldbassert and not make any of the compiler objects since
-  // I can't return errors directly from the constructor.  Further calls will
-  // check if the compiler was made and
-  // bag out if it wasn't.
-
-  if (!exe_scope) {
-lldbassert(exe_scope &&
-   "Can't make an expression parser with a null scope.");
-return;
-  }
-
-  lldb::TargetSP target_sp;
-  target_sp = exe_scope->CalculateTarget();
-  if (!target_sp) {
-lldbassert(target_sp.get() &&
-   "Can't make an expression parser with a null target.");
-return;
-  }
-
-  // 1. Create a new compiler instance.
-  m_compiler = std::make_unique();
+  // If the expression is being evaluated in the context of an existing stack
+  // frame, we introspect to see if the language runtime is available.
 
-  // Make sure clang uses the same VFS as LLDB.
-  m_compiler->createFileManager(FileSystem::Instance().GetVirtualFileSystem());
+  lldb::StackFrameSP frame_sp = exe_scope.CalculateStackFrame();
+  lldb::ProcessSP process_sp = exe_scope.CalculateProcess();
 
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLanguageType();
 
-  std::string abi;
-  ArchSpec target_arch;
-  target_arch = target_sp->GetArchitecture();
-
-  const auto target_machine = target

[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

2024-08-02 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -351,136 +352,32 @@ static void 
SetupDefaultClangDiagnostics(CompilerInstance &compiler) {
   }
 }
 
-//===--===//
-// Implementation of ClangExpressionParser
-//===--===//
-
-ClangExpressionParser::ClangExpressionParser(
-ExecutionContextScope *exe_scope, Expression &expr,
-bool generate_debug_info, std::vector include_directories,
-std::string filename)
-: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
-  m_pp_callbacks(nullptr),
-  m_include_directories(std::move(include_directories)),
-  m_filename(std::move(filename)) {
+static void SetupLangOpts(CompilerInstance &compiler,
+  ExecutionContextScope &exe_scope,
+  Expression const &expr) {

felipepiovezan wrote:

the LLVM codebase is more of a west const type of codebase ;) 

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

2024-08-02 Thread Adrian Prantl via lldb-commits

https://github.com/adrian-prantl approved this pull request.


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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

2024-08-02 Thread Adrian Prantl via lldb-commits


@@ -615,6 +484,147 @@ ClangExpressionParser::ClangExpressionParser(
   // 'fopen'). Those libc functions are already correctly handled by LLDB, and
   // additionally enabling them as expandable builtins is breaking Clang.
   lang_opts.NoBuiltin = true;
+}
+
+static void SetupImportStdModuleLangOpts(CompilerInstance &compiler) {
+  LangOptions &lang_opts = compiler.getLangOpts();
+  lang_opts.Modules = true;
+  // We want to implicitly build modules.
+  lang_opts.ImplicitModules = true;
+  // To automatically import all submodules when we import 'std'.
+  lang_opts.ModulesLocalVisibility = false;
+
+  // We use the @import statements, so we need this:
+  // FIXME: We could use the modules-ts, but that currently doesn't work.
+  lang_opts.ObjC = true;
+
+  // Options we need to parse libc++ code successfully.
+  // FIXME: We should ask the driver for the appropriate default flags.
+  lang_opts.GNUMode = true;
+  lang_opts.GNUKeywords = true;
+  lang_opts.CPlusPlus11 = true;
+  lang_opts.BuiltinHeadersInSystemModules = true;
+
+  // The Darwin libc expects this macro to be set.
+  lang_opts.GNUCVersion = 40201;
+}
+
+//===--===//
+// Implementation of ClangExpressionParser
+//===--===//
+
+ClangExpressionParser::ClangExpressionParser(
+ExecutionContextScope *exe_scope, Expression &expr,
+bool generate_debug_info, std::vector include_directories,
+std::string filename)
+: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
+  m_pp_callbacks(nullptr),
+  m_include_directories(std::move(include_directories)),
+  m_filename(std::move(filename)) {
+  Log *log = GetLog(LLDBLog::Expressions);
+
+  // We can't compile expressions without a target.  So if the exe_scope is
+  // null or doesn't have a target, then we just need to get out of here.  I'll
+  // lldbassert and not make any of the compiler objects since
+  // I can't return errors directly from the constructor.  Further calls will
+  // check if the compiler was made and
+  // bag out if it wasn't.
+
+  if (!exe_scope) {
+lldbassert(exe_scope &&
+   "Can't make an expression parser with a null scope.");
+return;
+  }
+
+  lldb::TargetSP target_sp;
+  target_sp = exe_scope->CalculateTarget();
+  if (!target_sp) {
+lldbassert(target_sp.get() &&
+   "Can't make an expression parser with a null target.");
+return;
+  }
+
+  // 1. Create a new compiler instance.
+  m_compiler = std::make_unique();

adrian-prantl wrote:

It seems unnecessary for this to be unique_ptr, but I assume this is the 
`IsValid` flag for the object?
It would be cleaner if we had a createClangExpressionParser static function 
that returned an Expected.

Not a big deal though.

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


[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-02 Thread David Spickett via lldb-commits

DavidSpickett wrote:

I'm not going to merge this myself as I'm finishing for the week, but you can 
if you want to get that test added sooner.

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


[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-02 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

Sounds good, I'll merge it and add the test. If the bot fails for whatever 
reason, I'll revert it. Thanks!

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (PR #101697)

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

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

`CreateTargetInfo` can return a `nullptr` in a couple cases. So we should log 
that and let the user know something is wrong (hence the `lldbassert`).

>From 6dd59090c0098c18d38629fa1030122b0edffa88 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 16:18:57 +0100
Subject: [PATCH] [lldb][ClangExpressionParser] Log and assert on failure to
 create TargetInfo

---
 .../Clang/ClangExpressionParser.cpp   | 28 +++
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..9d9403ebb9051 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -465,18 +465,24 @@ ClangExpressionParser::ClangExpressionParser(
   // A value of 0 means no limit for both LLDB and Clang.
   m_compiler->getDiagnostics().setErrorLimit(target_sp->GetExprErrorLimit());
 
-  auto target_info = TargetInfo::CreateTargetInfo(
-  m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
-  if (log) {
-LLDB_LOGF(log, "Target datalayout string: '%s'",
-  target_info->getDataLayoutString());
-LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
-LLDB_LOGF(log, "Target vector alignment: %d",
-  target_info->getMaxVectorAlign());
-  }
-  m_compiler->setTarget(target_info);
+  if (auto *target_info = TargetInfo::CreateTargetInfo(
+  m_compiler->getDiagnostics(),
+  m_compiler->getInvocation().TargetOpts)) {
+if (log) {
+  LLDB_LOGF(log, "Target datalayout string: '%s'",
+target_info->getDataLayoutString());
+  LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
+  LLDB_LOGF(log, "Target vector alignment: %d",
+target_info->getMaxVectorAlign());
+}
+m_compiler->setTarget(target_info);
+  } else {
+if (log)
+  LLDB_LOGF(log, "Failed to create TargetInfo for '%s'",
+m_compiler->getTargetOpts().Triple.c_str());
 
-  assert(m_compiler->hasTarget());
+lldbassert(false && "Failed to create TargetInfo.");
+  }
 
   // 4. Set language options.
   lldb::LanguageType language = expr.Language().AsLanguageType();

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (PR #101697)

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

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (PR #101697)

2024-08-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

`CreateTargetInfo` can return a `nullptr` in a couple cases. So we should log 
that and let the user know something is wrong (hence the `lldbassert`).

I didn't actually run into this. Just stumbled upon it from reading the code.

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


1 Files Affected:

- (modified) 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (+17-11) 


``diff
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..9d9403ebb9051 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -465,18 +465,24 @@ ClangExpressionParser::ClangExpressionParser(
   // A value of 0 means no limit for both LLDB and Clang.
   m_compiler->getDiagnostics().setErrorLimit(target_sp->GetExprErrorLimit());
 
-  auto target_info = TargetInfo::CreateTargetInfo(
-  m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
-  if (log) {
-LLDB_LOGF(log, "Target datalayout string: '%s'",
-  target_info->getDataLayoutString());
-LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
-LLDB_LOGF(log, "Target vector alignment: %d",
-  target_info->getMaxVectorAlign());
-  }
-  m_compiler->setTarget(target_info);
+  if (auto *target_info = TargetInfo::CreateTargetInfo(
+  m_compiler->getDiagnostics(),
+  m_compiler->getInvocation().TargetOpts)) {
+if (log) {
+  LLDB_LOGF(log, "Target datalayout string: '%s'",
+target_info->getDataLayoutString());
+  LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
+  LLDB_LOGF(log, "Target vector alignment: %d",
+target_info->getMaxVectorAlign());
+}
+m_compiler->setTarget(target_info);
+  } else {
+if (log)
+  LLDB_LOGF(log, "Failed to create TargetInfo for '%s'",
+m_compiler->getTargetOpts().Triple.c_str());
 
-  assert(m_compiler->hasTarget());
+lldbassert(false && "Failed to create TargetInfo.");
+  }
 
   // 4. Set language options.
   lldb::LanguageType language = expr.Language().AsLanguageType();

``




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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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

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

>From a4518719a09ef2910209663c62544dc5797f2df7 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 13:48:18 +0100
Subject: [PATCH 1/4] [lldb][ClangExpressionParser][NFC] Factor LangOptions
 logic out of ClangExpressionParser constructor

We plan to eventually use the Clang driver to initialize the
`CompilerInstance`.

This should make refactorings of this code more straightforward.
---
 lldb/include/lldb/Expression/Expression.h |   2 +-
 lldb/include/lldb/Expression/UserExpression.h |   2 +-
 .../Clang/ClangExpressionParser.cpp   | 301 +-
 3 files changed, 157 insertions(+), 148 deletions(-)

diff --git a/lldb/include/lldb/Expression/Expression.h 
b/lldb/include/lldb/Expression/Expression.h
index 356fe4b82ae43..8de9364436ccf 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -56,7 +56,7 @@ class Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  virtual ResultType DesiredResultType() { return eResultTypeAny; }
+  virtual ResultType DesiredResultType() const { return eResultTypeAny; }
 
   /// Flags
 
diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index b04d00b72e8fa..7ce463d2cb4e7 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -206,7 +206,7 @@ class UserExpression : public Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  ResultType DesiredResultType() override { return m_desired_type; }
+  ResultType DesiredResultType() const override { return m_desired_type; }
 
   /// Return true if validation code should be inserted into the expression.
   bool NeedsValidation() override { return true; }
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..11d519e738ee5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -77,6 +77,7 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ExecutionContextScope.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -351,62 +352,20 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
-//===--===//
-// Implementation of ClangExpressionParser
-//===--===//
-
-ClangExpressionParser::ClangExpressionParser(
-ExecutionContextScope *exe_scope, Expression &expr,
-bool generate_debug_info, std::vector include_directories,
-std::string filename)
-: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
-  m_pp_callbacks(nullptr),
-  m_include_directories(std::move(include_directories)),
-  m_filename(std::move(filename)) {
+static void SetupLangOpts(CompilerInstance &compiler,
+  ExecutionContextScope &exe_scope,
+  Expression const &expr) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  // We can't compile expressions without a target.  So if the exe_scope is
-  // null or doesn't have a target, then we just need to get out of here.  I'll
-  // lldbassert and not make any of the compiler objects since
-  // I can't return errors directly from the constructor.  Further calls will
-  // check if the compiler was made and
-  // bag out if it wasn't.
-
-  if (!exe_scope) {
-lldbassert(exe_scope &&
-   "Can't make an expression parser with a null scope.");
-return;
-  }
-
-  lldb::TargetSP target_sp;
-  target_sp = exe_scope->CalculateTarget();
-  if (!target_sp) {
-lldbassert(target_sp.get() &&
-   "Can't make an expression parser with a null target.");
-return;
-  }
-
-  // 1. Create a new compiler instance.
-  m_compiler = std::make_unique();
+  // If the expression is being evaluated in the context of an existing stack
+  // frame, we introspect to see if the language runtime is available.
 
-  // Make sure clang uses the same VFS as LLDB.
-  m_compiler->createFileManager(FileSystem::Instance().GetVirtualFileSystem());
+  lldb::StackFrameSP frame_sp = exe_scope.CalculateStackFrame();
+  lldb::ProcessSP process_sp = exe_scope.CalculateProcess();
 
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLanguageType();
 
-  std::string abi;
-  ArchSpec target_arch;
-  target_arch = target_sp->GetArchitecture();
-
-  const auto target_machine = target

[Lldb-commits] [lldb] 9d07f43 - Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (#101672)

2024-08-02 Thread via lldb-commits

Author: David Spickett
Date: 2024-08-02T08:55:26-07:00
New Revision: 9d07f43676f03460d913aabd503ae8154cabdda1

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

LOG: Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build 
issue (#101672)

This reverts commit 9effefbae8d96006a4dd29bb9ab8532fd408559d.

With the include order in ScriptedProcessPythonInterface.cpp fixed
(though I cannot explain exactly why it works) and removes the /H flag
intended for debugging this issue.

I think it is something to do with Process.h pulling in PosixApi.h
somewhere along the line, and including Process.h after lldb-python.h
means that NO_PID_T is defined to prevent a redefinition of pid_t.

Added: 

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt

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

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

Modified: 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Removed: 

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

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



diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
index 8c7e92bead32c..eb22a960b5345 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
@@ -21,7 +21,6 @@ endif()
 
 add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
   ScriptedPythonInterface.cpp
-  ScriptedProcessPythonInterface.cpp
   ScriptedThreadPythonInterface.cpp
 
   LINK_LIBS
@@ -38,5 +37,6 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
 
 add_subdirectory(OperatingSystemPythonInterface)
 add_subdirectory(ScriptedPlatformPythonInterface)
+add_subdirectory(ScriptedProcessPythonInterface)
 add_subdirectory(ScriptedThreadPlanPythonInterface)
 

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
new file mode 100644
index 0..66ed041853f67
--- /dev/null
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
@@ -0,0 +1,16 @@
+add_lldb_library(lldbPluginScriptInterpreterPythonScriptedProcessPythonInterface
 PLUGIN
+
+  ScriptedProcessPythonInterface.cpp
+
+  LINK_LIBS
+lldbCore
+lldbHost
+lldbInterpreter
+lldbTarget
+lldbPluginScriptInterpreterPython
+${Python3_LIBRARIES}
+${LLDB_LIBEDIT_LIBS}
+
+  LINK_COMPONENTS
+Support
+  )

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
similarity index 84%
rename from 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
rename to 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
index 313c597ce48f3..c744d7028d04e 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.cpp
@@ -6,22 +6,27 @@
 //
 
//===--===//
 
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Host/Config.h"
-#if LLDB_ENABLE_PYTHON
-// LLDB Python header must be included first
-#include "../lldb-python.h"
-#endif
-#include "lldb/Target/Process.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/lldb-enumerations.h"
 
 #if LLDB_ENABLE_PYTHON
 
-#include "../SWIGPythonBridge.h"
-#include "../ScriptInterpreterPythonImpl.h"
+// clang-format off
+// LLDB Python header must be included first
+#include "../../lldb-python.h"
+
+#include "../../SWIGPythonBridge.h"
+#include "../../ScriptInterpreterPythonImpl.h"
+#include "../ScriptedThreadPythonInterface.h"
 #include "ScriptedProcessPythonInterface.h"
-#include "ScriptedThreadPythonInterface.h"
+
+// Included in this position to prevent redefinition of pid_t on Windows.
+#include "lldb/Target/Process.h"
+//clang-form

[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-02 Thread Med Ismail Bennani via lldb-commits

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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


@@ -615,6 +484,147 @@ ClangExpressionParser::ClangExpressionParser(
   // 'fopen'). Those libc functions are already correctly handled by LLDB, and
   // additionally enabling them as expandable builtins is breaking Clang.
   lang_opts.NoBuiltin = true;
+}
+
+static void SetupImportStdModuleLangOpts(CompilerInstance &compiler) {
+  LangOptions &lang_opts = compiler.getLangOpts();
+  lang_opts.Modules = true;
+  // We want to implicitly build modules.
+  lang_opts.ImplicitModules = true;
+  // To automatically import all submodules when we import 'std'.
+  lang_opts.ModulesLocalVisibility = false;
+
+  // We use the @import statements, so we need this:
+  // FIXME: We could use the modules-ts, but that currently doesn't work.
+  lang_opts.ObjC = true;
+
+  // Options we need to parse libc++ code successfully.
+  // FIXME: We should ask the driver for the appropriate default flags.
+  lang_opts.GNUMode = true;
+  lang_opts.GNUKeywords = true;
+  lang_opts.CPlusPlus11 = true;
+  lang_opts.BuiltinHeadersInSystemModules = true;
+
+  // The Darwin libc expects this macro to be set.
+  lang_opts.GNUCVersion = 40201;
+}
+
+//===--===//
+// Implementation of ClangExpressionParser
+//===--===//
+
+ClangExpressionParser::ClangExpressionParser(
+ExecutionContextScope *exe_scope, Expression &expr,
+bool generate_debug_info, std::vector include_directories,
+std::string filename)
+: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
+  m_pp_callbacks(nullptr),
+  m_include_directories(std::move(include_directories)),
+  m_filename(std::move(filename)) {
+  Log *log = GetLog(LLDBLog::Expressions);
+
+  // We can't compile expressions without a target.  So if the exe_scope is
+  // null or doesn't have a target, then we just need to get out of here.  I'll
+  // lldbassert and not make any of the compiler objects since
+  // I can't return errors directly from the constructor.  Further calls will
+  // check if the compiler was made and
+  // bag out if it wasn't.
+
+  if (!exe_scope) {
+lldbassert(exe_scope &&
+   "Can't make an expression parser with a null scope.");
+return;
+  }
+
+  lldb::TargetSP target_sp;
+  target_sp = exe_scope->CalculateTarget();
+  if (!target_sp) {
+lldbassert(target_sp.get() &&
+   "Can't make an expression parser with a null target.");
+return;
+  }
+
+  // 1. Create a new compiler instance.
+  m_compiler = std::make_unique();

Michael137 wrote:

Yea this is how it always was. Didn't want to go too crazy with the refactor.

We actually don't want to create the manually `CompilerInstance` in the future 
anyway. So there's a good chance this goes away soon

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (PR #101697)

2024-08-02 Thread Adrian Prantl via lldb-commits

https://github.com/adrian-prantl approved this pull request.


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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (PR #101697)

2024-08-02 Thread Adrian Prantl via lldb-commits


@@ -465,18 +465,24 @@ ClangExpressionParser::ClangExpressionParser(
   // A value of 0 means no limit for both LLDB and Clang.
   m_compiler->getDiagnostics().setErrorLimit(target_sp->GetExprErrorLimit());
 
-  auto target_info = TargetInfo::CreateTargetInfo(
-  m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
-  if (log) {
-LLDB_LOGF(log, "Target datalayout string: '%s'",
-  target_info->getDataLayoutString());
-LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
-LLDB_LOGF(log, "Target vector alignment: %d",
-  target_info->getMaxVectorAlign());
-  }
-  m_compiler->setTarget(target_info);
+  if (auto *target_info = TargetInfo::CreateTargetInfo(
+  m_compiler->getDiagnostics(),
+  m_compiler->getInvocation().TargetOpts)) {
+if (log) {
+  LLDB_LOGF(log, "Target datalayout string: '%s'",
+target_info->getDataLayoutString());
+  LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
+  LLDB_LOGF(log, "Target vector alignment: %d",
+target_info->getMaxVectorAlign());
+}
+m_compiler->setTarget(target_info);
+  } else {
+if (log)
+  LLDB_LOGF(log, "Failed to create TargetInfo for '%s'",
+m_compiler->getTargetOpts().Triple.c_str());
 
-  assert(m_compiler->hasTarget());
+lldbassert(false && "Failed to create TargetInfo.");

adrian-prantl wrote:

Based on that there used to be an assert here, should this return?
Same comment as in the previous review — ideally this would return an 
llvm::Error here if it weren't a constructor.

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


[Lldb-commits] [lldb] c6ce324 - [lldb] Eliminate more Targer* in favor of Target& in CommandObjects (NFC)

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

Author: Jonas Devlieghere
Date: 2024-08-02T09:53:34-07:00
New Revision: c6ce324fa7fb2438b945fa1205b2a23138327e83

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

LOG: [lldb] Eliminate more Targer* in favor of Target& in CommandObjects (NFC)

The majority of the replaced Target pointers were already used
unconditionally and the few that were shouldn't even be NULL.

Added: 


Modified: 
lldb/source/Commands/CommandObjectBreakpoint.cpp
lldb/source/Commands/CommandObjectBreakpoint.h
lldb/source/Commands/CommandObjectBreakpointCommand.cpp
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Commands/CommandObjectSource.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp 
b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index aad03af11331c..abde27b2b53ad 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -848,7 +848,7 @@ class CommandObjectBreakpointModify : public 
CommandObjectParsed {
 BreakpointIDList valid_bp_ids;
 
 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-command, &target, result, &valid_bp_ids,
+command, target, result, &valid_bp_ids,
 BreakpointName::Permissions::PermissionKinds::disablePerm);
 
 if (result.Succeeded()) {
@@ -929,7 +929,7 @@ class CommandObjectBreakpointEnable : public 
CommandObjectParsed {
   // Particular breakpoint selected; enable that breakpoint.
   BreakpointIDList valid_bp_ids;
   CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-  command, &target, result, &valid_bp_ids,
+  command, target, result, &valid_bp_ids,
   BreakpointName::Permissions::PermissionKinds::disablePerm);
 
   if (result.Succeeded()) {
@@ -1035,7 +1035,7 @@ the second re-enables the first location.");
   BreakpointIDList valid_bp_ids;
 
   CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-  command, &target, result, &valid_bp_ids,
+  command, target, result, &valid_bp_ids,
   BreakpointName::Permissions::PermissionKinds::disablePerm);
 
   if (result.Succeeded()) {
@@ -1180,7 +1180,7 @@ class CommandObjectBreakpointList : public 
CommandObjectParsed {
   // Particular breakpoints selected; show info about that breakpoint.
   BreakpointIDList valid_bp_ids;
   CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-  command, &target, result, &valid_bp_ids,
+  command, target, result, &valid_bp_ids,
   BreakpointName::Permissions::PermissionKinds::listPerm);
 
   if (result.Succeeded()) {
@@ -1459,7 +1459,7 @@ class CommandObjectBreakpointDelete : public 
CommandObjectParsed {
 
   if (!command.empty()) {
 CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-command, &target, result, &excluded_bp_ids,
+command, target, result, &excluded_bp_ids,
 BreakpointName::Permissions::PermissionKinds::deletePerm);
 if (!result.Succeeded())
   return;
@@ -1478,7 +1478,7 @@ class CommandObjectBreakpointDelete : public 
CommandObjectParsed {
   }
 } else {
   CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
-  command, &target, result, &valid_bp_ids,
+  command, target, result, &valid_bp_ids,
   BreakpointName::Permissions::PermissionKinds::deletePerm);
   if (!result.Succeeded())
 return;
@@ -1781,7 +1781,7 @@ class CommandObjectBreakpointNameAdd : public 
CommandObjectParsed {
 // Particular breakpoint selected; disable that breakpoint.
 BreakpointIDList valid_bp_ids;
 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
-command, &target, result, &valid_bp_ids,
+command, target, result, &valid_bp_ids,
 BreakpointName::Permissions::PermissionKinds::listPerm);
 
 if (result.Succeeded()) {
@@ -1855,7 +1855,7 @@ class CommandObjectBreakpointNameDelete : public 
CommandObjectParsed {
 // Particular breakpoint selected; disable that breakpoint.
 BreakpointIDList valid_bp_ids;
 CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
-command, &target, result, &valid_bp_ids,
+command, target, result, &valid_bp_ids,
 BreakpointName::Permissions::PermissionKinds::deletePerm);
 
 if (result.Succeeded()) {
@@ -2328,7 +2328,7 @@ class CommandObjectBreakpointWrite : public 
CommandObjectParsed {
 BreakpointIDList valid_bp_ids;
 if (!command.empty()) {
   CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs(
-  command, &target, result, &valid_bp_ids,
+  command, target, result, &valid_bp_ids,
   BreakpointName::Perm

[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (PR #101697)

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


@@ -465,18 +465,24 @@ ClangExpressionParser::ClangExpressionParser(
   // A value of 0 means no limit for both LLDB and Clang.
   m_compiler->getDiagnostics().setErrorLimit(target_sp->GetExprErrorLimit());
 
-  auto target_info = TargetInfo::CreateTargetInfo(
-  m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
-  if (log) {
-LLDB_LOGF(log, "Target datalayout string: '%s'",
-  target_info->getDataLayoutString());
-LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
-LLDB_LOGF(log, "Target vector alignment: %d",
-  target_info->getMaxVectorAlign());
-  }
-  m_compiler->setTarget(target_info);
+  if (auto *target_info = TargetInfo::CreateTargetInfo(
+  m_compiler->getDiagnostics(),
+  m_compiler->getInvocation().TargetOpts)) {
+if (log) {
+  LLDB_LOGF(log, "Target datalayout string: '%s'",
+target_info->getDataLayoutString());
+  LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
+  LLDB_LOGF(log, "Target vector alignment: %d",
+target_info->getMaxVectorAlign());
+}
+m_compiler->setTarget(target_info);
+  } else {
+if (log)
+  LLDB_LOGF(log, "Failed to create TargetInfo for '%s'",
+m_compiler->getTargetOpts().Triple.c_str());
 
-  assert(m_compiler->hasTarget());
+lldbassert(false && "Failed to create TargetInfo.");

Michael137 wrote:

It's a bit awkward because this all happens in the constructor. And stopping 
the construction half-way probably won't buy us much. I think this is one of 
those unusual circumstance where we want to assert at runtime. I guess we could 
have a separate `Init` method for the `ClangExpressionParser`. Which returns 
`Expected`. Then update all the users to check the return of that.

But that's a larger refactor that we can do at some later point.

What used to happen in release builds (tbh I'm not sure if this ever really 
gets exercised in practice), is that `target_info` was a `nullptr`. And we just 
happily continued with the construction of the object.

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (PR #101697)

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

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (PR #101697)

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

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


[Lldb-commits] [lldb] d6cbcf9 - [lldb][ClangExpressionParser][NFC] Factor out TargetOpts logic out of ClangExpressionParser (#101681)

2024-08-02 Thread via lldb-commits

Author: Michael Buch
Date: 2024-08-02T18:13:35+01:00
New Revision: d6cbcf93b227befaad00957a56acd63c837c26ff

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

LOG: [lldb][ClangExpressionParser][NFC] Factor out TargetOpts logic out of 
ClangExpressionParser (#101681)

Same motivation as https://github.com/llvm/llvm-project/pull/101669. We
plan to eventually use the Clang driver to initialize the
`CompilerInstance`.

This should make refactorings of this code more straightforward.

**Changes**:
* Introduced `SetupTargetOpts`
* Called them from `ClangExpressionParser::ClangExpressionParser`
* Made `GetClangTargetABI` a file-local function since it's not using
any of the state in `ClangExpressionParser`, and isn't used anywhere
outside the source file

Added: 


Modified: 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h

Removed: 




diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..2d34f657793c3 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -351,6 +351,80 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
+/// Returns a string representing current ABI.
+///
+/// \param[in] target_arch
+/// The target architecture.
+///
+/// \return
+/// A string representing target ABI for the current architecture.
+static std::string GetClangTargetABI(const ArchSpec &target_arch) {
+  std::string abi;
+
+  if (target_arch.IsMIPS()) {
+switch (target_arch.GetFlags() & ArchSpec::eMIPSABI_mask) {
+case ArchSpec::eMIPSABI_N64:
+  abi = "n64";
+  break;
+case ArchSpec::eMIPSABI_N32:
+  abi = "n32";
+  break;
+case ArchSpec::eMIPSABI_O32:
+  abi = "o32";
+  break;
+default:
+  break;
+}
+  }
+  return abi;
+}
+
+static void SetupTargetOpts(CompilerInstance &compiler,
+lldb_private::Target const &target) {
+  Log *log = GetLog(LLDBLog::Expressions);
+  ArchSpec target_arch = target.GetArchitecture();
+
+  const auto target_machine = target_arch.GetMachine();
+  if (target_arch.IsValid()) {
+std::string triple = target_arch.GetTriple().str();
+compiler.getTargetOpts().Triple = triple;
+LLDB_LOGF(log, "Using %s as the target triple",
+  compiler.getTargetOpts().Triple.c_str());
+  } else {
+// If we get here we don't have a valid target and just have to guess.
+// Sometimes this will be ok to just use the host target triple (when we
+// evaluate say "2+3", but other expressions like breakpoint conditions and
+// other things that _are_ target specific really shouldn't just be using
+// the host triple. In such a case the language runtime should expose an
+// overridden options set (3), below.
+compiler.getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple();
+LLDB_LOGF(log, "Using default target triple of %s",
+  compiler.getTargetOpts().Triple.c_str());
+  }
+  // Now add some special fixes for known architectures: Any arm32 iOS
+  // environment, but not on arm64
+  if (compiler.getTargetOpts().Triple.find("arm64") == std::string::npos &&
+  compiler.getTargetOpts().Triple.find("arm") != std::string::npos &&
+  compiler.getTargetOpts().Triple.find("ios") != std::string::npos) {
+compiler.getTargetOpts().ABI = "apcs-gnu";
+  }
+  // Supported subsets of x86
+  if (target_machine == llvm::Triple::x86 ||
+  target_machine == llvm::Triple::x86_64) {
+compiler.getTargetOpts().FeaturesAsWritten.push_back("+sse");
+compiler.getTargetOpts().FeaturesAsWritten.push_back("+sse2");
+  }
+
+  // Set the target CPU to generate code for. This will be empty for any CPU
+  // that doesn't really need to make a special
+  // CPU string.
+  compiler.getTargetOpts().CPU = target_arch.GetClangTargetCPU();
+
+  // Set the target ABI
+  if (std::string abi = GetClangTargetABI(target_arch); !abi.empty())
+compiler.getTargetOpts().ABI = std::move(abi);
+}
+
 
//===--===//
 // Implementation of ClangExpressionParser
 
//===--===//
@@ -395,12 +469,6 @@ ClangExpressionParser::ClangExpressionParser(
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLanguageType();
 
-  std::string abi;
-  ArchSpec target_arch;
-  target_arch = target_sp->GetArchitecture();
-
-  const auto target_machine = target_arch.GetM

[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor out TargetOpts logic out of ClangExpressionParser (PR #101681)

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

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

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


@@ -9,6 +9,8 @@
 #include "lldb/API/SBSaveCoreOptions.h"
 #include "lldb/API/SBError.h"
 #include "lldb/API/SBFileSpec.h"
+#include "lldb/API/SBProcess.h"
+#include "lldb/API/SBThread.h"

Jlalond wrote:

They're actually not right now, all the SB classes are forward declares in 
`SBDefines`, and I followed the pattern where classes that need the actual 
implementation include the header in their cpp.

[SBProcess for 
refernece](https://github.com/llvm/llvm-project/blob/main/lldb/source/API/SBProcess.cpp#L35)

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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

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

>From a4518719a09ef2910209663c62544dc5797f2df7 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 13:48:18 +0100
Subject: [PATCH 1/4] [lldb][ClangExpressionParser][NFC] Factor LangOptions
 logic out of ClangExpressionParser constructor

We plan to eventually use the Clang driver to initialize the
`CompilerInstance`.

This should make refactorings of this code more straightforward.
---
 lldb/include/lldb/Expression/Expression.h |   2 +-
 lldb/include/lldb/Expression/UserExpression.h |   2 +-
 .../Clang/ClangExpressionParser.cpp   | 301 +-
 3 files changed, 157 insertions(+), 148 deletions(-)

diff --git a/lldb/include/lldb/Expression/Expression.h 
b/lldb/include/lldb/Expression/Expression.h
index 356fe4b82ae43..8de9364436ccf 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -56,7 +56,7 @@ class Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  virtual ResultType DesiredResultType() { return eResultTypeAny; }
+  virtual ResultType DesiredResultType() const { return eResultTypeAny; }
 
   /// Flags
 
diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index b04d00b72e8fa..7ce463d2cb4e7 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -206,7 +206,7 @@ class UserExpression : public Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  ResultType DesiredResultType() override { return m_desired_type; }
+  ResultType DesiredResultType() const override { return m_desired_type; }
 
   /// Return true if validation code should be inserted into the expression.
   bool NeedsValidation() override { return true; }
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..11d519e738ee5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -77,6 +77,7 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ExecutionContextScope.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -351,62 +352,20 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
-//===--===//
-// Implementation of ClangExpressionParser
-//===--===//
-
-ClangExpressionParser::ClangExpressionParser(
-ExecutionContextScope *exe_scope, Expression &expr,
-bool generate_debug_info, std::vector include_directories,
-std::string filename)
-: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
-  m_pp_callbacks(nullptr),
-  m_include_directories(std::move(include_directories)),
-  m_filename(std::move(filename)) {
+static void SetupLangOpts(CompilerInstance &compiler,
+  ExecutionContextScope &exe_scope,
+  Expression const &expr) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  // We can't compile expressions without a target.  So if the exe_scope is
-  // null or doesn't have a target, then we just need to get out of here.  I'll
-  // lldbassert and not make any of the compiler objects since
-  // I can't return errors directly from the constructor.  Further calls will
-  // check if the compiler was made and
-  // bag out if it wasn't.
-
-  if (!exe_scope) {
-lldbassert(exe_scope &&
-   "Can't make an expression parser with a null scope.");
-return;
-  }
-
-  lldb::TargetSP target_sp;
-  target_sp = exe_scope->CalculateTarget();
-  if (!target_sp) {
-lldbassert(target_sp.get() &&
-   "Can't make an expression parser with a null target.");
-return;
-  }
-
-  // 1. Create a new compiler instance.
-  m_compiler = std::make_unique();
+  // If the expression is being evaluated in the context of an existing stack
+  // frame, we introspect to see if the language runtime is available.
 
-  // Make sure clang uses the same VFS as LLDB.
-  m_compiler->createFileManager(FileSystem::Instance().GetVirtualFileSystem());
+  lldb::StackFrameSP frame_sp = exe_scope.CalculateStackFrame();
+  lldb::ProcessSP process_sp = exe_scope.CalculateProcess();
 
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLanguageType();
 
-  std::string abi;
-  ArchSpec target_arch;
-  target_arch = target_sp->GetArchitecture();
-
-  const auto target_machine = target

[Lldb-commits] [lldb] [lldb/test] Add test for the `scripting template list` command (PR #101726)

2024-08-02 Thread Med Ismail Bennani via lldb-commits

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

This patch adds a shell test to verify the output of the `scripting template 
list` command.

>From 52c63b228e903e1a4850f8cc172c9a7c929f7e40 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Fri, 2 Aug 2024 11:00:13 -0700
Subject: [PATCH] [lldb/test] Add test for the `scripting template list`
 command

This patch adds a shell test to verify the output of the `scripting
template list` command.

Signed-off-by: Med Ismail Bennani 
---
 .../command-scripting-template-list.test  | 38 +++
 1 file changed, 38 insertions(+)
 create mode 100644 
lldb/test/Shell/Commands/command-scripting-template-list.test

diff --git a/lldb/test/Shell/Commands/command-scripting-template-list.test 
b/lldb/test/Shell/Commands/command-scripting-template-list.test
new file mode 100644
index 0..906f012618443
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-scripting-template-list.test
@@ -0,0 +1,38 @@
+# REQUIRES: python
+# RUN: %lldb -s %s -o exit | FileCheck %s
+
+scripting template list
+# CHECK:Available scripted extension templates:
+# CHECK-NEXT:  Name: OperatingSystemPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock thread state
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:settings set target.process.python-os-plugin-path 

+# CHECK-NEXT:settings set 
process.experimental.os-plugin-reports-all-threads [0/1]
+# CHECK-NEXT:  Name: ScriptedPlatformPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock platform and interact with its processes.
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages: None
+# CHECK-NEXT:  Name: ScriptedProcessPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock process state
+# CHECK-NEXT:  API Usages:
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Attach
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Launch
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:process attach -C  [-k key -v value ...]
+# CHECK-NEXT:process launch -C  [-k key -v value ...]
+# CHECK-NEXT:  Name: ScriptedThreadPlanPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Alter thread stepping logic and stop reason
+# CHECK-NEXT:  API Usages: SBThread.StepUsingScriptedThreadPlan
+# CHECK-NEXT:  Command Interpreter Usages: thread step-scripted -C 
 [-k key -v value ...]
+
+scripting template list -l lua
+# CHECK: Available scripted extension templates: None

___
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 for the `scripting template list` command (PR #101726)

2024-08-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Med Ismail Bennani (medismailben)


Changes

This patch adds a shell test to verify the output of the `scripting template 
list` command.

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


1 Files Affected:

- (added) lldb/test/Shell/Commands/command-scripting-template-list.test (+38) 


``diff
diff --git a/lldb/test/Shell/Commands/command-scripting-template-list.test 
b/lldb/test/Shell/Commands/command-scripting-template-list.test
new file mode 100644
index 0..906f012618443
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-scripting-template-list.test
@@ -0,0 +1,38 @@
+# REQUIRES: python
+# RUN: %lldb -s %s -o exit | FileCheck %s
+
+scripting template list
+# CHECK:Available scripted extension templates:
+# CHECK-NEXT:  Name: OperatingSystemPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock thread state
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:settings set target.process.python-os-plugin-path 

+# CHECK-NEXT:settings set 
process.experimental.os-plugin-reports-all-threads [0/1]
+# CHECK-NEXT:  Name: ScriptedPlatformPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock platform and interact with its processes.
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages: None
+# CHECK-NEXT:  Name: ScriptedProcessPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock process state
+# CHECK-NEXT:  API Usages:
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Attach
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Launch
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:process attach -C  [-k key -v value ...]
+# CHECK-NEXT:process launch -C  [-k key -v value ...]
+# CHECK-NEXT:  Name: ScriptedThreadPlanPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Alter thread stepping logic and stop reason
+# CHECK-NEXT:  API Usages: SBThread.StepUsingScriptedThreadPlan
+# CHECK-NEXT:  Command Interpreter Usages: thread step-scripted -C 
 [-k key -v value ...]
+
+scripting template list -l lua
+# CHECK: Available scripted extension templates: None

``




https://github.com/llvm/llvm-project/pull/101726
___
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 for the `scripting template list` command (PR #101726)

2024-08-02 Thread Med Ismail Bennani via lldb-commits

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

>From d7242816f18d7b71013f60dfdbb0ddfa0af77e04 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Fri, 2 Aug 2024 11:04:07 -0700
Subject: [PATCH] [lldb/test] Add test for the `scripting template list`
 command

This patch adds a shell test to verify the output of the `scripting
template list` command.

Signed-off-by: Med Ismail Bennani 
---
 .../command-scripting-template-list.test  | 42 +++
 1 file changed, 42 insertions(+)
 create mode 100644 
lldb/test/Shell/Commands/command-scripting-template-list.test

diff --git a/lldb/test/Shell/Commands/command-scripting-template-list.test 
b/lldb/test/Shell/Commands/command-scripting-template-list.test
new file mode 100644
index 0..8dc3fe42931ab
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-scripting-template-list.test
@@ -0,0 +1,42 @@
+# REQUIRES: python
+# RUN: %lldb -s %s -o exit | FileCheck %s
+
+scripting template list
+# CHECK:Available scripted extension templates:
+
+# CHECK:  Name: OperatingSystemPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock thread state
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:settings set target.process.python-os-plugin-path 

+# CHECK-NEXT:settings set 
process.experimental.os-plugin-reports-all-threads [0/1]
+
+# CHECK:  Name: ScriptedPlatformPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock platform and interact with its processes.
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages: None
+
+# CHECK:  Name: ScriptedProcessPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock process state
+# CHECK-NEXT:  API Usages:
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Attach
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Launch
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:process attach -C  [-k key -v value ...]
+# CHECK-NEXT:process launch -C  [-k key -v value ...]
+
+# CHECK:  Name: ScriptedThreadPlanPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Alter thread stepping logic and stop reason
+# CHECK-NEXT:  API Usages: SBThread.StepUsingScriptedThreadPlan
+# CHECK-NEXT:  Command Interpreter Usages: thread step-scripted -C 
 [-k key -v value ...]
+
+scripting template list -l lua
+# CHECK: Available scripted extension templates: None

___
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 for the `scripting template list` command (PR #101726)

2024-08-02 Thread Med Ismail Bennani via lldb-commits

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

>From 3c3ed4f115a38ea4aed4901724caa5da2512a754 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Fri, 2 Aug 2024 11:05:43 -0700
Subject: [PATCH] [lldb/test] Add test for the `scripting template list`
 command

This patch adds a shell test to verify the output of the `scripting
template list` command as discussed in #101672.

Signed-off-by: Med Ismail Bennani 
---
 .../command-scripting-template-list.test  | 42 +++
 1 file changed, 42 insertions(+)
 create mode 100644 
lldb/test/Shell/Commands/command-scripting-template-list.test

diff --git a/lldb/test/Shell/Commands/command-scripting-template-list.test 
b/lldb/test/Shell/Commands/command-scripting-template-list.test
new file mode 100644
index 0..8dc3fe42931ab
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-scripting-template-list.test
@@ -0,0 +1,42 @@
+# REQUIRES: python
+# RUN: %lldb -s %s -o exit | FileCheck %s
+
+scripting template list
+# CHECK:Available scripted extension templates:
+
+# CHECK:  Name: OperatingSystemPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock thread state
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:settings set target.process.python-os-plugin-path 

+# CHECK-NEXT:settings set 
process.experimental.os-plugin-reports-all-threads [0/1]
+
+# CHECK:  Name: ScriptedPlatformPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock platform and interact with its processes.
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages: None
+
+# CHECK:  Name: ScriptedProcessPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock process state
+# CHECK-NEXT:  API Usages:
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Attach
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Launch
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:process attach -C  [-k key -v value ...]
+# CHECK-NEXT:process launch -C  [-k key -v value ...]
+
+# CHECK:  Name: ScriptedThreadPlanPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Alter thread stepping logic and stop reason
+# CHECK-NEXT:  API Usages: SBThread.StepUsingScriptedThreadPlan
+# CHECK-NEXT:  Command Interpreter Usages: thread step-scripted -C 
 [-k key -v value ...]
+
+scripting template list -l lua
+# CHECK: Available scripted extension templates: None

___
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 for the `scripting template list` command (PR #101726)

2024-08-02 Thread Med Ismail Bennani via lldb-commits

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

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

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

>From d7940af06873cedf5976dc829dd9377b2851ae25 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 23 Jul 2024 16:50:57 -0700
Subject: [PATCH 01/12] Implemplement a thread list that is currently unused
 for SBSaveCore. Run formatter

---
 lldb/include/lldb/API/SBSaveCoreOptions.h  | 24 +++
 lldb/include/lldb/Symbol/SaveCoreOptions.h | 10 +
 lldb/include/lldb/Target/Process.h |  5 +++
 lldb/source/API/SBSaveCoreOptions.cpp  | 20 +
 lldb/source/Core/PluginManager.cpp |  4 ++
 lldb/source/Symbol/SaveCoreOptions.cpp | 48 ++
 lldb/source/Target/Process.cpp | 12 ++
 7 files changed, 123 insertions(+)

diff --git a/lldb/include/lldb/API/SBSaveCoreOptions.h 
b/lldb/include/lldb/API/SBSaveCoreOptions.h
index e77496bd3a4a0..b485371ce8f55 100644
--- a/lldb/include/lldb/API/SBSaveCoreOptions.h
+++ b/lldb/include/lldb/API/SBSaveCoreOptions.h
@@ -53,6 +53,30 @@ class LLDB_API SBSaveCoreOptions {
   /// \return The output file spec.
   SBFileSpec GetOutputFile() const;
 
+  /// Add a thread to save in the core file.
+  ///
+  /// \param thread_id The thread ID to save.
+  void AddThread(lldb::tid_t thread_id);
+
+  /// Remove a thread from the list of threads to save.
+  ///
+  /// \param thread_id The thread ID to remove.
+  /// \return True if the thread was removed, false if it was not in the list.
+  bool RemoveThread(lldb::tid_t thread_id);
+
+  /// Get the number of threads to save. If this list is empty all threads will
+  /// be saved.
+  ///
+  /// \return The number of threads to save.
+  uint32_t GetNumThreads() const;
+
+  /// Get the thread ID at the given index.
+  ///
+  /// \param[in] index The index of the thread ID to get.
+  /// \return The thread ID at the given index, or an error
+  /// if there is no thread at the index.
+  lldb::tid_t GetThreadAtIndex(uint32_t index, SBError &error) const;
+
   /// Reset all options.
   void Clear();
 
diff --git a/lldb/include/lldb/Symbol/SaveCoreOptions.h 
b/lldb/include/lldb/Symbol/SaveCoreOptions.h
index 583bc1f483d04..d583b32b29508 100644
--- a/lldb/include/lldb/Symbol/SaveCoreOptions.h
+++ b/lldb/include/lldb/Symbol/SaveCoreOptions.h
@@ -14,6 +14,7 @@
 #include "lldb/lldb-types.h"
 
 #include 
+#include 
 #include 
 
 namespace lldb_private {
@@ -32,12 +33,21 @@ class SaveCoreOptions {
   void SetOutputFile(lldb_private::FileSpec file);
   const std::optional GetOutputFile() const;
 
+  void AddThread(lldb::tid_t tid);
+  bool RemoveThread(lldb::tid_t tid);
+  size_t GetNumThreads() const;
+  int64_t GetThreadAtIndex(size_t index) const;
+  bool ShouldSaveThread(lldb::tid_t tid) const;
+
+  Status EnsureValidConfiguration() const;
+
   void Clear();
 
 private:
   std::optional m_plugin_name;
   std::optional m_file;
   std::optional m_style;
+  std::set m_threads_to_save;
 };
 } // namespace lldb_private
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index c8475db8ae160..c551504c8583f 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -741,6 +741,11 @@ class Process : public 
std::enable_shared_from_this,
   Status CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style,
  CoreFileMemoryRanges &ranges);
 
+  /// Helper function for Process::SaveCore(...) that calculates the thread 
list
+  /// based upon options set within a given \a core_options object.
+  ThreadCollection::ThreadIterable
+  CalculateCoreFileThreadList(SaveCoreOptions &core_options);
+
 protected:
   virtual JITLoaderList &GetJITLoaders();
 
diff --git a/lldb/source/API/SBSaveCoreOptions.cpp 
b/lldb/source/API/SBSaveCoreOptions.cpp
index 6c3f74596203d..1d45313d2426a 100644
--- a/lldb/source/API/SBSaveCoreOptions.cpp
+++ b/lldb/source/API/SBSaveCoreOptions.cpp
@@ -75,6 +75,26 @@ lldb::SaveCoreStyle SBSaveCoreOptions::GetStyle() const {
   return m_opaque_up->GetStyle();
 }
 
+void SBSaveCoreOptions::AddThread(lldb::tid_t tid) {
+  m_opaque_up->AddThread(tid);
+}
+
+bool SBSaveCoreOptions::RemoveThread(lldb::tid_t tid) {
+  return m_opaque_up->RemoveThread(tid);
+}
+
+uint32_t SBSaveCoreOptions::GetNumThreads() const {
+  return m_opaque_up->GetNumThreads();
+}
+
+lldb::tid_t SBSaveCoreOptions::GetThreadAtIndex(uint32_t idx,
+SBError &error) const {
+  int64_t tid = m_opaque_up->GetThreadAtIndex(idx);
+  if (tid == -1)
+error.SetErrorString("Invalid index");
+  return 0;
+}
+
 void SBSaveCoreOptions::Clear() {
   LLDB_INSTRUMENT_VA(this);
   m_opaque_up->Clear();
diff --git a/lldb/source/Core/PluginManager.cpp 
b/lldb/source/Core/PluginManager.cpp
index 759ef3a8afe02..94e3cb85f31b9 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -714,6 +714,10 @@ Status PluginManager::SaveCore(const lldb::ProcessSP 
&process_sp

[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

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


@@ -9,6 +9,8 @@
 #include "lldb/API/SBSaveCoreOptions.h"
 #include "lldb/API/SBError.h"
 #include "lldb/API/SBFileSpec.h"
+#include "lldb/API/SBProcess.h"
+#include "lldb/API/SBThread.h"

Jlalond wrote:

Followed up offline, Greg was correct and it was proper to move these to the 
header.

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


[Lldb-commits] [lldb] 1fcddc0 - [lldb] Fix a warning

2024-08-02 Thread Kazu Hirata via lldb-commits

Author: Kazu Hirata
Date: 2024-08-02T11:10:21-07:00
New Revision: 1fcddc0dfa1b371bc0b278438d5f47cf8d03b511

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

LOG: [lldb] Fix a warning

This patch fixes:

  
lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp:177:10:
  error: unused variable 'str_len' [-Werror,-Wunused-variable]

Added: 


Modified: 
lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp 
b/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp
index 0d19d63fec0b8..d42e31c2aea0a 100644
--- 
a/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp
+++ 
b/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp
@@ -174,8 +174,7 @@ 
AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
   // For the reason string, we want the string not the address, so fetch that.
   std::string reason_string;
   Status error;
-  size_t str_len =
-  process->ReadCStringFromMemory(reason_addr, reason_string, error);
+  process->ReadCStringFromMemory(reason_addr, reason_string, error);
   if (error.Fail()) {
 // Even if we couldn't read the string, return the other data.
 LLDB_LOG(log, "Couldn't fetch reason string: {0}.", error);



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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

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

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

>From d7940af06873cedf5976dc829dd9377b2851ae25 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 23 Jul 2024 16:50:57 -0700
Subject: [PATCH 01/13] Implemplement a thread list that is currently unused
 for SBSaveCore. Run formatter

---
 lldb/include/lldb/API/SBSaveCoreOptions.h  | 24 +++
 lldb/include/lldb/Symbol/SaveCoreOptions.h | 10 +
 lldb/include/lldb/Target/Process.h |  5 +++
 lldb/source/API/SBSaveCoreOptions.cpp  | 20 +
 lldb/source/Core/PluginManager.cpp |  4 ++
 lldb/source/Symbol/SaveCoreOptions.cpp | 48 ++
 lldb/source/Target/Process.cpp | 12 ++
 7 files changed, 123 insertions(+)

diff --git a/lldb/include/lldb/API/SBSaveCoreOptions.h 
b/lldb/include/lldb/API/SBSaveCoreOptions.h
index e77496bd3a4a0..b485371ce8f55 100644
--- a/lldb/include/lldb/API/SBSaveCoreOptions.h
+++ b/lldb/include/lldb/API/SBSaveCoreOptions.h
@@ -53,6 +53,30 @@ class LLDB_API SBSaveCoreOptions {
   /// \return The output file spec.
   SBFileSpec GetOutputFile() const;
 
+  /// Add a thread to save in the core file.
+  ///
+  /// \param thread_id The thread ID to save.
+  void AddThread(lldb::tid_t thread_id);
+
+  /// Remove a thread from the list of threads to save.
+  ///
+  /// \param thread_id The thread ID to remove.
+  /// \return True if the thread was removed, false if it was not in the list.
+  bool RemoveThread(lldb::tid_t thread_id);
+
+  /// Get the number of threads to save. If this list is empty all threads will
+  /// be saved.
+  ///
+  /// \return The number of threads to save.
+  uint32_t GetNumThreads() const;
+
+  /// Get the thread ID at the given index.
+  ///
+  /// \param[in] index The index of the thread ID to get.
+  /// \return The thread ID at the given index, or an error
+  /// if there is no thread at the index.
+  lldb::tid_t GetThreadAtIndex(uint32_t index, SBError &error) const;
+
   /// Reset all options.
   void Clear();
 
diff --git a/lldb/include/lldb/Symbol/SaveCoreOptions.h 
b/lldb/include/lldb/Symbol/SaveCoreOptions.h
index 583bc1f483d04..d583b32b29508 100644
--- a/lldb/include/lldb/Symbol/SaveCoreOptions.h
+++ b/lldb/include/lldb/Symbol/SaveCoreOptions.h
@@ -14,6 +14,7 @@
 #include "lldb/lldb-types.h"
 
 #include 
+#include 
 #include 
 
 namespace lldb_private {
@@ -32,12 +33,21 @@ class SaveCoreOptions {
   void SetOutputFile(lldb_private::FileSpec file);
   const std::optional GetOutputFile() const;
 
+  void AddThread(lldb::tid_t tid);
+  bool RemoveThread(lldb::tid_t tid);
+  size_t GetNumThreads() const;
+  int64_t GetThreadAtIndex(size_t index) const;
+  bool ShouldSaveThread(lldb::tid_t tid) const;
+
+  Status EnsureValidConfiguration() const;
+
   void Clear();
 
 private:
   std::optional m_plugin_name;
   std::optional m_file;
   std::optional m_style;
+  std::set m_threads_to_save;
 };
 } // namespace lldb_private
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index c8475db8ae160..c551504c8583f 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -741,6 +741,11 @@ class Process : public 
std::enable_shared_from_this,
   Status CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style,
  CoreFileMemoryRanges &ranges);
 
+  /// Helper function for Process::SaveCore(...) that calculates the thread 
list
+  /// based upon options set within a given \a core_options object.
+  ThreadCollection::ThreadIterable
+  CalculateCoreFileThreadList(SaveCoreOptions &core_options);
+
 protected:
   virtual JITLoaderList &GetJITLoaders();
 
diff --git a/lldb/source/API/SBSaveCoreOptions.cpp 
b/lldb/source/API/SBSaveCoreOptions.cpp
index 6c3f74596203d..1d45313d2426a 100644
--- a/lldb/source/API/SBSaveCoreOptions.cpp
+++ b/lldb/source/API/SBSaveCoreOptions.cpp
@@ -75,6 +75,26 @@ lldb::SaveCoreStyle SBSaveCoreOptions::GetStyle() const {
   return m_opaque_up->GetStyle();
 }
 
+void SBSaveCoreOptions::AddThread(lldb::tid_t tid) {
+  m_opaque_up->AddThread(tid);
+}
+
+bool SBSaveCoreOptions::RemoveThread(lldb::tid_t tid) {
+  return m_opaque_up->RemoveThread(tid);
+}
+
+uint32_t SBSaveCoreOptions::GetNumThreads() const {
+  return m_opaque_up->GetNumThreads();
+}
+
+lldb::tid_t SBSaveCoreOptions::GetThreadAtIndex(uint32_t idx,
+SBError &error) const {
+  int64_t tid = m_opaque_up->GetThreadAtIndex(idx);
+  if (tid == -1)
+error.SetErrorString("Invalid index");
+  return 0;
+}
+
 void SBSaveCoreOptions::Clear() {
   LLDB_INSTRUMENT_VA(this);
   m_opaque_up->Clear();
diff --git a/lldb/source/Core/PluginManager.cpp 
b/lldb/source/Core/PluginManager.cpp
index 759ef3a8afe02..94e3cb85f31b9 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -714,6 +714,10 @@ Status PluginManager::SaveCore(const lldb::ProcessSP 
&process_sp

[Lldb-commits] [lldb] 5c1d768 - [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (#101697)

2024-08-02 Thread via lldb-commits

Author: Michael Buch
Date: 2024-08-02T19:13:41+01:00
New Revision: 5c1d7689738d144613e7915c0b6ec850dd5c3956

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

LOG: [lldb][ClangExpressionParser] Log and assert on failure to create 
TargetInfo (#101697)

`CreateTargetInfo` can return a `nullptr` in a couple cases. So we
should log that and let the user know something is wrong (hence the
`lldbassert`).

I didn't actually run into this. Just stumbled upon it from reading the
code.

Added: 


Modified: 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 2d34f657793c3..2bd58d568cc6d 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -495,18 +495,24 @@ ClangExpressionParser::ClangExpressionParser(
   // A value of 0 means no limit for both LLDB and Clang.
   m_compiler->getDiagnostics().setErrorLimit(target_sp->GetExprErrorLimit());
 
-  auto target_info = TargetInfo::CreateTargetInfo(
-  m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
-  if (log) {
-LLDB_LOGF(log, "Target datalayout string: '%s'",
-  target_info->getDataLayoutString());
-LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
-LLDB_LOGF(log, "Target vector alignment: %d",
-  target_info->getMaxVectorAlign());
-  }
-  m_compiler->setTarget(target_info);
+  if (auto *target_info = TargetInfo::CreateTargetInfo(
+  m_compiler->getDiagnostics(),
+  m_compiler->getInvocation().TargetOpts)) {
+if (log) {
+  LLDB_LOGF(log, "Target datalayout string: '%s'",
+target_info->getDataLayoutString());
+  LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
+  LLDB_LOGF(log, "Target vector alignment: %d",
+target_info->getMaxVectorAlign());
+}
+m_compiler->setTarget(target_info);
+  } else {
+if (log)
+  LLDB_LOGF(log, "Failed to create TargetInfo for '%s'",
+m_compiler->getTargetOpts().Triple.c_str());
 
-  assert(m_compiler->hasTarget());
+lldbassert(false && "Failed to create TargetInfo.");
+  }
 
   // 4. Set language options.
   lldb::LanguageType language = expr.Language().AsLanguageType();



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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (PR #101697)

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

https://github.com/Michael137 closed 
https://github.com/llvm/llvm-project/pull/101697
___
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 for the `scripting template list` command (PR #101726)

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


@@ -0,0 +1,42 @@
+# REQUIRES: python
+# RUN: %lldb -s %s -o exit | FileCheck %s
+
+scripting template list
+# CHECK:Available scripted extension templates:
+
+# CHECK:  Name: OperatingSystemPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock thread state
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:settings set target.process.python-os-plugin-path 

+# CHECK-NEXT:settings set 
process.experimental.os-plugin-reports-all-threads [0/1]
+
+# CHECK:  Name: ScriptedPlatformPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock platform and interact with its processes.
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages: None
+
+# CHECK:  Name: ScriptedProcessPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock process state
+# CHECK-NEXT:  API Usages:
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Attach
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Launch
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:process attach -C  [-k key -v value ...]
+# CHECK-NEXT:process launch -C  [-k key -v value ...]
+
+# CHECK:  Name: ScriptedThreadPlanPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Alter thread stepping logic and stop reason
+# CHECK-NEXT:  API Usages: SBThread.StepUsingScriptedThreadPlan
+# CHECK-NEXT:  Command Interpreter Usages: thread step-scripted -C 
 [-k key -v value ...]
+
+scripting template list -l lua
+# CHECK: Available scripted extension templates: None

JDevlieghere wrote:

Do you get the same output regardless of whether you're building with or 
without lua support? If so then this is fine, otherwise this would have to go 
into a separate test that contains `REQUIRES: lua`. 

https://github.com/llvm/llvm-project/pull/101726
___
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 for the `scripting template list` command (PR #101726)

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

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


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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

2024-08-02 Thread Greg Clayton via lldb-commits


@@ -32,13 +33,25 @@ class SaveCoreOptions {
   void SetOutputFile(lldb_private::FileSpec file);
   const std::optional GetOutputFile() const;
 
+  Status SetProcess(lldb::ProcessSP process_sp);
+
+  Status AddThread(lldb::ThreadSP thread_sp);
+  bool RemoveThread(lldb::ThreadSP thread_sp);
+  bool ShouldThreadBeSaved(lldb::tid_t tid) const;
+
+  Status EnsureValidConfiguration(lldb::ProcessSP process_to_save) const;

clayborg wrote:

rename to "process_sp"

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

2024-08-02 Thread Greg Clayton via lldb-commits

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

2024-08-02 Thread Greg Clayton via lldb-commits

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

Do the variable rename and all good

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


[Lldb-commits] [lldb] 737c387 - [lldb/test] Add test for the `scripting template list` command (#101726)

2024-08-02 Thread via lldb-commits

Author: Med Ismail Bennani
Date: 2024-08-02T11:20:39-07:00
New Revision: 737c387f8be15cf3d6004d3f58a3ce5763f7f9e8

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

LOG: [lldb/test] Add test for the `scripting template list` command (#101726)

Added: 
lldb/test/Shell/Commands/command-scripting-template-list.test

Modified: 


Removed: 




diff  --git a/lldb/test/Shell/Commands/command-scripting-template-list.test 
b/lldb/test/Shell/Commands/command-scripting-template-list.test
new file mode 100644
index 0..8dc3fe42931ab
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-scripting-template-list.test
@@ -0,0 +1,42 @@
+# REQUIRES: python
+# RUN: %lldb -s %s -o exit | FileCheck %s
+
+scripting template list
+# CHECK:Available scripted extension templates:
+
+# CHECK:  Name: OperatingSystemPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock thread state
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:settings set target.process.python-os-plugin-path 

+# CHECK-NEXT:settings set 
process.experimental.os-plugin-reports-all-threads [0/1]
+
+# CHECK:  Name: ScriptedPlatformPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock platform and interact with its processes.
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages: None
+
+# CHECK:  Name: ScriptedProcessPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock process state
+# CHECK-NEXT:  API Usages:
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Attach
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Launch
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:process attach -C  [-k key -v value ...]
+# CHECK-NEXT:process launch -C  [-k key -v value ...]
+
+# CHECK:  Name: ScriptedThreadPlanPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Alter thread stepping logic and stop reason
+# CHECK-NEXT:  API Usages: SBThread.StepUsingScriptedThreadPlan
+# CHECK-NEXT:  Command Interpreter Usages: thread step-scripted -C 
 [-k key -v value ...]
+
+scripting template list -l lua
+# CHECK: Available scripted extension templates: None



___
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 for the `scripting template list` command (PR #101726)

2024-08-02 Thread Med Ismail Bennani via lldb-commits

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


[Lldb-commits] [lldb] ObjectFileJSON and Section changes to support section.address field i… (PR #101062)

2024-08-02 Thread Ilhan Raja via lldb-commits

YungRaj wrote:

> > > I was hoping to fix everything in one Pull Request so that it at least 
> > > becomes usable once this merges.
> > 
> > 
> > The LLVM project generally 
> > [prefers](https://llvm.org/docs/CodeReview.html#code-reviews-speed-and-reciprocity)
> >  smaller patches as they're easier to review. We'll definitely want to fix 
> > the end-to-end issue and have a test, but the deserialization issue can 
> > stand on its own and deserves its own PR.
> 
> Sounds good. Will divide the pull requests into many of them.
> 
> So I tried to get symbolicating backtraces working, however, this is a bit 
> more challenging, because LLDB doesn't have a good intuition of building a 
> `AddressRange` e.g. the start to finish of a function. It's not that I 
> couldn't get addresses to symbolicate, but many functions that get 
> symbolicated are actually from functions before it that had the subsequent 
> function unsymbolicated. Thus the symbols clash and the backtraces are low 
> accuracy.
> 
> @JDevlieghere do you believe there is a way to fix LLDB's intuition of the 
> proper bounds of functions based on function prologues (e.g. `BTI`, 
> `PACIBSP`, `STP X29, X30, [SP, #-offset]!` on arm64) and epilogues (`RET`, 
> `RETAB`, etc on arm64) ? Technically, decompilers are able to effectively 
> build this intuition, but the metadata for that doesn't get exported into the 
> linker map files. Is this non-trivial in general? Could lifting via IR be 
> effective here (even though I doubt the LLDB source supports that)?
> 
> If this is not achievable, what would it take to get type information 
> supported by `ObjectFileJSON`? This isn't a strict requirement of mine, but 
> it'd be a nice to reduce the quantity of things that I would need to do by 
> hand.

It looks like the best way to do this is force the decompiler to produce the 
end address in a symbol file. This is not supported by linker map files, but 
can be procured using a IDAPython script.

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


[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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

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

>From a4518719a09ef2910209663c62544dc5797f2df7 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 13:48:18 +0100
Subject: [PATCH 1/5] [lldb][ClangExpressionParser][NFC] Factor LangOptions
 logic out of ClangExpressionParser constructor

We plan to eventually use the Clang driver to initialize the
`CompilerInstance`.

This should make refactorings of this code more straightforward.
---
 lldb/include/lldb/Expression/Expression.h |   2 +-
 lldb/include/lldb/Expression/UserExpression.h |   2 +-
 .../Clang/ClangExpressionParser.cpp   | 301 +-
 3 files changed, 157 insertions(+), 148 deletions(-)

diff --git a/lldb/include/lldb/Expression/Expression.h 
b/lldb/include/lldb/Expression/Expression.h
index 356fe4b82ae43..8de9364436ccf 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -56,7 +56,7 @@ class Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  virtual ResultType DesiredResultType() { return eResultTypeAny; }
+  virtual ResultType DesiredResultType() const { return eResultTypeAny; }
 
   /// Flags
 
diff --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index b04d00b72e8fa..7ce463d2cb4e7 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -206,7 +206,7 @@ class UserExpression : public Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// indifferent.
-  ResultType DesiredResultType() override { return m_desired_type; }
+  ResultType DesiredResultType() const override { return m_desired_type; }
 
   /// Return true if validation code should be inserted into the expression.
   bool NeedsValidation() override { return true; }
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 303e88feea20b..11d519e738ee5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -77,6 +77,7 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ExecutionContextScope.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -351,62 +352,20 @@ static void SetupDefaultClangDiagnostics(CompilerInstance 
&compiler) {
   }
 }
 
-//===--===//
-// Implementation of ClangExpressionParser
-//===--===//
-
-ClangExpressionParser::ClangExpressionParser(
-ExecutionContextScope *exe_scope, Expression &expr,
-bool generate_debug_info, std::vector include_directories,
-std::string filename)
-: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
-  m_pp_callbacks(nullptr),
-  m_include_directories(std::move(include_directories)),
-  m_filename(std::move(filename)) {
+static void SetupLangOpts(CompilerInstance &compiler,
+  ExecutionContextScope &exe_scope,
+  Expression const &expr) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  // We can't compile expressions without a target.  So if the exe_scope is
-  // null or doesn't have a target, then we just need to get out of here.  I'll
-  // lldbassert and not make any of the compiler objects since
-  // I can't return errors directly from the constructor.  Further calls will
-  // check if the compiler was made and
-  // bag out if it wasn't.
-
-  if (!exe_scope) {
-lldbassert(exe_scope &&
-   "Can't make an expression parser with a null scope.");
-return;
-  }
-
-  lldb::TargetSP target_sp;
-  target_sp = exe_scope->CalculateTarget();
-  if (!target_sp) {
-lldbassert(target_sp.get() &&
-   "Can't make an expression parser with a null target.");
-return;
-  }
-
-  // 1. Create a new compiler instance.
-  m_compiler = std::make_unique();
+  // If the expression is being evaluated in the context of an existing stack
+  // frame, we introspect to see if the language runtime is available.
 
-  // Make sure clang uses the same VFS as LLDB.
-  m_compiler->createFileManager(FileSystem::Instance().GetVirtualFileSystem());
+  lldb::StackFrameSP frame_sp = exe_scope.CalculateStackFrame();
+  lldb::ProcessSP process_sp = exe_scope.CalculateProcess();
 
   // Defaults to lldb::eLanguageTypeUnknown.
   lldb::LanguageType frame_lang = expr.Language().AsLanguageType();
 
-  std::string abi;
-  ArchSpec target_arch;
-  target_arch = target_sp->GetArchitecture();
-
-  const auto target_machine = target

[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

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

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

>From d7940af06873cedf5976dc829dd9377b2851ae25 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 23 Jul 2024 16:50:57 -0700
Subject: [PATCH 01/14] Implemplement a thread list that is currently unused
 for SBSaveCore. Run formatter

---
 lldb/include/lldb/API/SBSaveCoreOptions.h  | 24 +++
 lldb/include/lldb/Symbol/SaveCoreOptions.h | 10 +
 lldb/include/lldb/Target/Process.h |  5 +++
 lldb/source/API/SBSaveCoreOptions.cpp  | 20 +
 lldb/source/Core/PluginManager.cpp |  4 ++
 lldb/source/Symbol/SaveCoreOptions.cpp | 48 ++
 lldb/source/Target/Process.cpp | 12 ++
 7 files changed, 123 insertions(+)

diff --git a/lldb/include/lldb/API/SBSaveCoreOptions.h 
b/lldb/include/lldb/API/SBSaveCoreOptions.h
index e77496bd3a4a0..b485371ce8f55 100644
--- a/lldb/include/lldb/API/SBSaveCoreOptions.h
+++ b/lldb/include/lldb/API/SBSaveCoreOptions.h
@@ -53,6 +53,30 @@ class LLDB_API SBSaveCoreOptions {
   /// \return The output file spec.
   SBFileSpec GetOutputFile() const;
 
+  /// Add a thread to save in the core file.
+  ///
+  /// \param thread_id The thread ID to save.
+  void AddThread(lldb::tid_t thread_id);
+
+  /// Remove a thread from the list of threads to save.
+  ///
+  /// \param thread_id The thread ID to remove.
+  /// \return True if the thread was removed, false if it was not in the list.
+  bool RemoveThread(lldb::tid_t thread_id);
+
+  /// Get the number of threads to save. If this list is empty all threads will
+  /// be saved.
+  ///
+  /// \return The number of threads to save.
+  uint32_t GetNumThreads() const;
+
+  /// Get the thread ID at the given index.
+  ///
+  /// \param[in] index The index of the thread ID to get.
+  /// \return The thread ID at the given index, or an error
+  /// if there is no thread at the index.
+  lldb::tid_t GetThreadAtIndex(uint32_t index, SBError &error) const;
+
   /// Reset all options.
   void Clear();
 
diff --git a/lldb/include/lldb/Symbol/SaveCoreOptions.h 
b/lldb/include/lldb/Symbol/SaveCoreOptions.h
index 583bc1f483d04..d583b32b29508 100644
--- a/lldb/include/lldb/Symbol/SaveCoreOptions.h
+++ b/lldb/include/lldb/Symbol/SaveCoreOptions.h
@@ -14,6 +14,7 @@
 #include "lldb/lldb-types.h"
 
 #include 
+#include 
 #include 
 
 namespace lldb_private {
@@ -32,12 +33,21 @@ class SaveCoreOptions {
   void SetOutputFile(lldb_private::FileSpec file);
   const std::optional GetOutputFile() const;
 
+  void AddThread(lldb::tid_t tid);
+  bool RemoveThread(lldb::tid_t tid);
+  size_t GetNumThreads() const;
+  int64_t GetThreadAtIndex(size_t index) const;
+  bool ShouldSaveThread(lldb::tid_t tid) const;
+
+  Status EnsureValidConfiguration() const;
+
   void Clear();
 
 private:
   std::optional m_plugin_name;
   std::optional m_file;
   std::optional m_style;
+  std::set m_threads_to_save;
 };
 } // namespace lldb_private
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index c8475db8ae160..c551504c8583f 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -741,6 +741,11 @@ class Process : public 
std::enable_shared_from_this,
   Status CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style,
  CoreFileMemoryRanges &ranges);
 
+  /// Helper function for Process::SaveCore(...) that calculates the thread 
list
+  /// based upon options set within a given \a core_options object.
+  ThreadCollection::ThreadIterable
+  CalculateCoreFileThreadList(SaveCoreOptions &core_options);
+
 protected:
   virtual JITLoaderList &GetJITLoaders();
 
diff --git a/lldb/source/API/SBSaveCoreOptions.cpp 
b/lldb/source/API/SBSaveCoreOptions.cpp
index 6c3f74596203d..1d45313d2426a 100644
--- a/lldb/source/API/SBSaveCoreOptions.cpp
+++ b/lldb/source/API/SBSaveCoreOptions.cpp
@@ -75,6 +75,26 @@ lldb::SaveCoreStyle SBSaveCoreOptions::GetStyle() const {
   return m_opaque_up->GetStyle();
 }
 
+void SBSaveCoreOptions::AddThread(lldb::tid_t tid) {
+  m_opaque_up->AddThread(tid);
+}
+
+bool SBSaveCoreOptions::RemoveThread(lldb::tid_t tid) {
+  return m_opaque_up->RemoveThread(tid);
+}
+
+uint32_t SBSaveCoreOptions::GetNumThreads() const {
+  return m_opaque_up->GetNumThreads();
+}
+
+lldb::tid_t SBSaveCoreOptions::GetThreadAtIndex(uint32_t idx,
+SBError &error) const {
+  int64_t tid = m_opaque_up->GetThreadAtIndex(idx);
+  if (tid == -1)
+error.SetErrorString("Invalid index");
+  return 0;
+}
+
 void SBSaveCoreOptions::Clear() {
   LLDB_INSTRUMENT_VA(this);
   m_opaque_up->Clear();
diff --git a/lldb/source/Core/PluginManager.cpp 
b/lldb/source/Core/PluginManager.cpp
index 759ef3a8afe02..94e3cb85f31b9 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -714,6 +714,10 @@ Status PluginManager::SaveCore(const lldb::ProcessSP 
&process_sp

[Lldb-commits] [lldb] [lldb] Don't crash when attaching to pid and no binaries found (PR #100287)

2024-08-02 Thread Rose Silicon via lldb-commits

RSilicon wrote:

Should this be backported to 19.x?

https://github.com/llvm/llvm-project/pull/100287
___
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 for the `scripting template list` command (PR #101726)

2024-08-02 Thread Med Ismail Bennani via lldb-commits


@@ -0,0 +1,42 @@
+# REQUIRES: python
+# RUN: %lldb -s %s -o exit | FileCheck %s
+
+scripting template list
+# CHECK:Available scripted extension templates:
+
+# CHECK:  Name: OperatingSystemPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock thread state
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:settings set target.process.python-os-plugin-path 

+# CHECK-NEXT:settings set 
process.experimental.os-plugin-reports-all-threads [0/1]
+
+# CHECK:  Name: ScriptedPlatformPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock platform and interact with its processes.
+# CHECK-NEXT:  API Usages: None
+# CHECK-NEXT:  Command Interpreter Usages: None
+
+# CHECK:  Name: ScriptedProcessPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Mock process state
+# CHECK-NEXT:  API Usages:
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBAttachInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Attach
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessClassName
+# CHECK-NEXT:SBLaunchInfo.SetScriptedProcessDictionary
+# CHECK-NEXT:SBTarget.Launch
+# CHECK-NEXT:  Command Interpreter Usages:
+# CHECK-NEXT:process attach -C  [-k key -v value ...]
+# CHECK-NEXT:process launch -C  [-k key -v value ...]
+
+# CHECK:  Name: ScriptedThreadPlanPythonInterface
+# CHECK-NEXT:  Language: Python
+# CHECK-NEXT:  Description: Alter thread stepping logic and stop reason
+# CHECK-NEXT:  API Usages: SBThread.StepUsingScriptedThreadPlan
+# CHECK-NEXT:  Command Interpreter Usages: thread step-scripted -C 
 [-k key -v value ...]
+
+scripting template list -l lua
+# CHECK: Available scripted extension templates: None

medismailben wrote:

Yeah, I tested locally without Lua support.

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


[Lldb-commits] [lldb] 3e4af61 - [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (#100443)

2024-08-02 Thread via lldb-commits

Author: Jacob Lalonde
Date: 2024-08-02T13:35:05-07:00
New Revision: 3e4af616334eae532f308605b89ff158dd195180

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

LOG: [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options.  
(#100443)

In #98403 I enabled the SBSaveCoreOptions object, which allows users via
the scripting API to define what they want saved into their core file.
As the first option I've added a threadlist, so users can scan and
identify which threads and corresponding stacks they want to save.

In order to support this, I had to add a new method to `Process.h` on
how we identify which threads are to be saved, and I had to change the
book keeping in minidump to ensure we don't double save the stacks.

Important to @jasonmolenda I also changed the MachO coredump to accept
these new APIs.

Added: 
lldb/test/API/python_api/sbsavecoreoptions/basic_minidump.yaml
lldb/test/API/python_api/sbsavecoreoptions/basic_minidump_different_pid.yaml

Modified: 
lldb/include/lldb/API/SBProcess.h
lldb/include/lldb/API/SBSaveCoreOptions.h
lldb/include/lldb/API/SBThread.h
lldb/include/lldb/Symbol/SaveCoreOptions.h
lldb/include/lldb/Target/Process.h
lldb/source/API/SBSaveCoreOptions.cpp
lldb/source/API/SBThread.cpp
lldb/source/Core/PluginManager.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
lldb/source/Symbol/SaveCoreOptions.cpp
lldb/source/Target/Process.cpp

lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
lldb/test/API/python_api/sbsavecoreoptions/TestSBSaveCoreOptions.py

Removed: 




diff  --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 778be79583990..1624e02070b1b 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -586,6 +586,7 @@ class LLDB_API SBProcess {
   friend class SBBreakpointCallbackBaton;
   friend class SBBreakpointLocation;
   friend class SBCommandInterpreter;
+  friend class SBSaveCoreOptions;
   friend class SBDebugger;
   friend class SBExecutionContext;
   friend class SBFunction;

diff  --git a/lldb/include/lldb/API/SBSaveCoreOptions.h 
b/lldb/include/lldb/API/SBSaveCoreOptions.h
index e77496bd3a4a0..df0aa561de408 100644
--- a/lldb/include/lldb/API/SBSaveCoreOptions.h
+++ b/lldb/include/lldb/API/SBSaveCoreOptions.h
@@ -10,6 +10,10 @@
 #define LLDB_API_SBSAVECOREOPTIONS_H
 
 #include "lldb/API/SBDefines.h"
+#include "lldb/API/SBError.h"
+#include "lldb/API/SBFileSpec.h"
+#include "lldb/API/SBProcess.h"
+#include "lldb/API/SBThread.h"
 
 namespace lldb {
 
@@ -53,6 +57,29 @@ class LLDB_API SBSaveCoreOptions {
   /// \return The output file spec.
   SBFileSpec GetOutputFile() const;
 
+  /// Set the process to save, or unset if supplied with a default constructed
+  /// process.
+  ///
+  /// \param process The process to save.
+  /// \return Success if process was set, otherwise an error
+  /// \note This will clear all process specific options if a 
diff erent process
+  /// is specified than the current set process, either explicitly from this
+  /// api, or implicitly from any function that requires a process.
+  SBError SetProcess(lldb::SBProcess process);
+
+  /// Add a thread to save in the core file.
+  ///
+  /// \param thread The thread to save.
+  /// \note This will set the process if it is not already set, or return
+  /// and error if the SBThread is not from the set process.
+  SBError AddThread(lldb::SBThread thread);
+
+  /// Remove a thread from the list of threads to save.
+  ///
+  /// \param thread The thread to remove.
+  /// \return True if the thread was removed, false if it was not in the list.
+  bool RemoveThread(lldb::SBThread thread);
+
   /// Reset all options.
   void Clear();
 

diff  --git a/lldb/include/lldb/API/SBThread.h 
b/lldb/include/lldb/API/SBThread.h
index dcf6aa9d5424e..f8ae627da5ace 100644
--- a/lldb/include/lldb/API/SBThread.h
+++ b/lldb/include/lldb/API/SBThread.h
@@ -233,6 +233,7 @@ class LLDB_API SBThread {
   friend class SBBreakpoint;
   friend class SBBreakpointLocation;
   friend class SBBreakpointCallbackBaton;
+  friend class SBSaveCoreOptions;
   friend class SBExecutionContext;
   friend class SBFrame;
   friend class SBProcess;
@@ -253,6 +254,8 @@ class LLDB_API SBThread {
   SBError ResumeNewPlan(lldb_private::ExecutionContext &exe_ctx,
 lldb_private::ThreadPlan *new_plan);
 
+  lldb::ThreadSP GetSP() const;
+
   lldb::ExecutionContextRefSP m_opaque_sp;
 
   lldb_private::Thread *operator->();

[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

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

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

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

Michael137 wrote:

Looks like this broke the macOS buildbots: 
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/8988/execution/node/97/log/
```
FAIL: LLDB 
(/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang-arm64)
 :: test_lc_note_dsym (TestSkinnyCorefile.TestSkinnyCorefile)
UNSUPPORTED: LLDB 
(/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang-arm64)
 :: test_lc_note_dwarf (TestSkinnyCorefile.TestSkinnyCorefile) (skipping due to 
the following parameter(s): debug info format [This test is looking explicitly 
for a dSYM]) 
UNSUPPORTED: LLDB 
(/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang-arm64)
 :: test_lc_note_dwo (TestSkinnyCorefile.TestSkinnyCorefile) (test case does 
not fall in any category of interest for this run) 
Restore dir to: 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/test
==
FAIL: test_lc_note_dsym (TestSkinnyCorefile.TestSkinnyCorefile)
--
Traceback (most recent call last):
  File 
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py",
 line 1758, in test_method
return attrvalue(self)
  File 
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py",
 line 148, in wrapper
return func(*args, **kwargs)
  File 
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/macosx/skinny-corefile/TestSkinnyCorefile.py",
 line 111, in test_lc_note
self.runCmd("process save-core " + self.corefile)
  File 
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py",
 line 1003, in runCmd
self.assertTrue(self.res.Succeeded(), msg if (msg) else CMD_MSG(cmd))
AssertionError: False is not true : Command 'process save-core 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lldb-test-build.noindex/macosx/skinny-corefile/TestSkinnyCorefile.test_lc_note_dsym/process.core
Error output:
error: Failed to save core file for process: callers must set the core_style to 
something other than eSaveCoreUnspecified
' did not return successfully
Config=arm64-/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang
--
Ran 3 tests in 1.680s
```
Could you take a look?

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

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

Jlalond wrote:

@Michael137 ack, I'll make a fix

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


[Lldb-commits] [lldb] 12e3a06 - [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (#101669)

2024-08-02 Thread via lldb-commits

Author: Michael Buch
Date: 2024-08-02T22:27:40+01:00
New Revision: 12e3a06cb7615fbd91031420f3dec2a85d7877d6

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

LOG: [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of 
ClangExpressionParser constructor (#101669)

We plan to eventually use the Clang driver to initialize the
`CompilerInstance`.

This should make refactorings of this code more straightforward.

**Changes**:
* Introduced `SetupLangOpts` and `SetupImportStdModuleLangOpts`
* Called them from `ClangExpressionParser::ClangExpressionParser`

Added: 


Modified: 
lldb/include/lldb/Expression/Expression.h
lldb/include/lldb/Expression/UserExpression.h
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Removed: 




diff  --git a/lldb/include/lldb/Expression/Expression.h 
b/lldb/include/lldb/Expression/Expression.h
index 356fe4b82ae43..8de9364436ccf 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -56,7 +56,7 @@ class Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// in
diff erent.
-  virtual ResultType DesiredResultType() { return eResultTypeAny; }
+  virtual ResultType DesiredResultType() const { return eResultTypeAny; }
 
   /// Flags
 

diff  --git a/lldb/include/lldb/Expression/UserExpression.h 
b/lldb/include/lldb/Expression/UserExpression.h
index b04d00b72e8fa..7ce463d2cb4e7 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -206,7 +206,7 @@ class UserExpression : public Expression {
 
   /// Return the desired result type of the function, or eResultTypeAny if
   /// in
diff erent.
-  ResultType DesiredResultType() override { return m_desired_type; }
+  ResultType DesiredResultType() const override { return m_desired_type; }
 
   /// Return true if validation code should be inserted into the expression.
   bool NeedsValidation() override { return true; }

diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 2bd58d568cc6d..2a8bdf29314e4 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -77,6 +77,7 @@
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ExecutionContextScope.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -425,56 +426,20 @@ static void SetupTargetOpts(CompilerInstance &compiler,
 compiler.getTargetOpts().ABI = std::move(abi);
 }
 
-//===--===//
-// Implementation of ClangExpressionParser
-//===--===//
-
-ClangExpressionParser::ClangExpressionParser(
-ExecutionContextScope *exe_scope, Expression &expr,
-bool generate_debug_info, std::vector include_directories,
-std::string filename)
-: ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
-  m_pp_callbacks(nullptr),
-  m_include_directories(std::move(include_directories)),
-  m_filename(std::move(filename)) {
+static void SetupLangOpts(CompilerInstance &compiler,
+  ExecutionContextScope &exe_scope,
+  const Expression &expr) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  // We can't compile expressions without a target.  So if the exe_scope is
-  // null or doesn't have a target, then we just need to get out of here.  I'll
-  // lldbassert and not make any of the compiler objects since
-  // I can't return errors directly from the constructor.  Further calls will
-  // check if the compiler was made and
-  // bag out if it wasn't.
-
-  if (!exe_scope) {
-lldbassert(exe_scope &&
-   "Can't make an expression parser with a null scope.");
-return;
-  }
-
-  lldb::TargetSP target_sp;
-  target_sp = exe_scope->CalculateTarget();
-  if (!target_sp) {
-lldbassert(target_sp.get() &&
-   "Can't make an expression parser with a null target.");
-return;
-  }
-
-  // 1. Create a new compiler instance.
-  m_compiler = std::make_unique();
+  // If the expression is being evaluated in the context of an existing stack
+  // frame, we introspect to see if the language runtime is available.
 
-  // Make sure clang uses the same VFS as LLDB.
-  m_compiler->createFileManager(FileSystem::Instance().GetVirtualFileSystem());
+  lldb::StackFrameSP frame_sp = exe_scope.CalculateStackFrame();
+  

[Lldb-commits] [lldb] [lldb][ClangExpressionParser][NFC] Factor LangOptions logic out of ClangExpressionParser constructor (PR #101669)

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

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


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

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

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

LGTM!

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (PR #100443)

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

Jlalond wrote:

@Michael137 Has Green Dragon been down for awhile? I did break this test, but 
it looks like it was about [a month 
ago](https://github.com/llvm/llvm-project/commit/47d80ec1802d70082c8fd32b4396c98db2c4dba2#diff-96c5fb7a96b37c4401faaef482eaf8d4e1ecd38d49a1ff8eb96d361b0dfa24b9R6442).
 I'll make a patch to drop this as we let each respective flavor set their own 
default.

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

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

https://github.com/Jlalond created 
https://github.com/llvm/llvm-project/pull/101770

In #100443, Mach-o and Minidump now only call process API's that take a 
`SaveCoreOption` as the container for the style and information if a thread 
should be included in the core or not. This introduced a bug where in 
subsequent method calls we were not honoring the defaults of both 
implementations.

To solve this I have made a copy of each SaveCoreOptions that is mutable by the 
respective plugin. Originally I wanted to leave the SaveCoreOptions as non 
const so these default value mutations could be shown back to the user. 
Changing that behavior is outside of the scope of this bugfix, but is context 
for why we are making a copy.

CC: @Michael137

>From 11f8323bb40a537161c76b89d564c9ae96888d01 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Fri, 2 Aug 2024 15:44:17 -0700
Subject: [PATCH 1/3] Create copies in both minidump and mach-o so we can set a
 default value

---
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp| 16 ++--
 .../ObjectFile/Minidump/ObjectFileMinidump.cpp   | 11 +++
 .../macosx/skinny-corefile/TestSkinnyCorefile.py |  1 -
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4322bd7e2674f..d09eec0f9cb62 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6524,13 +6524,17 @@ struct page_object {
 bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
const lldb_private::SaveCoreOptions &options,
Status &error) {
-  auto core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreDirtyOnly;
   // The FileSpec and Process are already checked in PluginManager::SaveCore.
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
   const FileSpec outfile = options.GetOutputFile().value();
+
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
+  if (core_options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
+core_options.SetStyle(eSaveCoreDirtyOnly);
 
   Target &target = process_sp->GetTarget();
   const ArchSpec target_arch = target.GetArchitecture();
@@ -6561,7 +6565,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 
 if (make_core) {
   Process::CoreFileMemoryRanges core_ranges;
-  error = process_sp->CalculateCoreFileSaveRanges(options, core_ranges);
+  error = process_sp->CalculateCoreFileSaveRanges(core_options, 
core_ranges);
   if (error.Success()) {
 const uint32_t addr_byte_size = target_arch.GetAddressByteSize();
 const ByteOrder byte_order = target_arch.GetByteOrder();
@@ -6733,7 +6737,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 StructuredData::ArraySP threads(
 std::make_shared());
 for (const ThreadSP &thread_sp :
- process_sp->CalculateCoreFileThreadList(options)) {
+ process_sp->CalculateCoreFileThreadList(core_options)) {
   StructuredData::DictionarySP thread(
   std::make_shared());
   thread->AddIntegerItem("thread_id", thread_sp->GetID());
@@ -6756,7 +6760,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 all_image_infos_lcnote_up->payload_file_offset = file_offset;
 file_offset = CreateAllImageInfosPayload(
 process_sp, file_offset, all_image_infos_lcnote_up->payload,
-options);
+core_options);
 lc_notes.push_back(std::move(all_image_infos_lcnote_up));
 
 // Add LC_NOTE load commands
diff --git a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
index 2380ff4c00ca9..22f1323503115 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
@@ -62,10 +62,13 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
 
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
   // Minidump defaults to stacks only.
-  SaveCoreStyle core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreStackOnly;
+  if (core_options.GetSty

[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

2024-08-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jacob Lalonde (Jlalond)


Changes

In #100443, Mach-o and Minidump now only call process API's that take a 
`SaveCoreOption` as the container for the style and information if a thread 
should be included in the core or not. This introduced a bug where in 
subsequent method calls we were not honoring the defaults of both 
implementations.

To solve this I have made a copy of each SaveCoreOptions that is mutable by the 
respective plugin. Originally I wanted to leave the SaveCoreOptions as non 
const so these default value mutations could be shown back to the user. 
Changing that behavior is outside of the scope of this bugfix, but is context 
for why we are making a copy.

CC: @Michael137

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


3 Files Affected:

- (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (+10-6) 
- (modified) lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp 
(+7-4) 
- (modified) 
lldb/test/API/functionalities/process_save_core/TestProcessSaveCore.py (+28) 


``diff
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4322bd7e2674f..d09eec0f9cb62 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6524,13 +6524,17 @@ struct page_object {
 bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
const lldb_private::SaveCoreOptions &options,
Status &error) {
-  auto core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreDirtyOnly;
   // The FileSpec and Process are already checked in PluginManager::SaveCore.
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
   const FileSpec outfile = options.GetOutputFile().value();
+
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
+  if (core_options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
+core_options.SetStyle(eSaveCoreDirtyOnly);
 
   Target &target = process_sp->GetTarget();
   const ArchSpec target_arch = target.GetArchitecture();
@@ -6561,7 +6565,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 
 if (make_core) {
   Process::CoreFileMemoryRanges core_ranges;
-  error = process_sp->CalculateCoreFileSaveRanges(options, core_ranges);
+  error = process_sp->CalculateCoreFileSaveRanges(core_options, 
core_ranges);
   if (error.Success()) {
 const uint32_t addr_byte_size = target_arch.GetAddressByteSize();
 const ByteOrder byte_order = target_arch.GetByteOrder();
@@ -6733,7 +6737,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 StructuredData::ArraySP threads(
 std::make_shared());
 for (const ThreadSP &thread_sp :
- process_sp->CalculateCoreFileThreadList(options)) {
+ process_sp->CalculateCoreFileThreadList(core_options)) {
   StructuredData::DictionarySP thread(
   std::make_shared());
   thread->AddIntegerItem("thread_id", thread_sp->GetID());
@@ -6756,7 +6760,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 all_image_infos_lcnote_up->payload_file_offset = file_offset;
 file_offset = CreateAllImageInfosPayload(
 process_sp, file_offset, all_image_infos_lcnote_up->payload,
-options);
+core_options);
 lc_notes.push_back(std::move(all_image_infos_lcnote_up));
 
 // Add LC_NOTE load commands
diff --git a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
index 2380ff4c00ca9..22f1323503115 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
@@ -62,10 +62,13 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
 
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
   // Minidump defaults to stacks only.
-  SaveCoreStyle core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreStackOnly;
+  if (core_options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
+core_options.SetStyle(SaveCoreStyle::eSaveCoreStackOnly);
 
 

[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

2024-08-02 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
darker --check --diff -r 
1ae837ab34424a0b81bcc9a4fabc89e36cd57235...9d105b25b2e0721d68db8dca60cb155d233d0933
 lldb/test/API/functionalities/process_save_core/TestProcessSaveCore.py
``





View the diff from darker here.


``diff
--- TestProcessSaveCore.py  2024-08-02 23:03:03.00 +
+++ TestProcessSaveCore.py  2024-08-02 23:10:22.398544 +
@@ -101,13 +101,11 @@
 self.build()
 exe = self.getBuildArtifact("a.out")
 core = self.getBuildArtifact("core.dmp")
 target = self.dbg.CreateTarget(exe)
 target.BreakpointCreateByName("bar")
-process = target.LaunchSimple(
-None, None, self.get_process_working_directory()
-)
+process = target.LaunchSimple(None, None, 
self.get_process_working_directory())
 self.assertState(process.GetState(), lldb.eStateStopped)
 pid = process.GetProcessID()
 options = lldb.SBSaveCoreOptions()
 minidump_path = core + ".minidump"
 options.SetOutputFile(lldb.SBFileSpec(minidump_path))

``




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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

2024-08-02 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 1ae837ab34424a0b81bcc9a4fabc89e36cd57235 
9d105b25b2e0721d68db8dca60cb155d233d0933 --extensions cpp -- 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index d09eec0f9c..6efa4bd329 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6528,7 +6528,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
   const FileSpec outfile = options.GetOutputFile().value();
-
+
   // We have to make a local copy of the options, so that if we default
   // the save core style, we can proprogate that when we pass options
   // to process calculate save core ranges
@@ -6565,7 +6565,8 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 
 if (make_core) {
   Process::CoreFileMemoryRanges core_ranges;
-  error = process_sp->CalculateCoreFileSaveRanges(core_options, 
core_ranges);
+  error =
+  process_sp->CalculateCoreFileSaveRanges(core_options, core_ranges);
   if (error.Success()) {
 const uint32_t addr_byte_size = target_arch.GetAddressByteSize();
 const ByteOrder byte_order = target_arch.GetByteOrder();

``




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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

2024-08-02 Thread Greg Clayton via lldb-commits

https://github.com/clayborg commented:

Might actually be nice to make the SaveCoreOptions non const. Why? Because 
clients could see what the settings were set to if a plug-in modifies or 
overrides certain settings.

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

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

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

>From 11f8323bb40a537161c76b89d564c9ae96888d01 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Fri, 2 Aug 2024 15:44:17 -0700
Subject: [PATCH 1/4] Create copies in both minidump and mach-o so we can set a
 default value

---
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp| 16 ++--
 .../ObjectFile/Minidump/ObjectFileMinidump.cpp   | 11 +++
 .../macosx/skinny-corefile/TestSkinnyCorefile.py |  1 -
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4322bd7e2674f..d09eec0f9cb62 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6524,13 +6524,17 @@ struct page_object {
 bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
const lldb_private::SaveCoreOptions &options,
Status &error) {
-  auto core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreDirtyOnly;
   // The FileSpec and Process are already checked in PluginManager::SaveCore.
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
   const FileSpec outfile = options.GetOutputFile().value();
+
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
+  if (core_options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
+core_options.SetStyle(eSaveCoreDirtyOnly);
 
   Target &target = process_sp->GetTarget();
   const ArchSpec target_arch = target.GetArchitecture();
@@ -6561,7 +6565,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 
 if (make_core) {
   Process::CoreFileMemoryRanges core_ranges;
-  error = process_sp->CalculateCoreFileSaveRanges(options, core_ranges);
+  error = process_sp->CalculateCoreFileSaveRanges(core_options, 
core_ranges);
   if (error.Success()) {
 const uint32_t addr_byte_size = target_arch.GetAddressByteSize();
 const ByteOrder byte_order = target_arch.GetByteOrder();
@@ -6733,7 +6737,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 StructuredData::ArraySP threads(
 std::make_shared());
 for (const ThreadSP &thread_sp :
- process_sp->CalculateCoreFileThreadList(options)) {
+ process_sp->CalculateCoreFileThreadList(core_options)) {
   StructuredData::DictionarySP thread(
   std::make_shared());
   thread->AddIntegerItem("thread_id", thread_sp->GetID());
@@ -6756,7 +6760,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 all_image_infos_lcnote_up->payload_file_offset = file_offset;
 file_offset = CreateAllImageInfosPayload(
 process_sp, file_offset, all_image_infos_lcnote_up->payload,
-options);
+core_options);
 lc_notes.push_back(std::move(all_image_infos_lcnote_up));
 
 // Add LC_NOTE load commands
diff --git a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
index 2380ff4c00ca9..22f1323503115 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
@@ -62,10 +62,13 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
 
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
   // Minidump defaults to stacks only.
-  SaveCoreStyle core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreStackOnly;
+  if (core_options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
+core_options.SetStyle(SaveCoreStyle::eSaveCoreStackOnly);
 
   llvm::Expected maybe_core_file = FileSystem::Instance().Open(
   options.GetOutputFile().value(),
@@ -75,7 +78,7 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
 return false;
   }
   MinidumpFileBuilder builder(std::move(maybe_core_file.get()), process_sp,
-  options);
+  core_options);
 
   Log *log = GetLog(LLDBLog::Object);
   error = builder.AddHeaderAndCalculateDirectories();
diff --git a/lldb/test/API/macosx/skinny-corefile/TestSkinnyCorefile.py 
b/l

[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

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

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

>From 11f8323bb40a537161c76b89d564c9ae96888d01 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Fri, 2 Aug 2024 15:44:17 -0700
Subject: [PATCH 1/4] Create copies in both minidump and mach-o so we can set a
 default value

---
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp| 16 ++--
 .../ObjectFile/Minidump/ObjectFileMinidump.cpp   | 11 +++
 .../macosx/skinny-corefile/TestSkinnyCorefile.py |  1 -
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4322bd7e2674f..d09eec0f9cb62 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6524,13 +6524,17 @@ struct page_object {
 bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
const lldb_private::SaveCoreOptions &options,
Status &error) {
-  auto core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreDirtyOnly;
   // The FileSpec and Process are already checked in PluginManager::SaveCore.
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
   const FileSpec outfile = options.GetOutputFile().value();
+
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
+  if (core_options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
+core_options.SetStyle(eSaveCoreDirtyOnly);
 
   Target &target = process_sp->GetTarget();
   const ArchSpec target_arch = target.GetArchitecture();
@@ -6561,7 +6565,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 
 if (make_core) {
   Process::CoreFileMemoryRanges core_ranges;
-  error = process_sp->CalculateCoreFileSaveRanges(options, core_ranges);
+  error = process_sp->CalculateCoreFileSaveRanges(core_options, 
core_ranges);
   if (error.Success()) {
 const uint32_t addr_byte_size = target_arch.GetAddressByteSize();
 const ByteOrder byte_order = target_arch.GetByteOrder();
@@ -6733,7 +6737,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 StructuredData::ArraySP threads(
 std::make_shared());
 for (const ThreadSP &thread_sp :
- process_sp->CalculateCoreFileThreadList(options)) {
+ process_sp->CalculateCoreFileThreadList(core_options)) {
   StructuredData::DictionarySP thread(
   std::make_shared());
   thread->AddIntegerItem("thread_id", thread_sp->GetID());
@@ -6756,7 +6760,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 all_image_infos_lcnote_up->payload_file_offset = file_offset;
 file_offset = CreateAllImageInfosPayload(
 process_sp, file_offset, all_image_infos_lcnote_up->payload,
-options);
+core_options);
 lc_notes.push_back(std::move(all_image_infos_lcnote_up));
 
 // Add LC_NOTE load commands
diff --git a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
index 2380ff4c00ca9..22f1323503115 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
@@ -62,10 +62,13 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
 
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
   // Minidump defaults to stacks only.
-  SaveCoreStyle core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreStackOnly;
+  if (core_options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
+core_options.SetStyle(SaveCoreStyle::eSaveCoreStackOnly);
 
   llvm::Expected maybe_core_file = FileSystem::Instance().Open(
   options.GetOutputFile().value(),
@@ -75,7 +78,7 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
 return false;
   }
   MinidumpFileBuilder builder(std::move(maybe_core_file.get()), process_sp,
-  options);
+  core_options);
 
   Log *log = GetLog(LLDBLog::Object);
   error = builder.AddHeaderAndCalculateDirectories();
diff --git a/lldb/test/API/macosx/skinny-corefile/TestSkinnyCorefile.py 
b/l

[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

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

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


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

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

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

>From 11f8323bb40a537161c76b89d564c9ae96888d01 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Fri, 2 Aug 2024 15:44:17 -0700
Subject: [PATCH 1/4] Create copies in both minidump and mach-o so we can set a
 default value

---
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp| 16 ++--
 .../ObjectFile/Minidump/ObjectFileMinidump.cpp   | 11 +++
 .../macosx/skinny-corefile/TestSkinnyCorefile.py |  1 -
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4322bd7e2674f..d09eec0f9cb62 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6524,13 +6524,17 @@ struct page_object {
 bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
const lldb_private::SaveCoreOptions &options,
Status &error) {
-  auto core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreDirtyOnly;
   // The FileSpec and Process are already checked in PluginManager::SaveCore.
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
   const FileSpec outfile = options.GetOutputFile().value();
+
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
+  if (core_options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
+core_options.SetStyle(eSaveCoreDirtyOnly);
 
   Target &target = process_sp->GetTarget();
   const ArchSpec target_arch = target.GetArchitecture();
@@ -6561,7 +6565,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 
 if (make_core) {
   Process::CoreFileMemoryRanges core_ranges;
-  error = process_sp->CalculateCoreFileSaveRanges(options, core_ranges);
+  error = process_sp->CalculateCoreFileSaveRanges(core_options, 
core_ranges);
   if (error.Success()) {
 const uint32_t addr_byte_size = target_arch.GetAddressByteSize();
 const ByteOrder byte_order = target_arch.GetByteOrder();
@@ -6733,7 +6737,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 StructuredData::ArraySP threads(
 std::make_shared());
 for (const ThreadSP &thread_sp :
- process_sp->CalculateCoreFileThreadList(options)) {
+ process_sp->CalculateCoreFileThreadList(core_options)) {
   StructuredData::DictionarySP thread(
   std::make_shared());
   thread->AddIntegerItem("thread_id", thread_sp->GetID());
@@ -6756,7 +6760,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP 
&process_sp,
 all_image_infos_lcnote_up->payload_file_offset = file_offset;
 file_offset = CreateAllImageInfosPayload(
 process_sp, file_offset, all_image_infos_lcnote_up->payload,
-options);
+core_options);
 lc_notes.push_back(std::move(all_image_infos_lcnote_up));
 
 // Add LC_NOTE load commands
diff --git a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
index 2380ff4c00ca9..22f1323503115 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
@@ -62,10 +62,13 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
   assert(options.GetOutputFile().has_value());
   assert(process_sp);
 
+  // We have to make a local copy of the options, so that if we default
+  // the save core style, we can proprogate that when we pass options
+  // to process calculate save core ranges
+  lldb_private::SaveCoreOptions core_options = options;
   // Minidump defaults to stacks only.
-  SaveCoreStyle core_style = options.GetStyle();
-  if (core_style == SaveCoreStyle::eSaveCoreUnspecified)
-core_style = SaveCoreStyle::eSaveCoreStackOnly;
+  if (core_options.GetStyle() == SaveCoreStyle::eSaveCoreUnspecified)
+core_options.SetStyle(SaveCoreStyle::eSaveCoreStackOnly);
 
   llvm::Expected maybe_core_file = FileSystem::Instance().Open(
   options.GetOutputFile().value(),
@@ -75,7 +78,7 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
 return false;
   }
   MinidumpFileBuilder builder(std::move(maybe_core_file.get()), process_sp,
-  options);
+  core_options);
 
   Log *log = GetLog(LLDBLog::Object);
   error = builder.AddHeaderAndCalculateDirectories();
diff --git a/lldb/test/API/macosx/skinny-corefile/TestSkinnyCorefile.py 
b/l

[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

2024-08-02 Thread Greg Clayton via lldb-commits

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


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


[Lldb-commits] [lldb] [WIP] [lldb][ClangExpressionParser] Set BuiltinHeadersInSystemModules depending on SDK version (PR #101778)

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

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

This patch addresses an issue that will arise with future SDKs. The 
ClangExpressionParser currently unconditionally sets 
`-fbuiltin-headers-in-system-modules` when evaluating expressions with the 
`target.import-std-module` setting. This flag should, however, be set depending 
on the SDK version (which is what the Clang Darwin toolchain does).

Unfortunately, the compiler instance that we create with 
`ClangExpressionParser` never consults the Clang driver, and thus doesn't 
correctly infer `BuiltinHeadersInSystemModules`. Note, this isn't an issue with 
the `CompilerInstance` that the `ClangModulesDeclVendor` creates because it 
uses the `createInovcation` API, which calls into 
`Darwin::addClangTargetOptions`.

This patch mimicks how `sdkSupportsBuiltinModules` is used in 
`Darwin::addClangTargetOptions`.

This ensures that the `import-std-module` API tests run cleanly regardless of 
SDK version.

The plan is to make the `CompilerInstance` construction in 
`ClangExpressionParser` go through the driver, so we can avoid duplicating the 
logic in LLDB.

>From 3d7c2b87ec73a48de30e1c5387a7f0d8d817b0f4 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 23:38:18 +0100
Subject: [PATCH] [lldb][ClangExpressionParser] Set
 BuiltinHeadersInSystemModules depending on SDK version

This patch addresses an issue that will arise with future
SDKs. The ClangExpressionParser currently unconditionally
sets `-fbuiltin-headers-in-system-modules` when evaluating
expressions with the `target.import-std-module` setting.
This flag should, however, be set depending on the SDK
version (which is what the Clang Darwin toolchain does).

Unfortunately, the compiler instance that we create with
`ClangExpressionParser` never consults the Clang driver,
and thus doesn't correctly infer `BuiltinHeadersInSystemModules`.
Note, this isn't an issue with the `CompilerInstance` that the
`ClangModulesDeclVendor` creates because it uses the `createInovcation`
API, which calls into `Darwin::addClangTargetOptions`.

This patch mimicks how `sdkSupportsBuiltinModules` is used in
`Darwin::addClangTargetOptions`.

This ensures that the `import-std-module` API tests run cleanly
regardless of SDK version.

The plan is to make the `CompilerInstance` construction in
`ClangExpressionParser` go through the driver, so we can avoid
duplicating the logic in LLDB.
---
 .../Clang/ClangExpressionParser.cpp   | 69 ++-
 1 file changed, 66 insertions(+), 3 deletions(-)

diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 2a8bdf29314e4..c6217e2f13394 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/DarwinSDKInfo.h"
 #include "clang/Basic/DiagnosticIDs.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetInfo.h"
@@ -561,7 +562,62 @@ static void SetupLangOpts(CompilerInstance &compiler,
   lang_opts.NoBuiltin = true;
 }
 
-static void SetupImportStdModuleLangOpts(CompilerInstance &compiler) {
+// NOTE: should be kept in sync with sdkSupportsBuiltinModules in
+// Toolchains/Darwin.cpp
+static bool
+sdkSupportsBuiltinModulesImpl(const llvm::Triple &triple,
+  const std::optional &SDKInfo) {
+  if (!SDKInfo)
+return false;
+
+  VersionTuple SDKVersion = SDKInfo->getVersion();
+  switch (triple.getOS()) {
+  case Triple::OSType::MacOSX:
+return SDKVersion >= VersionTuple(15U);
+  case Triple::OSType::IOS:
+return SDKVersion >= VersionTuple(18U);
+  case Triple::OSType::TvOS:
+return SDKVersion >= VersionTuple(18U);
+  case Triple::OSType::WatchOS:
+return SDKVersion >= VersionTuple(11U);
+  case Triple::OSType::XROS:
+return SDKVersion >= VersionTuple(2U);
+  default:
+// New SDKs support builtin modules from the start.
+return true;
+  }
+}
+
+static bool
+sdkSupportsBuiltinModules(llvm::Triple const &triple,
+  std::vector const &include_dirs) {
+  static constexpr std::string_view s_sdk_suffix = ".sdk";
+  auto it = llvm::find_if(include_dirs, [](std::string const &path) {
+return path.find(s_sdk_suffix) != std::string::npos;
+  });
+  if (it == include_dirs.end())
+return false;
+
+  size_t suffix = it->find(s_sdk_suffix);
+  if (suffix == std::string::npos)
+return false;
+
+  auto VFS = FileSystem::Instance().GetVirtualFileSystem();
+  if (!VFS)
+return false;
+
+  std::string sdk_path = it->substr(0, suffix + s_sdk_suffix.size());
+  auto parsed = clang::parseDarwinSDKInfo(*VFS, sdk_path);
+  if (!parsed)
+return false;
+
+  return sdkSupportsBuiltinMod

[Lldb-commits] [lldb] [WIP] [lldb][ClangExpressionParser] Set BuiltinHeadersInSystemModules depending on SDK version (PR #101778)

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

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


[Lldb-commits] [lldb] [WIP] [lldb][ClangExpressionParser] Set BuiltinHeadersInSystemModules depending on SDK version (PR #101778)

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

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


[Lldb-commits] [lldb] [WIP] [lldb][ClangExpressionParser] Set BuiltinHeadersInSystemModules depending on SDK version (PR #101778)

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

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

>From 3d7c2b87ec73a48de30e1c5387a7f0d8d817b0f4 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 2 Aug 2024 23:38:18 +0100
Subject: [PATCH 1/2] [lldb][ClangExpressionParser] Set
 BuiltinHeadersInSystemModules depending on SDK version

This patch addresses an issue that will arise with future
SDKs. The ClangExpressionParser currently unconditionally
sets `-fbuiltin-headers-in-system-modules` when evaluating
expressions with the `target.import-std-module` setting.
This flag should, however, be set depending on the SDK
version (which is what the Clang Darwin toolchain does).

Unfortunately, the compiler instance that we create with
`ClangExpressionParser` never consults the Clang driver,
and thus doesn't correctly infer `BuiltinHeadersInSystemModules`.
Note, this isn't an issue with the `CompilerInstance` that the
`ClangModulesDeclVendor` creates because it uses the `createInovcation`
API, which calls into `Darwin::addClangTargetOptions`.

This patch mimicks how `sdkSupportsBuiltinModules` is used in
`Darwin::addClangTargetOptions`.

This ensures that the `import-std-module` API tests run cleanly
regardless of SDK version.

The plan is to make the `CompilerInstance` construction in
`ClangExpressionParser` go through the driver, so we can avoid
duplicating the logic in LLDB.
---
 .../Clang/ClangExpressionParser.cpp   | 69 ++-
 1 file changed, 66 insertions(+), 3 deletions(-)

diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 2a8bdf29314e4..c6217e2f13394 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/DarwinSDKInfo.h"
 #include "clang/Basic/DiagnosticIDs.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetInfo.h"
@@ -561,7 +562,62 @@ static void SetupLangOpts(CompilerInstance &compiler,
   lang_opts.NoBuiltin = true;
 }
 
-static void SetupImportStdModuleLangOpts(CompilerInstance &compiler) {
+// NOTE: should be kept in sync with sdkSupportsBuiltinModules in
+// Toolchains/Darwin.cpp
+static bool
+sdkSupportsBuiltinModulesImpl(const llvm::Triple &triple,
+  const std::optional &SDKInfo) {
+  if (!SDKInfo)
+return false;
+
+  VersionTuple SDKVersion = SDKInfo->getVersion();
+  switch (triple.getOS()) {
+  case Triple::OSType::MacOSX:
+return SDKVersion >= VersionTuple(15U);
+  case Triple::OSType::IOS:
+return SDKVersion >= VersionTuple(18U);
+  case Triple::OSType::TvOS:
+return SDKVersion >= VersionTuple(18U);
+  case Triple::OSType::WatchOS:
+return SDKVersion >= VersionTuple(11U);
+  case Triple::OSType::XROS:
+return SDKVersion >= VersionTuple(2U);
+  default:
+// New SDKs support builtin modules from the start.
+return true;
+  }
+}
+
+static bool
+sdkSupportsBuiltinModules(llvm::Triple const &triple,
+  std::vector const &include_dirs) {
+  static constexpr std::string_view s_sdk_suffix = ".sdk";
+  auto it = llvm::find_if(include_dirs, [](std::string const &path) {
+return path.find(s_sdk_suffix) != std::string::npos;
+  });
+  if (it == include_dirs.end())
+return false;
+
+  size_t suffix = it->find(s_sdk_suffix);
+  if (suffix == std::string::npos)
+return false;
+
+  auto VFS = FileSystem::Instance().GetVirtualFileSystem();
+  if (!VFS)
+return false;
+
+  std::string sdk_path = it->substr(0, suffix + s_sdk_suffix.size());
+  auto parsed = clang::parseDarwinSDKInfo(*VFS, sdk_path);
+  if (!parsed)
+return false;
+
+  return sdkSupportsBuiltinModulesImpl(triple, *parsed);
+}
+
+static void
+SetupImportStdModuleLangOpts(CompilerInstance &compiler,
+ llvm::Triple const &triple,
+ std::vector const &include_dirs) {
   LangOptions &lang_opts = compiler.getLangOpts();
   lang_opts.Modules = true;
   // We want to implicitly build modules.
@@ -578,7 +634,12 @@ static void SetupImportStdModuleLangOpts(CompilerInstance 
&compiler) {
   lang_opts.GNUMode = true;
   lang_opts.GNUKeywords = true;
   lang_opts.CPlusPlus11 = true;
-  lang_opts.BuiltinHeadersInSystemModules = true;
+
+  // FIXME: We should use the driver to derive this for use.
+  // ClangModulesDeclVendor already parses the SDKSettings for the purposes of
+  // this check.
+  lang_opts.BuiltinHeadersInSystemModules =
+  !sdkSupportsBuiltinModules(triple, include_dirs);
 
   // The Darwin libc expects this macro to be set.
   lang_opts.GNUCVersion = 40201;
@@ -663,7 +724,9 @@ ClangExpressionParser::ClangExpressionParser(
   if (auto *clang_expr = dyn_cast(&m_expr);
   clang_ex

[Lldb-commits] [lldb] 34766d0 - [LLDB][SBSaveCore] Fix bug where default values are not propagated. (#101770)

2024-08-02 Thread via lldb-commits

Author: Jacob Lalonde
Date: 2024-08-02T18:38:05-07:00
New Revision: 34766d0d488ba2fbefa80dcd0cc8720a0e753448

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

LOG: [LLDB][SBSaveCore] Fix bug where default values are not propagated. 
(#101770)

In #100443, Mach-o and Minidump now only call process API's that take a
`SaveCoreOption` as the container for the style and information if a
thread should be included in the core or not. This introduced a bug
where in subsequent method calls we were not honoring the defaults of
both implementations.

~~To solve this I have made a copy of each SaveCoreOptions that is
mutable by the respective plugin. Originally I wanted to leave the
SaveCoreOptions as non const so these default value mutations could be
shown back to the user. Changing that behavior is outside of the scope
of this bugfix, but is context for why we are making a copy.~~

Removed const on the savecoreoptions so defaults can be inspected by the
user

CC: @Michael137

Added: 


Modified: 
lldb/include/lldb/Core/PluginManager.h
lldb/include/lldb/lldb-private-interfaces.h
lldb/source/Core/PluginManager.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
lldb/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
lldb/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.h
lldb/test/API/functionalities/process_save_core/TestProcessSaveCore.py

Removed: 




diff  --git a/lldb/include/lldb/Core/PluginManager.h 
b/lldb/include/lldb/Core/PluginManager.h
index a23f834f471fb..e4e0c3eea67f8 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -194,7 +194,7 @@ class PluginManager {
   GetObjectFileCreateMemoryCallbackForPluginName(llvm::StringRef name);
 
   static Status SaveCore(const lldb::ProcessSP &process_sp,
- const lldb_private::SaveCoreOptions &core_options);
+ lldb_private::SaveCoreOptions &core_options);
 
   // ObjectContainer
   static bool RegisterPlugin(

diff  --git a/lldb/include/lldb/lldb-private-interfaces.h 
b/lldb/include/lldb/lldb-private-interfaces.h
index 87c5ff8d22fb6..b3c8cda899b95 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -57,7 +57,7 @@ typedef ObjectFile *(*ObjectFileCreateMemoryInstance)(
 const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
 const lldb::ProcessSP &process_sp, lldb::addr_t offset);
 typedef bool (*ObjectFileSaveCore)(const lldb::ProcessSP &process_sp,
-   const lldb_private::SaveCoreOptions 
&options,
+   lldb_private::SaveCoreOptions &options,
Status &error);
 typedef EmulateInstruction *(*EmulateInstructionCreateInstance)(
 const ArchSpec &arch, InstructionType inst_type);

diff  --git a/lldb/source/Core/PluginManager.cpp 
b/lldb/source/Core/PluginManager.cpp
index fbd78a7780578..f243807df509e 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -702,7 +702,7 @@ 
PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
 }
 
 Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
-   const lldb_private::SaveCoreOptions &options) {
+   lldb_private::SaveCoreOptions &options) {
   Status error;
   if (!options.GetOutputFile()) {
 error.SetErrorString("No output file specified");

diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4322bd7e2674f..22ece4f4dacf7 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6351,7 +6351,7 @@ static offset_t
 CreateAllImageInfosPayload(const lldb::ProcessSP &process_sp,
offset_t initial_file_offset,
StreamString &all_image_infos_payload,
-   const lldb_private::SaveCoreOptions &options) {
+   lldb_private::SaveCoreOptions &options) {
   Target &target = process_sp->GetTarget();
   ModuleList modules = target.GetImages();
 
@@ -6522,16 +6522,17 @@ struct page_object {
 };
 
 bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_s

[Lldb-commits] [lldb] [LLDB][SBSaveCore] Fix bug where default values are not propagated. (PR #101770)

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

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


[Lldb-commits] [lldb] [lldb] Change lldb's breakpoint handling behavior (PR #96260)

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

jasonmolenda wrote:

I had to work on some other things the past couple of weeks but got back to 
this for a bit this afternoon.   Wanted to add a quick update of where things 
are.

There were five debuginfo dexter tests that failed on ubuntu and dwarf5.  I can 
reproduce these (or at least four of them), it took me a little while to figure 
out how to run these tests and get more detailed output of what dexter was 
outputting.  I don't have a fix yet, but it does look like the change in how 
breakpoints are seen as hit is the cause.  These tests are written to work with 
multiple debuggers so it may require a little care to fix, I'll start on 
debugging them soon.

I thought about the arm-ubuntu failures.  I remember that armv7 doesn't have an 
instruction step feature, it uses a hardware breakpoint in the form of "stop 
when $pc is not equal to current-instruction-address".  These failures make a 
lot of sense when I think of that, and I don't know how I'll fix this yet.  
When we see a thread stopped at a BreakpointSite, we have three possibilities:

1.  The thread stopped here with no stop reason, it just happens to be sitting 
at a BreakpointSite and has not triggered it yet.  (another thread stopped for 
a Reason, and this thread just happens to be here)

2. The thread hit the breakpoint, the stop reason from the gdb stub will be 
"breakpoint-hit". thread.GetTemporaryResumeState() == eStateStepping means we 
were already at the BreakpointSite before, and the user did an instruction 
step, triggered the breakpoint and the pc has not advanced.  
thread.GetTemporaryResumeState() != eStateStepping means that we were running 
freely and hit the breakpoint.

3. We are at a BreakpointSite with an instruction-step reason, and 
thread.GetTemporaryResumeState() == eStateStepping which means the thread had 
been instruction stepping.  We have not hit the breakpoint yet.

You can already see the problem when we cannot distinguish between "process has 
halted because it finished instruction step" and "process has halted because it 
hit a breakpoint".  In this environment, we have

1.  The thread stopped here with no stop reason, it just happens to be sitting 
at a BreakpointSite and has not triggered it yet.  (another thread stopped for 
a Reason, and this thread just happens to be here)

2. We are at a BreakpointSite, and we have a "breakpoint hit" stop reason.  If 
thread.GetTemporaryResumeState() == eStateStepping, we EITHER have just 
finished an instruction step from the previous instruction and are now sitting 
at a BreakpointSite, OR we were previous at this same PC, instruction stepped 
and hit the breakpoint, pc has not advanced.  Both are reported as "breakpoint 
hit" on armv7, because of how instruction step is accomplished.  I don't see 
how we can distinguish between these two states, and this presents a big 
problem for my whole change of only making the stop reason "breakpoint-hit" 
when we've actually executed the breakpoint. 

I don't know what I'm going to do here, and besides armv7 this same problem 
will occur for a target that has no instruction-step primitive.  Another common 
trick is to have enough instruction emulation that you can tell what 
instruction will execute next by decoding the current instruction, and putting 
a breakpoint there.  That has the same effect as armv7's 
instruction-step-by-breakpoints -- the reported stop reason from the stub will 
be "breakpoint hit".

I haven't looked at the x86_64 windows/mingw failure reported by Martin yet.

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


[Lldb-commits] [lldb] [lldb] Change lldb's breakpoint handling behavior (PR #96260)

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

jasonmolenda wrote:

tbh my first reaction to this "no instruction stepping feature in hardware" is 
-- in addition to tracking the Thread::GetTemporaryResumeState(), if I tracked 
the pc that the thread was at when it resumed, I could tell if it has advanced 
(so someone has instruction stepped TO a BreakpointSite) or if we hit the 
BreakpointSite at $pc and $pc was wound back.  need to bounce this off of Jim 
next week.

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